Search in sources :

Example 26 with IdSearchControl

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

the class AuthenticatorOATH method getIdentity.

/**
     * Gets the AMIdentity of a user with username equal to userName.
     *
     * @return The AMIdentity of user with username equal to userName.
     */
private AMIdentity getIdentity() {
    AMIdentity theID = null;
    AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
    IdSearchControl idsc = new IdSearchControl();
    idsc.setRecursive(true);
    idsc.setAllReturnAttributes(true);
    // search for the identity
    Set<AMIdentity> results = Collections.emptySet();
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results.isEmpty()) {
            debug.error("OATH.getIdentity : User " + userName + " is not found");
        } else if (results.size() > 1) {
            debug.error("OATH.getIdentity : More than one user found for the userName " + userName);
        } else {
            theID = results.iterator().next();
        }
    } catch (IdRepoException e) {
        debug.error("OATH.getIdentity : Error searching Identities with username : " + userName, e);
    } catch (SSOException e) {
        debug.error("OATH.getIdentity : Module exception : ", e);
    }
    return theID;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 27 with IdSearchControl

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

the class DefaultAccountProvider method getSearchControl.

private IdSearchControl getSearchControl(IdSearchOpModifier modifier, Map<String, Set<String>> avMap) {
    IdSearchControl control = new IdSearchControl();
    control.setMaxResults(1);
    control.setSearchModifiers(modifier, avMap);
    return control;
}
Also used : IdSearchControl(com.sun.identity.idm.IdSearchControl)

Example 28 with IdSearchControl

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

the class AgentsModelImpl method getAgentGroupNames.

/**
     * Returns agent group names.
     *
     * @param realmName Realm where agent groups 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 getAgentGroupNames(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_GROUP", params);
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        IdSearchResults isr = repo.searchIdentities(IdType.AGENTGROUP, 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_GROUP", 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_GROUP", paramsEx);
        if (debug.warningEnabled()) {
            debug.warning("AgentsModelImpl.getAgentGroupNames " + 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_GROUP", paramsEx);
        debug.warning("AgentsModelImpl.getAgentGroupNames ", 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 29 with IdSearchControl

use of com.sun.identity.idm.IdSearchControl 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 30 with IdSearchControl

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

the class EntitiesModelImpl method getEntityNames.

/**
     * Returns entity names.
     *
     * @param realmName Name of Realm.
     * @param pattern Search Pattern.
     * @param strType Entity Type.
     */
public IdSearchResults getEntityNames(String realmName, String strType, String pattern) throws AMConsoleException {
    if (realmName == null) {
        realmName = "/";
    }
    int sizeLimit = getSearchResultLimit();
    int timeLimit = getSearchTimeOutLimit();
    String[] params = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit) };
    try {
        IdSearchControl idsc = new IdSearchControl();
        idsc.setMaxResults(sizeLimit);
        idsc.setTimeOut(timeLimit);
        idsc.setAllReturnAttributes(false);
        /*
            * For user identities we will modify the search filter so that
            * we can search on a non naming attribute. 
            */
        IdType ltype = IdUtils.getType(strType);
        if (ltype.equals(IdType.USER) && !pattern.equals("*")) {
            Map searchMap = new HashMap(2);
            Set patternSet = new HashSet(2);
            patternSet.add(pattern);
            searchMap.put(getUserSearchAttribute(), patternSet);
            idsc.setSearchModifiers(IdSearchOpModifier.OR, searchMap);
            /*
                * change the pattern to * since we are passing a searchMap.
                * pattern will be used in the default filter and given to
                * the naming attribute (uid in this case). Here we are passing
                * cn=John Doe in the searchMap, but the naming attribute is
                * set to *.
                * "(&(&(uid=*)(objectClass=inetOrgPerson))(|(cn=John Doe)))"
                */
            pattern = "*";
        }
        logEvent("ATTEMPT_SEARCH_IDENTITY", params);
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        IdSearchResults results = repo.searchIdentities(ltype, pattern, idsc);
        logEvent("SUCCEED_SEARCH_IDENTITY", params);
        return results;
    } catch (IdRepoException e) {
        String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
        logEvent("IDM_EXCEPTION_SEARCH_IDENTITY", paramsEx);
        if (debug.warningEnabled()) {
            debug.warning("EntitiesModelImpl.getEntityNames " + getErrorString(e));
        }
        throw new AMConsoleException("no.properties");
    } catch (SSOException e) {
        String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
        logEvent("SSO_EXCEPTION_SEARCH_IDENTITY", paramsEx);
        debug.warning("EntitiesModelImpl.getEntityNames ", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) IdSearchControl(com.sun.identity.idm.IdSearchControl) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) HashSet(java.util.HashSet)

Aggregations

IdSearchControl (com.sun.identity.idm.IdSearchControl)48 IdSearchResults (com.sun.identity.idm.IdSearchResults)43 IdRepoException (com.sun.identity.idm.IdRepoException)41 SSOException (com.iplanet.sso.SSOException)36 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)36 AMIdentity (com.sun.identity.idm.AMIdentity)35 Set (java.util.Set)25 HashSet (java.util.HashSet)20 SSOToken (com.iplanet.sso.SSOToken)15 Iterator (java.util.Iterator)14 IdType (com.sun.identity.idm.IdType)9 HashMap (java.util.HashMap)8 Map (java.util.Map)6 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)4 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)4 CLIException (com.sun.identity.cli.CLIException)3 IOutput (com.sun.identity.cli.IOutput)3 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2 DelegationException (com.sun.identity.delegation.DelegationException)2 TreeSet (java.util.TreeSet)2