自定义授权(accessDecisionManager)

  • xml配置:

<global-method-security access-decision-manager-ref="accessDecisionManager"/>
    <http pattern="/loggedout.jsp" security="none"/>
    <http pattern="/login.jsp" security="none"/>

    <http auto-config="true" access-decision-manager-ref="accessDecisionManager">
         <intercept-url pattern="/**" access="permitAll" /> 
        <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1"
        default-target-url="/listAccounts.html"/>
        <http-basic/>
        <logout logout-success-url="/loggedout.jsp" delete-cookies="JSESSIONID"/>
        <remember-me />
 
        <session-management invalid-session-url="/timeout.jsp">
            <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
        </session-management>
    </http>

<beans:bean id="accessDecisionManager"  class="org.springframework.security.access.vote.AffirmativeBased">  
   <beans:property name="allowIfAllAbstainDecisions" value="false"/>  
   <beans:property name="decisionVoters">  
     <beans:list>  
       <beans:bean class="net.mantis.security.auth.DatabaseRoleVoter"/>
       <beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>  
     </beans:list>  
   </beans:property>  
 </beans:bean>  

 

  • java code: DatabaseRoleVoter

 

public class DatabaseRoleVoter implements AccessDecisionVoter {
     @Override
    public boolean supports(ConfigAttribute arg0) {
        System.out.println(this.getClass().getName()
                + ".supports(ConfigAttribute arg0)");
        return true;
    }

    @Override
    public boolean supports(Class arg0) {
        System.out.println(this.getClass().getName() + ".supports(Class arg0)");
        return true;
    }

    @Override
    public int vote(Authentication au, Object arg1, Collection arg2) {
        int result = 0;
        String name = au.getName();
        if (name.equalsIgnoreCase("Rod")) {
            result = 1;
        } else {
            result = -1;
        }
        System.out.println(this.getClass().getName() + ".vote");
        System.out.println(arg1);
        System.out.println(arg2);
        return result;
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值