Search in sources :

Example 36 with AttrSet

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

the class CallBackHelper method postProcess.

// TODO: Remove this. Use the Maps interface only
public void postProcess(SSOToken token, String entryDN, String orgDN, AttrSet oldAttrSet, AttrSet newAttrSet, int operation, int objectType, boolean softDelete) throws AMException {
    // Use the external impls instantiated at the time of pre-processing
    Set implSet = getPrePostImpls(orgDN);
    if ((implSet != null) && (!implSet.isEmpty())) {
        Map newAttrMap = CommonUtils.attrSetToMap(newAttrSet);
        Map oldAttrMap = CommonUtils.attrSetToMap(oldAttrSet);
        // Iterate through the Pre-Processing Impls and execute
        Iterator itr = implSet.iterator();
        while (itr.hasNext()) {
            String className = (String) itr.next();
            AMCallBack impl = getCallBackObject(className);
            if (impl == null) {
                continue;
            }
            try {
                switch(operation) {
                    case CREATE:
                        impl.postProcessCreate(token, entryDN, newAttrMap, objectType);
                        break;
                    case MODIFY:
                        impl.postProcessModify(token, entryDN, oldAttrMap, newAttrMap, objectType);
                        break;
                    case DELETE:
                        impl.postProcessDelete(token, entryDN, oldAttrMap, softDelete, objectType);
                        break;
                }
            } catch (AMException ae) {
                // Exception thrown by the external impl
                debug.error("CallBackHelper.postProcess(): Preprocessing" + "impl " + impl.getClass().getName() + " exception thrown: ", ae);
            }
        }
    }
}
Also used : AMCallBack(com.iplanet.am.sdk.AMCallBack) AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) Iterator(java.util.Iterator) AMException(com.iplanet.am.sdk.AMException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with AttrSet

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

the class COSManager method assignDirectCOSDef.

/**
     * Assigns a direct (Classic) COS definition to a persistent object.
     * 
     * @param pObject
     *            The target persistent object.
     * @param cosDef
     *            The direct (Classic) COS definition.
     * @param cosTemplate
     *            A COS template belonging to the definition.
     * @param sMgr
     *            A SchemaManager instance.
     * 
     * @throws UMSException
     *             if an exception occurs
     */
private void assignDirectCOSDef(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
    //
    if (cosDef.getGuid() == null) {
        String msg = i18n.getString(IUMSConstants.COS_DEFINITION_NOT_PERSISTENT);
        throw new UMSException(msg);
    }
    // Make sure target entry is in same tree as COS Def parent.
    //
    DN targetDN = DN.valueOf(pObject.getGuid().getDn());
    DN cosParentDN = DN.valueOf(cosDef.getParentGuid().getDn());
    if (!(targetDN.isInScopeOf(cosParentDN, SearchScope.SUBORDINATES))) {
        String msg = i18n.getString(IUMSConstants.COS_TARGET_OBJECT_DIFFERENT_TREE);
        throw new UMSException(msg);
    }
    //
    if (cosDef.getCOSSpecifier().equalsIgnoreCase("nsrole"))
        return;
    ArrayList aList;
    AttrSet attrSet = new AttrSet();
    // Get cosSpecifier object class - should only be one.
    // Update the target entry with cosSpecifier object class.
    // Only add it if it doesn't already exist.
    //
    aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
    String cosSpecObjectClass = (String) aList.get(0);
    if (!objectClassExists(cosSpecObjectClass, pObject)) {
        attrSet.add(new Attr("objectclass", cosSpecObjectClass));
    }
    // Get the cos attributes from the definition (ex. mailquota).
    // For each of the attributes, get the objectclass. These
    // will be used to attach to the target entry. This is only
    // done if the cos attribute qualifier is not "operational"
    // (you don't need to add cos attribute object classes for
    // "operational" cos attribute qualifier.
    //
    String[] cosAttributes = cosDef.getCOSAttributes();
    String qualifier = null;
    Arrays.asList(ICOSDefinition.qualifiers);
    Attr attr = cosTemplate.getAttribute("objectclass");
    String[] cosTempObjClasses = attr.getStringValues();
    for (int i = 0; i < cosAttributes.length; i++) {
        StringTokenizer st = new StringTokenizer(cosAttributes[i]);
        st.nextToken();
        qualifier = st.nextToken();
        if ((!qualifier.equals(ICOSDefinition.qualifiers[ICOSDefinition.OPERATIONAL]))) {
            for (int j = 0; j < cosTempObjClasses.length; j++) {
                if (!cosTempObjClasses[j].equalsIgnoreCase("top") && !cosTempObjClasses[j].equalsIgnoreCase("costemplate") && !objectClassExists(cosTempObjClasses[j], pObject)) {
                    if (!attrSet.contains("objectclass", cosTempObjClasses[j])) {
                        attrSet.add(new Attr("objectclass", cosTempObjClasses[j]));
                    }
                }
            }
        }
    }
    //
    if (pObject.getAttribute(cosDef.getCOSSpecifier()) == null)
        attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
    if (attrSet.size() > 0) {
        pObject.modify(toModifications(ModificationType.ADD, attrSet));
        pObject.save();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) UMSException(com.iplanet.ums.UMSException) ArrayList(java.util.ArrayList) DN(org.forgerock.opendj.ldap.DN) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 38 with AttrSet

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

the class TemplateManager method replaceCreationTemplate.

/**
     * Replaces an existing CreationTemplate with the one specified.
     * 
     * @param template
     *            CreationTemplate to be modified
     * @param orgGuid
     *            the guid of the Organization where the config data is stored
     * @throws UMSException
     *             if an exception occurs
     */
public void replaceCreationTemplate(CreationTemplate template, Guid orgGuid) throws UMSException {
    if (template == null) {
        return;
    }
    String templateName = template.getName();
    if (templateName == null) {
        String msg = i18n.getString(IUMSConstants.MISSING_TEMPL_NAME);
        throw new IllegalArgumentException(msg);
    }
    AttrSet attrSet = toAttrSet(template);
    try {
        m_configManager.replaceCreationTemplate(orgGuid, templateName, attrSet);
    } catch (ConfigManagerException e) {
        throw new UMSException(e.getMessage());
    }
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet)

Example 39 with AttrSet

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

the class TemplateManager method decodeAttr.

/**
     * Decode single attribute with multiple values into an AttrSet. For
     * example:
     * 
     * <pre>
     *    Attribute:
     *       required: objectclass=top
     *       required: objectclass=groupofuniquenames
     *       required: cn
     *       required: sn
     *  
     *    Attribute Set:
     *       objectclass: top
     *       objectclass: groupofuniquenames
     *       cn:
     *       sn:
     * </pre>
     * 
     * @param attr
     *            Attribute to be decoded from
     * @param delimiter
     *            Delimiter used in the encoding
     * @return Decoded attribute set
     */
private AttrSet decodeAttr(Attr attr, String delimiter) {
    if (attr == null)
        return null;
    String[] values = attr.getStringValues();
    AttrSet attrSet = new AttrSet();
    for (int i = 0, size = attr.size(); i < size; i++) {
        String value = values[i];
        String attrName = null;
        String attrValue = null;
        int index = value.indexOf('=');
        if (index < 0) {
            attrName = value;
        } else {
            attrName = value.substring(0, index);
            attrValue = value.substring(index + 1, value.length());
        }
        if (attrValue != null && attrValue.length() != 0) {
            attrSet.add(new Attr(attrName, attrValue));
        } else {
            attrSet.add(new Attr(attrName));
        }
    }
    return attrSet;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 40 with AttrSet

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

the class TemplateManager method toSearchTemplate.

/**
     * Reads in a attribute set and converts name-value pairs to a
     * SearchTemplate object.
     * 
     * @param t
     *            attribute set contains template values
     * @return SearchTemplate object based on the name-value pairs
     */
private SearchTemplate toSearchTemplate(AttrSet t) {
    Attr nameAttr = t.getAttribute(TEMPLATE_NAME);
    String name = null;
    if (nameAttr != null) {
        name = nameAttr.getValue();
    }
    Attr filterAttr = t.getAttribute(SCHEMA2_SEARCH_FILTER);
    if (filterAttr == null) {
        filterAttr = t.getAttribute(TEMPLATE_SEARCH_FILTER);
    }
    String filter = null;
    if (filterAttr != null) {
        filter = filterAttr.getValue();
    }
    AttrSet attrSet = decodeAttr(t.getAttribute(TEMPLATE_ATTRS), "=");
    SearchTemplate template = new SearchTemplate();
    template = new SearchTemplate(name, attrSet, filter);
    return template;
}
Also used : 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