David.Turing's blog

           

          CAS如何跟普通的Web系統融合認證和授權

          CAS的作用是負責單點登錄,登錄細節當然要自己寫,CAS3有一個這樣的AuthenticationHandler 接口,繼承關系如下
          1,AbstractAuthenticationHandler implements AuthenticationHandler
          2,AbstractUsernamePasswordAuthenticationHandler extends AbstractAuthenticationHandler

          AbstractUsernamePasswordAuthenticationHandler 正是你認證管理的著手點,你寫一個類,如WeblogicAuthenticanHandler去擴展它。

          你先看看下面的接口:

          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這個接口是每個Hander都必須實現,當然,AbstractHandler將它轉交給 authenticateInternal 方法去實現。

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

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

          它拋出個各種不同的認證異常讓我輕松判斷認證過程中發生了什么事情,
               /**
                * 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;
               }

          如果一切正常,授權開始了。

               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,編程式授權便有了依據。
          同時,你還可以用Weblogic的聲明式授權,直接在web.xml中定義資源的授權規則。

          更多關于認證授權,請看[Weblogic Security In Action]
          http://dev2dev.bea.com.cn/bbs/servlet/D2DServlet/download/81-26770-158358-1697/WeblogicSecurityInAction(1).swf

          posted on 2006-02-09 13:50 david.turing 閱讀(4177) 評論(4)  編輯  收藏 所屬分類: Security領域

          評論

          # re: CAS如何跟普通的Web系統融合認證和授權 2007-01-25 00:15 sunky

          授權開始了?

          別搞笑了,授權是在cas-client進行的,對于cas-client,根本沒考慮跟JAVAEE安全的集成  回復  更多評論   

          # re: CAS如何跟普通的Web系統融合認證和授權 2007-01-25 00:17 sunky

          我對本BLOG的主人絕對表示敬意,能把自己的研究成果共享出來就是了不起的,但某些觀點還是不正確的,我對前面過激言論表示道歉。  回復  更多評論   

          # re: CAS如何跟普通的Web系統融合認證和授權 2007-01-25 00:25 sunky

          并不想夸夸其談。還是說點自己的建議吧

          授權如何跟應用服務器集成這一點,有很多種方案,無外乎如何讓應用服務器認識已經認證成功的用戶身份。這又視乎應用服務器廠商提供何種方案。比如,應由用服務器廠商與CAS緊密集成,通過配置,如果是CAS認證,則在認證中心認證后,在應用服務器的認證模塊中添加認證到CAS認證中心的模塊,以便認證中心的判斷;或者,應用服務器廠商提供接口,由SSO解決方案提供商實現到應用服務器的認證。還有別的方案,但不如前面提到的兩種方案這么方便。  回復  更多評論   

          # re: CAS如何跟普通的Web系統融合認證和授權 2007-01-25 10:12 david.turing

          1,認證跟授權分離, 可以實現組件甚至應用服務的分離.
          2,得益于1,因此,我們可以將原先各個獨立的應用服務器系統中認證模塊抽取到一個單點,做一個Single Sign-On
          3,于是原先的公式是
          N個認證模塊+N個授權模塊=>1個認證模塊+N個授權模塊
          你考慮的問題最終會體現實認證的互操作性,但目標仍然沒有脫離統一認證這個需求.
          但考慮到各個應用集成商之間對認證過程的不同實現標準, 的確需要一個統一的認證接口, SAML會是一個很好的開始.
          但前提是你是否充分理解了,在SSO的過程中,協議是如何安全地傳遞用戶的Credential,這一點非常關鍵, 以致于你提問題的方式也會有所不同.   回復  更多評論   

          導航

          統計

          常用鏈接

          留言簿(110)

          我參與的團隊

          隨筆分類(126)

          隨筆檔案(155)

          文章分類(9)

          文章檔案(19)

          相冊

          搜索

          積分與排名

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 灵璧县| 岳池县| 阿鲁科尔沁旗| 无为县| 奉节县| 保靖县| 洮南市| 阿图什市| 东方市| 鄂托克前旗| 温泉县| 连云港市| 攀枝花市| 鹤壁市| 凯里市| 临汾市| 寻乌县| 那坡县| 蒙自县| 山阳县| 康定县| 紫金县| 泰州市| 集贤县| 康平县| 嘉峪关市| 宝鸡市| 开阳县| 绥中县| 大兴区| 海丰县| 彭泽县| 班玛县| 当涂县| 白河县| 山阴县| 应城市| 茂名市| 玉溪市| 荃湾区| 岫岩|