use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class Adaptive method getIdentity.
private AMIdentity getIdentity() {
AMIdentity theID = null;
AMIdentityRepository amIdRepo = getAMIdentityRepository(getRequestOrg());
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setAllReturnAttributes(true);
// search for the identity
Set<AMIdentity> results = Collections.EMPTY_SET;
try {
idsc.setMaxResults(0);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
if (searchResults.getSearchResults().isEmpty() && !userSearchAttributes.isEmpty()) {
if (debug.messageEnabled()) {
debug.message("{}.getIdentity : searching user identity with alternative attributes {}", ADAPTIVE, userSearchAttributes);
}
final Map<String, Set<String>> searchAVP = CollectionUtils.toAvPairMap(userSearchAttributes, userName);
idsc.setSearchModifiers(IdSearchOpModifier.OR, searchAVP);
//workaround as data store always adds 'user-naming-attribute' to searchfilter
searchResults = amIdRepo.searchIdentities(IdType.USER, "*", idsc);
}
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results.isEmpty()) {
debug.error("{}.getIdentity : User '{}' is not found", ADAPTIVE, userName);
} else if (results.size() > 1) {
debug.error("{}.getIdentity : More than one user found for the userName '{}'", ADAPTIVE, userName);
} else {
theID = results.iterator().next();
}
} catch (IdRepoException e) {
debug.error("{}.getIdentity : Error searching Identities with username '{}' ", ADAPTIVE, userName, e);
} catch (SSOException e) {
debug.error("{}.getIdentity : Module exception", ADAPTIVE, e);
}
return theID;
}
use of com.sun.identity.idm.IdSearchResults 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;
}
use of com.sun.identity.idm.IdSearchResults 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();
}
use of com.sun.identity.idm.IdSearchResults 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());
}
}
use of com.sun.identity.idm.IdSearchResults 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());
}
}
Aggregations