Security configuration in Web. xml

Source: Internet
Author: User

Code in Web. xml

  1. <security-constraint>
  2. <display-name>
  3. Baseporject</display-name>
  4. <web-resource-collection>
  5. <web-resource-name>baseproject</web-resource-name>
  6. <url-pattern>*.jsp</url-pattern>
  7. <url-pattern>*.do</url-pattern>
  8. <http-method>get</http-method>
  9. <http-method>put</http-method>
  10. <http-method>head</http-method>
  11. <http-method>trace</http-method>
  12. <http-method>post</http-method>
  13. <http-method>delete</http-method>
  14. <http-method>options</http-method>
  15. </web-resource-collection>
  16. <auth-constraint>
  17. <description>
  18. Baseproject</description>
  19. <role-name>all role</role-name>
  20. </auth-constraint>
  21. <user-data-constraint>
  22. <transport-guarantee>none</transport-guarantee>
  23. </user-data-constraint>
  24. </security-constraint>
  25. <login-config>
XML code
  1. <!--four verification methods, attached at the end of the note-
  2. <auth-method>form</auth-method>
  3. <form-login-config>
  4. <form-login-page>/login.html</form-login-page>
  5. <form-error-page>/error.html</form-error-page>
  6. </form-login-config>
  7. </login-config>
  8. <security-role>
  9. <role-name>all role</role-name>
  10. </security-role>

The purpose of the Security-constriaint element here is to indicate what authentication method is used by the server. This element should appear in Web. XML in front of the login-config. It contains a possible child element, namely: Web-resource-collection, Auth-constraint, User-data-constraint, and Display-name. They are described in the following subsections.
1. Web-resource-collection this element determines which resources should be protected, and all security-constraint elements must contain at least one web- Resource-collection. This element consists of an web-resource-name element that gives an arbitrary identity name, a url-pattern element that determines which URL should be protected, an HTTP command that states that this protection applies (GET, post, and so on). The Http-method element of the default is all methods) and an optional description element that provides data.
It is important to note that Url-pattern only applies to clients that directly access these resources. In particular, it is not suitable for pages accessed through the MVC architecture using RequestDispatcher, or for pages that are not suitable for access using a similar jsp:forward approach.


2. The Auth-constraint element indicates which users should have access to protected resources. This element should contain one or more identities that have access to the user class Role-name element, and a description element that contains (optionally) a description role.

3. User-data-constraint
This optional element indicates that any transport layer protection is used when accessing related resources. It must contain a transport-guarantee child element (a valid value of none, integral, or confidential) and optionally contain a description element. The Transport-guarantee value of none will limit the communication protocol used. The integral value means that the data must be transmitted in a way that prevents the person who intercepts it from reading it. Although the rationale (and in the future HTTP version), there may be differences between integral and confidential, in the current practice, they are simply required to use SSL.

=========================================================

Four types of authentication:

Basic:http specification, Base64
<web-app>
......
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
......
</web-app>

DIGEST:HTTP specification, data integrity is strong, but not SSL
<web-app>
......
<login-config>
<auth-method>DIGEST</auth-method>
</login-config>
......
</web-app>

CLIENT-CERT:J2EE specification, strong data integrity, public key (PKC)
<web-app>
......
<login-config>
<auth-method>Client-cert</auth-method>
</login-config>
......
</web-app>

FORM:J2EE specification, data integrity is very weak, no encryption, allowing a custom landing interface.
<web-app>
......
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
......
</web-app>

Here the form method needs to explain is the login page fixed element: login.html

<form name= "LoginForm" method= "post" action= "J_security_check" >

<input name= "J_username" type= "text" >

<input name= "J_password" type= "password" >

<input type= "Submit" value= "Login" >

</form>

The action of the form must be J_security_check, method= "POST", User name Name= "j_username", Password name= "J_password" These are fixed elements

Security configuration in Web. xml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.