Java Spring方法级别的安全性在第二次调用时失败

Java Spring方法级别的安全性在第二次调用时失败,java,gwt,spring-security,gwt-rpc,Java,Gwt,Spring Security,Gwt Rpc,我想在我的GWT应用程序上使用方法级安全性。我尝试使用SpringSecurity3.1,因为我发现了一个工作示例,但它不使用表单登录。读取第一个方法调用后,成功获取SecurityContext,但在下一次调用之前将其清除: [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - Obtained a valid SecurityContext from SPRING_SECURITY_

我想在我的GWT应用程序上使用方法级安全性。我尝试使用SpringSecurity3.1,因为我发现了一个工作示例,但它不使用表单登录。读取第一个方法调用后,成功获取SecurityContext,但在下一次调用之前将其清除:

[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@6fe9f089: Authentication: org.example.MyAppName.server.auth.MyAppNameUserAuthentication@6fe9f089'
...
[org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor] - Authorization successful
...
[org.springframework.security.web.context.SecurityContextPersistenceFilter] - SecurityContextHolder now cleared, as request processing completed
...
[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
[org.springframework.security.web.context.SecurityContextPersistenceFilter] - SecurityContextHolder now cleared, as request processing completed
...
[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - HttpSession returned null object for SPRING_SECURITY_CONTEXT
第二次调用直接发生在第一次调用之后,也就是用户登录之后

是不是因为我按照另一个答案删除了
并添加了

我的过滤器如下所示:

<http pattern="/favicon.ico" security="none" />

<http access-decision-manager-ref="accessDecisionManager" use-expressions="true" auto-config="false" entry-point-ref="LoginUrlAuthenticationEntryPoint">
  <form-login login-page="/Login.html" always-use-default-target="true" default-target-url="/Main.html?gwt.codesvr=127.0.0.1:9997" />
  <intercept-url pattern="/Login.html" access="permitAll()" />
  <intercept-url pattern="/Login2.html" access="permitAll()" />
  <intercept-url pattern="/MyAppName/**" access="permitAll()" />
  <intercept-url pattern="/**" access="isAuthenticated()" />
  <logout delete-cookies="JSESSIONID" logout-success-url="/Login.html" />
  <remember-me token-validity-seconds="86400" key="key" user-service-ref="userDetailsService" />
</http>

按照我获得的示例,我将AspectJ用于全局方法安全性,但如果我能够使其正常工作,则不会使用它:

<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" mode="aspectj" proxy-target-class="true" >
  <expression-handler ref="expressionHandler"/>
</global-method-security>

感谢您抽出时间阅读此文章


如果需要更多详细信息,请告诉我。

此问题已解决

解决方案的最后一部分是删除将SecurityContextHolder设置为全局的请求


如果你有同样的问题,你可能会发现这篇文章很有帮助。

我认为你需要把它精简到易于管理的程度,没有多少人会费心阅读和费力阅读所有的文章来找出问题所在。谢谢你的评论。我已尝试删除3个成功呼叫中的2个的日志,因为它们可能是多余的。您实际上是如何解决此问题的?我也有同样的问题。我浏览了该链接,但没有任何帮助。@Tiny在尝试进行双因素身份验证时,我将SecurityContextHolder设置为全局,因此删除该链接可以解决我的问题,但可能是许多因素导致了该问题。我也没有收到卢克的回信,解释为什么这会造成我所经历的问题。