Adding user to session, spring security default login
You do make it complicated... :)
What you want is to add a custom authentication provider to spring's normal authentication manager. So you would configure the authentication manager like this:
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="authServiceImpl">
<security:password-encoder ref="passwordEncoder"/>
</security:authentication-provider>
</security:authentication-manager>
<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>
Now you only need to define the authServiceImpl bean inside your spring context. You can either do this through xml or annotations (my prefered way).
@Service
public class AuthServiceImpl implements AuthService {
You need to implement the AuthService interface. Just implement to methods from the interface - should be pretty straight forward. You don't need to put things into the SecurityContextHolder yourself - spring will do that.
What you want is this:
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
return MyUser user = myUserService.getMyUser(username);
}
Feel free to ask if you have any further questions.
EDIT: Or you could just have your UserService class implement the interface - I just did it like this because you didn't provide your UserService class.