配置完了Acegi的身份验证,接着就要用Acegi来控制访问了
Acegi通过投票管理器来决定是否有访问该资源的权限,投票方式有三种:
一票通过制(AffirmativeBased):有一票通过即可以访问该资源
全票通过制(ConsensusBased):只有全部通过才能访问资源
一票否决制(UnanimousBased):没有拒绝票时允许访问
配置如下:
xml 代码
- <!-- 访问决策投票管理 -->
- <bean id="accessDecisionManager"
- class="org.acegisecurity.vote.AffirmativeBased">
- <property name="allowIfAllAbstainDecisions" value="false" />
- <property name="decisionVoters">
- <list>
- <ref bean="roleVoter" />
- <bean class="org.acegisecurity.vote.AuthenticatedVoter" />
- </list>
- </property>
- </bean>
其中allowIfAllAbstainDecisions代表了弃权票的解决方式为:所有投票皆弃权,不允许访问
xml 代码
- <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter">
- <property name="rolePrefix">
- <value>AUTH_</value>
- </property>
- </bean>
投票管理器实现了AccessDecisionVoter接口,你可以自己编写投票器
其中常量ACCESS_GRANTED表示允许访问资源、ACCESS_DENIED表示拒绝访问资源,ACCESS_ABSTAIN表示不关心资源。