Search in sources :

Example 1 with AMEntryExistsException

use of com.iplanet.am.sdk.AMEntryExistsException 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 AMEntryExistsException

use of com.iplanet.am.sdk.AMEntryExistsException 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 AMEntryExistsException

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

the class ComplianceServicesImpl method checkIfDeletedOrg.

/**
     * Method which checks if the entry corresponding to orgDN represents a
     * deleted organization entry (entry with inetdomainstatus:deleted).
     * 
     * @param token
     *            a SSOToken object.
     * @param orgDN
     *            a String representing an organization DN.
     * 
     * @exception AMEntryExistsException
     *                if the orgDN corresponds to a deleted organization.
     */
protected void checkIfDeletedOrg(SSOToken token, String orgDN) throws AMEntryExistsException {
    Attr attr;
    try {
        PersistentObject po = UMSObject.getObject(token, new Guid(orgDN));
        attr = po.getAttribute(ORG_STATUS_ATTRIBUTE);
    } catch (UMSException ue) {
        if (debug.messageEnabled())
            debug.message("Compliance.checkIfDeletedOrg(): ", ue);
        return;
    }
    if (((attr != null) && (attr.size() != 0)) && attr.contains("deleted")) {
        // Org is deleted
        debug.warning("Compliance.checkIfDeletedOrg(): " + "deleted org entry: " + orgDN);
        throw new AMEntryExistsException(AMSDKBundle.getString("361"), "361");
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) Attr(com.iplanet.services.ldap.Attr) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException)

Example 4 with AMEntryExistsException

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

the class ComplianceServicesImpl method checkIfDeletedUser.

/**
     * Method which checks if the entry corresponding to userDN represents a
     * deleted user entry (entry with inetuserstatus:deleted)
     * 
     * @param token
     *            a SSOToken object
     * @param userDN
     *            a String representing a user DN
     * 
     * @exception AMEntryExistsException
     *                if the userDN corresponds to a deleted user
     */
protected void checkIfDeletedUser(SSOToken token, String userDN) throws AMEntryExistsException {
    String[] userAttribute = { USER_STATUS_ATTRIBUTE };
    Attr attr;
    try {
        PersistentObject po = UMSObject.getObject(token, new Guid(userDN), userAttribute);
        attr = po.getAttribute(USER_STATUS_ATTRIBUTE);
    } catch (UMSException ue) {
        if (debug.messageEnabled())
            debug.message("Compliance.checkIfDeletedUser(): ", ue);
        return;
    }
    if (attr != null) {
        String attrValue = attr.getValue();
        if (attrValue != null && attrValue.equalsIgnoreCase("deleted")) {
            debug.warning("Compliance.checkIfDeletedUser(): " + "deleted user entry: " + userDN);
            throw new AMEntryExistsException(AMSDKBundle.getString("329"), "329");
        }
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) Attr(com.iplanet.services.ldap.Attr) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException)

Example 5 with AMEntryExistsException

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

the class RemoteServicesImpl 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 {
        String tokenID = token.getTokenID().toString();
        Object[] objs = { tokenID, entryName, new Integer(objectType), parentDN, attributes };
        client.send(client.encodeMessage("createEntry", objs), sessionCookies.getLBCookie(tokenID), null);
    } catch (AMRemoteException amrex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.createEntry: entryName=" + entryName + ";  AMRemoteException caught exception=", amrex);
        }
        throw convertException(amrex);
    } catch (SSOException ssoe) {
        throw ssoe;
    } catch (RemoteException rex) {
        getDebug().error("RemoteServicesImpl.createEntry: caught " + "exception=", rex);
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    } catch (Exception ex) {
        if (getDebug().messageEnabled()) {
            getDebug().message("RemoteServicesImpl.createEntry: entryName=" + entryName + ";  caught exception=", ex);
        }
        throw new AMException(AMSDKBundle.getString("1000"), "1000");
    }
}
Also used : AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) RemoteException(java.rmi.RemoteException) AMEntryExistsException(com.iplanet.am.sdk.AMEntryExistsException) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) RemoteException(java.rmi.RemoteException) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException)

Aggregations

AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)5 Guid (com.iplanet.ums.Guid)4 PersistentObject (com.iplanet.ums.PersistentObject)4 UMSException (com.iplanet.ums.UMSException)4 AMException (com.iplanet.am.sdk.AMException)3 Attr (com.iplanet.services.ldap.Attr)2 AttrSet (com.iplanet.services.ldap.AttrSet)2 AccessRightsException (com.iplanet.ums.AccessRightsException)2 CreationTemplate (com.iplanet.ums.CreationTemplate)2 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)2 TemplateManager (com.iplanet.ums.TemplateManager)2 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 AMHashMap (com.iplanet.am.sdk.AMHashMap)1 AMUserEntryProcessed (com.iplanet.am.sdk.AMUserEntryProcessed)1 SSOException (com.iplanet.sso.SSOException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1