Example usage for javax.naming.directory Attributes put

List of usage examples for javax.naming.directory Attributes put

Introduction

In this page you can find the example usage for javax.naming.directory Attributes put.

Prototype

Attribute put(Attribute attr);

Source Link

Document

Adds a new attribute to the attribute set.

Usage

From source file:org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager.java

@Deprecated
protected void createAdminGroup(String dnOfGroupContext, String adminUserDN, DirContext initialDirContext)
        throws UserStoreException {
    //create set of attributes required to create admin group
    Attributes adminGroupAttributes = new BasicAttributes(true);
    //admin entry object class
    Attribute objectClassAttribute = new BasicAttribute(LDAPConstants.OBJECT_CLASS_NAME);
    objectClassAttribute.add(realmConfig.getUserStoreProperty(LDAPConstants.GROUP_ENTRY_OBJECT_CLASS));
    adminGroupAttributes.put(objectClassAttribute);

    //group name attribute
    String groupNameAttributeName = realmConfig.getUserStoreProperty(LDAPConstants.GROUP_NAME_ATTRIBUTE);
    Attribute groupNameAttribute = new BasicAttribute(groupNameAttributeName);
    String adminRoleName = realmConfig.getAdminRoleName();
    groupNameAttribute.add(UserCoreUtil.removeDomainFromName(adminRoleName));
    adminGroupAttributes.put(groupNameAttribute);

    //membership attribute
    Attribute membershipAttribute = new BasicAttribute(
            realmConfig.getUserStoreProperty(LDAPConstants.MEMBERSHIP_ATTRIBUTE));
    membershipAttribute.add(adminUserDN);
    adminGroupAttributes.put(membershipAttribute);

    DirContext groupContext = null;
    try {//from www  .j  a  v a  2s  . c  om
        groupContext = (DirContext) initialDirContext.lookup(dnOfGroupContext);
        String rdnOfAdminGroup = groupNameAttributeName + "="
                + UserCoreUtil.removeDomainFromName(adminRoleName);
        groupContext.bind(rdnOfAdminGroup, null, adminGroupAttributes);

    } catch (NamingException e) {
        String errorMessage = "Error occurred while creating the admin group.";
        if (logger.isDebugEnabled()) {
            logger.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    } finally {
        closeContext(groupContext);
    }
}

From source file:org.mule.module.ldap.api.jndi.LDAPJNDIConnection.java

/**
 * @param attrs//from  w w  w  . ja  v  a2s . c o  m
 * @return
 * @throws LDAPException
 */
private Attributes buildAttributes(LDAPEntryAttributes attrs) throws LDAPException {
    Attributes attributes = new BasicAttributes(IGNORE_CASE);

    for (Iterator<LDAPEntryAttribute> it = attrs.attributes(); it.hasNext();) {
        attributes.put(buildBasicAttribute((LDAPEntryAttribute) it.next()));
    }

    return attributes;
}

From source file:org.archone.ad.domain.LdapActions.java

@RPCAction(name = "group.add", required = { "groupId" })
@SecuredMethod(constraints = "administrator.by_domain")
public HashMap<String, Object> addGroup(OperationContext opContext) throws NamingException {
    String groupId = (String) opContext.getParams().get("groupId");

    GroupDn groupDn = nameHelper.newGroupDnFromId(groupId);
    DomainDn domainDn = nameHelper.newDomainDnFromDomain(groupDn.getDomain());

    DirContextAdapter userDirContext = (DirContextAdapter) SecurityUtils.getSubject().getPrincipal();

    Attributes attrs = new BasicAttributes();
    BasicAttribute ocattr = new BasicAttribute("objectclass");
    for (String objectClassName : ldapConfiguration.getGroupObjectClassList()) {
        ocattr.add(objectClassName);//from w w  w.j  a  va 2  s .  c o m
    }
    attrs.put(ocattr);

    String description = (String) opContext.getParams().get("description");
    if (description != null && !description.isEmpty()) {
        BasicAttribute descattr = new BasicAttribute("description");
        descattr.add(description);
        attrs.put(descattr);
    }

    userDirContext.bind(groupDn, null, attrs);

    HashMap<String, Object> response = new HashMap<String, Object>();

    response.put("success", true);

    return response;
}

From source file:CreateJavaSchema.java

/**
 * Inserts object class definitions from RFC 2713 into the schema.
 * /*from   w w w .j a v a 2s .  co 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  a va 2 s  .co  m*/
 *
 *     - 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: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.
 *//* www. j av a 2 s.  co  m*/
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.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.
 *///from  www  .ja  va2 s  . co m
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:org.archone.ad.domain.LdapActions.java

@RPCAction(name = "user.add", required = { "userId" })
@SecuredMethod(constraints = "administrator.by_domain")
public HashMap<String, Object> addUser(OperationContext opContext) throws NamingException {
    String userId = (String) opContext.getParams().get("userId");

    UserDn userDn = nameHelper.newUserDnFromId(userId);
    DomainDn domainDn = nameHelper.newDomainDnFromDomain(userDn.getDomain());

    DirContextAdapter userDirContext = (DirContextAdapter) SecurityUtils.getSubject().getPrincipal();

    Attributes attrs = new BasicAttributes();
    BasicAttribute ocattr = new BasicAttribute("objectclass");
    for (String objectClassName : ldapConfiguration.getUserObjectClassList()) {
        ocattr.add(objectClassName);/*w  ww.ja v a  2 s.  co m*/
    }
    attrs.put(ocattr);

    for (DisplayAttribute displayAttribute : displayAttributeHelper.getApiNameIndexedAttrDef().values()) {
        Object attrValue = opContext.getParams().get(displayAttribute.getApiName());

        if (attrValue != null) {
            BasicAttribute attr = new BasicAttribute(displayAttribute.getLdapName());

            if (attrValue instanceof List) {
                for (Object attrOneValue : (List) attrValue) {
                    attr.add(attrOneValue);
                }
            } else {
                attr.add(attrValue);
            }

            attrs.put(attr);

        } else if (displayAttribute.isMustHave()) {
            throw new RuntimeException(displayAttribute.getApiName() + " is required!");
        }

    }

    userDirContext.bind(userDn, null, attrs);

    HashMap<String, Object> response = new HashMap<String, Object>();

    response.put("success", true);

    return response;
}

From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java

public Attributes getLDAPGroupAttributes(long ldapServerId, UserGroup userGroup, User user,
        Properties groupMappings, Properties userMappings) throws Exception {

    Attributes attributes = new BasicAttributes(true);

    Attribute objectClass = new BasicAttribute(_OBJECT_CLASS);

    String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId);

    String[] defaultObjectClasses = PrefsPropsUtil.getStringArray(userGroup.getCompanyId(),
            PropsKeys.LDAP_GROUP_DEFAULT_OBJECT_CLASSES + postfix, StringPool.COMMA);

    for (int i = 0; i < defaultObjectClasses.length; i++) {
        objectClass.add(defaultObjectClasses[i]);
    }//from  ww  w.  java  2 s  .c  om

    attributes.put(objectClass);

    addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.GROUP_NAME), userGroup.getName(),
            attributes);
    addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.DESCRIPTION), userGroup.getDescription(),
            attributes);
    addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.USER),
            getUserDNName(ldapServerId, user, userMappings), attributes);

    return attributes;
}

From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java

public Attributes getLDAPUserAttributes(long ldapServerId, User user, Properties userMappings)
        throws SystemException {

    Attributes attributes = new BasicAttributes(true);

    Attribute objectClass = new BasicAttribute(_OBJECT_CLASS);

    String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId);

    String[] defaultObjectClasses = PrefsPropsUtil.getStringArray(user.getCompanyId(),
            PropsKeys.LDAP_USER_DEFAULT_OBJECT_CLASSES + postfix, StringPool.COMMA);

    for (int i = 0; i < defaultObjectClasses.length; i++) {
        objectClass.add(defaultObjectClasses[i]);
    }//from   www .  j  av a 2 s .  c  om

    attributes.put(objectClass);

    addAttributeMapping(userMappings.getProperty(UserConverterKeys.SCREEN_NAME), user.getScreenName(),
            attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.PASSWORD), user.getPasswordUnencrypted(),
            attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.EMAIL_ADDRESS), user.getEmailAddress(),
            attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.FULL_NAME), user.getFullName(), attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.FIRST_NAME), user.getFirstName(),
            attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.MIDDLE_NAME), user.getMiddleName(),
            attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.LAST_NAME), user.getLastName(), attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.JOB_TITLE), user.getJobTitle(), attributes);
    addAttributeMapping(userMappings.getProperty(UserConverterKeys.PORTRAIT), getUserPortrait(user),
            attributes);

    return attributes;
}