Java 如何在Spring security 3.2.3中拒绝无会话URL访问

Java 如何在Spring security 3.2.3中拒绝无会话URL访问,java,spring,spring-security,Java,Spring,Spring Security,我已将spring security从2.5迁移到3.2.3。如果我访问了一个URL,在没有/无效会话的情况下应该重定向到登录页面。目前,当我在tomcat上部署应用程序并在不登录的情况下访问任何URL时,它第一次工作并重定向到登录页面。第一次之后,如果我再次访问同一个URL而不按顺序登录,则会导致URL和应用程序崩溃。下面是我的自定义过滤器配置: <sec:http auto-config="true" pattern="/**" path-type="ant" authenticati

我已将spring security从2.5迁移到3.2.3。如果我访问了一个URL,在没有/无效会话的情况下应该重定向到登录页面。目前,当我在tomcat上部署应用程序并在不登录的情况下访问任何URL时,它第一次工作并重定向到登录页面。第一次之后,如果我再次访问同一个URL而不按顺序登录,则会导致URL和应用程序崩溃。下面是我的自定义过滤器配置:

<sec:http auto-config="true" pattern="/**" path-type="ant" authentication-manager-ref="authenticationManagerAlias">
    <sec:form-login always-use-default-target="true" default-target-url="/interceptor.do" authentication-failure-url="/login.do?code=auth" />
    <sec:access-denied-handler ref="accessDeniedHandler"/>
    <sec:session-management invalid-session-url="/login.do"> </sec:session-management>
    <sec:logout invalidate-session="true" logout-success-url="/login.do"/>

    <sec:custom-filter after="SECURITY_CONTEXT_FILTER" ref="securityContextFilter"/>
    <sec:custom-filter after="LOGOUT_FILTER" ref="customLogoutFilter"/>
    <sec:custom-filter after="PRE_AUTH_FILTER" ref="preAuthFilter"/>
    <sec:custom-filter after="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter"/>
    <sec:custom-filter after="EXCEPTION_TRANSLATION_FILTER" ref="exceptionTranslationFilter"/>
    <sec:custom-filter after="FILTER_SECURITY_INTERCEPTOR" ref="filterSecurityInterceptor"/>
</sec:http>

<sec:http auto-config="true" pattern="/**" path-type="ant" authentication-manager-ref="authenticationManagerAlias">
    <sec:form-login always-use-default-target="true" default-target-url="/interceptor.do" authentication-failure-url="/login.do?code=auth" />
    <sec:access-denied-handler ref="accessDeniedHandler"/>
    <sec:session-management invalid-session-url="/login.do"> </sec:session-management>
    <sec:logout invalidate-session="true" logout-success-url="/login.do"/>

    <sec:custom-filter after="SECURITY_CONTEXT_FILTER" ref="securityContextFilter"/>
    <sec:custom-filter after="LOGOUT_FILTER" ref="customLogoutFilter"/>
    <sec:custom-filter after="PRE_AUTH_FILTER" ref="preAuthFilter"/>
    <sec:custom-filter after="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter"/>
    <sec:custom-filter after="EXCEPTION_TRANSLATION_FILTER" ref="exceptionTranslationFilter"/>
    <sec:custom-filter after="FILTER_SECURITY_INTERCEPTOR" ref="filterSecurityInterceptor"/>
</sec:http>


请帮助我解决此问题。

第一次获得有效会话后,您可能可以访问此页面。你说撞车到底是什么意思?它最终是由于另一个问题而发生的。可能是此页面上的控制器需要来自已登录会话的数据,但无法获取,因为存在用户会话,但他未登录。是的,确切地说,它因其他原因崩溃。我如何避免创建这样的用户会话?您不应该只检查会话是否有效。您应该像下面这样检查用户角色:显然,只有在用户成功登录后,您将此角色分配给用户,这才有效。
<sec:http auto-config="true" pattern="/**" path-type="ant" authentication-manager-ref="authenticationManagerAlias">
    <sec:form-login always-use-default-target="true" default-target-url="/interceptor.do" authentication-failure-url="/login.do?code=auth" />
    <sec:access-denied-handler ref="accessDeniedHandler"/>
    <sec:session-management invalid-session-url="/login.do"> </sec:session-management>
    <sec:logout invalidate-session="true" logout-success-url="/login.do"/>

    <sec:custom-filter after="SECURITY_CONTEXT_FILTER" ref="securityContextFilter"/>
    <sec:custom-filter after="LOGOUT_FILTER" ref="customLogoutFilter"/>
    <sec:custom-filter after="PRE_AUTH_FILTER" ref="preAuthFilter"/>
    <sec:custom-filter after="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter"/>
    <sec:custom-filter after="EXCEPTION_TRANSLATION_FILTER" ref="exceptionTranslationFilter"/>
    <sec:custom-filter after="FILTER_SECURITY_INTERCEPTOR" ref="filterSecurityInterceptor"/>
</sec:http>