Search in sources :

Example 1 with DirectCOSDefinition

use of com.iplanet.ums.cos.DirectCOSDefinition in project OpenAM by OpenRock.

the class DirectoryServicesImpl method registerService.

/**
     * Register a service for an org or org unit policy to a profile
     * 
     * @param token
     *            token
     * @param orgDN
     *            DN of the org
     * @param serviceName
     *            Service Name
     */
public void registerService(SSOToken token, String orgDN, String serviceName) throws AMException, SSOException {
    try {
        // This returns a valid set only if the service has
        // Dynamic attributes
        Set attrNames = getServiceAttributesWithQualifier(token, serviceName);
        if ((attrNames != null) && !attrNames.isEmpty()) {
            PersistentObject po = UMSObject.getObjectHandle(token, new Guid(orgDN));
            DirectCOSDefinition dcos = createCOSDefinition(serviceName, attrNames);
            COSManager cm = COSManager.getCOSManager(token, po.getGuid());
            cm.addDefinition(dcos);
        }
    } catch (AccessRightsException e) {
        debug.error("DirectoryServicesImpl.registerService() " + "Insufficient access rights to register service: " + serviceName, e);
        throw new AMException(token, "460");
    } catch (EntryAlreadyExistsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.registerService() " + "Service " + serviceName + " already registered", e);
        }
        Object[] args = { serviceName };
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("464", args, locale), "464", args);
    } catch (SMSException e) {
        debug.error("DirectoryServicesImpl.registerService() Unable to " + "register service: " + serviceName, e);
        throw new AMException(token, "914");
    } catch (UMSException e) {
        debug.error("DirectoryServicesImpl.registerService() Unable to " + "register service: " + serviceName, e);
        throw new AMException(token, "914", e);
    }
}
Also used : DirectCOSDefinition(com.iplanet.ums.cos.DirectCOSDefinition) AccessRightsException(com.iplanet.ums.AccessRightsException) 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) UMSException(com.iplanet.ums.UMSException) SMSException(com.sun.identity.sm.SMSException) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) COSManager(com.iplanet.ums.cos.COSManager) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException)

Example 2 with DirectCOSDefinition

use of com.iplanet.ums.cos.DirectCOSDefinition in project OpenAM by OpenRock.

the class DirectoryServicesImpl method unRegisterService.

// Rename from removeService to unRegisterService
/**
     * Un register service for a AMro profile.
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the profile whose service is to be removed
     * @param objectType
     *            profile type
     * @param serviceName
     *            Service Name
     * @param type
     *            Template type
     */
public void unRegisterService(SSOToken token, String entryDN, int objectType, String serviceName, int type) throws AMException {
    if (type == AMTemplate.DYNAMIC_TEMPLATE) {
        // TODO:change "cn" to fleasible naming attribute for AMObject.ROLE
        try {
            PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
            COSManager cm = null;
            // COS Definition to obtaint depends on different profile type
            switch(objectType) {
                case AMObject.ROLE:
                case AMObject.FILTERED_ROLE:
                    cm = COSManager.getCOSManager(token, po.getParentGuid());
                    break;
                case AMObject.ORGANIZATION:
                case AMObject.ORGANIZATIONAL_UNIT:
                case AMObject.PEOPLE_CONTAINER:
                    cm = COSManager.getCOSManager(token, po.getGuid());
                    break;
                default:
                    // does not have COS
                    throw new AMException(token, "450");
            }
            DirectCOSDefinition dcos;
            try {
                dcos = (DirectCOSDefinition) cm.getDefinition(serviceName);
            } catch (COSNotFoundException e) {
                if (debug.messageEnabled()) {
                    debug.message("DirectoryServicesImpl." + "unRegisterService() " + "No COSDefinition found for service: " + serviceName);
                }
                Object[] args = { serviceName };
                String locale = CommonUtils.getUserLocale(token);
                throw new AMException(AMSDKBundle.getString("463", args, locale), "463", args);
            }
            // Remove the COS Definition and Template
            dcos.removeCOSTemplates();
            cm.removeDefinition(serviceName);
        } catch (AccessRightsException e) {
            debug.error("DirectoryServicesImpl.unRegisterService() " + "Insufficient Access rights to unRegister service: ", e);
            throw new AMException(token, "460");
        } catch (UMSException e) {
            debug.error("DirectoryServicesImpl.unRegisterService: " + "Unable to unregister service ", e);
            throw new AMException(token, "855", e);
        }
    }
}
Also used : DirectCOSDefinition(com.iplanet.ums.cos.DirectCOSDefinition) AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) COSManager(com.iplanet.ums.cos.COSManager) COSNotFoundException(com.iplanet.ums.cos.COSNotFoundException)

Example 3 with DirectCOSDefinition

use of com.iplanet.ums.cos.DirectCOSDefinition 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 4 with DirectCOSDefinition

use of com.iplanet.ums.cos.DirectCOSDefinition in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createCOSDefinition.

/**
     * Create a COS Definition based on serviceID & attribute set & type. For
     * policy attribute, will set cosattribute to "override" For other
     * attribute, will set cosattribute to "default"
     */
private DirectCOSDefinition createCOSDefinition(String serviceID, Set attrNames) throws UMSException {
    // new attribute set
    AttrSet attrs = new AttrSet();
    // set naming attribute to the serviceID
    Attr attr = new Attr(ICOSDefinition.DEFAULT_NAMING_ATTR, serviceID);
    attrs.add(attr);
    // add cosspecifier
    attr = new Attr(ICOSDefinition.COSSPECIFIER, "nsrole");
    attrs.add(attr);
    // add cosattribute
    attr = new Attr(ICOSDefinition.COSATTRIBUTE);
    Iterator iter = attrNames.iterator();
    while (iter.hasNext()) {
        String attrName = (String) iter.next();
        attr.addValue(attrName);
    }
    attrs.add(attr);
    return new DirectCOSDefinition(attrs);
}
Also used : DirectCOSDefinition(com.iplanet.ums.cos.DirectCOSDefinition) Iterator(java.util.Iterator) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Aggregations

DirectCOSDefinition (com.iplanet.ums.cos.DirectCOSDefinition)4 AMException (com.iplanet.am.sdk.AMException)3 AttrSet (com.iplanet.services.ldap.AttrSet)3 AccessRightsException (com.iplanet.ums.AccessRightsException)3 Guid (com.iplanet.ums.Guid)3 PersistentObject (com.iplanet.ums.PersistentObject)3 UMSException (com.iplanet.ums.UMSException)3 COSManager (com.iplanet.ums.cos.COSManager)3 Attr (com.iplanet.services.ldap.Attr)2 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)2 COSNotFoundException (com.iplanet.ums.cos.COSNotFoundException)2 SMSException (com.sun.identity.sm.SMSException)2 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)1 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 AMInvalidDNException (com.iplanet.am.sdk.AMInvalidDNException)1 AMPreCallBackException (com.iplanet.am.sdk.AMPreCallBackException)1 SSOException (com.iplanet.sso.SSOException)1 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)1 InvalidSearchFilterException (com.iplanet.ums.InvalidSearchFilterException)1 SizeLimitExceededException (com.iplanet.ums.SizeLimitExceededException)1