DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • How to Secure Your Angular Apps: End-to-End Encryption of API Calls
  • Flask Web Application for Smart Honeypot Deployment Using Reinforcement Learning

Trending

  • Top Gen AI Frameworks for Go in 2026: A Hands-On Comparison
  • Evaluating RAG in Production — What the Numbers Actually Revealed
  • The Permission Was Valid. The Action Was Not Authorized.
  • New York City Taxi Trips: Putting Neo4j and DuckDB to Work

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Understanding Web Security Using web.xml Via Use Cases

Understanding Web Security Using web.xml Via Use Cases

The deployment descriptor, web.xml is the most important Java EE configuration piece of Java EE Web applications.

By 
Anil Saldanha
·
Feb. 11, 09 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
365.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

The deployment descriptor, web.xml is the most important Java EE configuration piece of Java EE Web applications. The security configuration in this descriptor drives the semantics and operation of web container security. Hence it is very critical that web developers and administrators understand the various combinations possible in the security configuration in this descriptor.


Security Constraints


Security Constraints are least understood by web developers, even though they are critical for the security of Java EE Web applications. Specifying a combination of URL patterns, HTTP methods, roles and transport constraints can be daunting to a programmer or administrator. It is important to realize that any combination that was intended to be secure but was not specified via security constraints, will mean that the web container will allow those requests. Security Constraints consist of Web Resource Collections (URL patterns, HTTP methods), Authorization Constraint (role names) and User Data Constraints (whether the web request needs to be received over a protected transport such as TLS).


In this section, we will look at specifying the security constraints for multiple use cases.


Use Case: We would like to define a set of web resources that will have unchecked access. We will achieve this by omitting the authorization constrainsts (auth-constraint element).

<security-constraint>   <web-resource-collection>     <web-resource-name>All Access</web-resource-name>     <url-pattern>/unchecked/*</url-pattern>     <http-method>DELETE</http-method>     <http-method>PUT</http-method>     <http-method>HEAD</http-method>     <http-method>OPTIONS</http-method>     <http-method>TRACE</http-method>     <http-method>GET</http-method>     <http-method>POST</http-method>   </web-resource-collection>   <user-data-constraint>     <transport-guarantee>NONE</transport-guarantee>   </user-data-constraint></security-constraint>

Use Case: HTTP GET operation on a set of web resources should be accessible only by an user with the role "Employee". We will achieve this with the specification of authorization constraints (auth-constraint element with the role-name element).

<security-constraint>   <display-name>Restricted GET To Employees</display-name>   <web-resource-collection>      <web-resource-name>Restricted Access - Get Only</web-resource-name>      <url-pattern>/restricted/employee/*</url-pattern>      <http-method>GET</http-method>   </web-resource-collection>   <auth-constraint>      <role-name>Employee</role-name>   </auth-constraint>   <user-data-constraint>      <transport-guarantee>NONE</transport-guarantee>   </user-data-constraint></security-constraint>

 

CAUTION:  Remember that in this example, you have specified a http-method of GET.  This implies that security constraint is applied to GET.  All the other http methods (POST, PUT,TRACE,HEAD etc) are open.  If you do not want the vulnerability, then do not specify a http method.

 

 

Use Case: We would like to exclude a set of web resources from any access. This can arise when a certain portion of the web application needs to undergo some form of maintenance or is not applicable for a particular physical deployment of a generic web application. We will achieve this with authorization constraints that specify no roles.

<security-constraint>   <display-name>excluded</display-name>   <web-resource-collection>      <web-resource-name>No Access</web-resource-name>      <url-pattern>/excluded/*</url-pattern>      <url-pattern>/restricted/employee/excluded/*</url-pattern>      <url-pattern>/restricted/partners/excluded/*</url-pattern>   </web-resource-collection>   <web-resource-collection>      <web-resource-name>No Access</web-resource-name>      <url-pattern>/restricted/*</url-pattern>      <http-method>DELETE</http-method>      <http-method>PUT</http-method>      <http-method>HEAD</http-method>      <http-method>OPTIONS</http-method>      <http-method>TRACE</http-method>      <http-method>GET</http-method>      <http-method>POST</http-method>   </web-resource-collection>   <auth-constraint />   <user-data-constraint>      <transport-guarantee>NONE</transport-guarantee>   </user-data-constraint></security-constraint>



Authentication

A web container can authenticate a web client/user using either HTTP BASIC, HTTP DIGEST, HTTPS CLIENT or FORM based authentication schemes.


Use Case: We would like to utilize the browser authentication mechanism, HTTP BASIC as defined in the HTTP 1.0 specification.


The login-config.xml element in web.xml would look like the following:

<login-config>  <auth-method>BASIC</auth-method>  <realm-name>default</realm-name></login-config>



Use Case: We would like to utilize HTTPS Client authentication mechanism that is based on digital certificates. The authentication is based on the user's X509 certificate.


The login-config.xml element in web.xml would look like the following:

<login-config>  <auth-method>CLIENT-CERT</auth-method>  <realm-name>JMX Console</realm-name></login-config>


Use Case: We would like to utilize FORM based authentication mechanism.

FORM based mechanism provides flexibility in defining a custom jsp/html page for login and another page to direct for errors during login.


The login-config xml element in web.xml would look like the following:


<login-config>  <auth-method>FORM</auth-method>  <form-login-config>    <form-login-page>/login.html</form-login-page>    <form-error-page>/error.html</form-error-page>  </form-login-config></login-config>



In this case, the html page for login is the login.html and if any errors are encountered (including failed login), the user is directed to error.html

Reference

  1. Seven Security (Mis)Configurations in Java web.xml Files


About the Author: Anil Saldhana is the Lead Security Architect at JBoss. He blogs at http://anil-identity.blogspot.com

Web application security

Opinions expressed by DZone contributors are their own.

Related

  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • How to Secure Your Angular Apps: End-to-End Encryption of API Calls
  • Flask Web Application for Smart Honeypot Deployment Using Reinforcement Learning

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook