directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ersin Er" <ersin...@gmail.com>
Subject Re: [JNDI] Creating SubcontextS
Date Mon, 02 Apr 2007 06:37:03 GMT
On 4/2/07, Emmanuel Lecharny <elecharny@gmail.com> wrote:
> Ole Ersoy a écrit :
>
> > Anyone know whether we have / there exists a utility
> > library for creating subcontext(s).
> >
> > Sort of like commons FileUtil...but for JNDI.
> >
> > Here's what I want to do:
> > Suppose the suffix I'm binding to is ou=system.
> > That's the only entry so far.
> >
> > I wish to create the following entry:
> >
> > String testEntry = "cn=test, cn=test1, cn=test2, ou=system"
>
> You simply have to create entry "cn=test2, ou=system",  then entry
> "cn=test1, cn=test2, ou=system", then entry "cn=test, cn=test1,
> cn=test2, ou=system", and changing the context each time.
>
> It's like with directory :
> mkdir /system/test2
> mkdir /system/test2/test1
> mkdir /system/test2/test1/test
>
> you don't have such a command like
> mkdirall /system/test2/test1/test

Wrong example :-) You can do that:

mkdir -p /system/test2/test1/test

But what makes the difference here is that a file system directory can
be specified with just its name. However a directory entry cannot be
totally specified with its name only. You need to specify all the
required attributes in order to make an entry come to existance.

> Here, each entry must exist before you add sub elements to it (there is
> not exactly a difference between entires and context, a wontext is just
> a position in a tree. It's not the same as directory and files, even if
> a directory is seen as a file on linux - you can vi a directory -)
>
> So in your case, here what you can do :
>        Hashtable<String,Object> adminEnv = new
> Hashtable<String,Object>( envFinal );
>        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
>        env.put( Context.SECURITY_CREDENTIALS, "secret" );
>        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
>        env.put( Context.PROVIDER_URL, "ou=schema" );
>        systemRoot = new InitialLdapContext( env, null );
>
>        // creating cn=test2,ou=system
>        Attributes attributes = new AttributesImpl( true );
>        Attribute attribute = new AttributeImpl( "objectClass" );
>        attribute.add( "top" );
>        attribute.add( "person" );
>        attributes.put( attribute );
>        attributes.put( "cn", "test2" );
>        attributes.put( "sn", "test2" );
>
>        DirContext ctx = systemRoot.createSubcontext( "cn=test2",
> attributes" );
>
>        // creating cn=test1,cn=test2,ou=system
>        ctx = ( DirContext ) systemRoot.lookup( "cn=test2" );
>
>        Attributes attributes = new AttributesImpl( true );
>        Attribute attribute = new AttributeImpl( "objectClass" );
>        attribute.add( "top" );
>        attribute.add( "person" );
>        attributes.put( attribute );
>        attributes.put( "cn", "test1" );
>        attributes.put( "sn", "test1" );
>
>        ctx.createSubcontext( "cn=test1", attributes );
>
>        // creating cn=test,cn=test1,cn=test2,ou=system
>        ctx = ( DirContext ) systemRoot.lookup( "cn=test1,cn=test2" );
>
>        Attributes attributes = new AttributesImpl( true );
>        Attribute attribute = new AttributeImpl( "objectClass" );
>        attribute.add( "top" );
>        attribute.add( "person" );
>        attributes.put( attribute );
>        attributes.put( "cn", "test" );
>        attributes.put( "sn", "test" );
>
>        ctx.createSubcontext( "cn=test", attributes );
>
> It should work (not tested).
>
> Emmanuel
>
>


-- 
Ersin
Mime
View raw message