隨筆-193  評論-715  文章-1  trackbacks-0

          環境:
          BlazeDS 3.2.0.3978
          Tomcat 6.0.29 (本例在Tomcat 5.5中不能正常運行,因為Tomcat 5.5的context部分的設計與6.0不一樣)
          Java5

          1,在service-config.xml中加入認證和角色(組)的定義:
          <security>
                  
          <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat" />
                  
          <security-constraint id="trusted">
                  
          <auth-method>Basic</auth-method>
                      
          <roles>
                          
          <role>tomcat</role>
                      
          </roles>
                  
          </security-constraint>
                  
          <security-constraint id="users">
                      
          <auth-method>Basic</auth-method>
                      
          <roles>
                          
          <role>role1</role>
                          
          <role>tomcat</role>
                      
          </roles>
                  
          </security-constraint>
              
          </security>
          需要說明的是,這里的security-constraint tag相當于一個角色組,其id屬性就是角色組的ID,如users角色組包含role1和tomcat兩個角色。
          auth-method tag表示認證的方式,Basic即采用HTTP Basic認證方式,也可以自己實現認證方式,可調定為Custom,關于此種認證方式,我將在稍后分享給大家。

          這些角色和用戶,均被定義在Tomcat的conf/tomcat-users.xml配置中:
          <?xml version='1.0' encoding='utf-8'?>
          <tomcat-users>
          <!--
            NOTE:  By default, no user is included in the "manager" role required
            to operate the "/manager" web application.  If you wish to use this app,
            you must define such a user - the username and password are arbitrary.
          -->
          <!--
            NOTE:  The sample user and role entries below are wrapped in a comment
            and thus are ignored when reading this file. Do not forget to remove
            <!.. ..> that surrounds them.
          -->

            
          <role rolename="tomcat"/>
            
          <role rolename="role1"/>
            
          <role rolename="manager"/>
            
          <user username="admin" password="admin" roles="manager"/>
            
          <user username="tomcat" password="tomcat" roles="tomcat"/>
            
          <user username="both" password="tomcat" roles="tomcat,role1"/>
            
          <user username="role1" password="tomcat" roles="role1"/>

          </tomcat-users>


          2,在remote-config.xml中配置具體的destination的權限約束:
          <destination id="Domain">
                  
          <properties>
                      
          <source>com.robin.service.domain.DomainService</source>
                      
          <include-methods>
                      
          <method name="getAllDomains"/>
                      
          <method name="addOrUpdateDomain" security-constraint="trusted"/>
                      
          </include-methods>
                  
          </properties>
                  
          <security>
                      
          <security-constraint ref="users"/>
                  
          </security>
              
          </destination>
          在此配置中,定義所有的方法只要是users角色組中的用戶即可訪問,但是addOrUpdateDomain方法需要trusted角色組中的用戶才能訪問。

          3,將BlazeDS與Tomcat結合所依賴的lib復制到lib目錄中,包含flex-tomcat-common.jar和flex-tomcat-server.jar兩個JAR。

          4,修改Tomcat目錄下的conf/context.xml文件,加入如下Context(在Tomcat5.5中無法成功):
          <Valve className="flex.messaging.security.TomcatValve"/>

          好了,就這么簡單,重啟Tomcat,即可驗證了。

          總結一下:
          1,引入了角色組的概念,這個比較好。
          2,角色和用戶定義依賴于Tomcat,無法定義在如DBMS中,不方便修改。
          3,跨平臺性不好。
          4,資源與權限的映射關系在開發時已經綁定死,無法動態修改。


          PS:2010.4.28. 分享給大家不依賴Tomcat容器實現認證與授權的例子,如有需要,請參考:《BlazeDS自定義認證與權限控制

          本Blog所有內容不得隨意轉載,版權屬于作者所有。如需轉載請與作者聯系( fastzch@163.com    QQ:9184314)。
          未經許可的轉載,本人保留一切法律權益。
          一直以來,發現有某些人完全不尊重我的勞動成果,隨意轉載,提醒一下那些人小心哪天惹上官司。

          posted on 2010-04-27 09:56 Robin's Programming World 閱讀(2359) 評論(0)  編輯  收藏 所屬分類: JavaFlex & Flash
          主站蜘蛛池模板: 淳安县| 西林县| 浙江省| 通海县| 宁波市| 芜湖县| 尼玛县| 平安县| 嘉祥县| 东乌| 石家庄市| 青田县| 顺昌县| 湖南省| 新竹县| 柯坪县| 昌都县| 峨眉山市| 丁青县| 日照市| 天台县| 高阳县| 思茅市| 峡江县| 清苑县| 咸宁市| 桦南县| 越西县| 萝北县| 沙坪坝区| 普兰店市| 丽水市| 太保市| 嘉祥县| 措勤县| 宁城县| 逊克县| 蓬莱市| 遂平县| 太康县| 普安县|