2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

CAS如何跟普通的Web系統(tǒng)融合認(rèn)證和授權(quán)

 Joshua 2006-02-20

CAS的作用是負(fù)責(zé)單點(diǎn)登錄,登錄細(xì)節(jié)當(dāng)然要自己寫,CAS3有一個(gè)這樣的AuthenticationHandler 接口,繼承關(guān)系如下
1,AbstractAuthenticationHandler implements AuthenticationHandler
2,AbstractUsernamePasswordAuthenticationHandler extends AbstractAuthenticationHandler

AbstractUsernamePasswordAuthenticationHandler 正是你認(rèn)證管理的著手點(diǎn),你寫一個(gè)類,如WeblogicAuthenticanHandler去擴(kuò)展它。

你先看看下面的接口:

public interface AuthenticationHandler {

    /**
     * Method to determine if the credentials supplied can be authenticated.
     *
     * @param credentials The credentials to authenticate
     * @return true if authenticated and false they are not
     * @throws AuthenticationException An AuthenticationException can contain details about why a particular authentication request failed.
     * AuthenticationExceptions contain code/desc.
     */
    boolean authenticate(Credentials credentials) throws AuthenticationException;
}


authenticate這個(gè)接口是每個(gè)Hander都必須實(shí)現(xiàn),當(dāng)然,AbstractHandler將它轉(zhuǎn)交給 authenticateInternal 方法去實(shí)現(xiàn)。

認(rèn)證有兩種情況,成功或者失敗,true or false。
我使用Weblogic的LoginModule

loginContext = new LoginContext("WeblogicUsernamePasswordModule", new WeblogicCallbackHandler(username, password, url));

它拋出個(gè)各種不同的認(rèn)證異常讓我輕松判斷認(rèn)證過程中發(fā)生了什么事情,
     /**
      * Attempt authentication
      */
     try
     {
       // If we return without an exception, authentication succeeded
       loginContext.login();
     }
     catch(FailedLoginException fle)
     {
       System.out.println("Authentication Failed, " + fle.getMessage());
       loginsccess=false;
     }
     catch(AccountExpiredException aee)
     {
       System.out.println("Authentication Failed: Account Expired");
       loginsccess=false;
     }
     catch(CredentialExpiredException cee)
     {
       System.out.println("Authentication Failed: Credentials Expired");
       loginsccess=false;
     }
     catch(Exception e)
     {
       System.out.println("Authentication Failed: Unexpected Exception, " + e.getMessage());
       loginsccess=false;
     }

如果一切正常,授權(quán)開始了。

     if(loginsccess==true)
     {
      /**
       * Retrieve authenticated subject, perform SampleAction as Subject
       */
      subject = loginContext.getSubject();
      System.out.println("User["+ username+"]["+ password+"] Login Success, Subject is"+subject.toString());
      return true;
     }
     else
     {
      System.out.println("User["+ username+"]["+ password+"] Login Fail, Check!!!!!");
      return false;
     }

OK,獲得了Subject,那你就可以獲得principal,編程式授權(quán)便有了依據(jù)。
同時(shí),你還可以用Weblogic的聲明式授權(quán),直接在web.xml中定義資源的授權(quán)規(guī)則。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多