Search in sources :

Example 6 with IdSearchResults

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

the class Adaptive method getIdentity.

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.EMPTY_SET;
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
        if (searchResults.getSearchResults().isEmpty() && !userSearchAttributes.isEmpty()) {
            if (debug.messageEnabled()) {
                debug.message("{}.getIdentity : searching user identity with alternative attributes {}", ADAPTIVE, userSearchAttributes);
            }
            final Map<String, Set<String>> searchAVP = CollectionUtils.toAvPairMap(userSearchAttributes, userName);
            idsc.setSearchModifiers(IdSearchOpModifier.OR, searchAVP);
            //workaround as data store always adds 'user-naming-attribute' to searchfilter
            searchResults = amIdRepo.searchIdentities(IdType.USER, "*", idsc);
        }
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results.isEmpty()) {
            debug.error("{}.getIdentity : User '{}' is not found", ADAPTIVE, userName);
        } else if (results.size() > 1) {
            debug.error("{}.getIdentity : More than one user found for the userName '{}'", ADAPTIVE, userName);
        } else {
            theID = results.iterator().next();
        }
    } catch (IdRepoException e) {
        debug.error("{}.getIdentity : Error searching Identities with username '{}' ", ADAPTIVE, userName, e);
    } catch (SSOException e) {
        debug.error("{}.getIdentity : Module exception", ADAPTIVE, e);
    }
    return theID;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) 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 7 with IdSearchResults

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

the class UserDevicesDao method getIdentity.

/**
     * Gets the {@code AMIdentity} for the authenticated user.
     *
     * @param userName The user's name.
     * @param realm The user's realm.
     * @return An {@code AMIdentity}.
     * @throws InternalServerErrorException If there is a problem getting the user's identity.
     */
private AMIdentity getIdentity(String userName, String realm) throws InternalServerErrorException {
    final AMIdentity amIdentity;
    final AMIdentityRepository amIdRepo = AuthD.getAuth().getAMIdentityRepository(realm);
    final IdSearchControl idsc = new IdSearchControl();
    idsc.setAllReturnAttributes(true);
    Set<AMIdentity> results = Collections.emptySet();
    try {
        idsc.setMaxResults(NO_LIMIT);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results.isEmpty()) {
            throw new IdRepoException("getIdentity : User " + userName + " is not found");
        } else if (results.size() > 1) {
            throw new IdRepoException("getIdentity : More than one user found for the userName " + userName);
        }
        amIdentity = results.iterator().next();
    } catch (IdRepoException | SSOException e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
    return amIdentity;
}
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) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException)

Example 8 with IdSearchResults

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

the class Membership method userExists.

/** check if user exists */
private boolean userExists(String userID) throws IdRepoException, SSOException {
    AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
    IdSearchControl idsc = new IdSearchControl();
    idsc.setRecursive(true);
    idsc.setTimeOut(0);
    idsc.setAllReturnAttributes(true);
    // search for the identity
    Set results = Collections.EMPTY_SET;
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userID, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
    } catch (IdRepoException e) {
        if (debug.messageEnabled()) {
            debug.message("IdRepoException : Error searching " + " Identities with username : " + e.getMessage());
        }
    }
    return !results.isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException)

Example 9 with IdSearchResults

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

the class ConfigMonitoring method getAgentGroups.

private void getAgentGroups(String realm) {
    String classMethod = "ConfigMonitoring.getAgentGroups: ";
    /*
         *  given a realm, search the AMIdentityRepository for
         *  IdType.AGENTGROUP.
         *  this is similar to AgentsModelImpl.java:getAgentGroupNames(...)
         */
    StringBuffer sb = new StringBuffer(classMethod);
    try {
        IdSearchControl isc = new IdSearchControl();
        isc.setMaxResults(0);
        // should use set value, but for now...
        isc.setTimeOut(3000);
        isc.setAllReturnAttributes(false);
        AMIdentityRepository airepo = new AMIdentityRepository(ssoToken, realm);
        IdSearchResults isr = airepo.searchIdentities(IdType.AGENTGROUP, "*", isc);
        // set of AMIdentitys
        Set results = isr.getSearchResults();
        sb = new StringBuffer("AgentGroups for realm ");
        sb.append(realm).append("; size = ").append(results.size()).append(":\n");
        for (Iterator it = results.iterator(); it.hasNext(); ) {
            AMIdentity aid = (AMIdentity) it.next();
            processAgentIdentity(aid, sb);
        }
        debug.error(classMethod + sb.toString());
    } catch (IdRepoException e) {
        debug.error(classMethod + "idrepo error getting agents: " + e.getMessage());
    } catch (SSOException e) {
        debug.error(classMethod + "sso error getting agents: " + e.getMessage());
    }
}
Also used : 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)

Example 10 with IdSearchResults

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

the class ConfigMonitoring method getAgents.

private void getAgents(String realm) {
    String classMethod = "ConfigMonitoring.getAgents: ";
    StringBuffer sb = new StringBuffer(classMethod);
    try {
        IdSearchControl isc = new IdSearchControl();
        isc.setMaxResults(0);
        // should use set value, but for now...
        isc.setTimeOut(3000);
        isc.setAllReturnAttributes(false);
        AMIdentityRepository airepo = new AMIdentityRepository(ssoToken, realm);
        IdSearchResults isr = airepo.searchIdentities(IdType.AGENT, "*", isc);
        // set of AMIdentitys
        Set results = isr.getSearchResults();
        sb = new StringBuffer("Agents for realm ");
        sb.append(realm).append("; size = ").append(results.size()).append(":\n");
        for (Iterator it = results.iterator(); it.hasNext(); ) {
            AMIdentity aid = (AMIdentity) it.next();
            processAgentIdentity(aid, sb);
        }
        debug.error(classMethod + sb.toString());
    } catch (IdRepoException e) {
        debug.error(classMethod + "idrepo error getting agents: " + e.getMessage());
    } catch (SSOException e) {
        debug.error(classMethod + "sso error getting agents: " + e.getMessage());
    }
}
Also used : 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)

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