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);
}
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();
}
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);
}
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);
}
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);
}
}
Aggregations