Search in sources :

Example 6 with IdSearchControl

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

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

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

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

Example 10 with IdSearchControl

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

the class ListAgents method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String patternType = getStringOptionValue(IArgument.AGENT_TYPE);
    String filter = getStringOptionValue(IArgument.FILTER);
    if (patternType == null) {
        patternType = "";
    }
    if ((filter == null) || (filter.length() == 0)) {
        filter = "*";
    }
    String[] params = { realm, patternType, filter };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENTS", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        IdSearchResults isr = amir.searchIdentities(IdType.AGENTONLY, filter, new IdSearchControl());
        Set results = isr.getSearchResults();
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                if (!matchType(amid, patternType)) {
                    i.remove();
                }
            }
        }
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                Object[] args = { amid.getName(), amid.getUniversalId() };
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-agent-results"), args));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("search-agent-no-entries"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENTS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgents.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

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