List of usage examples for javax.naming.directory Attributes put
Attribute put(Attribute attr);
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 ww . j a v a 2 s. 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: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.jav a 2s . c o 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:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java
protected void setAttrRevised(Attributes pOrgRemoveAttributes) { LOG.log(Level.INFO, "setAttrRevised"); pOrgRemoveAttributes.put(new BasicAttribute(Constants.ldap_ddbOrg_Status, String.valueOf(ConstEnumOrgStatus.revised.name()))); }
From source file:org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager.java
public void addSharedGroupForTenant(Tenant tenant, DirContext mainDirContext) throws UserStoreException { if (!isSharedGroupEnabled()) { return;//from w w w . j a v a 2 s .c o m } Attributes groupAttributes = new BasicAttributes(true); String domainName = tenant.getDomain(); // create ou attribute String groupNameAttributeName = realmConfig .getUserStoreProperty(LDAPConstants.SHARED_TENANT_NAME_ATTRIBUTE); // create group entry's object class attribute Attribute objectClassAttribute = new BasicAttribute(LDAPConstants.OBJECT_CLASS_NAME); objectClassAttribute.add(realmConfig.getUserStoreProperty(LDAPConstants.SHARED_TENANT_OBJECT_CLASS)); groupAttributes.put(objectClassAttribute); DirContext groupContext = null; String searchBase = realmConfig.getUserStoreProperties().get(LDAPConstants.SHARED_GROUP_SEARCH_BASE); try { groupContext = (DirContext) mainDirContext.lookup(searchBase); NameParser ldapParser = groupContext.getNameParser(""); Name compoundGroupName = ldapParser.parse(groupNameAttributeName + "=" + domainName); groupContext.bind(compoundGroupName, null, groupAttributes); } catch (Exception e) { String errorMsg = "Shared tenant: " + domainName + "could not be added."; if (logger.isDebugEnabled()) { logger.debug(errorMsg, e); } throw new UserStoreException(errorMsg, e); } finally { JNDIUtil.closeContext(groupContext); } }
From source file:com.surevine.ldap2alfresco.ProfileFieldTextConverter.java
/** * Encode some attributes as Attributes. * @param json The JSON object to convert * @param attributes Collection of attributes to insert into *//*from w w w . j a va 2 s . c o m*/ public void toAttributes(final Attributes attributes, final JSONObject json) { BasicAttribute attr = new BasicAttribute(attributeLabel); try { if (allowMultiples) { JSONArray jsonValues = json.getJSONArray(jsonLabel); for (int x = 0; x < jsonValues.length(); x++) { String jsonValue = jsonValues.getString(x); if (jsonValue != null && jsonValue.length() > 0) { attr.add(jsonValue); } } } else { String jsonValue = json.getString(jsonLabel); if (jsonValue != null && jsonValue.length() > 0) { attr.add(jsonValue); } } } catch (JSONException e) { logException(Level.ERROR, e); return; } attributes.put(attr); }
From source file:org.apache.ambari.server.serveraction.kerberos.ADKerberosOperationHandler.java
/** * Creates a new principal in a previously configured KDC * <p/>/*from w ww . ja v a2 s . c o m*/ * The implementation is specific to a particular type of KDC. * * @param principal a String containing the principal to add * @param password a String containing the password to use when creating the principal * @param service a boolean value indicating whether the principal is to be created as a service principal or not * @return an Integer declaring the generated key number * @throws KerberosOperationException */ @Override public Integer createPrincipal(String principal, String password, boolean service) throws KerberosOperationException { if (!isOpen()) { throw new KerberosOperationException("This operation handler has not been opened"); } if (principal == null) { throw new KerberosOperationException("principal is null"); } if (password == null) { throw new KerberosOperationException("principal password is null"); } DeconstructedPrincipal deconstructedPrincipal = createDeconstructPrincipal(principal); String realm = deconstructedPrincipal.getRealm(); if (realm == null) { realm = ""; } Map<String, Object> context = new HashMap<String, Object>(); context.put("normalized_principal", deconstructedPrincipal.getNormalizedPrincipal()); context.put("principal_name", deconstructedPrincipal.getPrincipalName()); context.put("principal_primary", deconstructedPrincipal.getPrimary()); context.put("principal_instance", deconstructedPrincipal.getInstance()); context.put("realm", realm); context.put("realm_lowercase", realm.toLowerCase()); context.put("password", password); context.put("is_service", service); context.put("container_dn", this.principalContainerDn); context.put("principal_digest", DigestUtils.sha1Hex(deconstructedPrincipal.getNormalizedPrincipal())); Map<String, Object> data = processCreateTemplate(context); Attributes attributes = new BasicAttributes(); String cn = null; if (data != null) { for (Map.Entry<String, Object> entry : data.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if ("unicodePwd".equals(key)) { if (value instanceof String) { try { attributes.put(new BasicAttribute("unicodePwd", String.format("\"%s\"", password).getBytes("UTF-16LE"))); } catch (UnsupportedEncodingException ue) { throw new KerberosOperationException("Can not encode password with UTF-16LE", ue); } } } else { Attribute attribute = new BasicAttribute(key); if (value instanceof Collection) { for (Object object : (Collection) value) { attribute.add(object); } } else { attribute.add(value); if ("cn".equals(key) && (value != null)) { cn = value.toString(); } } attributes.put(attribute); } } } if (cn == null) { cn = deconstructedPrincipal.getNormalizedPrincipal(); } try { Name name = new CompositeName().add(String.format("cn=%s,%s", cn, principalContainerDn)); ldapContext.createSubcontext(name, attributes); } catch (NamingException ne) { throw new KerberosOperationException("Can not create principal : " + principal, ne); } return 0; }
From source file:CreateCorbaSchema.java
/** * Inserts attribute definitions from RFC 2714 into the schema. * //from w w w. java 2s . 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:CreateCorbaSchema.java
/** * Inserts object class definitions from RFC 2714 into the schema. * /*from www . j a v a2 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 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:com.funambol.LDAP.dao.impl.ContactDAO.java
/** * Convert a <i>Contact</i> into a LDAP inetOrgPerson set of attributes. * This method is used in from Client to Server * /*from ww w.j a va 2s . co m*/ * @param contact * contact to transform into Attributes * @return Attributes representation of the contact */ public Attributes createEntry(Contact contact) { if (logger.isTraceEnabled()) logger.trace("Working on contact:" + contact.getUid()); Attributes attributeSet = new BasicAttributes(); Attribute objClass = new BasicAttribute("objectClass"); if (logger.isDebugEnabled()) logger.debug("Ok let's add objectclass"); objClass.add("inetOrgPerson"); objClass.add("person"); attributeSet.put(objClass); try { if (contact.getUid() == null) { contact.setUid(createUniqueId(contact)); logger.info("UID is now: " + contact.getUid()); } // Split contact object into sub-objects Name name = contact.getName(); PersonalDetail personal = contact.getPersonalDetail(); BusinessDetail business = contact.getBusinessDetail(); List phones = personal.getPhones(); List businessPhones = business.getPhones(); List mails = personal.getEmails(); List note = contact.getNotes(); // personal address Address addr = personal.getAddress(); // if displayname doesn't exist and the firstname and the lastname // are not both defined, this will result in a NullPointerException // I don't want to support any other ways of doing this right now. // a solution could be to use an UID for the rdn if (name != null) { if (propertyCheck(name.getLastName())) { attributeSet.put(new BasicAttribute("sn", name.getLastName().getPropertyValueAsString())); } else { attributeSet.put(new BasicAttribute("sn", "")); } if (propertyCheck(name.getFirstName())) { attributeSet .put(new BasicAttribute("givenName", name.getFirstName().getPropertyValueAsString())); } else { attributeSet.put(new BasicAttribute("givenName", "")); } attributeSet.put(new BasicAttribute("cn", name.getFirstName().getPropertyValueAsString() + " " + name.getLastName().getPropertyValueAsString())); } // Company name if (business != null && propertyCheck(business.getCompany())) { attributeSet.put(new BasicAttribute("o", business.getCompany().getPropertyValueAsString())); } // Adding phones if (phones != null && !phones.isEmpty()) { Iterator iter2 = phones.iterator(); while (iter2.hasNext()) { Phone phone = (Phone) iter2.next(); // if empty, no need to check type if (!propertyCheck(phone)) continue; // Home phones if (phone.getPhoneType().equals("HomeTelephoneNumber")) { attributeSet.put(new BasicAttribute("homePhone", phone.getPropertyValueAsString())); } // MobilePhones if (phone.getPhoneType().equals("MobileTelephoneNumber")) attributeSet.put(new BasicAttribute("mobile", phone.getPropertyValueAsString())); } } // Adding business phones if (businessPhones != null && !businessPhones.isEmpty()) { Iterator iter2 = businessPhones.iterator(); while (iter2.hasNext()) { Phone phone = (Phone) iter2.next(); // if empty, no need to check type if (!propertyCheck(phone)) continue; // Business phones if (phone.getPhoneType().equals("BusinessTelephoneNumber")) { attributeSet.put(new BasicAttribute("telephoneNumber", phone.getPropertyValueAsString())); } // Fax if (phone.getPhoneType().equals("BusinessFaxNumber")) { attributeSet.put( new BasicAttribute("facsimiletelephonenumber", phone.getPropertyValueAsString())); } } } if (mails != null && !mails.isEmpty()) { Iterator iter1 = mails.iterator(); // For each email address, add it while (iter1.hasNext()) { Email mail = (Email) iter1.next(); if (propertyCheck(mail)) attributeSet.put(new BasicAttribute("mail", mail.getPropertyValueAsString())); } } // Address if (addr != null) { if (propertyCheck(personal.getAddress().getPostalCode())) attributeSet.put(new BasicAttribute("postalCode", personal.getAddress().getPostalCode().getPropertyValueAsString())); if (propertyCheck(personal.getAddress().getStreet())) attributeSet.put(new BasicAttribute("postalAddress", personal.getAddress().getStreet().getPropertyValueAsString())); if (propertyCheck(personal.getAddress().getCity())) attributeSet.put( new BasicAttribute("l", personal.getAddress().getCity().getPropertyValueAsString())); } // Notes if (note != null && !note.isEmpty()) { Iterator note1 = note.iterator(); while (note1.hasNext()) { Note nota = (Note) note1.next(); if (propertyCheck(nota)) attributeSet.put(new BasicAttribute("description", nota.getPropertyValueAsString())); } } logger.info("Resulting LDAPAttributeSet is:"); NamingEnumeration<String> ids = attributeSet.getIDs(); while (ids.hasMoreElements()) { String attrID = ids.nextElement(); logger.info(attrID + ": " + ((String) attributeSet.get(attrID).get())); } // Create the LDAPEntry with dn and attributes // THE DN is the DisplayName return attributeSet; } catch (Exception e) { logger.warn("Unable to create LDAPEntry from Contact: " + e.toString(), e); return null; } }
From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java
private void loadAttribute(Attributes attrs, String attrID, Object value, boolean oneWayEncrypted, boolean forUpdate, String encrypted, LdapAttributeValueTranslator translator) throws LdapMappingException { if (value instanceof Collection) { Collection<?> collection = (Collection<?>) value; for (Object colValue : collection) { loadSingleAttribute(attrs, attrID, colValue, oneWayEncrypted, forUpdate, encrypted, translator); }/*from www . j a v a 2 s .c o m*/ if (forUpdate && collection.isEmpty()) { attrs.put(new BasicAttribute(attrID)); } } else { loadSingleAttribute(attrs, attrID, value, oneWayEncrypted, forUpdate, encrypted, translator); } }