I've been attempting to log in a user automatically after a successful signup using grails with the spring-security-core plugin. While the forced login works, and all the authorities etc. are loaded, the @Secured annotations in other controllers won't recognise the granted authorities and consequently the browser gets stuck in a redirect loop between the secured and login pages.
My login action:
def forceLogin = {
PSysuser sysuser = flash.sysuser;
String username = flash.username ?: params.username;
String password = flash.password ?: params.password;
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
sysuser?.username ?: username,
sysuser?.password ?: password
);
request.session;
token.details = new WebAuthenticationDetails(request);
Authentication authenticatedUser = authenticationManager.authenticate(token);
SecurityContextHolder.context.authentication = authenticatedUser;
springSecurityService.reauthenticate(username, password); //doesn't appear to work, but doesn't hurt either.
redirect action:auth;
}
Does anyone know how I can get the annotations to work properly?