Example usage for javax.naming.directory DirContext getNameInNamespace

List of usage examples for javax.naming.directory DirContext getNameInNamespace

Introduction

In this page you can find the example usage for javax.naming.directory DirContext getNameInNamespace.

Prototype

public String getNameInNamespace() throws NamingException;

Source Link

Document

Retrieves the full name of this context within its own namespace.

Usage

From source file:CreateCorbaSchema.java

/**
 * Inserts object class definitions from RFC 2714 into the schema.
 *
 * This method maps the LDAP schema definitions in RFC 2714 onto the
 * proprietary attributes required by the Active Directory schema.
 *
 * The resulting object class definitions differ from those of RFC 2714
 * in the following ways://from  ww w .jav  a  2  s  .c  o  m
 *
 *     - Abstract and auxiliary classes are now defined as structural.
 *     - The corbaObject class now inherits from corbaContainer.
 *     - The corbaObjectReference class now inherits from corbaObject.
 *
 * The effect of these differences is that CORBA object references
 * cannot be mixed-in with other directory entries, they may only be
 * stored as stand-alone entries.
 *
 * The reason for these differences is due to the way auxiliary classes
 * are supported in Active Directory. Only the names of structural
 * classes (not auxiliary) may appear in the object class attribute of
 * an entry. Therefore, the abstract and auxiliary classes in the CORBA
 * schema definition is re-defined as structural.
 */
protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new object class definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("corbaContainer");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("cn", attrID));
    attrs1.put(new BasicAttribute("objectClass", "classSchema"));
    attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.10"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("mustContain", "cn"));
    attrs1.put(new BasicAttribute("objectClassCategory", "1"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs1.put(new BasicAttribute("subclassOf", "top"));
    attrs1.put(new BasicAttribute("possSuperiors", "top")); //any superior
    attrs1.put(new BasicAttribute("description", "Container for a CORBA object"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // corbaObject relys on corbaContainer

    attrID = new String("corbaObject");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("cn", attrID));
    attrs2.put(new BasicAttribute("objectClass", "classSchema"));
    attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.9"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));

    Attribute coMay = new BasicAttribute("mayContain");
    coMay.add("corbaRepositoryId");
    coMay.add("description");
    attrs2.put(coMay);

    attrs2.put(new BasicAttribute("objectClassCategory", "1"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs2.put(new BasicAttribute("subclassOf", "corbaContainer"));
    attrs2.put(new BasicAttribute("description", "CORBA object representation"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // corbaObjectReference relys on corbaObject

    attrID = new String("corbaObjectReference");
    Attributes attrs3 = new BasicAttributes();

    attrs3.put(new BasicAttribute("cn", attrID));
    attrs3.put(new BasicAttribute("objectClass", "classSchema"));
    attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.11"));
    attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs3.put(new BasicAttribute("mustContain", "corbaIor"));
    attrs3.put(new BasicAttribute("objectClassCategory", "1"));
    attrs3.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs3.put(new BasicAttribute("subclassOf", "corbaObject"));
    attrs3.put(new BasicAttribute("description", "CORBA interoperable object reference"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs3);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:CreateJavaSchema.java

/**
 * Inserts object class definitions from RFC 2713 into the schema.
 * //from   www  . ja v  a 2s.c  o m
 * This method maps the LDAP schema definitions in RFC 2713 onto the
 * proprietary attributes required by the Active Directory schema.
 * 
 * The resulting object class definitions differ from those of RFC 2713 in the
 * following ways:
 *  - Abstract and auxiliary classes are now defined as structural. - The
 * javaObject class now inherits from javaContainer. - The
 * javaNamingReference, javaSerializedObject and javaMarshalledObject now
 * inherit from javaObject.
 * 
 * The effect of these differences is that Java objects cannot be mixed-in
 * with other directory entries, they may only be stored as stand-alone
 * entries.
 * 
 * The reason for these differences is due to the way auxiliary classes are
 * supported the Active Directory. Only the names of structural classes (not
 * auxiliary) may appear in the object class attribute of an entry. Therefore,
 * the abstract and auxiliary classes in the Java schema definition are
 * re-defined as structural.
 */
protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new object class definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("javaContainer");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("objectClass", "classSchema"));
    attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.1"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("mustContain", "cn"));
    attrs1.put(new BasicAttribute("objectClassCategory", "1"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs1.put(new BasicAttribute("subclassOf", "top"));
    attrs1.put(new BasicAttribute("possSuperiors", "top")); // any superior
    attrs1.put(new BasicAttribute("description", "Container for a Java object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // because javaObject relys on javaContainer

    attrID = new String("javaObject");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("objectClass", "classSchema"));
    attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.4"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs2.put(new BasicAttribute("mustContain", "javaClassName"));

    Attribute joMay = new BasicAttribute("mayContain");
    joMay.add("javaClassNames");
    joMay.add("javaCodeBase");
    joMay.add("javaDoc");
    joMay.add("description");
    attrs2.put(joMay);

    attrs2.put(new BasicAttribute("objectClassCategory", "1"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs2.put(new BasicAttribute("subclassOf", "javaContainer"));
    attrs2.put(new BasicAttribute("description", "Java object representation"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // because next 3 rely on javaObject

    attrID = new String("javaSerializedObject");
    Attributes attrs3 = new BasicAttributes();

    attrs3.put(new BasicAttribute("objectClass", "classSchema"));
    attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.5"));
    attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs3.put(new BasicAttribute("mustContain", "javaSerializedData"));
    attrs3.put(new BasicAttribute("objectClassCategory", "1"));
    attrs3.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs3.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs3.put(new BasicAttribute("description", "Java serialized object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs3);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaNamingReference");
    Attributes attrs4 = new BasicAttributes();

    attrs4.put(new BasicAttribute("objectClass", "classSchema"));
    attrs4.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs4.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.7"));
    attrs4.put(new BasicAttribute("lDAPDisplayName", attrID));

    Attribute jnrMay = new BasicAttribute("mayContain");
    jnrMay.add("javaReferenceAddress");
    jnrMay.add("javaFactory");
    attrs4.put(jnrMay);

    attrs4.put(new BasicAttribute("objectClassCategory", "1"));
    attrs4.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs4.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs4.put(new BasicAttribute("description", "JNDI reference"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs4);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaMarshalledObject");
    Attributes attrs5 = new BasicAttributes();

    attrs5.put(new BasicAttribute("objectClass", "classSchema"));
    attrs5.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs5.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.8"));
    attrs5.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs5.put(new BasicAttribute("mustContain", "javaSerializedData"));
    attrs5.put(new BasicAttribute("objectClassCategory", "1"));
    attrs5.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs5.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs5.put(new BasicAttribute("description", "Java marshalled object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs5);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:CreateJavaSchema.java

/**
 * Inserts object class definitions from RFC 2713 into the schema.
 *
 * This method maps the LDAP schema definitions in RFC 2713 onto the
 * proprietary attributes required by the Active Directory schema.
 *
 * The resulting object class definitions differ from those of RFC 2713
 * in the following ways:/*from   ww  w. j av a 2s.com*/
 *
 *     - Abstract and auxiliary classes are now defined as structural.
 *     - The javaObject class now inherits from javaContainer.
 *     - The javaNamingReference, javaSerializedObject and
 *       javaMarshalledObject now inherit from javaObject.
 *
 * The effect of these differences is that Java objects cannot be
 * mixed-in with other directory entries, they may only be stored as
 * stand-alone entries.
 *
 * The reason for these differences is due to the way auxiliary classes
 * are supported the Active Directory. Only the names of structural
 * classes (not auxiliary) may appear in the object class attribute of
 * an entry. Therefore, the abstract and auxiliary classes in the Java
 * schema definition are re-defined as structural.
 */
protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new object class definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("javaContainer");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("objectClass", "classSchema"));
    attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.1"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("mustContain", "cn"));
    attrs1.put(new BasicAttribute("objectClassCategory", "1"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs1.put(new BasicAttribute("subclassOf", "top"));
    attrs1.put(new BasicAttribute("possSuperiors", "top")); //any superior
    attrs1.put(new BasicAttribute("description", "Container for a Java object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // because javaObject relys on javaContainer

    attrID = new String("javaObject");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("objectClass", "classSchema"));
    attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.4"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs2.put(new BasicAttribute("mustContain", "javaClassName"));

    Attribute joMay = new BasicAttribute("mayContain");
    joMay.add("javaClassNames");
    joMay.add("javaCodeBase");
    joMay.add("javaDoc");
    joMay.add("description");
    attrs2.put(joMay);

    attrs2.put(new BasicAttribute("objectClassCategory", "1"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs2.put(new BasicAttribute("subclassOf", "javaContainer"));
    attrs2.put(new BasicAttribute("description", "Java object representation"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // because next 3 rely on javaObject

    attrID = new String("javaSerializedObject");
    Attributes attrs3 = new BasicAttributes();

    attrs3.put(new BasicAttribute("objectClass", "classSchema"));
    attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.5"));
    attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs3.put(new BasicAttribute("mustContain", "javaSerializedData"));
    attrs3.put(new BasicAttribute("objectClassCategory", "1"));
    attrs3.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs3.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs3.put(new BasicAttribute("description", "Java serialized object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs3);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaNamingReference");
    Attributes attrs4 = new BasicAttributes();

    attrs4.put(new BasicAttribute("objectClass", "classSchema"));
    attrs4.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs4.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.7"));
    attrs4.put(new BasicAttribute("lDAPDisplayName", attrID));

    Attribute jnrMay = new BasicAttribute("mayContain");
    jnrMay.add("javaReferenceAddress");
    jnrMay.add("javaFactory");
    attrs4.put(jnrMay);

    attrs4.put(new BasicAttribute("objectClassCategory", "1"));
    attrs4.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs4.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs4.put(new BasicAttribute("description", "JNDI reference"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs4);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaMarshalledObject");
    Attributes attrs5 = new BasicAttributes();

    attrs5.put(new BasicAttribute("objectClass", "classSchema"));
    attrs5.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs5.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.8"));
    attrs5.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs5.put(new BasicAttribute("mustContain", "javaSerializedData"));
    attrs5.put(new BasicAttribute("objectClassCategory", "1"));
    attrs5.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs5.put(new BasicAttribute("subclassOf", "javaObject"));
    attrs5.put(new BasicAttribute("description", "Java marshalled object"));

    schemaCtx.createSubcontext("CN=" + attrID, attrs5);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:CreateJavaSchema.java

/**
 * Inserts attribute definitions from RFC 2713 into the schema.
 *
 * This method maps the LDAP schema definitions in RFC 2713 onto the
 * proprietary attributes required by the Active Directory schema.
 *
 * The resulting attribute definitions are identical to those of RFC 2713.
 *///from ww  w  . j av a2 s  . c  om
protected void insertADAttributes(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new attribute definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("javaClassName");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("adminDescription", attrID));
    attrs1.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.6"));
    attrs1.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));
    attrs1.put(new BasicAttribute("cn", attrID));
    attrs1.put(
            new BasicAttribute("description", "Fully qualified name of distinguished Java class or interface"));
    attrs1.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs1.put(new BasicAttribute("isSingleValued", "TRUE"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("name", attrID));
    attrs1.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs1.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs1.put(new BasicAttribute("oMSyntax", "64"));
    attrs1.put(new BasicAttribute("searchFlags", "0"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaCodeBase");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("adminDescription", attrID));
    attrs2.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.7"));
    attrs2.put(new BasicAttribute("attributeSyntax", "2.5.5.5"));
    attrs2.put(new BasicAttribute("cn", attrID));
    attrs2.put(new BasicAttribute("description", "URL(s) specifying the location of class definition"));
    attrs2.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs2.put(new BasicAttribute("isSingleValued", "FALSE"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs2.put(new BasicAttribute("name", attrID));
    attrs2.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs2.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs2.put(new BasicAttribute("oMSyntax", "22"));
    attrs2.put(new BasicAttribute("searchFlags", "0"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaSerializedData");
    Attributes attrs3 = new BasicAttributes();

    attrs3.put(new BasicAttribute("adminDescription", attrID));
    attrs3.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.8"));
    attrs3.put(new BasicAttribute("attributeSyntax", "2.5.5.10"));
    attrs3.put(new BasicAttribute("cn", attrID));
    attrs3.put(new BasicAttribute("description", "Serialized form of a Java object"));
    attrs3.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs3.put(new BasicAttribute("isSingleValued", "TRUE"));
    attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs3.put(new BasicAttribute("name", attrID));
    attrs3.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs3.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs3.put(new BasicAttribute("oMSyntax", "4"));
    attrs3.put(new BasicAttribute("searchFlags", "0"));
    attrs3.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs3);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaFactory");
    Attributes attrs4 = new BasicAttributes();

    attrs4.put(new BasicAttribute("adminDescription", attrID));
    attrs4.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.10"));
    attrs4.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));
    attrs4.put(new BasicAttribute("cn", attrID));
    attrs4.put(new BasicAttribute("description", "Fully qualified Java class name of a JNDI object factory"));
    attrs4.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs4.put(new BasicAttribute("isSingleValued", "TRUE"));
    attrs4.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs4.put(new BasicAttribute("name", attrID));
    attrs4.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs4.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs4.put(new BasicAttribute("oMSyntax", "64"));
    attrs4.put(new BasicAttribute("searchFlags", "0"));
    attrs4.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs4);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaReferenceAddress");
    Attributes attrs5 = new BasicAttributes();

    attrs5.put(new BasicAttribute("adminDescription", attrID));
    attrs5.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.11"));
    attrs5.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));
    attrs5.put(new BasicAttribute("cn", attrID));
    attrs5.put(new BasicAttribute("description", "Addresses associated with a JNDI Reference"));
    attrs5.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs5.put(new BasicAttribute("isSingleValued", "FALSE"));
    attrs5.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs5.put(new BasicAttribute("name", attrID));
    attrs5.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs5.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs5.put(new BasicAttribute("oMSyntax", "64"));
    attrs5.put(new BasicAttribute("searchFlags", "0"));
    attrs5.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs5);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaDoc");
    Attributes attrs6 = new BasicAttributes();

    attrs6.put(new BasicAttribute("adminDescription", attrID));
    attrs6.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.12"));
    attrs6.put(new BasicAttribute("attributeSyntax", "2.5.5.5"));
    attrs6.put(new BasicAttribute("cn", attrID));
    attrs6.put(new BasicAttribute("description", "The Java documentation for the class"));
    attrs6.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs6.put(new BasicAttribute("isSingleValued", "FALSE"));
    attrs6.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs6.put(new BasicAttribute("name", attrID));
    attrs6.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs6.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs6.put(new BasicAttribute("oMSyntax", "22"));
    attrs6.put(new BasicAttribute("searchFlags", "0"));
    attrs6.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs6);
    System.out.println("    [" + attrID + "]");

    attrID = new String("javaClassNames");
    Attributes attrs7 = new BasicAttributes();

    attrs7.put(new BasicAttribute("adminDescription", attrID));
    attrs7.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.13"));
    attrs7.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));
    attrs7.put(new BasicAttribute("cn", attrID));
    attrs7.put(new BasicAttribute("description", "Fully qualified Java class or interface name"));
    attrs7.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs7.put(new BasicAttribute("isSingleValued", "FALSE"));
    attrs7.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs7.put(new BasicAttribute("name", attrID));
    attrs7.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs7.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs7.put(new BasicAttribute("oMSyntax", "64"));
    attrs7.put(new BasicAttribute("searchFlags", "0"));
    attrs7.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs7);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:com.aurel.track.util.LdapUtil.java

/**
 * Returns the CN (common name) for a given login name
 * /*from w  ww . j  ava 2s  .  c  om*/
 * @param loginName
 *            the loginName of the user
 * @return CN as a String(if found), or null (else)
 */
private static String getCn(TSiteBean siteBean, String loginName) throws NamingException {
    String keyDn = null;
    DirContext ctx = getInitialContext(siteBean.getLdapServerURL(), siteBean.getLdapBindDN(),
            siteBean.getLdapBindPassword());
    if (ctx != null) {
        SearchControls ctls = new SearchControls();
        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        // Search for the user-id
        String searchStr = "(" + siteBean.getLdapAttributeLoginName() + "=" + loginName + ")";
        NamingEnumeration<SearchResult> answer = ctx.search("", searchStr, ctls);
        if (answer.hasMore()) {
            // retrieve the CN
            SearchResult sr = answer.next();
            keyDn = sr.getName();// + "," + ctx.getNameInNamespace();
            LOGGER.debug("Name = " + keyDn);
            String nameInNamespace = ctx.getNameInNamespace();
            LOGGER.debug("Name in namespace " + nameInNamespace);
            if (nameInNamespace != null && nameInNamespace.trim().length() > 0) {
                keyDn += "," + ctx.getNameInNamespace();
            }
            LOGGER.debug("entry found for LDAP-search >" + searchStr + "<: dn= >" + keyDn + "<!");
            answer.close(); // wo don't need more answers
        } else {
            LOGGER.debug("no entry found for LDAP-search >" + searchStr + "<!");
        }
        ctx.close();
    }
    return keyDn;
}

From source file:CreateCorbaSchema.java

/**
 * Inserts attribute definitions from RFC 2714 into the schema.
 * /*from   w  ww .  ja  v a  2  s. co m*/
 * This method maps the LDAP schema definitions in RFC 2714 onto the
 * proprietary attributes required by the Active Directory schema.
 * 
 * The resulting attribute definitions are identical to those of RFC 2714.
 */
protected void insertADAttributes(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new attribute definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("corbaIor");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("adminDescription", attrID));
    attrs1.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.14"));
    attrs1.put(new BasicAttribute("attributeSyntax", "2.5.5.5"));
    attrs1.put(new BasicAttribute("cn", attrID));
    attrs1.put(
            new BasicAttribute("description", "Stringified interoperable object reference of a CORBA object"));
    attrs1.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs1.put(new BasicAttribute("isSingleValued", "TRUE"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("name", attrID));
    attrs1.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs1.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs1.put(new BasicAttribute("oMSyntax", "22"));
    attrs1.put(new BasicAttribute("searchFlags", "0"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    attrID = new String("corbaRepositoryId");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("adminDescription", attrID));
    attrs2.put(new BasicAttribute("attributeID", "1.3.6.1.4.1.42.2.27.4.1.15"));
    attrs2.put(new BasicAttribute("attributeSyntax", "2.5.5.12"));
    attrs2.put(new BasicAttribute("cn", attrID));
    attrs2.put(new BasicAttribute("description", "Repository ids of interfaces implemented by a CORBA object"));
    attrs2.put(new BasicAttribute("distinguishedName", "CN=" + attrID + "," + dn));
    attrs2.put(new BasicAttribute("isSingleValued", "FALSE"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs2.put(new BasicAttribute("name", attrID));
    attrs2.put(new BasicAttribute("objectCategory", "CN=Attribute-Schema," + dn));
    attrs2.put(new BasicAttribute("objectClass", "attributeSchema"));
    attrs2.put(new BasicAttribute("oMSyntax", "64"));
    attrs2.put(new BasicAttribute("searchFlags", "0"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:CreateCorbaSchema.java

/**
 * Inserts object class definitions from RFC 2714 into the schema.
 * /*  w  w w . jav a 2  s.co  m*/
 * This method maps the LDAP schema definitions in RFC 2714 onto the
 * proprietary attributes required by the Active Directory schema.
 * 
 * The resulting object class definitions differ from those of RFC 2714 in the
 * following ways:
 *  - Abstract and auxiliary classes are now defined as structural. - The
 * corbaObject class now inherits from corbaContainer. - The
 * corbaObjectReference class now inherits from corbaObject.
 * 
 * The effect of these differences is that CORBA object references cannot be
 * mixed-in with other directory entries, they may only be stored as
 * stand-alone entries.
 * 
 * The reason for these differences is due to the way auxiliary classes are
 * supported in Active Directory. Only the names of structural classes (not
 * auxiliary) may appear in the object class attribute of an entry. Therefore,
 * the abstract and auxiliary classes in the CORBA schema definition is
 * re-defined as structural.
 */
protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException {

    System.out.println("  [inserting new object class definitions ...]");

    String dn = schemaCtx.getNameInNamespace();
    String attrID;

    attrID = new String("corbaContainer");
    Attributes attrs1 = new BasicAttributes();

    attrs1.put(new BasicAttribute("cn", attrID));
    attrs1.put(new BasicAttribute("objectClass", "classSchema"));
    attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.10"));
    attrs1.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs1.put(new BasicAttribute("mustContain", "cn"));
    attrs1.put(new BasicAttribute("objectClassCategory", "1"));
    attrs1.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs1.put(new BasicAttribute("subclassOf", "top"));
    attrs1.put(new BasicAttribute("possSuperiors", "top")); // any superior
    attrs1.put(new BasicAttribute("description", "Container for a CORBA object"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs1);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // corbaObject relys on corbaContainer

    attrID = new String("corbaObject");
    Attributes attrs2 = new BasicAttributes();

    attrs2.put(new BasicAttribute("cn", attrID));
    attrs2.put(new BasicAttribute("objectClass", "classSchema"));
    attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.9"));
    attrs2.put(new BasicAttribute("lDAPDisplayName", attrID));

    Attribute coMay = new BasicAttribute("mayContain");
    coMay.add("corbaRepositoryId");
    coMay.add("description");
    attrs2.put(coMay);

    attrs2.put(new BasicAttribute("objectClassCategory", "1"));
    attrs2.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs2.put(new BasicAttribute("subclassOf", "corbaContainer"));
    attrs2.put(new BasicAttribute("description", "CORBA object representation"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs2);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // corbaObjectReference relys on corbaObject

    attrID = new String("corbaObjectReference");
    Attributes attrs3 = new BasicAttributes();

    attrs3.put(new BasicAttribute("cn", attrID));
    attrs3.put(new BasicAttribute("objectClass", "classSchema"));
    attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE"));
    attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.11"));
    attrs3.put(new BasicAttribute("lDAPDisplayName", attrID));
    attrs3.put(new BasicAttribute("mustContain", "corbaIor"));
    attrs3.put(new BasicAttribute("objectClassCategory", "1"));
    attrs3.put(new BasicAttribute("systemOnly", "FALSE"));
    attrs3.put(new BasicAttribute("subclassOf", "corbaObject"));
    attrs3.put(new BasicAttribute("description", "CORBA interoperable object reference"));

    schemaCtx.createSubcontext("cn=" + attrID, attrs3);
    System.out.println("    [" + attrID + "]");

    flushADSchemaMods(rootCtx); // finally
}

From source file:nl.nn.adapterframework.ldap.LdapSender.java

private XmlBuilder subContextsToXml(String entryName, String[] subs, DirContext dirContext)
        throws NamingException {

    XmlBuilder contextElem = new XmlBuilder("Context");
    XmlBuilder currentContextElem = new XmlBuilder("CurrentContext");
    currentContextElem.setValue(entryName + "," + dirContext.getNameInNamespace());
    contextElem.addSubElement(currentContextElem);

    if (subs != null) {
        log.error("Subs.length = " + subs.length);
        for (int i = 0; i < subs.length; i++) {
            XmlBuilder subContextElem = new XmlBuilder("SubContext");

            subContextElem.setValue(subs[i]);

            contextElem.addSubElement(subContextElem);
        }/*from www.j a va2  s  .c  o m*/
    }
    return contextElem;
}

From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java

protected boolean authenticate(String username) throws Exception {
    DirContext context = open();
    try {/* ww w  .j av a2 s. co  m*/

        String filter = userSearchMatchingFormat.format(new String[] { username });
        SearchControls constraints = new SearchControls();
        if (userSearchSubtreeBool) {
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }

        // setup attributes
        String[] attribs;
        if (userRoleName == null) {
            attribs = new String[] {};
        } else {
            attribs = new String[] { userRoleName };
        }
        constraints.setReturningAttributes(attribs);

        NamingEnumeration results = context.search(userBase, filter, constraints);

        if (results == null || !results.hasMore()) {
            log.error("No roles associated with user " + username);
            loginSucceeded = false;
            throw new FailedLoginException();
        }

        SearchResult result = (SearchResult) results.next();

        if (results.hasMore()) {
            // ignore for now
        }
        NameParser parser = context.getNameParser("");
        Name contextName = parser.parse(context.getNameInNamespace());
        Name baseName = parser.parse(userBase);
        Name entryName = parser.parse(result.getName());
        Name name = contextName.addAll(baseName);
        name = name.addAll(entryName);
        String dn = name.toString();

        Attributes attrs = result.getAttributes();
        if (attrs == null) {
            return false;
        }
        ArrayList<String> roles = null;
        if (userRoleName != null) {
            roles = addAttributeValues(userRoleName, attrs, roles);
        }
        // check the credentials by binding to server
        // bindUser(context, dn);
        // if authenticated add more roles
        roles = getRoles(context, dn, username, roles);
        for (String role : roles) {
            groups.add(role);
        }
        if (groups.isEmpty()) {
            log.error("No roles associated with user " + username);
            loginSucceeded = false;
            throw new FailedLoginException();
        } else
            loginSucceeded = true;

    } catch (CommunicationException e) {
        close(context);
        throw (LoginException) new FailedLoginException().initCause(e);
    } catch (NamingException e) {
        close(context);
        throw (LoginException) new FailedLoginException().initCause(e);
    }
    return true;
}

From source file:org.cloudfoundry.identity.uaa.ldap.extension.SpringSecurityLdapTemplate.java

/**
 * Composes an object from the attributes of the given DN.
 *
 * @param dn the directory entry which will be read
 * @param attributesToRetrieve the named attributes which will be retrieved from the directory entry.
 *
 * @return the object created by the mapper
 *//* w  w  w .j  av a 2  s. c  om*/
public DirContextOperations retrieveEntry(final String dn, final String[] attributesToRetrieve) {

    return (DirContextOperations) executeReadOnly(new ContextExecutor() {
        public Object executeWithContext(DirContext ctx) throws NamingException {
            Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve);

            // Object object = ctx.lookup(LdapUtils.getRelativeName(dn, ctx));

            return new DirContextAdapter(attrs, new DistinguishedName(dn),
                    new DistinguishedName(ctx.getNameInNamespace()));
        }
    });
}