使用需要用户名和密码的WebService对SpringSecurity用户进行身份
发布时间:2020-12-16 21:39:34 所属栏目:安全 来源:网络整理
导读:目前我正在使用Spring Security编写Web应用程序.我们有一个Web服务,通??过用户名和密码验证用户. 网络服务: String [] login(String username,String password); 如何配置Spring Security以将提供的用户名和密码传递给Web服务? 我编写了一个只接收用户名的
目前我正在使用Spring Security编写Web应用程序.我们有一个Web服务,通??过用户名和密码验证用户.
网络服务: String [] login(String username,String password); 如何配置Spring Security以将提供的用户名和密码传递给Web服务? 我编写了一个只接收用户名的UserDetailsS??ervice. 我认为问题在于你的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; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |