Search in sources :

Example 11 with RepoSearchResults

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

the class ADMailBasedRepoTest method searchReturnsSearchAttributeValues.

@Test(description = "OPENAM-3428")
public void searchReturnsSearchAttributeValues() throws Exception {
    CrestQuery crestQuery = new CrestQuery(DEMO_MAIL);
    RepoSearchResults results = idrepo.search(null, IdType.USER, crestQuery, 0, 0, null, true, IdRepo.OR_MOD, null, true);
    assertThat(results.getErrorCode()).isEqualTo(ResultCode.SUCCESS.intValue());
    assertThat(results.getType()).isEqualTo(IdType.USER);
    assertThat(results.getSearchResults()).isNotEmpty().hasSize(1).containsOnly(DEMO_MAIL);
}
Also used : CrestQuery(org.forgerock.openam.utils.CrestQuery) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) Test(org.testng.annotations.Test)

Example 12 with RepoSearchResults

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

the class GenericRepoTest method searchReturnsEmptyResultsIfNoMatch.

@Test
public void searchReturnsEmptyResultsIfNoMatch() throws Exception {
    CrestQuery crestQuery = new CrestQuery("invalid");
    RepoSearchResults results = idrepo.search(null, IdType.USER, crestQuery, 0, 0, null, true, IdRepo.AND_MOD, null, true);
    assertThat(results.getErrorCode()).isEqualTo(ResultCode.SUCCESS.intValue());
    assertThat(results.getType()).isEqualTo(IdType.USER);
    assertThat(results.getSearchResults()).isEmpty();
    assertThat(results.getResultAttributes()).isEmpty();
}
Also used : CrestQuery(org.forgerock.openam.utils.CrestQuery) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) Test(org.testng.annotations.Test)

Example 13 with RepoSearchResults

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

the class AgentsRepo method search.

@Override
public RepoSearchResults search(SSOToken token, IdType type, CrestQuery crestQuery, int maxTime, int maxResults, Set<String> returnAttrs, boolean returnAllAttrs, int filterOp, Map<String, Set<String>> avPairs, boolean recursive) throws IdRepoException, SSOException {
    if (crestQuery.hasQueryFilter()) {
        throw new IdRepoException("AgentsRepo does not support search by query filter");
    }
    String pattern = crestQuery.getQueryId();
    if (debug.messageEnabled()) {
        debug.message("AgentsRepo.search() called: " + type + ": " + pattern);
    }
    if (initializationException != null) {
        debug.error("AgentsRepo.search: " + "Realm " + realmName + " does not exist.");
        throw (initializationException);
    }
    Set agentRes = new HashSet(2);
    Map agentAttrs = new HashMap();
    int errorCode = RepoSearchResults.SUCCESS;
    try {
        if (type.equals(IdType.AGENTONLY) || type.equals(IdType.AGENT)) {
            // Get the config from 'default' group.
            ServiceConfig orgConfig = getOrgConfig(token);
            agentRes = getAgentPattern(token, type, orgConfig, pattern, avPairs);
        } else if (type.equals(IdType.AGENTGROUP)) {
            // Get the config from specified group.
            ServiceConfig agentGroupConfig = getAgentGroupConfig(token);
            agentRes = getAgentPattern(token, type, agentGroupConfig, pattern, avPairs);
        }
        if (agentRes != null && (!agentRes.isEmpty())) {
            Iterator it = agentRes.iterator();
            while (it.hasNext()) {
                String agName = (String) it.next();
                Map attrsMap = getAttributes(token, type, agName);
                if (attrsMap != null && !attrsMap.isEmpty()) {
                    agentAttrs.put(agName, attrsMap);
                } else {
                    return new RepoSearchResults(new HashSet(), RepoSearchResults.SUCCESS, Collections.EMPTY_MAP, type);
                }
            }
        }
    } catch (SSOException sse) {
        debug.error("AgentsRepo.search(): Unable to retrieve entries: ", sse);
        Object[] args = { NAME };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SEARCH_FAILED, args);
    }
    return new RepoSearchResults(agentRes, errorCode, agentAttrs, type);
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ServiceConfig(com.sun.identity.sm.ServiceConfig) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 14 with RepoSearchResults

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

the class FilesRepo method getMemberships.

/*
     * (non-Javadoc)
     *
     * @see com.sun.identity.idm.IdRepo#getMemberships(
     *      com.iplanet.sso.SSOToken, com.sun.identity.idm.IdType,
     *      java.lang.String, com.sun.identity.idm.IdType)
     */
public Set getMemberships(SSOToken token, IdType type, String name, IdType membershipType) throws IdRepoException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("FilesRepo.getMemberships called " + type + ": " + name + ": " + membershipType);
    }
    if (initializationException != null) {
        debug.error("FilesRepo.getMemeberships: throwing initialization exception");
        throw (initializationException);
    }
    // Memerships can be returned for users and agents
    if (!type.equals(IdType.USER) && !type.equals(IdType.AGENT)) {
        debug.message("FilesRepo:getMemberships supported for users and agents");
        Object[] args = { NAME };
        throw (new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.MEMBERSHIPS_FOR_NOT_USERS_NOT_ALLOWED, args));
    }
    // Set to maintain the members
    Set results = new HashSet();
    if (membershipType.equals(IdType.ROLE)) {
        // Get the role attribute and return
        Set returnAttrs = new HashSet();
        returnAttrs.add(roleMembershipAttribute);
        Map attrs = getAttributes(token, type, name, returnAttrs);
        if (attrs != null) {
            Set roles = (Set) attrs.get(roleMembershipAttribute);
            if (roles != null) {
                results = roles;
            }
        }
    } else if (membershipType.equals(IdType.GROUP)) {
        // Get the list of groups and search for memberships
        Set returnAttrs = new HashSet();
        returnAttrs.add(groupMembersAttribute);
        RepoSearchResults allGroups = search(token, membershipType, "*", 0, 0, returnAttrs, false, IdRepo.OR_MOD, null, false);
        Map groupAttrs = null;
        if ((allGroups != null) && ((groupAttrs = allGroups.getResultAttributes()) != null)) {
            // Prefix name with IdType
            name = type.getName() + name;
            for (Iterator i = groupAttrs.keySet().iterator(); i.hasNext(); ) {
                String sname = (String) i.next();
                Map attrs = (Map) groupAttrs.get(sname);
                Set ids = (Set) attrs.get(groupMembersAttribute);
                if (ids != null && ids.contains(name)) {
                    results.add(sname);
                }
            }
        }
    } else {
        // throw unsupported operation exception
        Object[] args = { NAME, IdOperation.READ.getName(), membershipType.getName() };
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
    }
    return (results);
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) Set(java.util.Set) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 15 with RepoSearchResults

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

the class AgentsRepo method removeIdentityFromAgentAuthenticators.

private void removeIdentityFromAgentAuthenticators(String name) {
    SSOToken superAdminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        Map map = new HashMap(2);
        Set set = new HashSet(2);
        set.add("SharedAgent");
        map.put("AgentType", set);
        CrestQuery crestQuery = new CrestQuery("*");
        RepoSearchResults results = search(superAdminToken, IdType.AGENTONLY, crestQuery, 0, 0, null, true, 0, null, false);
        Set res = results.getSearchResults();
        if ((res != null) && !res.isEmpty()) {
            for (Iterator i = res.iterator(); i.hasNext(); ) {
                String agentName = (String) i.next();
                Map attrValues = getAttributes(superAdminToken, IdType.AGENTONLY, agentName);
                Set agentToReads = (Set) attrValues.get("AgentsAllowedToRead");
                if ((agentToReads != null) && !agentToReads.isEmpty()) {
                    if (agentToReads.remove(name)) {
                        Map attrMap = new HashMap(2);
                        attrMap.put("AgentsAllowedToRead", agentToReads);
                        setAttributes(superAdminToken, IdType.AGENTONLY, agentName, attrMap, false);
                    }
                }
            }
        }
    } catch (IdRepoException e) {
        debug.warning("AgentRepo.removeIdentityFromAgentAuthenticators", e);
    } catch (SSOException e) {
        debug.warning("AgentRepo.removeIdentityFromAgentAuthenticators", e);
    }
}
Also used : CrestQuery(org.forgerock.openam.utils.CrestQuery) SSOToken(com.iplanet.sso.SSOToken) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) RepoSearchResults(com.sun.identity.idm.RepoSearchResults) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Aggregations

RepoSearchResults (com.sun.identity.idm.RepoSearchResults)25 HashSet (java.util.HashSet)19 Set (java.util.Set)18 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)14 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)13 HashMap (java.util.HashMap)13 Map (java.util.Map)12 IdRepoException (com.sun.identity.idm.IdRepoException)11 Iterator (java.util.Iterator)11 CrestQuery (org.forgerock.openam.utils.CrestQuery)11 Test (org.testng.annotations.Test)7 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)4 NotificationSet (com.iplanet.services.comm.share.NotificationSet)3 SSOException (com.iplanet.sso.SSOException)3 IdRepo (com.sun.identity.idm.IdRepo)3 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)3 AMHashMap (com.iplanet.am.sdk.AMHashMap)2 SSOToken (com.iplanet.sso.SSOToken)2 AMIdentity (com.sun.identity.idm.AMIdentity)2 IdSearchResults (com.sun.identity.idm.IdSearchResults)2