2

Spring Security 1.2.7.1 および Spring Security UI 0.2 で Grails 2.1.1 を使用しています。

メモリ内データベースを使用して 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" 
    }

私の 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

アプリケーションを起動した後の User.user テーブルの行。これらの値をどのように変更しても、ログインしようとすると、ユーザーが無効になっていることが示されます。

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

1 に答える 1

2

DB に直接変更を加えてもエラーが発生し、「インメモリ DB」で動作する場合、MySQL に問題がある可能性があると思います。

MySQL が、Hibernate が正しく使用できない型を使用して値を格納している可能性があります。boolean

DB からユーザーを取得し、手動で確認することでテストできます。

if( ! user.enabled ) println "not enabled"  // or something like that

このメーリング リストの最後の 3 つの投稿はboolean、MySQL でa を正しくマップするための解決策を提供します。

カスタムの方言を使用して、BIT(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 
   } 
于 2012-10-21T21:25:21.977 に答える