我的公司有一个特定的身份验证提供程序,它是一个内部 REST 网络服务。 事实上,您向 Web 服务提供了一个登录名/密码,它会返回一个 token (有效期为几个小时),该 token 必须在每个下一个对 Web 服务的业务请求的 header 中提供。
我需要创建一个 Web 应用程序,并且需要将其插入到此身份验证提供程序中。 将其与 Spring Security 集成的最佳方式是什么?
如何在不要求用户重新登录的情况下管理我的网络应用程序中的 token 过期?
最佳答案
如果要使用 spring security 并将身份验证委托(delegate)给 web 服务,则需要实现 spring security 框架提供的 AuthenticationProvider 接口(interface)。你可以做这样的事情
public class AuthProviderImpl implements AuthenticationProvider
{
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException
{
WebServiceAuthClient client = //get an handle to your web service
//get user name, password from authenticate object
client.autheticat(username, pwd);
}
}
配置您的 Web 应用程序以使用 Spring Security http://static.springsource.org/spring-security/site/petclinic-tutorial.html
关于java - 使用 rest web 服务的 spring security 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828344/