目前我正在使用Spring Security编写Web应用程序.我们有一个Web服务,通过用户名和密码验证用户.
网络服务:
String [] login(String username,String password);
如何配置Spring Security以将提供的用户名和密码传递给Web服务?
我编写了一个只接收用户名的UserDetailsService.
我认为问题在于你的xml.你关掉了自动配置吗?你的类是否扩展了AbstractUserDetailsAuthenticationProvider?
解决方法
扩展org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider
/** * @author rodrigoap * */ public class WebServiceUserDetailsAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { @Override protected UserDetails retrieveUser(String username,UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { //Improve this line: String password = authentication.getCredentials().toString(); // Invoke your webservice here GrantedAuthority[] grantedAuth = loginWebService.login(username,password); // create UserDetails. Warning: User is deprecated! UserDetails userDetails = new User(username,password,grantedAuth); return userDetails; } }