javablogspot

Just another WordPress.com weblog

Understanding Web Security Using web.xml Via Use Cases

Posted by damuchinni on February 14, 2009

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).

01.<security-constraint>
02. <web-resource-collection>
03. <web-resource-name>All Access</web-resource-name>
04. <url-pattern>/unchecked/*</url-pattern>
05. <http-method>DELETE</http-method>
06. <http-method>PUT</http-method>
07. <http-method>HEAD</http-method>
08. <http-method>OPTIONS</http-method>
09. <http-method>TRACE</http-method>
10. <http-method>GET</http-method>
11. <http-method>POST</http-method>
12. </web-resource-collection>
13. <user-data-constraint>
14. <transport-guarantee>NONE</transport-guarantee>
15. </user-data-constraint>
16.</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).

01.<security-constraint>
02. <display-name>Restricted GET To Employees</display-name>
03. <web-resource-collection>
04. <web-resource-name>Restricted Access - Get Only</web-resource-name>
05. <url-pattern>/restricted/employee/*</url-pattern>
06. <http-method>GET</http-method>
07. </web-resource-collection>
08. <auth-constraint>
09. <role-name>Employee</role-name>
10. </auth-constraint>
11. <user-data-constraint>
12. <transport-guarantee>NONE</transport-guarantee>
13. </user-data-constraint>
14.</security-constraint>


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.

01.<security-constraint>
02. <display-name>excluded</display-name>
03. <web-resource-collection>
04. <web-resource-name>No Access</web-resource-name>
05. <url-pattern>/excluded/*</url-pattern>
06. <url-pattern>/restricted/employee/excluded/*</url-pattern>
07. <url-pattern>/restricted/partners/excluded/*</url-pattern>
08. </web-resource-collection>
09. <web-resource-collection>
10. <web-resource-name>No Access</web-resource-name>
11. <url-pattern>/restricted/*</url-pattern>
12. <http-method>DELETE</http-method>
13. <http-method>PUT</http-method>
14. <http-method>HEAD</http-method>
15. <http-method>OPTIONS</http-method>
16. <http-method>TRACE</http-method>
17. <http-method>GET</http-method>
18. <http-method>POST</http-method>
19. </web-resource-collection>
20. <auth-constraint />
21. <user-data-constraint>
22. <transport-guarantee>NONE</transport-guarantee>
23. </user-data-constraint>
24.</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:

1.<login-config>
2. <auth-method>BASIC</auth-method>
3. <realm-name>default</realm-name>
4.</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:

1.<login-config>
2. <auth-method>CLIENT-CERT</auth-method>
3. <realm-name>JMX Console</realm-name>
4.</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:

1.<login-config>
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>

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: