Search in sources :

Example 56 with AMException

use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method getAttributesFromDS.

/**
     * Gets the specific 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 attrNames
     *            a Set of names of the attributes that need to be retrieved.
     *            The attrNames should not be null.
     * @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 getAttributesFromDS(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    if (attrNames == null) {
        return getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
    }
    try {
        // Convert the attrNames to String[]
        String[] names = (String[]) attrNames.toArray(new String[attrNames.size()]);
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        // Perform compliance related checks
        AttrSet attrSet;
        if (!ignoreCompliance && ComplianceServicesImpl.isComplianceUserDeletionEnabled()) {
            // check for deleted user by getting complaince attributes
            attrSet = complianceImpl.verifyAndGetAttributes(po, names);
        } else {
            attrSet = po.getAttributes(names);
        }
        AMHashMap attributes = (AMHashMap) CommonUtils.attrSetToMap(attrSet, byteValues);
        // Obtain DC tree attributes if applicable            
        Map dcAttributes = getDCTreeAttributes(token, entryDN, attrNames, byteValues, profileType);
        attributes.copy(dcAttributes);
        return attributes;
    } 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) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 57 with AMException

use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.

the class CallBackHelper method preProcess.

public Map preProcess(SSOToken token, String entryDN, String orgDN, Map oldAttrMap, Map newAttrMap, int operation, int objectType, boolean softDelete) throws AMException {
    Set implSet = getPrePostImpls(orgDN);
    if (implSet != null && !implSet.isEmpty()) {
        // Post processing impls present
        // 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 {
                Map map;
                switch(operation) {
                    case CREATE:
                        map = impl.preProcessCreate(token, entryDN, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case MODIFY:
                        map = impl.preProcessModify(token, entryDN, oldAttrMap, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case DELETE:
                        impl.preProcessDelete(token, entryDN, oldAttrMap, softDelete, objectType);
                        break;
                }
            } catch (AMException ae) {
                // Exception thrown by the external impl
                debug.error("CallBackHelper.preProcess(): Preprocessing" + "impl " + className + " exception thrown by impl:", ae);
                throw ae;
            }
        }
        return newAttrMap;
    }
    // not null as newAttrSet will be the latest one needed for updation
    return ((newAttrMap != null) ? newAttrMap : oldAttrMap);
}
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 58 with AMException

use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.

the class CallBackHelper method preProcess.

// TODO: Remove this. Use the Maps interface only
public AttrSet preProcess(SSOToken token, String entryDN, String orgDN, AttrSet oldAttrSet, AttrSet newAttrSet, int operation, int objectType, boolean softDelete) throws AMException {
    Set implSet = getPrePostImpls(orgDN);
    if (implSet != null && !implSet.isEmpty()) {
        // Post processing impls present
        // Iterate through the Pre-Processing Impls and execute
        Iterator itr = implSet.iterator();
        Map newAttrMap = CommonUtils.attrSetToMap(newAttrSet);
        Map oldAttrMap = CommonUtils.attrSetToMap(oldAttrSet);
        while (itr.hasNext()) {
            String className = (String) itr.next();
            AMCallBack impl = getCallBackObject(className);
            if (impl == null) {
                continue;
            }
            try {
                Map map;
                switch(operation) {
                    case CREATE:
                        map = impl.preProcessCreate(token, entryDN, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case MODIFY:
                        map = impl.preProcessModify(token, entryDN, oldAttrMap, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case DELETE:
                        impl.preProcessDelete(token, entryDN, oldAttrMap, softDelete, objectType);
                        break;
                }
            } catch (AMException ae) {
                // Exception thrown by the external impl
                debug.error("CallBackHelper.preProcess(): Preprocessing" + "impl " + className + " exception thrown by impl:", ae);
                throw ae;
            }
        }
        return CommonUtils.mapToAttrSet(newAttrMap);
    }
    // not null as newAttrSet will be the latest one needed for updation
    return ((newAttrSet != null) ? newAttrSet : oldAttrSet);
}
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 59 with AMException

use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.

the class CallBackHelper method postProcess.

public void postProcess(SSOToken token, String entryDN, String orgDN, Map oldAttrMap, Map newAttrMap, 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())) {
        // 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)

Example 60 with AMException

use of com.iplanet.am.sdk.AMException in project OpenAM by OpenRock.

the class OrgConfigViaAMSDK method setAttributes.

/**
     * Sets attributes to AMSDK Organization. The organziation attribute names
     * are defined in the IdRepo service.
     */
void setAttributes(Map attributes) throws SMSException {
    Map amsdkAttrs = null;
    // These attributes must be defined in ../idm/xml/idRepoService.xml
    if (attributes != null && !attributes.isEmpty()) {
        Map smsIdRepoAttrs = new CaseInsensitiveHashMap(attributes);
        // Iterate through the attribute mappings
        Map attrs = getAttributeMapping();
        Map existingAttributes = getAttributes();
        if (attrs != null && !attrs.isEmpty()) {
            for (Iterator items = attrs.keySet().iterator(); items.hasNext(); ) {
                String key = (String) items.next();
                Set value = (Set) smsIdRepoAttrs.get(key);
                if (value != null) {
                    if (amsdkAttrs == null) {
                        amsdkAttrs = new HashMap();
                    }
                    boolean notEmptyFlg = false;
                    if (!value.isEmpty()) {
                        for (Iterator iter = value.iterator(); iter.hasNext(); ) {
                            String val = (String) iter.next();
                            // Avoid empty string storage.
                            if (val.length() > 0) {
                                notEmptyFlg = true;
                            }
                        }
                        if (notEmptyFlg) {
                            amsdkAttrs.put(attrs.get(key), value);
                        }
                    } else {
                        Set existingValues = (Set) existingAttributes.get(key);
                        if (existingValues != null && !existingValues.isEmpty()) {
                            amsdkAttrs.put(attrs.get(key), value);
                        }
                    }
                }
            }
        }
    }
    // Update the organization entry
    if (amsdkAttrs != null) {
        try {
            parentOrg.setAttributes(amsdkAttrs);
            parentOrg.store();
        } catch (AMException ame) {
            if (debug.messageEnabled()) {
                debug.message("OrgConfigViaAMSDK::createSub" + "Organization: failed with AMException", ame);
            }
            throw (new SMSException(AMSDKBundle.BUNDLE_NAME, ame.getMessage(), ame, ame.getMessage()));
        } catch (SSOException ssoe) {
            throw (new SMSException(bundle.getString("sms-INVALID_SSO_TOKEN"), ssoe, "sms-INVALID_SSO_TOKEN"));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Iterator(java.util.Iterator) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Aggregations

AMException (com.iplanet.am.sdk.AMException)127 SSOException (com.iplanet.sso.SSOException)56 Set (java.util.Set)35 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)34 Guid (com.iplanet.ums.Guid)33 UMSException (com.iplanet.ums.UMSException)33 Map (java.util.Map)33 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)32 RemoteException (java.rmi.RemoteException)31 AttrSet (com.iplanet.services.ldap.AttrSet)28 HashSet (java.util.HashSet)28 HashMap (java.util.HashMap)26 Iterator (java.util.Iterator)22 PersistentObject (com.iplanet.ums.PersistentObject)20 SSOToken (com.iplanet.sso.SSOToken)14 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)13 AMHashMap (com.iplanet.am.sdk.AMHashMap)12 AccessRightsException (com.iplanet.ums.AccessRightsException)12 SMSException (com.sun.identity.sm.SMSException)12 DN (org.forgerock.opendj.ldap.DN)12