Sun Java System Application Server |
The Stateless Session bean has a Remote business interface with four business methods, two for positive test cases, two for negative test cases.
import javax.ejb.Remote; @Remote public interface Sless { public String helloRolesAllowed(); public String helloRolesAllowed2(); public String helloPermitAll(); public String helloDenyAll(); }
Unlike prior versions of EJB, the remote interface is not
required to extend java.rmi.Remote and its business methods are not
required to throw java.rmi.RemoteException.
The business interface is designated as a remote business interface via the @javax.ejb.Remote annotation.
The bean implementation is:
@Stateless public class SlessEJB implements Sless { @RolesAllowed("javaee") public String helloRolesAllowed() { return "SlessEJB.helloRolesAllowed(): Hello World"; } @RolesAllowed("noauthuser") public String helloRolesAllowed2() { return "SlessEJB.helloRolesAllowed2(): Hello World"; } @PermitAll public String helloPermitAll() { return "SlessEJB.helloPermitAll(): Hello World"; } @DenyAll public String helloDenyAll() { return "SlessEJB.helloDenyAll(): Hello World"; } }
@javax.ejb.Stateless is a component-defining annotation that designates
this class as the bean class for a Stateless Session Bean.
@javax.annotation.security.DenyAll is a an annotation indicating that
the given method is not accessible by everyone.
@javax.annotation.security.PermitAll is an annotation indicating that
the given method or all business methods of the given class is/are
accessbile by everyone.
@javax.annotation.security.RolesAllowed is an annotation indicating
that the given method is only accessible for given list of roles.
The good news is that standard deployment descriptor is no longer required! The two Java files above are sufficient to completely describe this stateless session bean.
You only need security-role-mapping in the sun-application.xml
file.
The JNDI name for the Remote Stateless Session bean will
default to the class name of its Remote business interface .
Follow these instructions to build, deploy, and run this sample application.
app_dir
is the sample application base
directory: samples_install_dir/javaee5/enterprise/security-stateless-ear
.
Change directory to app_dir.
app_dir>
ant
all
bpp-run-secure-app-client:
[echo] running application client container.
[exec] SlessEJB.helloRolesAllowed(): Hello World
[exec] Expected Exception for sless.helloRolesAllowed2()
[exec] SlessEJB.helloPermitAll(): Hello World
[exec] Expected Exception for sless.helloDenyAll()
Note that the following exception would be seen in $javaee.domaindir/logs/server.log
for negative tests: helloRolesAllowed2() and helloDenyAll().
javax.ejb.AccessLocalException: Client not authorized for
this invocation.
app_dir> ant ear
compiles and packages the application
app_dir> ant
deploy
deploys it to application server
app_dir> ant
create-file-user
creates a file realm user javaee
app_dir> ant run
runs the test java client
app_dir> ant
delete-file-user
deletes a file realm user javaee
app_dir> ant
clean
app_dir> ant
undeploy
Follow these instructions to build, deploy, and run this sample application using NetBeans IDE.
create-file-user
which is a pre-requisite for running this sample using NetBeans IDE.
samples_install_dir/javaee5/enterprise/security-stateless-ear
as the project.security-stateless-ear
and select Run Project
which will build, deploy and run the project. As part of running the sample, it will popup a dialog box for user name and password. Enter javaee for both user name and password, then it will continue with execution and display the output. Sample output is given below. Copying 1 file to /home/sreeni/IAS/SAMPLES/WS/glassfish-samples/ws/javaee5/enterprise/security-stateless-ear/dist SlessEJB.helloRolesAllowed(): Hello World Expected Exception for sless.helloRolesAllowed2() SlessEJB.helloPermitAll(): Hello World Expected Exception for sless.helloDenyAll() run-security-stateless-appclient: BUILD SUCCESSFUL (total time: 10 minutes 11 seconds)
If you have problems when running the application, refer to troubleshooting document.
Copyright © 2006 Sun Microsystems, Inc. All rights reserved.