OK, I got this working. I was a little confused about how to access beans declared in my securityContext.xml, but I found out and here goes:
Code:
SecurityContext context = SecurityContextHolder.getContext();
try{
GrantedAuthority[] grantedAuthorities = new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_user")};
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(username, password, grantedAuthorities);
authentication.setDetails(request.getRemoteAddr());
ProviderManager pm = (ProviderManager)WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("authenticationManager");
pm.doAuthentication(authentication);
context.setAuthentication(authentication);
}catch(AuthenticationException e){
context.setAuthentication(null);
log.error("Login failed after registration. This should never happen: ", e);
}catch(BeansException e){
log.error("Could not get bean from web application context: ", e);
}
The important part is how you access the ProviderManager from outside the filter chain (ie, inside a struts action). This line resolves an Object from the context using the bean name and you just cast it to whatever type it should be.
Code:
ProviderManager pm = (ProviderManager)WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("authenticationManager");
Remember, I am not checking credentials or anything here, so it is only performed after a successful registration using the same username and password that was used to register.