Spring安全登录与restWeb服务

我的公司有一个特定的身份validation提供程序,它是一个内部REST Web服务。 实际上,您为Web服务提供了一个登录名/密码,它返回一个令牌(有效期为几个小时),必须在每个下一个Web服务请求的标题中给出。

我需要创建一个Web应用程序,我需要将其插入此身份validation提供程序。 将它与Spring Security集成的最佳方法是什么?

如何在不要求用户重新登录的情况下管理我的webapp中的令牌过期?

如果要将Spring安全性与身份validation委托给Web服务一起使用,则需要实现spring安全框架提供的AuthenticationProvider接口。 你可以做这样的事情

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

我刚刚遇到了与原始问题非常相似的情况,这就是我将要工作的内容: http : //static.springsource.org/spring-security/site/docs/3.0.x/reference/preauth。 HTML

编辑:

在我们的情况下,会话和绑定到它的cookie都是外部管理的,我们只能基于外部会话存储validation和授权每个请求。

所以我们将使用自定义的SecurityContextRepository。

EDIT2:

编写一个SecurityContextRepository来检查每个请求对公共令牌存储是微不足道的,将它连接到Spring Security是疯了:security-context.xml中的http元素不允许自定义securityContextPersistenceFilter,所以我不得不用普通bean模拟它。 一点也不好玩。