ITお絵かき修行

3歩歩いても忘れないために

http-method-omissionを試す

サーブレット3.0の仕様から追加された「http-method-omission」について。

詳しくは下記ブログ参照。
New Security Features in Glassfish v3 (Java EE 6) - Part I (Yours Officially...Nithya Subramanian)

<security-constraint>
        <display-name>WebConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>test</web-resource-name>
            <description/>
            <url-pattern>/test.jsp</url-pattern>
            <http-method-omission>GET</http-method-omission>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>dev</role-name>
         </auth-constraint>
   </security-constraint>

which means that the auth-constraint for the resource accessible by the url-pattern /test.jsp is applicable for all methods except GET.

認証対象のURLパターン「/test.jsp」に対して実行するHTTPメソッドのうち、
"<http-method-omission>"で指定したメソッド(※上記の例ではGETメソッド)については認証処理の対象外となる。

・・・合ってるか不安なので実際に試してみた。


【前提・目標?】
・全てのJSPファイルに対し、BASIC認証をかける設定とする
・<http-method-omission>の値をGET・POSTの状態にした時、
 任意のJSPファイルへブラウザよりアクセスし、表示される内容を確認する。


【環境】
・Tomcat7.0.56


【検証】
1.web.xmlに、全てのJSPに対し、BASIC認証をかける設定を行う。

「web.xml
DTDXMLスキーマ定義

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  id="serv" version="3.0">


※ルートタグ配下の末尾に追記。

<security-constraint>
  <web-resource-collection>
    <web-resource-name>admin page</web-resource-name>
    <url-pattern>*.jsp</url-pattern>
  </web-resource-collection>

  <auth-constraint>
    <role-name>admin</role-name>
  </auth-constraint>
  <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
  </user-data-constraint>
</security-constraint>

<security-role>
  <role-name>admin</role-name>
</security-role>

<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>admin page</realm-name>
</login-config>

2.tomcat-user.xmlにユーザ・ロールの設定を行う。(権限は適当)

  <role rolename="admin"/>
  <user username="admin" password="password" roles="admin"/>


3.適当なプロジェクト・JSPを作る

4.上記の状態で資産デプロイ・サーバ起動を行う

5.JSPへアクセスする。
→自分の場合は「http://localhost:8080/TestServlet/TestJSP.jsp」へアクセスした。
 アクセスすると、BASIC認証のダイアログが表示された。
f:id:hhhhhskw:20141115210854j:plain

6."<http-method-omission>"にGETメソッドを指定する。

「web.xml

<security-constraint>
  <web-resource-collection>
    <web-resource-name>admin page</web-resource-name>
    <url-pattern>*.jsp</url-pattern>
    <http-method-omission>GET</http-method-omission>
  </web-resource-collection>



7.JSPへアクセスする。
→アクセスすると、作成したJSPファイルの内容が表示された。
f:id:hhhhhskw:20141115210855j:plain

8."<http-method-omission>"にPOSTメソッドを指定する。

「web.xml

<security-constraint>
  <web-resource-collection>
    <web-resource-name>admin page</web-resource-name>
    <url-pattern>*.jsp</url-pattern>
    <http-method-omission>POST</http-method-omission>
  </web-resource-collection>

 
9.JSPへアクセスする。
→アクセスすると、BASIC認証のダイアログが表示された。
f:id:hhhhhskw:20141115210856j:plain


【結論】
・"<http-method-omission>"に指定したHTTPメソッドは認証処理の対象外となる、であってた

英単語ターゲット1400(4訂版) (大学JUKEN新書)

英単語ターゲット1400(4訂版) (大学JUKEN新書)

  • 作者: 宮川 幸久,ターゲット編集部
  • 出版社/メーカー: 旺文社
  • 発売日: 2011/11/23
  • メディア: 単行本
  • 購入: 3人 クリック: 10回
  • この商品を含むブログを見る