Search in sources :

Example 31 with IdSearchResults

use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.

the class AgentsModelImpl method getAgentNames.

/**
     * Returns agent names.
     *
     * @param realmName Realm where agents reside.
     * @param setTypes Agent Types.
     * @param pattern Search Pattern.
     * @param results Set to contains the results.
     * @return error code.
     * @throws AMConsoleException if result cannot be returned.
     */
public int getAgentNames(String realmName, Set setTypes, String pattern, Set results) throws AMConsoleException {
    int sizeLimit = getSearchResultLimit();
    int timeLimit = getSearchTimeOutLimit();
    String[] params = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit) };
    try {
        IdSearchControl idsc = new IdSearchControl();
        idsc.setMaxResults(sizeLimit);
        idsc.setTimeOut(timeLimit);
        idsc.setAllReturnAttributes(false);
        logEvent("ATTEMPT_SEARCH_AGENT", params);
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        IdSearchResults isr = repo.searchIdentities(IdType.AGENTONLY, pattern, idsc);
        Set res = isr.getSearchResults();
        if ((res != null) && !res.isEmpty()) {
            for (Iterator i = res.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                if (matchType(amid, setTypes)) {
                    results.add(amid);
                }
            }
        }
        logEvent("SUCCEED_SEARCH_AGENT", params);
        return isr.getErrorCode();
    } catch (IdRepoException e) {
        String[] paramsEx = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
        logEvent("EXCEPTION_SEARCH_AGENT", paramsEx);
        if (debug.warningEnabled()) {
            debug.warning("AgentsModelImpl.getAgentNames " + getErrorString(e));
        }
        throw new AMConsoleException("no.properties");
    } catch (SSOException e) {
        String[] paramsEx = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
        logEvent("EXCEPTION_SEARCH_AGENT", paramsEx);
        debug.warning("AgentsModelImpl.getAgentNames ", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdSearchControl(com.sun.identity.idm.IdSearchControl) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 32 with IdSearchResults

use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.

the class AMModelBase method getSpecialUsers.

/**
     * Returns a set of special user identities. This set of identities 
     * typically should not be displayed in the console. 
     *
     * @param realmName Name of Realm.
     * @return a set of <code>AMIdentity</code> entries that should not be 
     *     displayed in the console.
     */
public Set getSpecialUsers(String realmName) {
    Set identities = null;
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        IdSearchResults results = repo.getSpecialIdentities(IdType.USER);
        identities = results.getSearchResults();
    } catch (IdRepoException e) {
        debug.warning("AMModelBase.getSpecialUsers", e);
    } catch (SSOException e) {
        debug.warning("AMModelBase.getSpecialUsers", e);
    }
    return (identities == null) ? Collections.EMPTY_SET : identities;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 33 with IdSearchResults

use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.

the class IdentitySubjectEditViewBean method getPossibleValues.

private Set getPossibleValues(IdentitySubjectModel model, String realmName, Set values) {
    Set possibleValues = null;
    String searchEntityType = (String) getPageSessionAttribute(ENTITY_TYPE);
    if ((searchEntityType != null) && (searchEntityType.length() > 0)) {
        String pattern = (String) propertySheetModel.getValue(FILTER);
        try {
            IdSearchResults results = model.getEntityNames(realmName, searchEntityType, pattern);
            int errorCode = results.getErrorCode();
            switch(errorCode) {
                case IdSearchResults.SIZE_LIMIT_EXCEEDED:
                    setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.sizelimit.exceeded");
                    break;
                case IdSearchResults.TIME_LIMIT_EXCEEDED:
                    setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.timelimit.exceeded");
                    break;
            }
            possibleValues = results.getSearchResults();
            // remove the system users which should not be displayed.
            Set hiddenUsers = model.getSpecialUsers(realmName);
            possibleValues.removeAll(hiddenUsers);
            if ((possibleValues != null) && !possibleValues.isEmpty()) {
                if (submitCycle) {
                    CCAddRemove child = (CCAddRemove) getChild(VALUES_MULTIPLE_CHOICE_VALUE);
                    Set selected = getValues(addRemoveModel.getSelectedOptionList());
                    if ((selected != null) && !selected.isEmpty()) {
                        Set amids = getAMIdentity(model, selected);
                        possibleValues.removeAll(amids);
                    }
                } else if (values != null) {
                    possibleValues.removeAll(values);
                }
            }
        } catch (AMConsoleException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
        }
    }
    return (possibleValues != null) ? possibleValues : Collections.EMPTY_SET;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) CCAddRemove(com.sun.web.ui.view.addremove.CCAddRemove)

Example 34 with IdSearchResults

use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.

the class IdentitySubjectAddViewBean method getPossibleValues.

/**
     * Returns a set of supported AMIdentity objects for a realm.
     */
private Set getPossibleValues(IdentitySubjectModel model, String realmName) {
    Set possibleValues = null;
    String entityType = (String) getPageSessionAttribute(ENTITY_TYPE);
    if ((entityType != null) && (entityType.length() > 0)) {
        String pattern = (String) propertySheetModel.getValue(FILTER);
        try {
            IdSearchResults results = model.getEntityNames(realmName, entityType, pattern);
            int errorCode = results.getErrorCode();
            switch(errorCode) {
                case IdSearchResults.SIZE_LIMIT_EXCEEDED:
                    setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.sizelimit.exceeded");
                    break;
                case IdSearchResults.TIME_LIMIT_EXCEEDED:
                    setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.timelimit.exceeded");
                    break;
            }
            possibleValues = results.getSearchResults();
            if ((possibleValues != null) && !possibleValues.isEmpty()) {
                // remove the system users which should not be displayed.
                Set hiddenUsers = model.getSpecialUsers(realmName);
                possibleValues.removeAll(hiddenUsers);
                // remove the identities that are already selected
                Set selected = getValues(addRemoveModel.getSelectedOptionList());
                if ((selected != null) && !selected.isEmpty()) {
                    Set amids = getAMIdentity(model, selected);
                    possibleValues.removeAll(amids);
                }
            }
        } catch (AMConsoleException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
        }
    }
    return (possibleValues != null) ? possibleValues : Collections.EMPTY_SET;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 35 with IdSearchResults

use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.

the class AuthD method getIdentity.

/**
     * Returns the <code>AMIdentity</code> object for the given parameters.
     * If there is no such identity, or there is more then one matching identity,
     * then an AuthException will be thrown.
     *
     * @param idType Identity Type.
     * @param idName Identity Name.
     * @param orgName organization name.
     * @return <code>AMIdentity</code> object.
     * @throws AuthException if there was no result, or if there was more results
     * then one.
     */
public AMIdentity getIdentity(IdType idType, String idName, String orgName) throws AuthException {
    if (debug.messageEnabled()) {
        debug.message("IdType is :" + idType);
        debug.message("IdName is :" + idName);
        debug.message("orgName is :" + orgName);
    }
    AMIdentity amIdentity = null;
    // Try getting the identity using IdUtils.getIdentity(...)
    try {
        if (debug.messageEnabled()) {
            debug.message("AuthD.getIdentity() from IdUtils Name: " + idName + " Org: " + orgName);
        }
        amIdentity = IdUtils.getIdentity(getSSOAuthSession(), idName, orgName);
        if ((amIdentity != null) && (amIdentity.isExists()) && (amIdentity.getType().equals(idType)) && (amIdentity.getAttributes() != null)) {
            if (debug.messageEnabled()) {
                debug.message("AuthD.getIdentity obtained identity" + "using IdUtil.getIdentity: " + amIdentity);
            }
            return (amIdentity);
        }
    } catch (IdRepoException e) {
        // Ignore this exception and continue with search
        if (debug.messageEnabled()) {
            debug.message("AuthD.getIdentity: Got IdRepoException while " + "getting Identity from IdUtils: " + e.getMessage());
        }
    } catch (SSOException ssoe) {
        // Ignore this exception and continue with search
        if (debug.messageEnabled()) {
            debug.message("AuthD.getIdentity: Got SSOException while " + "getting Identity from IdUtils: " + ssoe.getMessage());
        }
    }
    // Obtain AMIdentity object by searching within IdRepo
    try {
        amIdentity = null;
        idName = DNUtils.DNtoName(idName);
        AMIdentityRepository amIdRepo = getAMIdentityRepository(orgName);
        IdSearchControl idsc = new IdSearchControl();
        idsc.setRecursive(true);
        idsc.setTimeOut(0);
        idsc.setMaxResults(0);
        idsc.setAllReturnAttributes(false);
        IdSearchResults searchResults = amIdRepo.searchIdentities(idType, idName, idsc);
        Set results = Collections.EMPTY_SET;
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if ((results != null) && (results.size() > 1)) {
            // multiple user match found, throw exception,
            // user need to login as super admin to fix it
            debug.error("getIdentity: Multiple matches found for " + "user '" + idName);
            throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
        }
        Iterator users = results.iterator();
        if (users.hasNext()) {
            amIdentity = (AMIdentity) users.next();
        }
    } catch (SSOException sso) {
        if (debug.messageEnabled()) {
            debug.message("getIdentity error " + sso.getMessage());
        }
    } catch (IdRepoException ide) {
        if (debug.messageEnabled()) {
            debug.message("IdRepoException error " + ide.getMessage());
        }
    }
    if (amIdentity == null) {
        throw new AuthException(AMAuthErrorCode.AUTH_PROFILE_ERROR, null);
    }
    return amIdentity;
}
Also used : Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException)

Aggregations

IdSearchResults (com.sun.identity.idm.IdSearchResults)60 IdRepoException (com.sun.identity.idm.IdRepoException)46 IdSearchControl (com.sun.identity.idm.IdSearchControl)43 SSOException (com.iplanet.sso.SSOException)39 AMIdentity (com.sun.identity.idm.AMIdentity)39 Set (java.util.Set)37 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)36 HashSet (java.util.HashSet)28 SSOToken (com.iplanet.sso.SSOToken)17 Iterator (java.util.Iterator)16 Map (java.util.Map)12 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)11 HashMap (java.util.HashMap)11 IdType (com.sun.identity.idm.IdType)9 AMHashMap (com.iplanet.am.sdk.AMHashMap)6 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)4 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 CLIException (com.sun.identity.cli.CLIException)3 IOutput (com.sun.identity.cli.IOutput)3