Grails Spring安全UI MySQL所有用户已禁用?

Grails Spring安全UI MySQL所有用户已禁用?,mysql,grails,spring-security,Mysql,Grails,Spring Security,我将Grails2.1.1与SpringSecurity1.2.7.1和SpringSecurityUI0.2一起使用 当我在BootStrap.groovy中使用内存数据库创建一些测试用户时,我能够登录并管理用户——一切正常。但是,当我将数据源切换到MySQL数据库时,服务会声明在我尝试登录时用户帐户已禁用。我已经检查过了,密码看起来是正确的散列(即,它与数据库中的内容匹配)。我对用户所做的唯一修改是包含一个研究ID。在尝试调试代码时,我发现org.codehaus.groovy.grails

我将Grails2.1.1与SpringSecurity1.2.7.1和SpringSecurityUI0.2一起使用

当我在BootStrap.groovy中使用内存数据库创建一些测试用户时,我能够登录并管理用户——一切正常。但是,当我将数据源切换到MySQL数据库时,服务会声明在我尝试登录时用户帐户已禁用。我已经检查过了,密码看起来是正确的散列(即,它与数据库中的内容匹配)。我对用户所做的唯一修改是包含一个研究ID。在尝试调试代码时,我发现org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser指示enabled=false

非常感谢您的帮助

我的数据源:

    dataSource {
        driverClassName = "com.mysql.jdbc.Driver"
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        url = "jdbc:mysql://localhost/users"
        username = "root"
        password = ""
        dbCreate = "create-drop" 
    }
My BootStrap.groovy代码:

    def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
    def userRole = new Role(authority: 'ROLE_USER').save(flush: true)

    def testAdmin = new User(username: 'me', enabled: true, password: 'password', studyID: '0')
    testAdmin.save(flush: true)
    UserRole.create testAdmin, adminRole, true

    def testUser = new User(username: '100', enabled: true, password: 'test', studyID: '101')
    testUser.save(flush: true)
    UserRole.create testUser, userRole, true

    assert User.count() == 2
    assert Role.count() == 2
    assert UserRole.count() == 2
启动应用程序后my User.User表中的一行。无论我如何更改这些值,登录尝试都会声明用户已禁用:

id  version account_expired account_locked  enabled password    password_expired    studyid username
        1   0   1   1   1   5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a...   1   0   me

如果直接对数据库进行更改也会导致错误,并且它与“内存中的数据库”一起工作,我认为MySQL可能是问题所在

可能是MySQL使用Hibernate无法正确使用的类型来存储值,作为
boolean

您可以通过从数据库检索用户并手动检查来测试:

if( ! user.enabled ) println "not enabled"  // or something like that
上的最后3篇文章给出了在MySQL中正确映射
布尔值的解决方案:

您可以使用自定义方言将位(1)更改为布尔值:

   import org.hibernate.dialect.MySQL5InnoDBDialect 
   import java.sql.Types 

   class MyCustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect { 
      MyCustomMySQL5InnoDBDialect() { 
         registerColumnType(Types.BIT, 'boolean') 
      } 
   }
并使用它指定DataSource.groovy中的类:

   dataSource { 
      pooled = true 
      driverClassName = 'com.mysql.jdbc.Driver' 
      username = ... 
      password = ... 
      dialect = com.foo.bar.MyCustomMySQL5InnoDBDialect 
   } 

它是否真的说该帐户已“禁用”?因为您发布的行表示帐户已过期、已锁定,并且密码也已过期。如果这些值设置为true,则无法登录。是。我收到“对不起,您的帐户已被禁用”。我已尝试为用户手动更改数据库中的account\u expired/account\u locked/password\u expired字段,但没有任何区别。在org.codehaus.groovy.grails.plugins.springsecurity.DefaultPreAuthenticationChecks from public void check(UserDetails user)…中引发错误。。。如果(!user.isEnabled()){log.debug(“用户帐户被禁用”);抛出新的DisabledException(messages.getMessage(“AbstractUserDetailsAuthenticationProvider.disabled”,“用户被禁用”),user;}宾果!谢谢你的帮助。在这里发布解决方案。