1 29 30 package com.caucho.ejb.burlap; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.naming.AbstractModel; 34 import com.caucho.naming.ContextImpl; 35 import com.caucho.util.Base64; 36 import com.caucho.util.L10N; 37 38 import javax.naming.Context ; 39 import javax.naming.NamingException ; 40 import javax.naming.spi.InitialContextFactory ; 41 import java.util.Hashtable ; 42 43 46 public class BurlapContextFactory implements InitialContextFactory { 47 private static final L10N L = new L10N(BurlapContextFactory.class); 48 49 private AbstractModel _model; 50 51 54 public Context getInitialContext(Hashtable <?,?> environment) 55 throws NamingException 56 { 57 String prefix = (String ) environment.get(Context.PROVIDER_URL); 58 59 String user = (String ) environment.get(Context.SECURITY_PRINCIPAL); 60 String pw = (String ) environment.get(Context.SECURITY_CREDENTIALS); 61 62 if (user != null) { 63 String auth = Base64.encode(user + ':' + pw); 64 65 if (! prefix.endsWith("/")) 66 prefix = prefix + '/'; 67 68 BurlapModel model = new BurlapModel(prefix); 69 BurlapClientContainer client; 70 try { 71 client = new BurlapClientContainer(model.getURLPrefix()); 72 client.setBasicAuthentication(auth); 73 } catch (ConfigException e) { 74 throw new NamingException (e.toString()); 75 } 76 77 model.setClientContainer(client); 78 79 return new ContextImpl(model, environment); 80 } 81 82 if (_model == null) 83 _model = new BurlapModel(prefix); 84 85 return new ContextImpl(_model, environment); 86 } 87 } 88 | Popular Tags |