对于某些Web服务,我想禁用会话.我在配置中添加了create-session ="never":
<beans:bean id="http403EntryPoint"
class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"/>
<http use-expressions="true" entry-point-ref="http403EntryPoint"
create-session="never">
<custom-filter ref="x509Filter" position="PRE_AUTH_FILTER"/>
</http>
Run Code Online (Sandbox Code Playgroud)
这适用于大多数情况,除非预先验证的用户具有未在应用程序中注册的客户端证书,因此我们的AuthenticationUserDetailsService会抛出UsernameNotFoundException.如果用户没有证书或具有已注册的证书,则不会创建任何会话(HTTP响应中没有Set-Cookie标头).在所描述的情况下,发送cookie.即使客户端证书已更改(基本上允许会话固定攻击 - 应用程序使用已保存的身份验证而不是在每次调用时重新进行身份验证),也会对每个后续请求评估它(cookie或会话).
我们使用Spring security 3.0.5.使用Tomcat 6和7以及JBoss 7.1.1进行测试.
为什么在描述的场景中创建会话?
PS:通过在AbstractPreAuthenticatedProcessingFilter中设置checkForPrincipalChanges可能会解决会话固定问题,但我对为何创建会话的答案感兴趣.
罪魁祸首是https://jira.spring.io/browse/SEC-1476:
如果发生未经授权的访问,AbstractPreAuthenticatedProcessingFilter类中的以下方法将创建一个会话并将异常存储在其中:
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) {
SecurityContextHolder.clearContext();
if (logger.isDebugEnabled()) {
logger.debug("Cleared security context due to exception", failed);
}
request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, failed);
}
Run Code Online (Sandbox Code Playgroud)
在修复中,他们更改了最后一行,删除了 getSession() 调用,以便将 AuthenticationException 存储在请求中。
为了修复我们的项目,我创建了一个扩展X509AuthenticationFilter的新类,并在那里用相同的内容覆盖了方法unsuccessfulAuthentication ,只是我还删除了getSession()调用。
| 归档时间: |
|
| 查看次数: |
489 次 |
| 最近记录: |