InvokedBean.ejb Sample

This topic inludes the source code for the InvokedBean.ejb Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/EJBs/security/

Sample Source Code


01 package security;
02 
03 import javax.ejb.*;
04 import weblogic.ejb.*;
05 
06 /**
07  * @ejbgen:session default-transaction="Supports"
08  *   ejb-name = "Invoked"
09  *
10  * @ejbgen:jndi-name local="ejb.InvokedLocal"
11  *
12  * @ejbgen:file-generation remote-class="false" remote-class-name = "Invoked" remote-home="false" remote-home-name = "InvokedHome" local-class="true" local-class-name = "InvokedLocal" local-home="true" local-home-name = "InvokedLocalHome"
13  
14  * @ejbgen:security-role-ref role-link="manager" role-name="manager"
15  * @ejbgen:security-role-ref role-link="engineer" role-name="engineer"
16  */
17 public class InvokedBean
18   extends GenericSessionBean
19   implements SessionBean
20 {
21   private javax.ejb.SessionContext context;
22    
23   public void ejbCreate() {
24     // Your code here
25   }
26 
27   public void setSessionContext(SessionContext ctx) {
28      context = ctx;
29   }
30 
31     /**
32      * @ejbgen:local-method
33      */
34     public String discoverRole()
35     {
36         
37         if(context.isCallerInRole("manager")) {
38             return "You are a manager";
39         }
40         else if(context.isCallerInRole("engineer")) {
41             return "You are an engineer";
42         }
43         else {
44             return "I cannot determine your security role";
45         }
46     }
47 }
48