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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Specifying Method Permissions Using Annotations<br />

<strong>The</strong> method permissions for the methods of a bean class can be specified on the class, the<br />

business methods of the class, or both. Method permissions can be specified on a method of the<br />

bean class to override the method permissions value specified on the entire bean class. <strong>The</strong><br />

following annotations are used to specify method permissions:<br />

■ @RolesAllowed("list-of-roles")<br />

<strong>The</strong> value of the @RolesAllowed annotation is a list of security role names to be mapped to<br />

the security roles that are permitted to execute the specified method or methods. Specifying<br />

this annotation on the bean class means that it applies to all applicable business methods of<br />

the class.<br />

■ @PermitAll<br />

<strong>The</strong> @PermitAll annotation specifies that all security roles are permitted to execute the<br />

specified method or methods. Specifying this annotation on the bean class means that it<br />

applies to all applicable business methods of the class.<br />

■ @DenyAll<br />

<strong>The</strong> @DenyAll annotation specifies that no security roles are permitted to execute the<br />

specified method or methods.<br />

<strong>The</strong> following example code illustrates the use of these annotations:<br />

@RolesAllowed("admin")<br />

public class SomeClass {<br />

public void aMethod () {...}<br />

public void bMethod () {...}<br />

...<br />

}<br />

@Stateless public class MyBean implements A extends SomeClass {<br />

}<br />

@RolesAllowed("HR")<br />

public void aMethod () {...}<br />

public void cMethod () {...}<br />

...<br />

Securing Enterprise Beans<br />

In this example, assuming aMethod, bMethod, and cMethod are methods of business interface A,<br />

the method permissions values of methods aMethod and bMethod are @RolesAllowed("HR")<br />

and @RolesAllowed("admin") respectively. <strong>The</strong> method permissions for method cMethod have<br />

not been specified.<br />

To clarify, the annotations are not inherited by the subclass per se, they apply to methods of the<br />

superclass which are inherited by the subclass. Also, annotations do not apply to CMP entity<br />

beans.<br />

Chapter 29 • Securing <strong>Java</strong> <strong>EE</strong> Applications 805

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

Saved successfully!

Ooh no, something went wrong!