使用需要用户名和密码的WebService对SpringSecurity用户进行身份验证

目前我正在使用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;
  }

}

相关文章

1.使用ajax调用varxhr;functioninvoke(){if(window.ActiveXO...
               好不容易把WebService服务器...
1新建一个工程项目用来做服务端增加一个MyService1类文件pac...
packagecom.transsion.util;importjava.io.BufferedReader;i...
再生产wsdl文件时重写描述文件1usingSystem;2usingSystem.Co...
一般情况下,使用eclipse自带的jax-ws生成webservice会自动生...