2012-01-27 15 views
2

サンプルURL http://localhost:8080/examples/jsp/security/protected/index.jspを初めて開くと、usernamepasswordフィールドのログインフォームが表示されます。このフォームのHTMLコードはlogin.jspファイルにありますが、index.jspから呼び出すコードはありません。この呼び出しはどのようにフルフィルされますか?Tomcat7のセキュリティサンプルはlogin.jspをどのように呼び出しますか?

答えて

3

これは、対応するweb.xmlに定義されています。

<!-- Default login configuration uses form-based authentication --> 
<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>Example Form-Based Authentication Area</realm-name> 
    <form-login-config> 
    <form-login-page>/jsp/security/protected/login.jsp</form-login-page> 
    <form-error-page>/jsp/security/protected/error.jsp</form-error-page> 
    </form-login-config> 
</login-config> 

あなたは<tomcat>/webapps/examples/WEB-INFでファイルを見つけます。これは、組み込みのJava EEセキュリティ機能を使用します。先行するsecurity-constraintセクションでは、保護するリソースを定義しています。

<security-constraint> 
     <display-name>Example Security Constraint</display-name> 
     <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name> 
     <!-- Define the context-relative URL(s) to be protected --> 
     <url-pattern>/jsp/security/protected/*</url-pattern> 
     <!-- If you list http methods, only those methods are protected --> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
     </web-resource-collection> 
     <auth-constraint> 
     <!-- Anyone with one of the listed roles may access this area --> 
     <role-name>tomcat</role-name> 
     <role-name>role1</role-name> 
     </auth-constraint> 
    </security-constraint> 
関連する問題