Search in sources :

Example 66 with AMIdentityRepository

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

the class ServicesModelImpl method addIdentityUnassignedServices.

private void addIdentityUnassignedServices(String realmName, Set names) {
    /*
         * It is ok that administrator such as policy administrator
         * does not have access to AMIdentityRepository. We just ignore it.
         */
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        names.addAll(realmIdentity.getAssignableServices());
    } catch (IdRepoException e) {
        debug.warning("ServicesModelImpl.addIdentityUnassignedServices", e);
    } catch (SSOException e) {
        debug.warning("ServicesModelImpl.addIdentityUnassignedServices", e);
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 67 with AMIdentityRepository

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

the class ServicesProfileModelImpl method getAttributeValues.

/**
     * Returns attribute values of the service profile.
     *
     * @return attribute values of the service profile.
     */
public Map getAttributeValues() {
    Map map = null;
    String[] params = { currentRealm, serviceName, "*" };
    logEvent("ATTEMPT_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", params);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), currentRealm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignedServices();
        if (servicesFromIdRepo.contains(serviceName)) {
            map = realmIdentity.getServiceAttributes(serviceName);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(getUserSSOToken(), currentRealm);
            map = orgCfgMgr.getServiceAttributes(serviceName);
        }
        logEvent("SUCCEED_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", params);
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SSO_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("ServicesProfileModelImpl.getAttributeValues", e);
    } catch (IdRepoException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("IDREPO_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("ServicesProfileModelImpl.getAttributeValues", e);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { currentRealm, serviceName, strError };
        logEvent("SMS_EXCEPTION_GET_ATTR_VALUE_OF_SERVICE_UNDER_REALM", paramsEx);
        debug.error("ServicesProfileModelImpl.getAttributeValues", e);
    }
    return (map != null) ? map : Collections.EMPTY_MAP;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map)

Example 68 with AMIdentityRepository

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

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

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

Aggregations

AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)138 IdRepoException (com.sun.identity.idm.IdRepoException)103 SSOException (com.iplanet.sso.SSOException)94 AMIdentity (com.sun.identity.idm.AMIdentity)85 Set (java.util.Set)82 HashSet (java.util.HashSet)58 SSOToken (com.iplanet.sso.SSOToken)56 IdSearchControl (com.sun.identity.idm.IdSearchControl)36 IdSearchResults (com.sun.identity.idm.IdSearchResults)36 Iterator (java.util.Iterator)32 CLIException (com.sun.identity.cli.CLIException)29 HashMap (java.util.HashMap)29 IdType (com.sun.identity.idm.IdType)28 Map (java.util.Map)27 IOutput (com.sun.identity.cli.IOutput)26 SMSException (com.sun.identity.sm.SMSException)24 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)20 List (java.util.List)13 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)12 Callback (javax.security.auth.callback.Callback)6