public Context getInitialContext(Hashtable env) throws NamingException {
Class[] interfaces = {Naming.class};
Interceptor[] interceptors;
Naming naming;
// Get the login principal and credentials from the JNDI env
Object credentials = env.get(Context.SECURITY_CREDENTIALS);
Object principal = env.get(Context.SECURITY_PRINCIPAL);
Object protocol = env.get(Context.SECURITY_PROTOCOL);
if (principal != null && credentials != null)
{
if (protocol != null)
{
login(principal, credentials, protocol);
}
else
{
associateSecurityInformation(principal, credentials);
}
Interceptor[] tmp = {IsLocalInterceptor.singleton, SecurityClientInterceptor.singleton, InvokeRemoteInterceptor.singleton};
interceptors = tmp;
}
else
{
Interceptor[] tmp = {IsLocalInterceptor.singleton, InvokeRemoteInterceptor.singleton};
interceptors = tmp;
}
if (NamingContext.localServer != null) return new NamingContext(env, null, NamingContext.localServer);
String providerUrl = (String) env.get(Context.PROVIDER_URL);
if (providerUrl == null)
{
throw new RuntimeException("PROVIDER_URL not provided in jndi.properties. Automatic discovery not implemented yet.");
}
try
{
naming = (Naming) Remoting.createPojiProxy("JNDI", interfaces, providerUrl, interceptors);
}
catch (Exception e)
{
throw new RuntimeException("Unable to create Naming proxy", e);
}
return new NamingContext(env, null, naming);
}
|