1    package com.instantbank.servicing.control.util;
2    
3    import java.rmi.RemoteException;
4    import javax.rmi.PortableRemoteObject;
5    import javax.naming.InitialContext;
6    import javax.naming.NamingException;
7    import javax.ejb.CreateException;
8    import javax.ejb.SessionContext;
9    
10   import com.instantbank.common.utilcomponents.JNDINames;
11   import com.instantbank.component.parameter.ejb.ParameterHome;
12   import com.instantbank.servicing.control.ejb.ServicingControllerHome;
13   
14   /**
15    *  This is a utility class for obtaining EJB references.
16    *
17    * @author Instant-bank (Consuelo Franky)
18    * @created September 2002
19    */
20   public final class EJBUtil {
21   
22     /**
23      *  get Home reference to a ServicingController EJB
24      *
25      * @return The ServicingControllerHome value
26      * @exception Exception
27      */
28     public static ServicingControllerHome getServicingControllerHome() throws Exception {
29       try {
30         InitialContext initial = new InitialContext();
31         Object objref = initial.lookup(JNDINames.SERVICING_SCC_EJBHOME);
32         return (ServicingControllerHome)
33           PortableRemoteObject.narrow(objref, ServicingControllerHome.class);
34       }
35       catch(NamingException ne) {
36         throw new Exception(ne.getMessage());
37       }
38     }
39   
40   
41     /**
42      *  get Home reference to a Parameter EJB
43      *
44      * @return The ParameterHome value
45      * @exception Exception
46      */
47     public static ParameterHome getParameterHome() throws Exception {
48       try {
49         InitialContext initial = new InitialContext();
50         Object objref = initial.lookup(JNDINames.PARAMETER_EJBHOME);
51         return (ParameterHome)
52           PortableRemoteObject.narrow(objref, ParameterHome.class);
53       }
54       catch(NamingException ne) {
55         throw new Exception(ne.getMessage());
56       }
57     }
58   
59   
60   
61     /**
62      *  get the current user from the context
63      *
64      * @param context is the context
65      * @return The userId value
66      * @exception Exception
67      */
68     public static String getUserId(SessionContext context)
69        throws Exception {
70       String userId = context.getCallerPrincipal().getName();
71       return userId;
72     }
73   
74   
75     /**
76      *  determine if the current user belongs to a role
77      *
78      * @param context is the context
79      * @param rol role of sistem
80      * @return The userInRole value
81      * @exception Exception
82      */
83     public static boolean isUserInRole(SessionContext context, String rol)
84        throws Exception {
85       return (context.isCallerInRole(rol));
86     }
87   
88   }
89