Search in sources :

Example 31 with UMSException

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

the class DirectCOSDefinition method addCOSTemplate.

/**
     * Adds a COS Template to this COS definition. This COS definition must be
     * persistent before adding the template.
     * 
     * @param cosTemplate
     *            The COS Template to be added.
     * 
     * @throws UMSException
     *             The exception thrown from the data layer.
     * @supported.api
     */
public void addCOSTemplate(COSTemplate cosTemplate) throws UMSException {
    if (getGuid() == null) {
        String msg = i18n.getString(IUMSConstants.DEFINITION_NOT_PERSISTENT);
        throw new UMSException(msg);
    }
    if (getAttribute(ICOSDefinition.COSTEMPLATEDN) == null) {
        this.modify(new Attr(ICOSDefinition.COSTEMPLATEDN, getGuid().getDn()), ModificationType.ADD);
        this.save();
    }
    this.addChild(cosTemplate);
}
Also used : UMSException(com.iplanet.ums.UMSException) Attr(com.iplanet.services.ldap.Attr)

Example 32 with UMSException

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

the class DirectoryServicesImpl method removeSubtree.

/**
     * Private method used by "removeEntry" to delete an entire subtree
     */
private void removeSubtree(SSOToken token, String entryDN, boolean softDelete) throws AMException, SSOException {
    int type = AMObject.UNKNOWN_OBJECT_TYPE;
    try {
        Guid guid = new Guid(entryDN);
        PersistentObject po = UMSObject.getObjectHandle(internalToken, guid);
        // first get all the children of the object
        SearchControl control = new SearchControl();
        control.setSearchScope(SearchControl.SCOPE_SUB);
        String searchFilter = "(|(objectclass=*)(objectclass=ldapsubEntry))";
        List list = new ArrayList();
        // get number of RDNs in the entry itself
        int entryRDNs = DN.valueOf(entryDN).size();
        // to count maximum level of RDNs in the search return
        int maxRDNCount = entryRDNs;
        // go through all search results, add DN to the list, and
        // set the maximun RDN count, will be used to remove DNs
        SearchResults children = po.getChildren(searchFilter, control);
        while (children.hasMoreElements()) {
            PersistentObject object = children.next();
            DN dn = DN.valueOf(object.getDN());
            if (debug.messageEnabled()) {
                debug.message("DirectoryServicesImpl.removeEntry(): " + "found child: " + object.getDN());
            }
            int count = dn.size();
            if (count > maxRDNCount) {
                maxRDNCount = count;
            }
            list.add(dn);
        }
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.removeEntry(): max " + "RDNs: " + maxRDNCount);
        }
        // go through all search results, delete entries from the
        // bottom up, starting from entries whose's RDN count
        // equals the maxRDNCount
        // TODO : If the list has too many entries, then the multiple
        // iteration in the inner for loop may be the bottleneck.
        // One enhancement to the existing algorithm is to store all
        // the entries by level in a different List. Per Sai's comments
        int len = list.size();
        for (int i = maxRDNCount; i >= entryRDNs; i--) {
            for (int j = 0; j < len; j++) {
                DN dn = (DN) list.get(j);
                // check if we need delete it now
                if (dn.size() == i) {
                    // remove the entry
                    if (debug.messageEnabled()) {
                        debug.message("DirectoryServicesImpl." + "removeEntry(): del " + dn.toString());
                    }
                    String rfcDN = dn.toString();
                    type = AMObject.UNKNOWN_OBJECT_TYPE;
                    try {
                        type = getObjectType(internalToken, rfcDN);
                    } catch (AMException ae) {
                        // Not a managed type, just delete it.
                        Guid g = new Guid(rfcDN);
                        UMSObject.removeObject(token, g);
                    }
                    // Do a non-recursive delete
                    if (type != AMObject.UNKNOWN_OBJECT_TYPE && type != AMObject.UNDETERMINED_OBJECT_TYPE) {
                        try {
                            removeSingleEntry(token, rfcDN, type, softDelete);
                        } catch (AMPreCallBackException amp) {
                            debug.error("DirectoryServicesImpl." + "removeSubTree: Aborting delete of: " + rfcDN + " due to pre-callback exception", amp);
                        }
                    }
                    // remove the deleted entry from the list
                    list.remove(j);
                    // move back pointer, as current element is removed
                    j--;
                    // reduce list length
                    len--;
                }
            }
        }
    } catch (AccessRightsException e) {
        debug.error("DirectoryServicesImpl.removeEntry() Insufficient " + "access rights to remove entry: " + entryDN, e);
        throw new AMException(token, "460");
    } catch (EntryNotFoundException e) {
        String entry = getEntryName(e);
        debug.error("DirectoryServicesImpl.removeEntry() Entry not found: " + entry, e);
        String msgid = getEntryNotFoundMsgID(type);
        Object[] args = { entry };
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString(msgid, args, locale), msgid, args);
    } catch (UMSException e) {
        debug.error("DirectoryServicesImpl.removeEntry() Unable to remove: " + " Internal error occurred: ", e);
        throw new AMException(token, "325", e);
    }
}
Also used : AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) ArrayList(java.util.ArrayList) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) RDN(org.forgerock.opendj.ldap.RDN) DN(org.forgerock.opendj.ldap.DN) Guid(com.iplanet.ums.Guid) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) SearchControl(com.iplanet.ums.SearchControl) AMPreCallBackException(com.iplanet.am.sdk.AMPreCallBackException)

Example 33 with UMSException

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

the class DirectoryServicesImpl method verifyAndGetOrgDN.

/**
     * Gets the Organization DN for the specified entryDN. If the entry itself
     * is an org, then same DN is returned.
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the entry whose parent Organization is to be obtained
     * @param childDN
     *            the immediate entry whose parent Organization is to be
     *            obtained
     * @return the DN String of the parent Organization
     * @throws AMException
     *             if an error occured while obtaining the parent Organization
     */
public String verifyAndGetOrgDN(SSOToken token, String entryDN, String childDN) throws AMException {
    if (entryDN.isEmpty() || DN.valueOf(entryDN).size() <= 0) {
        debug.error("DirectoryServicesImpl.verifyAndGetOrgDN() Invalid " + "DN: " + entryDN);
        throw new AMException(token, "157");
    }
    String organizationDN = null;
    boolean errorCondition = false;
    try {
        PersistentObject po = UMSObject.getObjectHandle(internalToken, new Guid(childDN));
        String searchFilter = getOrgSearchFilter(entryDN);
        SearchResults result = po.search(searchFilter, aName, scontrol);
        if (result.hasMoreElements()) {
            // ABANDON logged in directory server access logs.
            while (result.hasMoreElements()) {
                result.next();
            }
            organizationDN = po.getGuid().toString().toLowerCase();
        }
    } catch (InvalidSearchFilterException e) {
        errorCondition = true;
        debug.error("DirectoryServicesImpl.verifyAndGetOrgDN(): Invalid " + "search filter, unable to get Parent Organization: ", e);
    } catch (UMSException ue) {
        errorCondition = true;
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.verifyAndGetOrgDN(): " + "Unable to Obtain Parent Organization", ue);
        }
        LdapException lex = (LdapException) ue.getRootCause();
        ResultCode errorCode = lex.getResult().getResultCode();
        if (retryErrorCodes.contains("" + errorCode)) {
            throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
        }
    }
    if (errorCondition) {
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("124", locale), "124");
    }
    return organizationDN;
}
Also used : UMSException(com.iplanet.ums.UMSException) InvalidSearchFilterException(com.iplanet.ums.InvalidSearchFilterException) AMException(com.iplanet.am.sdk.AMException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 34 with UMSException

use of com.iplanet.ums.UMSException 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 35 with UMSException

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

the class DirectoryServicesImpl method search.

/**
     * Searches the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the entry to start the search with
     * @param searchFilter
     *            search filter
     * @param searchScope
     *            search scope, BASE, ONELEVEL or SUBTREE
     * @return Set set of matching DNs
     */
public Set search(SSOToken token, String entryDN, String searchFilter, int searchScope) throws AMException {
    Set resultSet = Collections.EMPTY_SET;
    try {
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        SearchControl control = new SearchControl();
        control.setSearchScope(searchScope);
        SearchResults results = po.search(searchFilter, control);
        resultSet = searchResultsToSet(results);
    } catch (UMSException ue) {
        LdapException lex = (LdapException) ue.getRootCause();
        ResultCode errorCode = lex.getResult().getResultCode();
        if (retryErrorCodes.contains("" + errorCode)) {
            throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
        }
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.search(token:, entryDN: " + entryDN + ", searchFilter: " + searchFilter + "searchScope: " + searchScope + " error occurred: ", ue);
        }
        processInternalException(token, ue, "341");
    }
    return resultSet;
}
Also used : 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) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Aggregations

UMSException (com.iplanet.ums.UMSException)48 Guid (com.iplanet.ums.Guid)40 AMException (com.iplanet.am.sdk.AMException)31 PersistentObject (com.iplanet.ums.PersistentObject)24 AttrSet (com.iplanet.services.ldap.AttrSet)16 Attr (com.iplanet.services.ldap.Attr)14 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)11 AccessRightsException (com.iplanet.ums.AccessRightsException)10 DomainComponentTree (com.iplanet.ums.dctree.DomainComponentTree)8 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)6 SearchResults (com.iplanet.ums.SearchResults)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DN (org.forgerock.opendj.ldap.DN)6 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)5 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)5 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)5 TreeMap (java.util.TreeMap)5 LdapException (org.forgerock.opendj.ldap.LdapException)5