我采用的springsecurity2
web.xml配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext.xml
classpath:/applicationContext*.xml
classpath:/security.xml <!-- -->
</param-value>
</context-param>
<!-- -->
<filter>
<filter-name>securityFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>springSecurityFilterChain</param-value>
</init-param>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- -->
<filter-mapping>
<filter-name>securityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
security.xml中如下:
<intercept-url pattern="/admin/*" access="ROLE_ADMIN,ROLE_SERVICE,ROLE_KNOWLEDGE"/> <form-login login-page="/loginAdmin.jsp" authentication-failure-url="/loginAdmin.jsp?error=true" login-processing-url="/j_spring_check" default-target-url="/admin/index" always-use-default-target='true'/>
在admin/index下的action中 可以得到userDetails 或ManagementUser
ManagementUser mu =(ManagementUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
System.out.println(""+mu);
但是在其他的时候访问 getAuthentication()就为空
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
今天改配置把 要使用中的action的拦截器 filters="none" 变化为相应的权限access="ROLE_ADMIN,ROLE_SERVICE"后 测试 后得到的userDetails 或ManagementUser 均不为空,可能有此可以得出 当设置filters="none" 时getAuthentication()得出为空,具体的为什么 还真不知道