【发布时间】:2017-03-15 14:30:09
【问题描述】:
我想要实现的是一个不安全的页面(例如 /index),但是在经过身份验证后,它应该可以访问身份验证对象以显示已登录的用户。
根据Spring文档,认证对象在不通过安全过滤链时是不可用的:
如果要在请求期间使用 SecurityContext 内容的内容,则它必须通过安全过滤器链。否则 SecurityContextHolder 将不会被填充并且内容将为空。
但是要禁用页面安全,安全过滤器被禁用:
<http pattern="/index" security="none"/>
类似于 filters=”none”,这也将完全禁用该请求路径的安全过滤器链 - 因此当应用程序处理请求时,Spring Security 功能将不可用。
我也不能使用<intercept-url pattern="/index" access="permitAll" />,因为这会授予所有经过身份验证的用户权限。因为AbstractSecurityInterceptor会在没有找到认证对象时抛出AuthenticationCredentialsNotFoundException。
作为 Spring Security 的新手,我如何构建一个可以访问 SecurityContext 的非安全页面? (使用带有 XML 配置的 Spring Security 3.2.9)
【问题讨论】:
标签: java spring spring-security