久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    jaas tomcat的實例

     whiskey1122 2009-03-01
    這有個 jaas tomcat的實例, 先看下吧:  http://zhidao.baidu.com/question/31047013.html 
    準備文件和目錄
    創建文件login.jsp和error.jsp
    login.jsp的內容
    <html>
    <head>
    <meta HTTP-EQUIV="Content-Type" Content="text-html; charset=gbk">
    <title>login</title>
    </head>
    <body>
    <form method="POST" action="j_security_check">
    姓名:<input type="text" name="j_username"/>
    <br/>
    密碼:<input type="password" name="j_password"/>
    <br/>
    <input type="submit" value="提交"/>
    </form>
    </body>
    </html>

    在根目錄下創建目錄web,在新建的目錄下創建一個文件index.jsp,內容如下
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=GBK">
    <title>Apache-Axis</title>
    </head>
    <body bgcolor="#FFFFFF">
    request.FORM_AUTH:<%=request.FORM_AUTH%><br/>
    request.getRemoteUser():<%=request.getRemoteUser()%><br/>
    </body>
    </html>


    設置配置文件
    在web.xml中添加以下內容
    <web-app>
    ...
    <security-constraint>
    <!-- Sample Security Constraint -->
    <web-resource-collection>
    <!-- We're going to protect this resource and make it available only to users in "role1". -->
    <web-resource-name>protected-resources</web-resource-name>
    <url-pattern>/web/*</url-pattern>
    <http-method>HEAD</http-method>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    <http-method>PUT</http-method>
    <http-method>DELETE</http-method>
    </web-resource-collection>
    <!-- NOTE: This role names will be retrieved by Josso using the propper identity store. -->
    <auth-constraint>
    <role-name>role1</role-name>
    </auth-constraint>
    <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
    </security-constraint>

    <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
    <form-login-page>/login.jsp</form-login-page>
    <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
    </login-config>

    <security-role >
    <description>Role 1</description>
    <role-name>role1</role-name>
    </security-role>
    </web-app>
    測試
    打開tomcat目錄下的conf/tomcat-users.xml文件,內容如下
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
    <role rolename="tomcat"/>
    <role rolename="role1"/>
    <user username="tomcat" password="tomcat" roles="tomcat"/>
    <user username="role1" password="tomcat" roles="role1"/>
    <user username="both" password="tomcat" roles="tomcat,role1"/>
    </tomcat-users>

    啟動tomcat,在瀏覽器中輸入地址http://localhost:8080/hello/web/,顯示的內容不是/web/index.html,而是login.jsp的內容,輸入both或者role1的用戶名和密碼,將會看到web/index.html的內容,當然,如果輸入錯誤,則會提示錯誤信息。驗證通過后,我們可以看到如下內容:
    request.FORM_AUTH:FORM
    request.getRemoteUser():both? //用戶名


    sun公司也有提供了一個關于JAAS的實例,可供實際分析JAAS使用原理,本人在網上找了許久這方面的文章,希望對你有幫助。

    1、首先下載實例代碼

    http://java./j2se/1.4.2/docs/guide/security/jaas/tutorials/sample_jaas.config
    http://java./j2se/1.4.2/docs/guide/security/jaas/tutorials/SampleAcn.java
    http://java./j2se/1.4.2/docs/guide/security/jaas/tutorials/SampleLoginModule.java
    http://java./j2se/1.4.2/docs/guide/security/jaas/tutorials/SamplePrincipal.java
    http://java./j2se/1.4.2/docs/guide/security/jaas/tutorials/sampleacn.policy

    2、SampleAcn.java 放在 sample 目錄中, SampleLoginModule.java 放在 sample/module 之下, 而 SamplePricipal 放在 sample/principal 之下。

    3、將 config 和 policy 配置文件放到項目的根目錄中,切記,否則無法找到此文件。

    4、將所有文件編譯后執行以下命令

    java -Djava.security.auth.login.config==sample_jaas.config sample.SampleAcn

    如果使用Eclipse則在Run... SampleAcn.java 類時把-Djava.security.auth.login.config==sample_jaas.config 參數填寫入Arguments標簽頁面的VM arguments框中。

    5、此時在控制臺顯示要求用戶輸入user name:和password:,分別輸入testUser和testPassword即可驗證通過。

    至于Jaas原理,有時間可以研究一下源代碼即可。

      本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發現有害或侵權內容,請點擊一鍵舉報。
      轉藏 分享 獻花(0

      0條評論

      發表

      請遵守用戶 評論公約

      類似文章 更多

      主站蜘蛛池模板: 99RE6热在线精品视频观看| 国产情侣激情在线对白| 在国产线视频A在线视频| 无码射肉在线播放视频| 在线看片免费人成视频电影| 午夜福利在线观看6080| 18禁美女裸体爆乳无遮挡| 日韩有码中文字幕av| 亚洲最大成人网色| 一本一道av中文字幕无码| 日韩免费无码一区二区三区| 久久久久久综合网天天| 亚洲高潮喷水无码AV电影| 欧美日韩中文国产一区发布| 少妇私密推油呻吟在线播放| 人妻少妇精品一区二区三区| 免费网站看V片在线毛| 97人人添人人澡人人澡人人澡 | 亚洲欧美日韩综合久久久| 亚洲AV福利天堂在线观看| 四虎国产精品永久在线下载| 午夜在线观看免费观看 视频| 亚洲欧美国产日韩天堂区| 亚洲AV永久无码天堂网一线| 黄色A级国产免费大片视频| 精品亚洲麻豆1区2区3区| 亚洲日韩久热中文字幕| 人妻少妇精品视频专区| 97无码免费人妻超级碰碰夜夜| 中国CHINA体内裑精亚洲日本| 亚洲AV永久精品无码桃色| 欧美午夜成人片在线观看| 国产精品高清中文字幕| 欧美成人家庭影院| 午夜福利试看120秒体验区| 国产乱码1卡二卡3卡四卡5| 国产草草影院ccyycom| 人妻少妇久久久久久97人妻| 国产桃色无码视频在线观看| 色综合AV综合无码综合网站| 亚洲人亚洲人成电影网站色|