1 22 package org.jboss.ejb3; 23 24 import java.util.Properties ; 25 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 30 34 public class InitialContextFactory 35 { 36 private static Properties props = null; 37 private static Properties securityProperties = null; 38 39 public static InitialContext getInitialContext() throws NamingException 40 { 41 InitialContext jndiContext; 42 43 if (props == null) 44 jndiContext = new InitialContext (); 45 else 46 { 47 if (securityProperties != null) 48 { 49 Properties combinedProps = new Properties (); 50 combinedProps.putAll(props); 51 combinedProps.putAll(securityProperties); 52 jndiContext = new InitialContext (combinedProps); 53 } 54 else 55 jndiContext = new InitialContext (props); 56 } 57 58 return jndiContext; 59 } 60 61 public static void setProperties(Properties properties) 62 { 63 props = properties; 64 } 65 66 public static void setSecurity(String user, String password) 67 { 68 if (props != null) 69 { 70 securityProperties = new Properties (); 71 securityProperties.put(Context.SECURITY_PRINCIPAL, user); 72 securityProperties.put(Context.SECURITY_CREDENTIALS, password); 73 securityProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); 74 } 75 } 76 77 } 78 79 | Popular Tags |