意思就是只有具有相应权限的用户才能打开相应的url, 这个应该怎么配置,哪位能给个例子?下面的代码能不能做到访问/writeAction.do的时候要求具有ROLE_WRITER?能不能给分析一下 <bean id="methodDefinitionSourceAdvisor"
class="org.acegisecurity.intercept.method.aopalliance.MethodDefinitionSourceAdvisor">
<constructor-arg>
<bean
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref bean="methodAccessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value> com.xxx.WriteAction.execute=ROLE_WRITER
</value>
</property>
</bean>
</constructor-arg>
</bean>
class="org.acegisecurity.intercept.method.aopalliance.MethodDefinitionSourceAdvisor">
<constructor-arg>
<bean
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref bean="methodAccessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value> com.xxx.WriteAction.execute=ROLE_WRITER
</value>
</property>
</bean>
</constructor-arg>
</bean>
解决方案 »
- jsp用户修改信息 更新问题
- 求助:Struts2的验证信息如何传递给JSON
- windows7下做的servlet如何部署到ubuntu系统上面去?望有经验的帮忙!
- 请问requet.sendRedirect()和RequestDispatcher.forward()有什么区别
- displaytag 怎么设置导出Excel文件的格式,知道的朋友帮帮忙。
- 怎样实现无刷新的,动态生成的联动下了框。
- 怎样在网上找到是用JAVA做成的 网站啊,我想转行学JAVA,但找不到成品网站啊!
- 在线等 货币格式的转换方法
- 急,在jsp和servlet中如何判断网络连接超时?
- 请教一个概念的问题
- jstl出现missing quotes for attribute value错误
- 两个月考下驾照,高兴,散分!!!
类似ROLE_WRITER, 可以在properties文件,或者数据库里定义的吧,有没有使用数据库的例子,user表应该是怎么定义的?role是怎么拿的?
believefym1161#163.com
在authenticationProcessingFilter中加入如下属性:
<property name="exceptionMappings">
<props>
<prop key="org.acegisecurity.BadCredentialsException">/XXX.jsp</prop>
<prop key="org.acegisecurity.DisabledException">/YYY.jsp</prop>
</props>
</property>资料的话,可以看看 罗时飞 的《敏捷acegi、cas 构建安全的java系统》
<prop key="org.acegisecurity.BadCredentialsException">/XXX.jsp </prop>
我现在也是类似这样配置的,但是这样的话,XXX.jsp将作为所有没有相应权限而去访问资源后的跳转页面比如我想访问a.jsp, 如果没有相应的权限,则仍然能到a.jsp,但是只是在页面上提示说没有权限,而不在页面上显示相应的业务数据不知道acegi能不能实现这样定制的功能,感觉好像这个框架不太好实现这样的需求,求证一下
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager">
<ref local="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref local="httpRequestAccessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value>
<![CDATA[
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
\A/welcome/.*\Z=Anonymous,Authenticated
\A/public/.*\Z=Anonymous,Authenticated
\A/login.*\Z=Anonymous,Authenticated
\A/ping/alive.gif.*\Z=Anonymous,Authenticated
\A/j_acegi_security_check.*\Z=Anonymous,Authenticated
\A/getmondrianmodel.*\Z=Anonymous,Authenticated
\A/getimage.*\Z=Anonymous,Authenticated
\A/getresource.*\Z=Anonymous,Authenticated
\A/admin.*\Z=Admin
\A/auditreport.*\Z=Admin
\A/auditreportlist.*\Z=Admin
\A/versioncontrol.*\Z=Admin
\A/propertieseditor.*\Z=Admin
\A/propertiespanel.*\Z=Admin
\A/subscriptionadmin.*\Z=Admin
\A/resetrepository.*\Z=Admin
\A/viewaction.*solution.admin.*\Z=Admin
\A/scheduleradmin.*\Z=Admin
\A/publish.*\Z=Admin
\A/logout.*\Z=Anonymous
\A/.*\Z=Authenticated
]]>
</value>
</property>
</bean>
像你的那个就可以写成 <bean id="filterInvocationInterceptor"
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager">
<ref local="authenticationManager" />
</property>
<property name="accessDecisionManager">
<ref local="httpRequestAccessDecisionManager" />
</property>
<property name="objectDefinitionSource">
<value>
<![CDATA[
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
\A/writeAction.do/.*\Z=ROLE_WRITER
]]>
</value>
</property>
</bean>URL的写法你再推敲下,Struts我用的不多,2.想用数据库验证的话你要将验证方式修改一下 <bean id="authenticationManager"
class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref bean="daoAuthenticationProvider" />
</list>
</property>
</bean> <bean id="daoAuthenticationProvider"
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="authenticationDao">
<ref bean="authenticationDao"/>
</property>
</bean> <bean id="authenticationDao"
class="org.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="usersByUserNameQuery"> <!--确认用户存在-->
<value>SELECT login, password FROM student WHERE login=?</value>
</property>
<property name=”authoritiesByUserNameQuery”> <!--获得角色-->
<value>SELECT login, privilege FROM user_privileges where login=?</value>
</property>
</bean>
3.acegi是利用了URL过滤机制实现,所以配置自然也要在过滤器的配置文件里了
一旦AuthenticationProcessingFilter成功认证用户,这一过滤器便会调用自身的
sucessfulAuthentication方法,去HttpSession的ACEGI_SAVED_REQUEST_KEY属性中查找SavedRequest对象,从而返回给IE客户之前的URL信息。上面是从书上帮你抄的,它没说认证失败后如何获得SavedRequest对象,不过应该是可以的,LZ自己想想办法,哈~
能不能为不同的页面定制不同的无权限后的跳转页面
比如, 没有相应的权限访问a.jsp后跳转到a_error.jsp,
访问b.jsp后跳转到b_error.jsp,而不是像上面配置文件那样统一跳转到XXX.jsp
CREATE TABLE IF NOT EXISTS T_URL_FORWARD(
UF_ID INTEGER NOT NULL AUTO_INCREMENT COMMENT 'ID',
ROLE_ID int(4) NOT NULL COMMENT '角色ID',
PRG_SUB_NAME varchar(20) NOT NULL COMMENT '子项目名',
TASK_DEF_ID bigint(20) COMMENT '任务定义ID',
KEY_NAME varchar(50) NULL COMMENT '导向关键字',
URL varchar(100) NOT NULL COMMENT '链接导向',
PRIMARY KEY (UF_ID),
UNIQUE KEY (ROLE_ID,TASK_DEF_ID)
)然后你参考那个过滤器使用反射方式,不同用户不同链接。到时候你用内存数据库什么的,比用
acegi 快的不是一点半点。spring实在太臃肿。
比如
/a.jsp=ROLE_A,ROLE_B
这样是ROLE_A或ROLE_B都可以访问,我如何使得同时具有ROLE_A和ROLE_B才能访问