use of com.sun.identity.idm.IdSearchResults 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);
}
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdentityMembershipConditionAddViewBean method getPossibleValues.
/**
* Returns a set of supported AMIdentity objects for a realm.
*/
private Set getPossibleValues(IdentitySubjectModel model, String realmName) {
Set possibleValues = null;
String entityType = (String) getPageSessionAttribute(ENTITY_TYPE);
if ((entityType != null) && (entityType.length() > 0)) {
String pattern = (String) propertySheetModel.getValue(FILTER);
try {
IdSearchResults results = model.getEntityNames(realmName, entityType, pattern);
int errorCode = results.getErrorCode();
switch(errorCode) {
case IdSearchResults.SIZE_LIMIT_EXCEEDED:
setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.sizelimit.exceeded");
break;
case IdSearchResults.TIME_LIMIT_EXCEEDED:
setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.timelimit.exceeded");
break;
}
possibleValues = results.getSearchResults();
if ((possibleValues != null) && !possibleValues.isEmpty()) {
// remove the system users which should not be displayed.
Set hiddenUsers = model.getSpecialUsers(realmName);
possibleValues.removeAll(hiddenUsers);
// remove the identities that are already selected
Set selected = getValues(addRemoveModel.getSelectedOptionList());
if ((selected != null) && !selected.isEmpty()) {
Set amids = helper.getAMIdentity(model.getUserSSOToken(), selected);
possibleValues.removeAll(amids);
}
}
} catch (AMConsoleException e) {
setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
}
}
return (possibleValues != null) ? possibleValues : Collections.EMPTY_SET;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdentityMembershipConditionEditViewBean method getPossibleValues.
/**
* Returns a set of supported AMIdentity objects for a realm.
*/
private Set getPossibleValues(IdentitySubjectModel model, String realmName) {
Set possibleValues = null;
String entityType = (String) getPageSessionAttribute(ENTITY_TYPE);
if ((entityType != null) && (entityType.length() > 0)) {
String pattern = (String) propertySheetModel.getValue(FILTER);
try {
IdSearchResults results = model.getEntityNames(realmName, entityType, pattern);
int errorCode = results.getErrorCode();
switch(errorCode) {
case IdSearchResults.SIZE_LIMIT_EXCEEDED:
setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.sizelimit.exceeded");
break;
case IdSearchResults.TIME_LIMIT_EXCEEDED:
setInlineAlertMessage(CCAlert.TYPE_WARNING, "message.warning", "message.timelimit.exceeded");
break;
}
possibleValues = results.getSearchResults();
if ((possibleValues != null) && !possibleValues.isEmpty()) {
// remove the system users which should not be displayed.
Set hiddenUsers = model.getSpecialUsers(realmName);
possibleValues.removeAll(hiddenUsers);
// remove the identities that are already selected
Set selected = getValues(addRemoveModel.getSelectedOptionList());
if ((selected != null) && !selected.isEmpty()) {
Set amids = helper.getAMIdentity(model.getUserSSOToken(), selected);
possibleValues.removeAll(amids);
}
}
} catch (AMConsoleException e) {
setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
}
}
return (possibleValues != null) ? possibleValues : Collections.EMPTY_SET;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class OATH method getIdentity.
/**
* Gets the AMIdentity of a user with username equal to uName.
*
* @param uName username of the user to get.
* @return The AMIdentity of user with username equal to uName or null
* if error while trying to find user.
*/
private AMIdentity getIdentity(String uName) {
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, uName, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results == null || results.isEmpty()) {
throw new IdRepoException("OATH.getIdentity : User " + userName + " is not found");
} else if (results.size() > 1) {
throw new IdRepoException("OATH.getIdentity: More than one user found for the userName: " + userName);
}
theID = results.iterator().next();
} catch (IdRepoException e) {
debug.error("OATH.getIdentity: error searching Identities with username : " + userName, e);
} catch (SSOException e) {
debug.error("OATH.getIdentity: AuthOATH module exception : ", e);
}
return theID;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdentitySubjectModelImpl method getEntityNames.
/**
* Returns entity names.
*
* @param pattern Search Pattern.
* @param strType Entity Type.
* @param realmName Name of Realm.
*/
public IdSearchResults getEntityNames(String realmName, String strType, String pattern) throws AMConsoleException {
if (realmName == null) {
realmName = "/";
}
if ((pattern == null) || (pattern.trim().length() == 0)) {
pattern = "*";
}
int sizeLimit = getSearchResultLimit();
int timeLimit = getSearchTimeOutLimit();
String[] params = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit) };
try {
AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
IdType type = IdUtils.getType(strType);
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setMaxResults(sizeLimit);
idsc.setTimeOut(timeLimit);
logEvent("ATTEMPT_SEARCH_IDENTITY", params);
IdSearchResults results = repo.searchIdentities(type, pattern, idsc);
logEvent("SUCCEED_SEARCH_IDENTITY", params);
return results;
} catch (IdRepoException e) {
String strError = getErrorString(e);
String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), strError };
logEvent("IDM_EXCEPTION_SEARCH_IDENTITY", paramsEx);
throw new AMConsoleException(strError);
} catch (SSOException e) {
String strError = getErrorString(e);
String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), strError };
logEvent("SSO_EXCEPTION_SEARCH_IDENTITY", paramsEx);
throw new AMConsoleException(strError);
}
}
Aggregations