directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@gmail.com>
Subject Re: Got more than one attributeType for oid of "uidNumber"
Date Mon, 22 Dec 2008 08:32:48 GMT
ayyagarikiran wrote:
> the DN of schema should be ou=schema i.e
> ldap://localhost:10389/ou=schema
>
> HTH
>
> Kiran Ayyagari
Thanks Kiran. There are other error in the code. Here is a working version :

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapContext;

public class ActivateSchem {

    public static void main(String[] args) {
        ActivateSchem obj = new ActivateSchem();
        Hashtable env = obj.connectionEnvApache();
        obj.activate(env);
    }
   
    /** Connect to Apache DS.
     * @return
     */
    private Hashtable connectionEnvApache(){
        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:12389/");
        env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
        env.put(Context.SECURITY_CREDENTIALS, "secret");
        return env;
    }
   
   
    private void activate(Hashtable env){
        try {
               
                DirContext ctx = new InitialDirContext(env);
                //DirContext schemaRoot = ctx.getSchema("");
                Attributes nisAttrs = ctx.getAttributes( 
"cn=nis,ou=schema" );
                boolean isNisDisabled = false;

                if ( nisAttrs.get( "m-disabled" ) != null )
                {
                    isNisDisabled = ( ( String ) nisAttrs.get( 
"m-disabled").get() ).equalsIgnoreCase( "TRUE" );
                }

                // if nis is disabled then enable it
                if ( isNisDisabled )
                {
                    Attribute disabled = new BasicAttribute( 
"m-disabled", "FALSE" );
                    ModificationItem[] mods = new ModificationItem[] {
                        new ModificationItem( 
DirContext.REPLACE_ATTRIBUTE,disabled ) };
                    ctx.modifyAttributes( "cn=nis,ou=schema", mods );
                }
            } catch (NamingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
}


-- 
--
cordialement, regards,
Emmanuel L├ęcharny
www.iktek.com
directory.apache.org



Mime
View raw message