目次へ

解答例 - 実習課題3 - 10.アクセス制限

(実習課題3)

実習課題2のWebアプリケーションの認証方式として、BASIC認証を指定しなさい。

解答例

<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

  <servlet>
    <servlet-name>Clock</servlet-name>
    <jsp-file>/jsp/clock.jsp</jsp-file>
  </servlet>

  <servlet-mapping>
    <servlet-name>Clock</servlet-name>
    <url-pattern>/servlet10-1</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Clock</servlet-name>
    <url-pattern>/admin/servlet10-1</url-pattern>
  </servlet-mapping>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>all jsp-file</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
    </auth-constraint>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>admin page</web-resource-name>
      <url-pattern>/admin/*</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>
  <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>admin page</realm-name>
  </login-config>

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

</web-app>

↑このページの先頭へ

こちらもチェック!

PR
  • XMLDB.jp