Search in sources :

Example 1 with EntryAlreadyExistsException

use of com.iplanet.ums.EntryAlreadyExistsException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createUser.

/**
     * Method to create a user entry
     */
private void createUser(SSOToken token, PersistentObject parentObj, Map attributes, String profileName) throws UMSException, AMEntryExistsException, AMException {
    String orgDN = getOrganizationDN(internalToken, parentObj.getDN());
    // Invoke the Pre Processing plugin
    String entryDN = getNamingAttribute(AMObject.USER) + "=" + profileName + "," + parentObj.getDN();
    attributes = callBackHelper.preProcess(token, entryDN, orgDN, null, attributes, CallBackHelper.CREATE, AMObject.USER, false);
    AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
    makeNamingFirst(attrSet, getNamingAttribute(AMObject.USER), profileName);
    // Invoke the user password validation plugin
    UserPasswordValidationHelper pluginImpl = new UserPasswordValidationHelper(token, orgDN);
    try {
        pluginImpl.validate(CommonUtils.attrSetToMap(attrSet));
    } catch (AMException ame) {
        debug.error("DirectoryServicesImpl.createUser(): Invalid " + "characters for user", ame);
        throw ame;
    }
    TemplateManager tempMgr = TemplateManager.getTemplateManager();
    CreationTemplate creationTemp = tempMgr.getCreationTemplate("BasicUser", new Guid(orgDN), TemplateManager.SCOPE_ANCESTORS);
    attrSet = combineOCs(creationTemp, attrSet);
    // User user = new User(creationTemp, attrSet);
    PersistentObject user = new PersistentObject(creationTemp, attrSet);
    try {
        parentObj.addChild(user);
    } catch (AccessRightsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createUser(): Insufficient " + "Access rights to create user", e);
        }
        throw new AMException(token, "460");
    } catch (EntryAlreadyExistsException ee) {
        if (ComplianceServicesImpl.isComplianceUserDeletionEnabled()) {
            // COMPLIANCE
            // If the existing entry is marked for deletion, then
            // the error message should be different.
            complianceImpl.checkIfDeletedUser(token, user.getDN());
        }
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createUser() User " + "already exists: ", ee);
        }
        throw new AMEntryExistsException(token, "328", ee);
    } catch (UMSException ue) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createUser(): Internal " + "Error occurred. Unable to create User Entry", ue);
        }
        processInternalException(token, ue, "324");
    }
    // Invoke Post processing impls
    callBackHelper.postProcess(token, user.getDN(), orgDN, null, attributes, CallBackHelper.CREATE, AMObject.USER, false);
    // TODO: REMOVE after Portal moves to new API's
    AMUserEntryProcessed postPlugin = getUserPostPlugin();
    if (postPlugin != null) {
        Map attrMap = CommonUtils.attrSetToMap(attrSet);
        postPlugin.processUserAdd(token, user.getDN(), attrMap);
    }
    EmailNotificationHelper mailerObj = new EmailNotificationHelper(user.getDN());
    mailerObj.setUserCreateNotificationList();
    mailerObj.sendUserCreateNotification(attributes);
}
Also used : AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) AMException(com.iplanet.am.sdk.AMException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException) AttrSet(com.iplanet.services.ldap.AttrSet) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) CreationTemplate(com.iplanet.ums.CreationTemplate) TemplateManager(com.iplanet.ums.TemplateManager) AMUserEntryProcessed(com.iplanet.am.sdk.AMUserEntryProcessed) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 2 with EntryAlreadyExistsException

use of com.iplanet.ums.EntryAlreadyExistsException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createEntity.

/**
     * Method to create a user entry
     */
private void createEntity(SSOToken token, PersistentObject parentObj, int objectType, Map attributes, String profileName) throws UMSException, AMEntryExistsException, AMException {
    String orgDN = getOrganizationDN(internalToken, parentObj.getDN());
    // Invoke the Pre Processing plugin
    AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
    makeNamingFirst(attrSet, getNamingAttribute(objectType), profileName);
    String ctName = getCreationTemplateName(objectType);
    if (ctName == null) {
        // Create a user if no CT defined.
        ctName = "BasicUser";
    }
    TemplateManager tempMgr = TemplateManager.getTemplateManager();
    CreationTemplate creationTemp = tempMgr.getCreationTemplate(ctName, new Guid(orgDN), TemplateManager.SCOPE_ANCESTORS);
    attrSet = combineOCs(creationTemp, attrSet);
    PersistentObject user = new PersistentObject(creationTemp, attrSet);
    try {
        parentObj.addChild(user);
    } catch (AccessRightsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntity():" + " Insufficient Access rights to create entity", e);
        }
        throw new AMException(token, "460");
    } catch (EntryAlreadyExistsException ee) {
        if (ComplianceServicesImpl.isComplianceUserDeletionEnabled()) {
            // COMPLIANCE
            // If the existing entry is marked for deletion, then
            // the error message should be different.
            complianceImpl.checkIfDeletedUser(token, user.getDN());
        }
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntity() Entity " + "already exists: ", ee);
        }
        throw new AMEntryExistsException(token, "462", ee);
    } catch (UMSException ue) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntity(): Internal " + "Error occurred. Unable to create User Entry", ue);
        }
        processInternalException(token, ue, "324");
    }
}
Also used : CreationTemplate(com.iplanet.ums.CreationTemplate) AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) TemplateManager(com.iplanet.ums.TemplateManager) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException) AttrSet(com.iplanet.services.ldap.AttrSet) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException)

Example 3 with EntryAlreadyExistsException

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

use of com.iplanet.ums.EntryAlreadyExistsException 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 5 with EntryAlreadyExistsException

use of com.iplanet.ums.EntryAlreadyExistsException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method createEntry.

/**
     * Create an entry in the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryName
     *            name of the entry (naming value), e.g. "sun.com", "manager"
     * @param objectType
     *            Profile Type, ORGANIZATION, AMObject.ROLE, AMObject.USER, etc.
     * @param parentDN
     *            the parent DN
     * @param attributes
     *            the initial attribute set for creation
     */
public void createEntry(SSOToken token, String entryName, int objectType, String parentDN, Map attributes) throws AMEntryExistsException, AMException, SSOException {
    try {
        if (entryName == null || entryName.length() == 0) {
            throw new AMException(token, "320");
        } else if (parentDN == null) {
            throw new AMException(token, "322");
        }
        // tmpDN to be used only when validating since the method
        // expects a DN.
        String tmpDN = getNamingAttribute(objectType) + "=" + entryName + "," + parentDN;
        validateAttributeUniqueness(tmpDN, objectType, true, attributes);
        // Get handle to the parent object
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(parentDN));
        switch(objectType) {
            case AMObject.USER:
                createUser(token, po, attributes, entryName);
                break;
            case AMObject.MANAGED_ROLE:
            case // same as MANAGED ROLE
            AMObject.ROLE:
                createRole(token, po, attributes, entryName);
                break;
            case AMObject.ORGANIZATION:
                createOrganization(token, po, attributes, entryName);
                break;
            case AMObject.STATIC_GROUP:
            case AMObject.GROUP:
                createGroup(token, po, attributes, entryName);
                break;
            case AMObject.ASSIGNABLE_DYNAMIC_GROUP:
                createAssignDynamicGroup(token, po, attributes, entryName);
                break;
            case AMObject.DYNAMIC_GROUP:
                createDynamicGroup(token, po, attributes, entryName);
                break;
            case AMObject.PEOPLE_CONTAINER:
                createPeopleContainer(po, attributes, entryName);
                break;
            case AMObject.ORGANIZATIONAL_UNIT:
                createOrganizationalUnit(token, po, attributes, entryName);
                break;
            case AMObject.GROUP_CONTAINER:
                createGroupContainer(po, attributes, entryName);
                break;
            case AMObject.FILTERED_ROLE:
                createFilteredRole(token, po, attributes, entryName);
                break;
            case AMObject.RESOURCE:
                createResource(po, attributes, entryName);
                break;
            case AMObject.UNDETERMINED_OBJECT_TYPE:
            case AMObject.UNKNOWN_OBJECT_TYPE:
                throw new AMException(token, "326");
            default:
                // Supported generic type
                createEntity(token, po, objectType, attributes, entryName);
        }
    } catch (AccessRightsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntry() " + "Insufficient access rights to create entry: " + entryName, e);
        }
        throw new AMException(token, "460");
    } catch (EntryAlreadyExistsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntry() Entry: " + entryName + "already exists: ", e);
        }
        String msgid = getEntryExistsMsgID(objectType);
        String name = getEntryName(e);
        Object[] args = { name };
        throw new AMException(AMSDKBundle.getString(msgid, args), msgid, args);
    } catch (UMSException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.createEntry() Unable to " + "create entry: " + entryName, e);
        }
        throw new AMException(token, "324", e);
    }
}
Also used : AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) AMException(com.iplanet.am.sdk.AMException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) EntryAlreadyExistsException(com.iplanet.ums.EntryAlreadyExistsException)

Aggregations

AMException (com.iplanet.am.sdk.AMException)5 AccessRightsException (com.iplanet.ums.AccessRightsException)5 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)5 Guid (com.iplanet.ums.Guid)5 PersistentObject (com.iplanet.ums.PersistentObject)5 UMSException (com.iplanet.ums.UMSException)5 AttrSet (com.iplanet.services.ldap.AttrSet)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 CreationTemplate (com.iplanet.ums.CreationTemplate)2 TemplateManager (com.iplanet.ums.TemplateManager)2 COSManager (com.iplanet.ums.cos.COSManager)2 DirectCOSDefinition (com.iplanet.ums.cos.DirectCOSDefinition)2 SMSException (com.sun.identity.sm.SMSException)2 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 AMHashMap (com.iplanet.am.sdk.AMHashMap)1 AMInvalidDNException (com.iplanet.am.sdk.AMInvalidDNException)1 AMPreCallBackException (com.iplanet.am.sdk.AMPreCallBackException)1 AMUserEntryProcessed (com.iplanet.am.sdk.AMUserEntryProcessed)1 Attr (com.iplanet.services.ldap.Attr)1 SSOException (com.iplanet.sso.SSOException)1