I’ve installed Spring Security plugin to my Grails application, saw login which works fine, but when I wanted to create Registration for users and authenticate the user after the registration, manually in the code, I couldn’t.
Is there any solution to that? How can it be that Spring Security does not allow simple using pushing of authenticated users to the session or Spring Security Context.
Here is what I tried:
UsernamePasswordAuthenticationToken uat = new UsernamePasswordAuthenticationToken(user.email, user.password, null);
uat.setDetails(user);
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(uat);
This authenticates the user, but I couldn’t get him with the next code:
springSecurityService.currentUser
Only with this:
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
I am confused now, what is the right way to use Spring Security.
I started to build now my own UserDetailsService, but I confused and don’t know what are the next steps if I want to create my own Authentication method?
You can force authentication with:
see http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html#6.2%20SpringSecurityService