我开始使用grails的spring-security-core-1.1.3插件。
我的身份验证应用程序将请求发送到服务器:

def authSomeAction = { 
    def req = ...//http requet here 
    if(req.contains("yes")){ 
       render "There is such user" 
    }else{ 
       render "There is no such user" 
    } 
} 

我只有在客户端创建用户后,才能使用SpringSecurityUtils.reauthenticate(username,password)方法成功进行身份验证

任何人都可以详细请我帮助我了解如何实施
插件在客户端工作(没有数据库)...?

请您参考如下方法:

我对Grails还是很陌生,所以我可能显然不合时宜,但是我怀疑您的问题可能与创建用户时对密码进行编码的方式有关。使用“客户端”创建用户时,您使用的方法与使用其他方法时是否一样?

例如,当我第一次开始使用spring-security-ui插件时,我使用 bundle 的实用程序创建了用户,但他们都无法登录。如果我正确理解,则从spring-security以来便更新了spring-security-core。 -ui,这将对 Controller 中的密码进行编码的需求转移到用户本身内。例如,在该插件随附的spring-security-ui UserController.save()中,会发生以下情况:

if (params.password) { 
    String salt = saltSource instanceof NullSaltSource ? null : params.username 
    user.password = springSecurityService.encodePassword(params.password, salt) 
} 

但是我的User类然后有这个(直接来自s2插件示例)
def beforeInsert() { 
    encodePassword() 
} 
 
def beforeUpdate() { 
    if (isDirty('password')) { 
        encodePassword() 
    } 
} 
 
protected void encodePassword() { 
    password = springSecurityService.encodePassword(password) 
} 

由于我的User类自行管理编码,因此出现了双重编码,这导致使用它创建的登录失败。您的应用程序中可能会发生类似的事情吗?在创建非客户端用户时,是否以相同的方式编码?


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!