解答例 - 実習課題2 - 11.認証方式
(実習課題2)
実習課題1のWebアプリケーションを、FORM認証を使用するように改良しなさい。
解答例
<?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>FORM</auth-method>
<form-login-config>
<form-login-page>/input.html</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
</web-app>
<html> <head> <title>Servlet11章Exercise2</title> </head> <body> <h1>FORM認証画面</h1> <form action="j_security_check" method="post"> <input type="text" name="j_username"> <input type="password" name="j_password"> <input type="submit" value="ログイン"> </form> </body> </html>
<html> <head> <title>Servlet11章Exercise2</title> </head> <body> <h1>Error画面</h1> パスワードが違う又は、権限がありません。 </body> </html>

