Matt Raible wrote:
// log user in automatically
Authentication auth = new UsernamePasswordAuthenticationToken
(user.getUsername(), user.getConfirmPassword());
auth.sentAuthenticated(true);
try {
ProviderManager authenticationManager = (ProviderManager)
getBean("authenticationManager");
SecurityContext ctx = SecurityContextHolder.getContext();
ctx.setAuthentication
(authenticationManager.doAuthentication(auth));
} catch (NoSuchBeanDefinitionException n) {
// ignore, should only happen when testing
}
You can continue to use the constructor shown above, but don't call
setAuthenticated(true). This will be performed by the
UsernamePasswordAuthenticationToken when the AuthenticationProvider
creates a new Authentication object to return. You don't want to be
setting it earlier, as the GrantedAuthority[]s haven't been populated.
Whilst not Acegi Security related, you might like to consider dependency
injecting that "authenticationManager" rather than performing a lookup.
Maybe try:
Authentication auth = new UsernamePasswordAuthenticationToken
(user.getUsername(), user.getConfirmPassword());
Authentication response = authenticationManager.authenticate(auth);
SecurityContextHolder.getContext().setAuthentication(response);
If this still doesn't work, try following the debug logs. It might be
something to do with filters changing the SecurityContextHolder,
particularly if you're going from an anonymous user. Did you see the
"Logic bug with AnonymousProcessingFilter" thread yesterday?
Cheers
Ben
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Home: http://acegisecurity.sourceforge.net
Acegisecurity-developer mailing list
Acegisecurity-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/acegisecurity-developer