使用SSH做一个项目,其中使用到了struts2,权限访问控制使用了acegi,通过acegi可以对URL进行很好的控制了,但是对struts2的方法的控制却不行,查了好多,也没找到什么好方法,请各位高人看看那里配置的不对。现在的情况是如果只有methodSecurityInterceptor这部分,那么运行不报错,但是也没有实现权限的控制,如果按下面的写法,结果总是报org.acegisecurity.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext错误,我怀疑是<property name="beanNames"><list><value>budget</value></list>中的budget无法解析,但是,budget是在spring中配置了的bean,它对应的是
<bean id="budget" class="action.budget.BudgetAction">
<property name="budgetService" ><ref bean="budgetService" /></property>
</bean>,是在另外一个文件中定义的,我们其它部分的运行都是没问题的,实在不知道这里是怎么回事了,请大家帮帮忙,谢谢<!-- 测试对方法的拦截 -->
<bean id="methodSecurityInterceptor"
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref bean="accessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value>
action.budget.BudgetAction.addbudget=ROLE_ADMIN,ROLE_BUDGET_ADMIN
</value>
</property>
</bean>
<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>budget</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>methodSecurityInterceptor</value>
</list>
</property>
</bean>
<bean id="budget" class="action.budget.BudgetAction">
<property name="budgetService" ><ref bean="budgetService" /></property>
</bean>,是在另外一个文件中定义的,我们其它部分的运行都是没问题的,实在不知道这里是怎么回事了,请大家帮帮忙,谢谢<!-- 测试对方法的拦截 -->
<bean id="methodSecurityInterceptor"
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref bean="accessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value>
action.budget.BudgetAction.addbudget=ROLE_ADMIN,ROLE_BUDGET_ADMIN
</value>
</property>
</bean>
<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>budget</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>methodSecurityInterceptor</value>
</list>
</property>
</bean>
要是bean的话应该用<ref bean="budget"/>
要把acegi的配置放到struts2 FilterDispatcher的前面
<filter>
<filter-name>AcegiFilterChainProxy</filter-name>
<filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>org.acegisecurity.util.FilterChainProxy</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AcegiFilterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 以前用户可以正常登陆的配制为
<filter>
<filter-name>AcegiFilterChainProxy</filter-name>
<filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>org.acegisecurity.util.FilterChainProxy</param-value>
</init-param>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>AcegiFilterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AcegiFilterChainProxy</filter-name>
<filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>org.acegisecurity.util.FilterChainProxy</param-value>
</init-param>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>AcegiFilterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>