![](/img/trans.png)
[英]Disable Spring Security Basic Login - Spring REST web service
[英]spring security login with rest web service
我公司有一个特定的身份验证提供程序,它是一个内部REST Web服务。 实际上,您向Web服务提供了登录名/密码,并且它返回令牌(有效期为几个小时),该令牌必须在标头中提供给Web服务的每个下一个业务请求。
我需要创建一个Web应用程序,并将其插入此身份验证提供程序。 将其与Spring Security集成的最佳方法是什么?
如何在不要求用户重新登录的情况下管理Web应用程序中的令牌到期?
如果您想使用带有身份验证的Spring Security委托给Web服务,则需要实现springs安全框架提供的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都是从外部进行管理的,我们只能基于外部会话存储来验证和授权每个请求。
因此,我们将改用自定义SecurityContextRepository。
EDIT2:
编写一个SecurityContextRepository来检查公共令牌存储中的每个请求是微不足道的,将其连接到Spring Security中是很疯狂的:security-context.xml中的http元素不允许自定义securityContextPersistenceFilter,因此我不得不用普通bean来模拟它。 一点都不有趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.