繁体   English   中英

Grails,从 Acegi 升级到 Spring 安全插件

[英]Grails, upgrading from Acegi to Spring security plugin

昨天我开始将我们的 Grails 应用程序从 Acegi 插件 0.5.2 升级到 Spring 安全插件。 我遇到了一些问题,也许有人可以在这里提供帮助?

进行必要的更改后(如 Burt Beckwith 在Migrating from the Acegi Plugin 中所述),我能够再次启动 Grails 应用程序(哇哦。),但是。 登录不再起作用。

我们的情况如下:我们使用我们的 Grails 应用程序纯作为其应用程序逻辑。 身份验证是通过网络服务使用用户名和密码完成的。 作为后端,我们使用应用程序 (dao) 的数据库和 LDAP 后端。 目前,我们已禁用 LDAP,以简化测试。

这是进行身份验证的代码:

def authenticate(String username, String password) {
try {
      println "Trying authentication with user " + username + " and password " + password + "."
      def tempToken = new UsernamePasswordAuthenticationToken(username, password)
      println "Temptoken is " + tempToken
      def token = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password))
      println "Authentication token received was: " + token
    } catch (AuthenticationException authenticationException) {
        return false
    }
    return true     
}

这将打印到日志:

Trying authentication with user admin and password admin.
Temptoken is org.springframework.security.providers.UsernamePasswordAuthenticationToken@1f: Principal: admin; Password: [PROTECTED]; Authenticated: false; Details: null; Not granted any authorities

然后一切都停止了。

我们使用的领域类相当简单。 我们不使用 class 之类的用户角色来连接人员及其权限。 相反,我们使用多对多映射,因为这对我们一直有效并且易于维护。

我们的权限域class:

class Authority {
static hasMany = [people: Person]

/** description */
String description
/** ROLE String */
String authority = ''

String authorityType

static constraints = {
    authority(help:'x',class:'wide',blank: false,unique:true)
    description(help:'x',class:'extrawide')
    authorityType(help:'x',class:'wide')
    people(help:'x',selectSort:'username',display:false)
}   

String toString() {
      return authority;
}   
}

而我们的 Person 域 class:

class Person  {

static hasMany = [authorities: Authority]
static belongsTo = Authority

//Authority primaryGroup

/** Username */
String username
/** User Real Name*/
String userRealName
String familyName
String givenName

/** MD5 Password */
String passwd
/** enabled */
boolean enabled

String email
boolean emailShow

/** description */
String description = ''



static constraints = {
    username(blank: false, unique: true,help:'x',class:'wide')
    userRealName(blank: false,help:'x',class:'wide')
    familyName(blank: false,help:'x',class:'wide')
    givenName(blank: false,help:'x',class:'wide')
    email(help:'x',class:'wide')
    emailShow(help:'x')
    enabled(help:'x')
    passwd(blank: false,password:true,show:false,help:'x',class:'wide')
    authorities(nullable:true,help:'x',sortable:true,selectSort:'authority')        
}

String toString() {
      return username;
  }
}

在 Config.Groovy 中,我们定义了:

security {
active = false
cacheUsers = false

grails.plugins.springsecurity.providerNames = ['daoAuthenticationProvider', 'anonymousAuthenticationProvider', 'rememberMeAuthenticationProvider']

grails.plugins.springsecurity.userLookUp.userDomainClassName = "Person"
grails.plugins.springsecurity.authority.className = "Authority"

就文档而言,这应该无论如何都可以工作(对于“旧” Acegi 设置也是如此)。

为了收集更多信息,我短暂激活了 LDAP 并发现了同样的问题。 WireShark 告诉我,在登录过程中没有进行 LDAP 调用。 我的猜测是,Authenticate function 中的代码有问题,或者 SpringSecurity 不知道如何获取我们的域类。

我很乐意阅读任何见解!

似乎令牌无效,因此 authenticate() 调用失败并生成异常(IIRC 只有在调用成功时才返回一个值)。

我的第一次尝试是检查数据库是否有一行用于用户:'admin',密码:'admin' 的环境。

经过一番思考,我会仔细检查 Person class 中的密码属性。 通过在域 class 中的映射,或者更好地通过

userLookup.passwordPropertyName = "passwd"

更新:第三件事要检查。

active = false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM