1 25 26 package org.objectweb.easybeans.examples.security; 27 28 import java.util.Hashtable ; 29 30 import javax.ejb.EJBAccessException ; 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 35 39 public final class ClientSecurity { 40 41 44 private static final String DEFAULT_INITIAL_CONTEXT_FACTORY = "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"; 45 46 49 private ClientSecurity() { 50 51 } 52 53 58 public static void main(final String [] args) throws Exception { 59 Context ictx = getInitialContext(); 60 61 StatelessRemote statelessBean = (StatelessRemote) ictx.lookup("securityBean"); 63 64 System.out.println("Calling methods that everybody can call..."); 66 statelessBean.allRolesAllowed(); 67 68 System.out.println("Call a bean with run-as in order to have 'admin' role..."); 70 statelessBean.callRunAsBean(); 71 72 try { 74 statelessBean.deniedForAll(); 75 System.out.println("Access granted which is not expected"); 76 } catch (EJBAccessException e) { 77 System.out.println("Access denied as expected (method is denied)"); 78 } 79 80 } 81 82 86 private static Context getInitialContext() throws NamingException { 87 88 Hashtable <String , Object > env = new Hashtable <String , Object >(); 92 env.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactory()); 93 94 97 return new InitialContext (env); 98 } 99 100 105 private static String getInitialContextFactory() { 106 String prop = System.getProperty("easybeans.client.initial-context-factory"); 107 if (prop == null) { 109 prop = DEFAULT_INITIAL_CONTEXT_FACTORY; 110 } 111 return prop; 112 } 113 114 115 } 116 | Popular Tags |