I am using Grails 2.1.1 with Spring Security 1.2.7.1 and Spring Security UI 0.2.
When I create some test users in BootStrap.groovy using an in memory database I am able to log in and manage users–everything works fine. However, when I switch my data source to a MySQL database, the service states that the user account is disabled when I try to log in. I have checked and the password appears to be hashing correctly (i.e., it matches what’s in the database). The only modification I made to a user is to include a Study ID. In attempting to debug the code I’ve found that org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser indicates enabled=false.
Any help is greatly appreciated!
My DataSource:
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 code:
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
A row from my User.user table after starting the application. No matter how I change these values, login attempts state that the user is disabled:
id version account_expired account_locked enabled password password_expired studyid username
1 0 1 1 1 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a... 1 0 me
If making changes directly into the DB also gives the error and it works with the ‘in memory DB’, I think that MySQL might be the problem.
It can be that MySQL is storing the values using a type that Hibernate cannot use correctly as a
booleanYou can test that by retrieving a user from the DB and manually check:
The last 3 posts on this mail list give a solution to correctly map a
booleanin MySQL:You can use a custom dialect to change BIT(1) to boolean:
And use it specify the class in DataSource.groovy: