Grails Spring-Security-Core plugin - Unable to authenticate user

So, I am banging my head against the wall, trying to get spring-security-core-1.2.7.1 to work with Grails 2.0 ...

I looked through the tutorial and ran s2. Read that the new plugin encrypts passwords for you, so my bootstrap looks like this:

def userRole = Role.findByAuthority('ROLE_USER') ?: new Role(authority: 'ROLE_USER').save(failOnError: true) def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true) def adminUser = User.findByUsername('admin') ?: new User( username: 'admin', password: "admin", enabled: true).save(failOnError: true) def testUser = User.findByUsername('test') ?: new User( username: 'test', password: "test", enabled: true).save(failOnError: true) if (!adminUser.authorities.contains(adminRole)) { UserRole.create adminUser, adminRole } if (!testUser.authorities.contains(userRole)) { UserRole.create testUser, userRole } 

I can look at the H2 database, and I see the users, their encoded passwords, I see that the roles are created and can see that the user role mappings are also created correctly.

However, I still get "Sorry, we could not find the user with this username and password." in the login invitation for both users.

I have included log4j debug 'org.springframework.security', but all I really get out of the logs is:

 2012-01-23 23:08:44,875 ["http-bio-8080"-exec-5] DEBUG dao.DaoAuthenticationProvider - Authentication failed: password does not match stored value 
+4
source share
4 answers

I do not see anything wrong with your code. I use the same version of Grails and the spring security plugin, and the following code works for me in Bootstrap.groovy :

 def init = { servletContext -> // create some roles def userRole = createRole('ROLE_USER') def adminRole = createRole('ROLE_ADMIN') // create some users User admin = createUser('Admin', ' admin@mailinator.com ', adminRole) User user = createUser('User', ' user@yahoo.co.uk ', userRole) } private User createUser(name, username, role) { def defaultPassword = 'password' User user = User.findByUsername(username) ?: new User( name: name, username: username, password: defaultPassword, passwordConfirm: defaultPassword, enabled: true).save() if (!user.authorities.contains(role)) { UserRole.create user, role } user } private createRole(String roleName) { Role.findByAuthority(roleName) ?: new Role(authority: roleName).save() } 
+2
source

You can fix the problem with multiple data sources by updating the User class. See fooobar.com/questions/1392675 / ...

0
source

I had a similar problem. Because I forgot to add

 grails.plugin.springsecurity.userLookup.userDomainClassName ='yourpackage.User' grails.plugin.springsecurity.userLookup.authorityJoinClassName =yourpackage.UserRole' grails.plugin.springsecurity.authority.className ='yourpackage.Role' 

After that, authentication was performed.

0
source

In the OP source code, why is the user name in single quotes and the password in double quotes. This can be a problem.

-3
source

Source: https://habr.com/ru/post/1392662/


All Articles