use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class AgentsModelImpl method getAgentNames.
/**
* Returns agent names.
*
* @param realmName Realm where agents reside.
* @param setTypes Agent Types.
* @param pattern Search Pattern.
* @param results Set to contains the results.
* @return error code.
* @throws AMConsoleException if result cannot be returned.
*/
public int getAgentNames(String realmName, Set setTypes, String pattern, Set results) throws AMConsoleException {
int sizeLimit = getSearchResultLimit();
int timeLimit = getSearchTimeOutLimit();
String[] params = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit) };
try {
IdSearchControl idsc = new IdSearchControl();
idsc.setMaxResults(sizeLimit);
idsc.setTimeOut(timeLimit);
idsc.setAllReturnAttributes(false);
logEvent("ATTEMPT_SEARCH_AGENT", params);
AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
IdSearchResults isr = repo.searchIdentities(IdType.AGENTONLY, pattern, idsc);
Set res = isr.getSearchResults();
if ((res != null) && !res.isEmpty()) {
for (Iterator i = res.iterator(); i.hasNext(); ) {
AMIdentity amid = (AMIdentity) i.next();
if (matchType(amid, setTypes)) {
results.add(amid);
}
}
}
logEvent("SUCCEED_SEARCH_AGENT", params);
return isr.getErrorCode();
} catch (IdRepoException e) {
String[] paramsEx = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
logEvent("EXCEPTION_SEARCH_AGENT", paramsEx);
if (debug.warningEnabled()) {
debug.warning("AgentsModelImpl.getAgentNames " + getErrorString(e));
}
throw new AMConsoleException("no.properties");
} catch (SSOException e) {
String[] paramsEx = { realmName, setTypes.toString(), pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
logEvent("EXCEPTION_SEARCH_AGENT", paramsEx);
debug.warning("AgentsModelImpl.getAgentNames ", e);
throw new AMConsoleException(getErrorString(e));
}
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class AMModelBase method getSpecialUsers.
/**
* Returns a set of special user identities. This set of identities
* typically should not be displayed in the console.
*
* @param realmName Name of Realm.
* @return a set of <code>AMIdentity</code> entries that should not be
* displayed in the console.
*/
public Set getSpecialUsers(String realmName) {
Set identities = null;
try {
AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
IdSearchResults results = repo.getSpecialIdentities(IdType.USER);
identities = results.getSearchResults();
} catch (IdRepoException e) {
debug.warning("AMModelBase.getSpecialUsers", e);
} catch (SSOException e) {
debug.warning("AMModelBase.getSpecialUsers", e);
}
return (identities == null) ? Collections.EMPTY_SET : identities;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdentitySubjectEditViewBean method getPossibleValues.
private Set getPossibleValues(IdentitySubjectModel model, String realmName, Set values) {
Set possibleValues = null;
String searchEntityType = (String) getPageSessionAttribute(ENTITY_TYPE);
if ((searchEntityType != null) && (searchEntityType.length() > 0)) {
String pattern = (String) propertySheetModel.getValue(FILTER);
try {
IdSearchResults results = model.getEntityNames(realmName, searchEntityType, 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();
// remove the system users which should not be displayed.
Set hiddenUsers = model.getSpecialUsers(realmName);
possibleValues.removeAll(hiddenUsers);
if ((possibleValues != null) && !possibleValues.isEmpty()) {
if (submitCycle) {
CCAddRemove child = (CCAddRemove) getChild(VALUES_MULTIPLE_CHOICE_VALUE);
Set selected = getValues(addRemoveModel.getSelectedOptionList());
if ((selected != null) && !selected.isEmpty()) {
Set amids = getAMIdentity(model, selected);
possibleValues.removeAll(amids);
}
} else if (values != null) {
possibleValues.removeAll(values);
}
}
} 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 IdentitySubjectAddViewBean 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 = getAMIdentity(model, 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 AuthD method getIdentity.
/**
* Returns the <code>AMIdentity</code> object for the given parameters.
* If there is no such identity, or there is more then one matching identity,
* then an AuthException will be thrown.
*
* @param idType Identity Type.
* @param idName Identity Name.
* @param orgName organization name.
* @return <code>AMIdentity</code> object.
* @throws AuthException if there was no result, or if there was more results
* then one.
*/
public AMIdentity getIdentity(IdType idType, String idName, String orgName) throws AuthException {
if (debug.messageEnabled()) {
debug.message("IdType is :" + idType);
debug.message("IdName is :" + idName);
debug.message("orgName is :" + orgName);
}
AMIdentity amIdentity = null;
// Try getting the identity using IdUtils.getIdentity(...)
try {
if (debug.messageEnabled()) {
debug.message("AuthD.getIdentity() from IdUtils Name: " + idName + " Org: " + orgName);
}
amIdentity = IdUtils.getIdentity(getSSOAuthSession(), idName, orgName);
if ((amIdentity != null) && (amIdentity.isExists()) && (amIdentity.getType().equals(idType)) && (amIdentity.getAttributes() != null)) {
if (debug.messageEnabled()) {
debug.message("AuthD.getIdentity obtained identity" + "using IdUtil.getIdentity: " + amIdentity);
}
return (amIdentity);
}
} catch (IdRepoException e) {
// Ignore this exception and continue with search
if (debug.messageEnabled()) {
debug.message("AuthD.getIdentity: Got IdRepoException while " + "getting Identity from IdUtils: " + e.getMessage());
}
} catch (SSOException ssoe) {
// Ignore this exception and continue with search
if (debug.messageEnabled()) {
debug.message("AuthD.getIdentity: Got SSOException while " + "getting Identity from IdUtils: " + ssoe.getMessage());
}
}
// Obtain AMIdentity object by searching within IdRepo
try {
amIdentity = null;
idName = DNUtils.DNtoName(idName);
AMIdentityRepository amIdRepo = getAMIdentityRepository(orgName);
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setTimeOut(0);
idsc.setMaxResults(0);
idsc.setAllReturnAttributes(false);
IdSearchResults searchResults = amIdRepo.searchIdentities(idType, idName, idsc);
Set results = Collections.EMPTY_SET;
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if ((results != null) && (results.size() > 1)) {
// multiple user match found, throw exception,
// user need to login as super admin to fix it
debug.error("getIdentity: Multiple matches found for " + "user '" + idName);
throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
}
Iterator users = results.iterator();
if (users.hasNext()) {
amIdentity = (AMIdentity) users.next();
}
} catch (SSOException sso) {
if (debug.messageEnabled()) {
debug.message("getIdentity error " + sso.getMessage());
}
} catch (IdRepoException ide) {
if (debug.messageEnabled()) {
debug.message("IdRepoException error " + ide.getMessage());
}
}
if (amIdentity == null) {
throw new AuthException(AMAuthErrorCode.AUTH_PROFILE_ERROR, null);
}
return amIdentity;
}
Aggregations