use of com.sun.identity.idm.IdSearchControl in project OpenAM by OpenRock.
the class AuthenticatorOATH method getIdentity.
/**
* Gets the AMIdentity of a user with username equal to userName.
*
* @return The AMIdentity of user with username equal to userName.
*/
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.emptySet();
try {
idsc.setMaxResults(0);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results.isEmpty()) {
debug.error("OATH.getIdentity : User " + userName + " is not found");
} else if (results.size() > 1) {
debug.error("OATH.getIdentity : More than one user found for the userName " + userName);
} else {
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 : Module exception : ", e);
}
return theID;
}
use of com.sun.identity.idm.IdSearchControl in project OpenAM by OpenRock.
the class DefaultAccountProvider method getSearchControl.
private IdSearchControl getSearchControl(IdSearchOpModifier modifier, Map<String, Set<String>> avMap) {
IdSearchControl control = new IdSearchControl();
control.setMaxResults(1);
control.setSearchModifiers(modifier, avMap);
return control;
}
use of com.sun.identity.idm.IdSearchControl in project OpenAM by OpenRock.
the class AgentsModelImpl method getAgentGroupNames.
/**
* Returns agent group names.
*
* @param realmName Realm where agent groups 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 getAgentGroupNames(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_GROUP", params);
AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
IdSearchResults isr = repo.searchIdentities(IdType.AGENTGROUP, 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_GROUP", 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_GROUP", paramsEx);
if (debug.warningEnabled()) {
debug.warning("AgentsModelImpl.getAgentGroupNames " + 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_GROUP", paramsEx);
debug.warning("AgentsModelImpl.getAgentGroupNames ", e);
throw new AMConsoleException(getErrorString(e));
}
}
use of com.sun.identity.idm.IdSearchControl 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.IdSearchControl in project OpenAM by OpenRock.
the class EntitiesModelImpl method getEntityNames.
/**
* Returns entity names.
*
* @param realmName Name of Realm.
* @param pattern Search Pattern.
* @param strType Entity Type.
*/
public IdSearchResults getEntityNames(String realmName, String strType, String pattern) throws AMConsoleException {
if (realmName == null) {
realmName = "/";
}
int sizeLimit = getSearchResultLimit();
int timeLimit = getSearchTimeOutLimit();
String[] params = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit) };
try {
IdSearchControl idsc = new IdSearchControl();
idsc.setMaxResults(sizeLimit);
idsc.setTimeOut(timeLimit);
idsc.setAllReturnAttributes(false);
/*
* For user identities we will modify the search filter so that
* we can search on a non naming attribute.
*/
IdType ltype = IdUtils.getType(strType);
if (ltype.equals(IdType.USER) && !pattern.equals("*")) {
Map searchMap = new HashMap(2);
Set patternSet = new HashSet(2);
patternSet.add(pattern);
searchMap.put(getUserSearchAttribute(), patternSet);
idsc.setSearchModifiers(IdSearchOpModifier.OR, searchMap);
/*
* change the pattern to * since we are passing a searchMap.
* pattern will be used in the default filter and given to
* the naming attribute (uid in this case). Here we are passing
* cn=John Doe in the searchMap, but the naming attribute is
* set to *.
* "(&(&(uid=*)(objectClass=inetOrgPerson))(|(cn=John Doe)))"
*/
pattern = "*";
}
logEvent("ATTEMPT_SEARCH_IDENTITY", params);
AMIdentityRepository repo = new AMIdentityRepository(getUserSSOToken(), realmName);
IdSearchResults results = repo.searchIdentities(ltype, pattern, idsc);
logEvent("SUCCEED_SEARCH_IDENTITY", params);
return results;
} catch (IdRepoException e) {
String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
logEvent("IDM_EXCEPTION_SEARCH_IDENTITY", paramsEx);
if (debug.warningEnabled()) {
debug.warning("EntitiesModelImpl.getEntityNames " + getErrorString(e));
}
throw new AMConsoleException("no.properties");
} catch (SSOException e) {
String[] paramsEx = { realmName, strType, pattern, Integer.toString(sizeLimit), Integer.toString(timeLimit), getErrorString(e) };
logEvent("SSO_EXCEPTION_SEARCH_IDENTITY", paramsEx);
debug.warning("EntitiesModelImpl.getEntityNames ", e);
throw new AMConsoleException(getErrorString(e));
}
}
Aggregations