我想在GWT应用程序上使用方法级安全性。我正在尝试使用Spring Security 3.1,因为我找到了一个工作示例here,但它没有使用form-login。阅读this answer后,第一个方法调用成功获取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="/MyAppName/**" security="none" />
并添加了<intercept-url pattern="/MyAppName/**" access="permitAll()" />
?
我的过滤器如下:
<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>
感谢您抽出宝贵时间阅读本文
如果需要更多详细信息,请与我们联系。