tomcat - Spring Security Tomcat 6.x 与 Tomcat 7.x 访问此资源需要完全身份验证

标签 tomcat spring-security

目前我正在使用 Spring 安全登录的应用程序中工作。

Spring Security 3.2.7.RELEASE 与 Tomcat 6.0.43

我正在尝试将应用程序升级到 Tomcat 7.0.62。

下面是我的配置的一部分。我注意到在 Tomcat 6.0.43 中,SecurityContextHolderAwareRequestFilter 包含身份验证:SecurityContextHolder.getContext().getAuthentication()。但是在 Tomcat 7.0.62 中运行时却没有。

我无法弄清楚为什么会发生这种情况,因为缺少身份验证,它不断碰到完整身份验证,才能在 exceptionTranslationFilter 中访问此资源。

也许有人有提示或方向可以研究?

<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
    <security:filter-chain-map path-type="ant">
        <security:filter-chain pattern="/error/*"
            filters="none" />
        <security:filter-chain pattern="/back*"
            filters="none" />
        <security:filter-chain pattern="/j_spring_security_check*"
            filters="httpSessionContextIntegrationFilter,authenticationProcessingFilter" />
        <security:filter-chain pattern="/**"
            filters="logoutFilter, httpSessionContextIntegrationFilter,securityContextHolderAwareRequestFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor" />
    </security:filter-chain-map>
</bean>

<bean id="httpSessionContextIntegrationFilter"
    class="org.springframework.security.web.context.SecurityContextPersistenceFilter" />

<bean id="securityContextHolderAwareRequestFilter"
    class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter" />

<bean id="anonymousProcessingFilter"
    class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter">
    <property name="key" value="changeThis" />
    <property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS" />
</bean>

<bean id="exceptionTranslationFilter" class="org.springframework.security.web.access.ExceptionTranslationFilter">
    <property name="authenticationEntryPoint">
        <bean
            class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
            <property name="loginFormUrl" value="/login.jsp" />
            <property name="forceHttps" value="false" />
        </bean>
    </property>
    <property name="accessDeniedHandler">
        <bean
            class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
            <property name="errorPage" value="/accessDenied.jsp" />
        </bean>
    </property>
</bean>

最佳答案

在剥离我的应用程序后,我发现 web.xml 中的 cookie-config 是它不起作用的原因:

   <session-config>
        <session-timeout>600</session-timeout>
        <cookie-config>
            <http-only>true</http-only>
            <secure>true</secure>
        </cookie-config>
    </session-config>

删除 cookie-config 解决了我的问题,因为显然你可以在 tomcat 的 server.xml/context.xml 中安排它。

关于tomcat - Spring Security Tomcat 6.x 与 Tomcat 7.x 访问此资源需要完全身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31225185/

相关文章:

java - 警告 : org. springframework.web.servlet.PageNotFound - 不支持请求方法 'GET'

spring - 如何使用远程 token 服务?

java - 将表单提交到 servlet 中的 .java 页面的问题

Tomcat 过滤器映射无法通过 ProxyPass 工作

Broken pipe 错误后 Tomcat servlet 映射错误

java - 在 Tomcat 7 中扩展 AuthenticatorBase

java - Redis 与两个不同的 Web 应用程序共享 session

java - 有没有办法将扩展 WebMvcConfigurerAdapter 和 WebSecurityConfigurerAdapter 的 @Configurations 合并到一个 @Configuration 中?

java - Spring 安全: can't clear authentication object

mysql - 如何在 Apache Tomcat 7 中设置 JDBCRealm?