Search in sources :

Example 16 with IdSearchResults

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

the class WindowsDesktopSSO method searchUserAccount.

/**
     * Searches for an account with user Id userID in the organization organization
     * @param attributeValue The attributeValue to compare when searching for an
     *  identity in the organization
     * @param organization organization or the organization name where the identity will be
     *  looked up
     * @return the attribute value for the identity searched. Empty string if not found or
     *  null if an error occurs
     */
private String searchUserAccount(String attributeValue, String organization) throws AuthLoginException {
    String classMethod = "WindowsDesktopSSO.searchUserAccount: ";
    if (organization.isEmpty()) {
        organization = "/";
    }
    if (debug.messageEnabled()) {
        debug.message(classMethod + " searching for user " + attributeValue + " in the organization =" + organization);
    }
    // And the search criteria
    IdSearchControl searchControl = new IdSearchControl();
    searchControl.setMaxResults(1);
    searchControl.setTimeOut(3000);
    searchControl.setSearchModifiers(IdSearchOpModifier.OR, buildSearchControl(attributeValue));
    searchControl.setAllReturnAttributes(false);
    try {
        AMIdentityRepository amirepo = new AMIdentityRepository(getSSOSession(), organization);
        IdSearchResults searchResults = amirepo.searchIdentities(IdType.USER, "*", searchControl);
        if (searchResults.getErrorCode() == IdSearchResults.SUCCESS && searchResults != null) {
            Set<AMIdentity> results = searchResults.getSearchResults();
            if (!results.isEmpty()) {
                if (debug.messageEnabled()) {
                    debug.message(classMethod + results.size() + " result(s) obtained");
                }
                AMIdentity userDNId = results.iterator().next();
                if (userDNId != null) {
                    if (debug.messageEnabled()) {
                        debug.message(classMethod + "user = " + userDNId.getUniversalId());
                        debug.message(classMethod + "attrs =" + userDNId.getAttributes(getUserAliasList()));
                    }
                    return attributeValue.trim();
                }
            }
        }
    } catch (IdRepoException idrepoex) {
        String[] data = { attributeValue, organization };
        throw new AuthLoginException(amAuthWindowsDesktopSSO, "idRepoSearch", data, idrepoex);
    } catch (SSOException ssoe) {
        String[] data = { attributeValue, organization };
        throw new AuthLoginException(amAuthWindowsDesktopSSO, "ssoSearch", data, ssoe);
    }
    if (debug.messageEnabled()) {
        debug.message(classMethod + " No results were found !");
    }
    return null;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdSearchControl(com.sun.identity.idm.IdSearchControl) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException)

Example 17 with IdSearchResults

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

the class IdRepoJAXRPCObjectImpl method getSpecialIdentities_idrepo.

public Map getSpecialIdentities_idrepo(String token, String type, String amOrgName) throws RemoteException, IdRepoException, SSOException {
    SSOToken ssoToken = getSSOToken(token);
    IdType idtype = IdUtils.getType(type);
    IdSearchResults result = idServices.getSpecialIdentities(ssoToken, idtype, amOrgName);
    return IdSearchResultsToMap(result);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdType(com.sun.identity.idm.IdType)

Example 18 with IdSearchResults

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

the class IdCachedServicesImpl method search.

@Override
public IdSearchResults search(SSOToken token, IdType type, IdSearchControl ctrl, String orgName, CrestQuery crestQuery) throws IdRepoException, SSOException {
    IdSearchResults answer = new IdSearchResults(type, orgName);
    cacheStats.incrementSearchRequestCount(getSize());
    if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
        long li = (long) getSize();
        monIdRepo.incSearchRqts(li);
    }
    //
    if (crestQuery.hasQueryId()) {
        String pattern = crestQuery.getQueryId();
        //
        if ((pattern.indexOf('*') == -1) && ServiceManager.isRealmEnabled()) {
            // First check if the specific identity is in cache.
            // If yes, get Attributes from cache.
            // If not search in server.
            AMIdentity uvid = new AMIdentity(token, pattern, type, orgName, null);
            String universalID = uvid.getUniversalId().toLowerCase();
            IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(universalID);
            if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists() && (ctrl.getSearchModifierMap() == null)) {
                // Check if search is for a specific identity
                // Search is for a specific user, look in the cache
                Map attributes;
                try {
                    cacheStats.updateSearchHitCount(getSize());
                    if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
                        long li = (long) getSize();
                        monIdRepo.incSearchCacheHits(li);
                    }
                    if (ctrl.isGetAllReturnAttributesEnabled()) {
                        attributes = getAttributes(token, type, pattern, orgName, null);
                    } else {
                        Set attrNames = ctrl.getReturnAttributes();
                        attributes = getAttributes(token, type, pattern, attrNames, orgName, null, true);
                    }
                    // Construct IdSearchResults
                    AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
                    answer.addResult(id, attributes);
                    return answer;
                } catch (IdRepoException ide) {
                    // Check if the exception is name not found
                    if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
                        // Throw the exception
                        throw (ide);
                    }
                }
            }
        }
    }
    // Not in Cache.  Do a search on the server.
    return super.search(token, type, ctrl, orgName, crestQuery);
}
Also used : Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map)

Example 19 with IdSearchResults

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

the class IdRepoSampleGetSpecialIds method getSpecialIds.

/*
     *  The special AMIdentities are for internal use only.
     */
public void getSpecialIds() {
    try {
        IdSearchResults isr = null;
        Set isrSet = null;
        Map isrMap = null;
        /*
             * get special role identities
             */
        isr = idRepo.getSpecialIdentities(IdType.ROLE);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Roles");
        /*
             * get special user identities
             */
        sampleUtils.waitForReturn("Hit <return> to get special users: ");
        isr = idRepo.getSpecialIdentities(IdType.USER);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Users");
        /*
             * get special group identities
             */
        sampleUtils.waitForReturn("Hit <return> to get special groups: ");
        isr = idRepo.getSpecialIdentities(IdType.GROUP);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Groups");
        /*
             * get special agent identities
             */
        sampleUtils.waitForReturn("Hit <return> to get special agents: ");
        isr = idRepo.getSpecialIdentities(IdType.AGENT);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Agents");
        /*
             * get special realm identities
             */
        sampleUtils.waitForReturn("Hit <return> to get special realms: ");
        isr = idRepo.getSpecialIdentities(IdType.REALM);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Realms");
        /*
             * get special Filtered Role identities
             */
        sampleUtils.waitForReturn("Hit <return> to get special filtered roles: ");
        isr = idRepo.getSpecialIdentities(IdType.FILTEREDROLE);
        isrSet = isr.getSearchResults();
        isrMap = isr.getResultAttributes();
        processSpecialIdentity(isrMap, isrSet, "Special Filtered Roles");
    } catch (IdRepoException ire) {
        System.err.println("idRepoProcessing:IdRepoException: " + ire.getMessage());
    } catch (SSOException ssoe) {
        System.err.println("idRepoProcessing:SSOException: " + ssoe.getMessage());
    }
    return;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 20 with IdSearchResults

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

the class IdRemoteCachedServicesImpl method search.

@Override
public IdSearchResults search(SSOToken token, IdType type, IdSearchControl ctrl, String orgName, CrestQuery crestQuery) throws IdRepoException, SSOException {
    IdSearchResults answer = new IdSearchResults(type, orgName);
    // in legacy mode we must do search in order
    // to get the AMSDKDN component added to AMIdentity's uvid.
    // otherwise unix and anonymous login will fail.
    cacheStats.incrementSearchRequestCount(getSize());
    if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
        long li = (long) getSize();
        monIdRepo.incSearchRqts(li);
    }
    boolean isCached = false;
    if (crestQuery.hasQueryId()) {
        String pattern = crestQuery.getQueryId();
        if ((pattern.indexOf('*') == -1) && ServiceManager.isRealmEnabled()) {
            // First check if the specific identity is in cache.
            // If yes, get Attributes from cache.
            // If not search in server.
            AMIdentity uvid = new AMIdentity(token, pattern, type, orgName, null);
            String universalID = uvid.getUniversalId().toLowerCase();
            IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(universalID);
            if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists() && (ctrl.getSearchModifierMap() == null)) {
                // Check if search is for a specific identity
                // Search is for a specific user, look in the cache
                Map attributes;
                try {
                    cacheStats.updateSearchHitCount(getSize());
                    if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
                        long li = (long) getSize();
                        monIdRepo.incSearchCacheHits(li);
                    }
                    if (ctrl.isGetAllReturnAttributesEnabled()) {
                        attributes = getAttributes(token, type, pattern, orgName, null);
                    } else {
                        Set attrNames = ctrl.getReturnAttributes();
                        attributes = getAttributes(token, type, pattern, attrNames, orgName, null, true);
                    }
                    // Construct IdSearchResults
                    AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
                    answer.addResult(id, attributes);
                    isCached = true;
                } catch (IdRepoException ide) {
                    // Check if the exception is name not found
                    if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
                        // Throw the exception
                        throw (ide);
                    }
                }
            }
        }
    }
    if (!isCached) {
        // Not in Cache.  Do a search in server.
        answer = super.search(token, type, ctrl, orgName, crestQuery);
    }
    return (answer);
}
Also used : Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) IdCacheBlock(com.sun.identity.idm.common.IdCacheBlock) AMHashMap(com.iplanet.am.sdk.AMHashMap) Map(java.util.Map)

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