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.

Working with Realms, Users, Groups, and Roles<br />

782<br />

Mapping Roles to Users and Groups<br />

When you are developing a <strong>Java</strong> <strong>EE</strong> application, you don’t need to know what categories of<br />

users have been defined for the realm in which the application will be run. In the <strong>Java</strong> <strong>EE</strong><br />

platform, the security architecture provides a mechanism for mapping the roles defined in the<br />

application to the users or groups defined in the runtime realm. To map a role name permitted<br />

by the application or module to principals (users) and groups defined on the server, use the<br />

security-role-mapping element in the runtime deployment descriptor<br />

(sun-application.xml, sun-web.xml,orsun-ejb-jar.xml) file. <strong>The</strong> entry needs to declare a<br />

mapping between a security role used in the application and one or more groups or principals<br />

defined for the applicable realm of the Application Server. An example for the sun-web.xml file<br />

is shown below:<br />

<br />

<br />

DIRECTOR<br />

mcneely<br />

<br />

<br />

MANAGER<br />

manager<br />

<br />

<br />

<strong>The</strong> role name can be mapped to either a specific principal (user), a group, or both. <strong>The</strong><br />

principal or group names referenced must be valid principals or groups in the current default<br />

realm of the Application Server. <strong>The</strong> role-name in this example must exactly match the<br />

role-name in the security-role element of the corresponding web.xml file or the role name<br />

defined in the @DeclareRoles or @RolesAllowed annotations.<br />

Sometimes the role names used in the application are the same as the group names defined on<br />

the Application Server. Under these circumstances, you can enable a default principal-to-role<br />

mapping on the Application Server using the Admin Console. From the Admin Console, select<br />

Configuration, then Security, then check the enable box beside Default Principal to Role<br />

Mapping. If you need more information about using the Admin Console, see “Adding Users to<br />

the Application Server” on page 779.<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!