acegi 拦截struts2的方法,急!!!分数不够可再加!!!!

toss2000 2009-04-13 02:59:01
使用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>

...全文
220 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
toss2000 2009-04-14
  • 打赏
  • 举报
回复
不相信没有高手哦
toss2000 2009-04-14
  • 打赏
  • 举报
回复
终于搞定了,zidasine说的对,我又整理了一下,之所以我的改成这样无法登录,是因为,我允许输入中文名进行登录的,现在只要把中文名转一下码就行了,揭帖
<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>
toss2000 2009-04-14
  • 打赏
  • 举报
回复
zidasine,我按照你的提示在web.xml中做了如下修改,结果以前能进行登录的用户现在登录不进去了……,下面的代码是根据提示修改的
<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>
cjg520jie 2009-04-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zidasine 的回复:]
可以看下这个http://hi.baidu.com/obullxl/blog/item/6e7a8550db3cd36784352422.html
[/Quote]

顶下
zidasine 2009-04-14
  • 打赏
  • 举报
回复
zidasine 2009-04-14
  • 打赏
  • 举报
回复
web.xml中应该配置了吧
要把acegi的配置放到struts2 FilterDispatcher的前面
mumu_java 2009-04-14
  • 打赏
  • 举报
回复
acegi没搞过,帮顶。
zidasine 2009-04-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zidasine 的回复:]
<list> <value>budget </value> </list>中的budget无法解析,但是,budget是在spring中配置了的bean,
要是bean的话应该用 <ref bean="budget"/>
[/Quote]上面看错了 后面继续回答
zidasine 2009-04-14
  • 打赏
  • 举报
回复
<list> <value>budget </value> </list>中的budget无法解析,但是,budget是在spring中配置了的bean,
要是bean的话应该用<ref bean="budget"/>
toss2000 2009-04-13
  • 打赏
  • 举报
回复
没人理我哦……

81,119

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧