List of usage examples for javax.naming.directory DirContext createSubcontext
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException;
From source file:org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager.java
/** * Create main context corresponding to tenant. * * @param rootDN Root domain name. * @param orgName Organization name * @param initialDirContext The directory connection. * @throws UserStoreException If an error occurred while creating context. */// www.j av a 2 s. c om protected void createOrganizationalContext(String rootDN, String orgName, DirContext initialDirContext) throws UserStoreException { DirContext subContext = null; DirContext organizationalContext = null; try { //get the connection context for rootDN subContext = (DirContext) initialDirContext.lookup(rootDN); Attributes contextAttributes = new BasicAttributes(true); //create organizational object class attribute Attribute objectClass = new BasicAttribute(LDAPConstants.OBJECT_CLASS_NAME); objectClass.add(tenantMgtConfig.getTenantStoreProperties() .get(UserCoreConstants.TenantMgtConfig.PROPERTY_ORGANIZATIONAL_OBJECT_CLASS)); contextAttributes.put(objectClass); //create organizational name attribute String organizationalNameAttribute = tenantMgtConfig.getTenantStoreProperties() .get(UserCoreConstants.TenantMgtConfig.PROPERTY_ORGANIZATIONAL_ATTRIBUTE); Attribute organization = new BasicAttribute(organizationalNameAttribute); organization.add(orgName); contextAttributes.put(organization); //construct organization rdn. String rdnOfOrganizationalContext = organizationalNameAttribute + "=" + orgName; if (logger.isDebugEnabled()) { logger.debug("Adding sub context: " + rdnOfOrganizationalContext + " under " + rootDN + " ..."); } //create organization sub context organizationalContext = subContext.createSubcontext(rdnOfOrganizationalContext, contextAttributes); if (logger.isDebugEnabled()) { logger.debug("Sub context: " + rdnOfOrganizationalContext + " was added under " + rootDN + " successfully."); } } catch (NamingException e) { String errorMsg = "Error occurred while adding the organizational unit " + "sub context."; if (logger.isDebugEnabled()) { logger.debug(errorMsg, e); } throw new UserStoreException(errorMsg, e); } finally { closeContext(organizationalContext); closeContext(subContext); } }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static boolean registerUser(LDAPUser lus, UserRequest userReq, String OrgDN, String OrgUDN) { boolean registration = false; DirContext ctx = null; try {/*ww w. j a va 2 s .c o m*/ ctx = getAuthContext(lus.getUsername(), lus.getPassword()); Attributes attrsBag = new BasicAttributes(); Attribute oc = new BasicAttribute("objectClass"); oc.add("inetOrgPerson"); oc.add("organizationalPerson"); oc.add("person"); oc.add("top"); attrsBag.put(oc); Attribute sn = new BasicAttribute("sn", userReq.getSurname()); attrsBag.put(sn); Attribute cn = new BasicAttribute("cn", userReq.getUsername()); attrsBag.put(cn); Attribute dispName = new BasicAttribute("displayName", userReq.getUsername()); attrsBag.put(dispName); Attribute uPass = new BasicAttribute("userPassword", userReq.getPassword()); attrsBag.put(uPass); Attribute regAdd = new BasicAttribute("registeredAddress", userReq.getPreferredMail()); attrsBag.put(regAdd); if (userReq.getTitle() != null && !userReq.getTitle().isEmpty()) { Attribute title = new BasicAttribute("title", userReq.getTitle()); attrsBag.put(title); } Attribute gName = new BasicAttribute("givenName", userReq.getGivenname()); attrsBag.put(gName); Attribute inits = new BasicAttribute("initials", userReq.getGivenname().substring(0, 1).toUpperCase() + userReq.getSurname().substring(0, 1).toUpperCase()); attrsBag.put(inits); Attribute mails = new BasicAttribute("mail"); mails.add(userReq.getPreferredMail()); for (String adMail : userReq.getAdditionalMails().split("[,\\s;]")) if (!adMail.isEmpty()) mails.add(adMail.trim()); attrsBag.put(mails); Attribute org = new BasicAttribute("o", OrgDN); attrsBag.put(org); if (OrgUDN != null && !OrgUDN.isEmpty()) { Attribute orgU = new BasicAttribute("ou", OrgUDN); attrsBag.put(orgU); } ResourceBundle rb = ResourceBundle.getBundle("ldap"); ctx.createSubcontext("cn=" + userReq.getUsername() + "," + rb.getString("peopleRoot"), attrsBag); ModificationItem[] modItems = new ModificationItem[1]; modItems[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("uniqueMember", "cn=" + userReq.getUsername() + "," + rb.getString("peopleRoot"))); ctx.modifyAttributes(rb.getString("usersGroup"), modItems); registration = true; } catch (NameNotFoundException ex) { _log.error(ex); } catch (NamingException e) { _log.error(e); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception e) { // Never mind this. } } } return registration; }
From source file:org.tolven.ldapmgr.LDAPMgrPlugin.java
protected void updateRootDN(DirContext dirContext, SearchControls controls) { String ldapRootDN = getRootDN(); NamingEnumeration<SearchResult> namingEnum = null; try {//from w w w . jav a 2 s .c om boolean schemaExists = false; String name = null; String base = null; try { int index = ldapRootDN.indexOf(","); if (index == -1) { throw new RuntimeException("Expected to find at least one comma in the rootDN"); } else { name = ldapRootDN.substring(0, index); base = ldapRootDN.substring(index + 1); } namingEnum = dirContext.search(base, name, controls); schemaExists = namingEnum.hasMore(); } catch (NamingException ex) { throw new RuntimeException("Could find rootDN schema", ex); } if (schemaExists) { logger.info("LDAP schema for " + ldapRootDN + " already exists"); } else { String dn = name + "," + base; Attributes attributes = new BasicAttributes(); Attribute objclass = new BasicAttribute("objectclass"); objclass.add("organizationalRole"); attributes.put(objclass); attributes.put(name.substring(0, name.indexOf("=")), name.substring(name.indexOf("=") + 1)); try { dirContext.createSubcontext(dn, attributes); } catch (NamingException ex) { throw new RuntimeException("Could not create rootDN schema", ex); } logger.info("Created LDAP schema for " + ldapRootDN); } } finally { if (namingEnum != null) { try { namingEnum.close(); } catch (NamingException ex) { throw new RuntimeException("Could not close the naming enumeration for the ldap rootDN schema", ex); } } } }
From source file:org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager.java
/** * Create sub contexts under the tenant's main context. * * @param dnOfParentContext domain name of the parent context. * @param nameOfCurrentContext name of the current context. * @param initialDirContext The directory connection. * @throws UserStoreException if an error occurs while creating context. *///from w w w .ja va 2 s.com protected void createOrganizationalSubContext(String dnOfParentContext, String nameOfCurrentContext, DirContext initialDirContext) throws UserStoreException { DirContext subContext = null; DirContext organizationalContext = null; try { //get the connection for tenant's main context subContext = (DirContext) initialDirContext.lookup(dnOfParentContext); Attributes contextAttributes = new BasicAttributes(true); //create sub unit object class attribute Attribute objectClass = new BasicAttribute(LDAPConstants.OBJECT_CLASS_NAME); objectClass.add(tenantMgtConfig.getTenantStoreProperties() .get(UserCoreConstants.TenantMgtConfig.PROPERTY_ORG_SUB_CONTEXT_OBJ_CLASS)); contextAttributes.put(objectClass); //create org sub unit name attribute String orgSubUnitAttributeName = tenantMgtConfig.getTenantStoreProperties() .get(UserCoreConstants.TenantMgtConfig.PROPERTY_ORG_SUB_CONTEXT_ATTRIBUTE); Attribute organizationSubUnit = new BasicAttribute(orgSubUnitAttributeName); organizationSubUnit.add(nameOfCurrentContext); contextAttributes.put(organizationSubUnit); //construct the rdn of org sub context String rdnOfOrganizationalContext = orgSubUnitAttributeName + "=" + nameOfCurrentContext; if (logger.isDebugEnabled()) { logger.debug("Adding sub context: " + rdnOfOrganizationalContext + " under " + dnOfParentContext + " ..."); } //create sub context organizationalContext = subContext.createSubcontext(rdnOfOrganizationalContext, contextAttributes); if (logger.isDebugEnabled()) { logger.debug("Sub context: " + rdnOfOrganizationalContext + " was added under " + dnOfParentContext + " successfully."); } } catch (NamingException e) { String errorMsg = "Error occurred while adding the organizational unit " + "sub context."; if (logger.isDebugEnabled()) { logger.debug(errorMsg, e); } throw new UserStoreException(errorMsg, e); } finally { closeContext(organizationalContext); closeContext(subContext); } }
From source file:org.apache.archiva.redback.common.ldap.role.DefaultLdapRoleMapper.java
public boolean saveRole(String roleName, DirContext context) throws MappingException { if (hasRole(context, roleName)) { return true; }//from w w w . ja v a2s .c om String groupName = findGroupName(roleName); if (groupName == null) { if (this.useDefaultRoleName) { groupName = roleName; } else { log.warn("skip group creation as no mapping for roleName:'{}'", roleName); return false; } } List<String> allGroups = getAllGroups(context); if (allGroups.contains(groupName)) { log.info("group {} already exists for role.", groupName, roleName); return false; } Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("groupOfUniqueNames"); attributes.put(objectClass); attributes.put("cn", groupName); // attribute mandatory when created a group so add admin as default member BasicAttribute basicAttribute = new BasicAttribute(getLdapGroupMember()); basicAttribute.add(this.userIdAttribute + "=admin," + getBaseDn()); attributes.put(basicAttribute); try { String dn = "cn=" + groupName + "," + this.groupsDn; context.createSubcontext(dn, attributes); log.info("created group with dn:'{}", dn); return true; } catch (NameAlreadyBoundException e) { log.info("skip group '{}' creation as already exists", groupName); return true; } catch (LdapException e) { throw new MappingException(e.getMessage(), e); } catch (NamingException e) { throw new MappingException(e.getMessage(), e); } }
From source file:CreateCorbaSchema.java
/** * Inserts object class definitions from RFC 2714 into the schema. * //from ww w. ja v a 2 s. c om * 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: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 w ww . ja v a2 s . co m 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:CreateCorbaSchema.java
/** * Inserts attribute definitions from RFC 2714 into the schema. * //from www .jav a 2 s . c o 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:ldap.ActiveLoginImpl.java
/** * This adds a new user. It requires at the minimum a name, it should also * usually have a surname and a password at a minimum. * * @param account//from ww w .ja va 2s. com * @throws Exception */ public void addAccount(UserAccount account, DirContext context, String userBaseDN) throws Exception { // set some default values for the user entry if they haven't been manually added. //if (account.get(Config.USER_NAMING_ATT) == null) if (account.get(LdapConstants.ldapAttrCn) == null) throw new NamingException("addAccount(), UserAccount has no naming Attribute"); if (account.get(LdapConstants.ldapObjectClass) == null) { //Attribute oc = new BasicAttribute("objectClass"); Attribute oc = new BasicAttribute(LdapConstants.ldapObjectClass); if (LdapConstants.ldapObjectClassEmployeeEnable) { //oc.add("employee"); oc.add(LdapConstants.ldapObjectClassEmployee); } //old redbasin stuff /* if (LdapConstants.ldapAttrTopEnable) { oc.add(LdapConstants.ldapAttrTop); } if (LdapConstants.ldapAttrPersonEnable) { oc.add(LdapConstants.ldapAttrPerson); } if (LdapConstants.ldapAttrOrgPersonEnable) { oc.add(LdapConstants.ldapAttrOrgPerson); } if (LdapConstants.ldapAttrInetOrgPersonEnable) { oc.add(LdapConstants.ldapAttrInetOrgPerson); } */ account.put(oc); } /* made changes */ /* if (account.get("cn") == null) account.put("cn", account.getUserID()); if (account.get("sn") == null) account.put("sn", "xxx"); // put in default value for required attribute */ if (account.get(LdapConstants.ldapAttrCn) == null) account.put(LdapConstants.ldapAttrCn, account.getUserID()); if (account.get(LdapConstants.ldapAttrSn) == null) account.put(LdapConstants.ldapAttrSn, "xxx"); // put in default value for required attribute //logger.info("ADDING: \n" + account.getUserDN() + "\n" + account.toString()); logger.info("ADDING: \n" + userBaseDN + "\n" + account.toString()); /** * deal with the password adding later */ /* Attributes attributes = copyAttributes(account); UserAccount myaccount = hashPasswordAttribute(attributes); */ // use this only when we add the user //context.createSubcontext(account.getUserDN(), account); context.createSubcontext(userBaseDN, account); }