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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • 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
  • Design Principles-Building a Secure Cloud Architecture

Trending

  • Cosmos DB Disaster Recovery: Multi-Region Write Pitfalls and How to Evade Them
  • Agile and Quality Engineering: A Holistic Perspective
  • How Trustworthy Is Big Data?
  • Infrastructure as Code (IaC) Beyond the Basics
  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 user avatar
Anil Saldanha
·
Feb. 11, 09 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
363.7K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • 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
  • Design Principles-Building a Secure Cloud Architecture

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!