10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Defining Security Requirements forWeb Applications<br />

852<br />

security constraint for that particular request URI. It is common to have some unprotected<br />

resources and some protected resources. In this case, you will define security constraints and a<br />

login method, but they will not be used to control access to the unprotected resources. Users<br />

won’t be asked to log in until the first time they enter a protected request URI.<br />

<strong>The</strong> <strong>Java</strong> Servlet specification defines the request URI as the part of a URL after the host name<br />

and port. For example, let’s say you have an e-commerce site with a browsable catalog that you<br />

would want anyone to be able to access, and a shopping cart area for customers only. You could<br />

set up the paths for your web application so that the pattern /cart/* is protected but nothing<br />

else is protected. Assuming that the application is installed at context path /myapp, the following<br />

are true:<br />

■ http://localhost:8080/myapp/index.jsp is not protected.<br />

■ http://localhost:8080/myapp/cart/index.jsp is protected.<br />

A user will not be prompted to log in until the first time that user accesses a resource in the<br />

cart/ subdirectory.<br />

Specifying Separate Security Constraints for Different Resources<br />

You can create a separate security constraint for different resources within your application. For<br />

example, you could allow users with the role of PARTNER access to the POST method of all<br />

resources with the URL pattern /acme/wholesale/*, and allow users with the role of CLIENT<br />

access to the POST method of all resources with the URL pattern /acme/retail/*. An example<br />

of a deployment descriptor that would demonstrate this functionality is the following:<br />

// SECURITY CONSTRAINT #1<br />

<br />

<br />

wholesale<br />

/acme/wholesale/*<br />

GET<br />

POST<br />

<br />

<br />

PARTNER<br />

<br />

<br />

CONFIDENTIAL<br />

<br />

<br />

// SECURITY CONSTRAINT #2<br />

<br />

<br />

retail<br />

/acme/retail/*<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!