I'm using LDAP with JBoss by binding my LDAP server's initial context into
the JBoss JNDI namespace and this works great. About 30 lines of code is
all it takes:
private void initializeLdap(InitialContext iniCtx) throws NamingException
{
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.setProperty(Context.PROVIDER_URL, "ldap://banshee-int:389/");
env.setProperty(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
env.setProperty(Context.SECURITY_CREDENTIALS, "secret");
try
{
InitialLdapContext ldapCtx = new InitialLdapContext(env, null);
//Bind a reference to the LDAP root context using NonSerializableWrapper as the
ObjectFactory
NonSerializableWrapper.add(ldapJndiName, ldapCtx);
String className = "javax.naming.ldap.InitialLdapContext";
String factory = NonSerializableWrapper.class.getName();
StringRefAddr addr = new StringRefAddr("nns", ldapJndiName);
Reference memoryRef = new Reference(className, addr, factory, null);
iniCtx.rebind(ldapJndiName, memoryRef);
PkgCategory.info("Bound projects ldap context at: "+ldapJndiName);
}
catch(Throwable t)
{
PkgCategory.alert("Failed to setup projects ldap context", t);
NamingException ne = new NamingException("Failed to setup projects ldap context");
ne.setRootCause(t);
throw ne;
}
}
The NonSerializableWrapper class is just a simple in memory object factory:
public class NonSerializableWrapper implements ObjectFactory
{
private static Map wrapperMap = Collections.synchronizedMap(new HashMap());
public static void add(String key, Object target)
{
wrapperMap.put(key, target);
}
// --- Begin ObjectFactory interface methods
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
env) throws Exception
{ // Get the nns value from the Reference obj and use it as the map key
Reference ref = (Reference) obj;
RefAddr addr = ref.get("nns");
String key = (String) addr.getContent();
Object target = wrapperMap.get(key);
return target;
}
// --- End ObjectFactory interface methods
}
>> Furthermore, as it does not seem to be persistant, does anyone use another
>> JNDI implementation with JBoss which would be :
>> - Java
>> - Directory
>> - persistant
>
>You mean like a Java LDAP server? I don't know of anyone like that, no.
>
>regards,
> Rickard
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]