background image

getCallerPrincipal Method

<< Running the Secure Cart Example | Modifying ConverterBean >>
<< Running the Secure Cart Example | Modifying ConverterBean >>

getCallerPrincipal Method

appclient-command-common:
[exec] Caught an unexpected exception!
[exec] javax.ejb.EJBException: nested exception is: java.rmi.AccessException:
CORBA NO_PERMISSION 9998 Maybe; nested exception is:
[exec]
org.omg.CORBA.NO_PERMISSION:
----------BEGIN server-side stack trace----------
[exec] org.omg.CORBA.NO_PERMISSION:
vmcid: 0x2000
minor code: 1806
If you see this response, verify the user name and password of the user that you entered in the
login dialog, make sure that user is assigned to the group user, and rerun the client application.
Example: Using the isCallerInRole and
getCallerPrincipal
Methods
This example demonstrates how to use the getCallerPrincipal() and
isCallerInRole(String role)
methods with an enterprise bean. This example starts with a
very simple EJB application, converter, and modifies the methods of the ConverterBean so
that currency conversion will only occur when the requester is in the role of BeanUser.
For this tutorial, you will add the security elements to an enterprise bean; add the security
elements to the deployment descriptor; build, package, and deploy the application; and then
build and run the client application. The completed version of this example can be found at
tut-install/javaeetutorial5/examples/ejb/converter-secure. This example was developed
by starting with the unsecured enterprise bean application, converter, which is discussed in
Chapter 21, "Getting Started with Enterprise Beans"
and is found in the directory
tut-install/javaeetutorial5/examples/ejb/converter/. This section builds on this example
by adding the necessary elements to secure the application using the getCallerPrincipal()
and isCallerInRole(String role) methods, which are discussed in more detail in
"Accessing
an Enterprise Bean Caller's Security Context" on page 799
.
In general, the following steps are necessary when using the getCallerPrincipal() and
isCallerInRole(String role)
methods with an enterprise bean. In the example application
included with this tutorial, many of these steps have been completed for you and are listed here
simply to show what needs to be done should you wish to create a similar application.
1. Create a simple enterprise bean application, such as the converter example. See
Chapter 21,
"Getting Started with Enterprise Beans"
for more information on creating and
understanding this example. This section of the tutorial starts with this unsecured
application and demonstrates how to access an enterprise bean caller's security context. The
completed example application discussed in this section can be found at
tut-install/javaeetutorial5/examples/ejb/converter-secure/.
2. If you have not already done so, follow the steps in
"Building the Examples" on page 70
to set
properties specific to your installation.
Enterprise Bean Example Applications
The Java EE 5 Tutorial · September 2007
826