|
here is the problem, because of i used followed code to get my authenticationManager.
<s:authentication-manager alias="authenticationManager">
<s:authentication-provider user-service-ref="userDetailsServiceImpl">
<s:password-encoder hash="md5" />
</s:authentication-provider>
</s:authentication-manager>
and in my datebase i only stored the encoded password.so i don't know how to authenticate the user with authenticationManager.
even if i don't how to get my authenticationManager.
after check the spring security api. i know that i don't need use authenticationManager to authenticate the user.
so here is the code.
Authentication authentication = new UsernamePasswordAuthenticationToken(userInfo.getUserName().trim(),
userInfo.getPassword().trim());
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService((UserDetailsService) SpringUtil.getBean("userDetailsServiceImpl"));
authentication = daoAuthenticationProvider.authenticate(authentication);
SecurityContext securityContext = SecurityContextHolder.getContext();
securityContext.setAuthentication(authentication); |
|