Search in sources :

Example 41 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class TemplateManager method toCreationTemplate.

/**
     * Reads in a attribute set and converts name-value pairs to a
     * CreationTemplate object.
     * 
     * @param t
     *            attribute set contains template values
     * @return CreationTemplate object based on the name-value pairs
     */
private CreationTemplate toCreationTemplate(AttrSet t) {
    Attr nameAttr = t.getAttribute(TEMPLATE_NAME);
    String name = null;
    if (nameAttr != null) {
        name = nameAttr.getValue();
    }
    Attr namingAttr = t.getAttribute(TEMPLATE_NAMINGATTRIBUTE);
    String namingAttribute = null;
    if (namingAttr != null) {
        namingAttribute = namingAttr.getValue();
    }
    Attr classAttr = t.getAttribute(TEMPLATE_JAVACLASS);
    String[] classNames = null;
    if (classAttr != null) {
        classNames = classAttr.getStringValues();
    }
    AttrSet required = decodeAttr(t.getAttribute(TEMPLATE_REQUIRED), "=");
    AttrSet optional = decodeAttr(t.getAttribute(TEMPLATE_OPTIONAL), "=");
    AttrSet validated = decodeAttr(t.getAttribute(TEMPLATE_VALIDATED), "=");
    CreationTemplate template = new CreationTemplate();
    ArrayList classes = new ArrayList();
    try {
        if (classNames != null) {
            for (int i = 0; i < classNames.length; i++) {
                Class cls = Class.forName(classNames[i]);
                classes.add(cls);
            }
        }
        template = new CreationTemplate(name, required, optional, classes);
    } catch (ClassNotFoundException e) {
        template = new CreationTemplate(name, required, optional);
    }
    if (validated != null) {
        template.setValidation(validated);
    }
    if (namingAttribute != null) {
        template.setNamingAttribute(namingAttribute);
    }
    return template;
}
Also used : ArrayList(java.util.ArrayList) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 42 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createGroup.

private void createGroup(SSOToken token, PersistentObject parentObj, Map attributes, String profileName) throws UMSException, AMException {
    // Invoke the Pre Processing plugin
    String orgDN = getOrganizationDN(internalToken, parentObj.getDN());
    String entryDN = getNamingAttribute(AMObject.GROUP) + "=" + profileName + "," + parentObj.getDN();
    attributes = callBackHelper.preProcess(token, entryDN, orgDN, null, attributes, CallBackHelper.CREATE, AMObject.GROUP, false);
    AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
    makeNamingFirst(attrSet, getNamingAttribute(AMObject.GROUP), profileName);
    TemplateManager tempMgr = TemplateManager.getTemplateManager();
    CreationTemplate creationTemp = tempMgr.getCreationTemplate("BasicGroup", new Guid(orgDN), TemplateManager.SCOPE_ANCESTORS);
    attrSet = combineOCs(creationTemp, attrSet);
    com.iplanet.ums.StaticGroup sgroup = new com.iplanet.ums.StaticGroup(creationTemp, attrSet);
    parentObj.addChild(sgroup);
    Attr um = attrSet.getAttribute(UNIQUE_MEMBER_ATTRIBUTE);
    if (um != null) {
        String[] values = um.getStringValues();
        Set members = new HashSet();
        members.addAll(Arrays.asList(values));
        updateUserAttribute(token, members, sgroup.getDN(), true);
    }
    // Invoke Post processing impls
    callBackHelper.postProcess(token, sgroup.getDN(), orgDN, null, attributes, CallBackHelper.CREATE, AMObject.GROUP, false);
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) Guid(com.iplanet.ums.Guid) StaticGroup(com.iplanet.ums.StaticGroup) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet) CreationTemplate(com.iplanet.ums.CreationTemplate) StaticGroup(com.iplanet.ums.StaticGroup) TemplateManager(com.iplanet.ums.TemplateManager) HashSet(java.util.HashSet)

Example 43 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class DirectoryServicesImpl method getDCTreeAttributes.

/**
     * Gets the attributes for this entryDN from the corresponding DC Tree node.
     * The attributes are fetched only for Organization entries in DC tree mode.
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the dn of the entry
     * @param attrNames
     *            attribute names
     * @param byteValues
     *            <code>true</code> if result in byte
     * @param objectType
     *            the object type.
     * @return an AttrSet of values or null if not found
     * @throws AMException
     *             if error encountered in fetching the DC node attributes.
     */
public Map getDCTreeAttributes(SSOToken token, String entryDN, Set attrNames, boolean byteValues, int objectType) throws AMException, SSOException {
    // Already an RFC String
    String rootDN = AMStoreConnection.getAMSdkBaseDN();
    if (dcTreeImpl.isRequired() && (objectType == AMObject.ORGANIZATION) && (!LDAPUtils.formatToRFC(entryDN).equalsIgnoreCase(rootDN))) {
        String dcNode = dcTreeImpl.getCanonicalDomain(internalToken, entryDN);
        if (dcNode != null) {
            String[] names = (attrNames == null ? null : (String[]) attrNames.toArray(new String[attrNames.size()]));
            AttrSet dcAttrSet = dcTreeImpl.getDomainAttributes(internalToken, entryDN, names);
            return CommonUtils.attrSetToMap(dcAttrSet, byteValues);
        }
    }
    return null;
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet)

Example 44 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createAMTemplate.

/**
     * Create an AMTemplate (COSTemplate)
     * 
     * @param token
     *            token
     * @param entryDN
     *            DN of the profile whose template is to be set
     * @param objectType
     *            the entry type
     * @param serviceName
     *            Service Name
     * @param attributes
     *            attributes to be set
     * @param priority
     *            template priority
     * @return String DN of the newly created template
     */
public String createAMTemplate(SSOToken token, String entryDN, int objectType, String serviceName, Map attributes, int priority) throws AMException {
    // TBD, each time a Org/PC is created, need to create default role
    COSManager cm = null;
    DirectCOSDefinition dCOS = null;
    String roleDN = null;
    // TBD, change "cn" to flesible naming attrsibute for AMObject.ROLE
    try {
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        // get COS Definition depends on different profile type
        switch(objectType) {
            case AMObject.ROLE:
            case AMObject.FILTERED_ROLE:
                roleDN = entryDN;
                cm = COSManager.getCOSManager(token, po.getParentGuid());
                dCOS = (DirectCOSDefinition) cm.getDefinition(serviceName);
                break;
            case AMObject.ORGANIZATION:
            case AMObject.ORGANIZATIONAL_UNIT:
            case AMObject.PEOPLE_CONTAINER:
                roleDN = "cn=" + CONTAINER_DEFAULT_TEMPLATE_ROLE + "," + entryDN;
                cm = COSManager.getCOSManager(token, po.getGuid());
                dCOS = (DirectCOSDefinition) cm.getDefinition(serviceName);
                break;
            default:
                // does not have COS
                throw new AMException(token, "450");
        }
        // add template priority
        AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
        if (priority != AMTemplate.UNDEFINED_PRIORITY) {
            Attr attr = new Attr("cospriority");
            attr.addValue("" + priority);
            attrSet.add(attr);
        }
        COSTemplate template = createCOSTemplate(serviceName, attrSet, roleDN);
        dCOS.addCOSTemplate(template);
        return template.getGuid().toString();
    } catch (COSNotFoundException e) {
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.createAMTemplate() " + "COSDefinition for service: " + serviceName + " not found: ", e);
        }
        Object[] args = { serviceName };
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("459", locale), "459", args);
    } catch (EntryAlreadyExistsException e) {
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.createAMTemplate: template " + "already exists for " + serviceName, e);
        }
        String[] params = { serviceName };
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("854", params, locale), "854", params);
    } catch (AccessRightsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createAMTemplate() " + "Insufficient access rights to create template for: " + serviceName + " & entryDN: " + entryDN, e);
        }
        throw new AMException(token, "460");
    } catch (UMSException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createAMTemplate() Unable" + " to create AMTemplate for: " + serviceName + " & entryDN: " + entryDN, e);
        }
        Object[] args = { serviceName };
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("459", locale), "459", args, e);
    } catch (Exception e) {
        if (debug.warningEnabled())
            debug.warning("DirectoryServicesImpl.createAMTemplate", e);
        throw new AMException(token, "451");
    }
}
Also used : AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) COSTemplate(com.iplanet.ums.cos.COSTemplate) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException) Attr(com.iplanet.services.ldap.Attr) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException) UMSException(com.iplanet.ums.UMSException) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) SizeLimitExceededException(com.iplanet.ums.SizeLimitExceededException) AMInvalidDNException(com.iplanet.am.sdk.AMInvalidDNException) TimeLimitExceededException(com.iplanet.ums.TimeLimitExceededException) SSOException(com.iplanet.sso.SSOException) AccessRightsException(com.iplanet.ums.AccessRightsException) LdapException(org.forgerock.opendj.ldap.LdapException) InvalidSearchFilterException(com.iplanet.ums.InvalidSearchFilterException) SMSException(com.sun.identity.sm.SMSException) AMException(com.iplanet.am.sdk.AMException) AMPreCallBackException(com.iplanet.am.sdk.AMPreCallBackException) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) COSNotFoundException(com.iplanet.ums.cos.COSNotFoundException) AttrSet(com.iplanet.services.ldap.AttrSet) DirectCOSDefinition(com.iplanet.ums.cos.DirectCOSDefinition) COSManager(com.iplanet.ums.cos.COSManager) COSNotFoundException(com.iplanet.ums.cos.COSNotFoundException)

Example 45 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class DirectoryServicesImpl method getAttributes.

/**
     * Gets all attributes corresponding to the entryDN. This method obtains the
     * DC Tree node attributes and also performs compliance related verification
     * checks in compliance mode. Note: In compliance mode you can skip the
     * compliance checks by setting ignoreCompliance to "false".
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the DN of the entry whose attributes need to retrieved
     * @param ignoreCompliance
     *            a boolean value specificying if compliance related entries
     *            need to ignored or not. Ignored if true.
     * @return a Map containing attribute names as keys and Set of values
     *         corresponding to each key.
     * @throws AMException
     *             if an error is encountered in fetching the attributes
     */
public Map getAttributes(SSOToken token, String entryDN, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    try {
        // Obtain attributes from directory
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        AttrSet attrSet = po.getAttributes(po.getAttributeNames());
        /*
             * Add this 'dn' explicitly to the result set and return. reason:
             * when queried with this entrydn/dn the lower level api/ ldapjdk
             * does not return this attribute, but returns other ones.
             */
        attrSet.add(new Attr("dn", entryDN));
        attrSet.add(new Attr("entryDN", entryDN));
        // Perform Compliance related checks
        checkComplianceAttributes(attrSet, ignoreCompliance);
        AMHashMap attributes = (AMHashMap) CommonUtils.attrSetToMap(attrSet, byteValues);
        Map dcAttributes = getDCTreeAttributes(token, entryDN, null, byteValues, profileType);
        attributes.copy(dcAttributes);
        return attributes;
    } catch (IllegalArgumentException ie) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.getAttributes(): " + "Unable to get attributes: ", ie);
        }
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("330", locale), "330");
    } catch (UMSException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.getAttributes(): " + "Unable to get attributes: ", e);
        }
        // Extract the ldap error code from Exception
        throw new AMException(token, "330", e);
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) AMHashMap(com.iplanet.am.sdk.AMHashMap) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Aggregations

AttrSet (com.iplanet.services.ldap.AttrSet)61 Attr (com.iplanet.services.ldap.Attr)33 Guid (com.iplanet.ums.Guid)19 Iterator (java.util.Iterator)16 Set (java.util.Set)14 UMSException (com.iplanet.ums.UMSException)13 AMException (com.iplanet.am.sdk.AMException)12 CreationTemplate (com.iplanet.ums.CreationTemplate)12 TemplateManager (com.iplanet.ums.TemplateManager)12 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 PersistentObject (com.iplanet.ums.PersistentObject)6 SSOException (com.iplanet.sso.SSOException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 AccessRightsException (com.iplanet.ums.AccessRightsException)3 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)3