use of com.sun.identity.idm.IdSearchControl 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.IdSearchControl 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.IdSearchControl 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.IdSearchControl 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());
}
}
use of com.sun.identity.idm.IdSearchControl in project OpenAM by OpenRock.
the class ListAgents method handleRequest.
/**
* Services a Commandline Request.
*
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc) throws CLIException {
super.handleRequest(rc);
ldapLogin();
SSOToken adminSSOToken = getAdminSSOToken();
IOutput outputWriter = getOutputWriter();
String realm = getStringOptionValue(IArgument.REALM_NAME);
String patternType = getStringOptionValue(IArgument.AGENT_TYPE);
String filter = getStringOptionValue(IArgument.FILTER);
if (patternType == null) {
patternType = "";
}
if ((filter == null) || (filter.length() == 0)) {
filter = "*";
}
String[] params = { realm, patternType, filter };
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENTS", params);
try {
AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
IdSearchResults isr = amir.searchIdentities(IdType.AGENTONLY, filter, new IdSearchControl());
Set results = isr.getSearchResults();
if ((results != null) && !results.isEmpty()) {
for (Iterator i = results.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
if (!matchType(amid, patternType)) {
i.remove();
}
}
}
if ((results != null) && !results.isEmpty()) {
for (Iterator i = results.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
Object[] args = { amid.getName(), amid.getUniversalId() };
outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-agent-results"), args));
}
} else {
outputWriter.printlnMessage(getResourceString("search-agent-no-entries"));
}
writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENTS", params);
} catch (IdRepoException e) {
String[] args = { realm, patternType, filter, e.getMessage() };
debugError("ListAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
String[] args = { realm, patternType, filter, e.getMessage() };
debugError("ListAgents.handleRequest", e);
writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENTS", args);
throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
Aggregations