use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class WindowsDesktopSSO method searchUserAccount.
/**
* Searches for an account with user Id userID in the organization organization
* @param attributeValue The attributeValue to compare when searching for an
* identity in the organization
* @param organization organization or the organization name where the identity will be
* looked up
* @return the attribute value for the identity searched. Empty string if not found or
* null if an error occurs
*/
private String searchUserAccount(String attributeValue, String organization) throws AuthLoginException {
String classMethod = "WindowsDesktopSSO.searchUserAccount: ";
if (organization.isEmpty()) {
organization = "/";
}
if (debug.messageEnabled()) {
debug.message(classMethod + " searching for user " + attributeValue + " in the organization =" + organization);
}
// And the search criteria
IdSearchControl searchControl = new IdSearchControl();
searchControl.setMaxResults(1);
searchControl.setTimeOut(3000);
searchControl.setSearchModifiers(IdSearchOpModifier.OR, buildSearchControl(attributeValue));
searchControl.setAllReturnAttributes(false);
try {
AMIdentityRepository amirepo = new AMIdentityRepository(getSSOSession(), organization);
IdSearchResults searchResults = amirepo.searchIdentities(IdType.USER, "*", searchControl);
if (searchResults.getErrorCode() == IdSearchResults.SUCCESS && searchResults != null) {
Set<AMIdentity> results = searchResults.getSearchResults();
if (!results.isEmpty()) {
if (debug.messageEnabled()) {
debug.message(classMethod + results.size() + " result(s) obtained");
}
AMIdentity userDNId = results.iterator().next();
if (userDNId != null) {
if (debug.messageEnabled()) {
debug.message(classMethod + "user = " + userDNId.getUniversalId());
debug.message(classMethod + "attrs =" + userDNId.getAttributes(getUserAliasList()));
}
return attributeValue.trim();
}
}
}
} catch (IdRepoException idrepoex) {
String[] data = { attributeValue, organization };
throw new AuthLoginException(amAuthWindowsDesktopSSO, "idRepoSearch", data, idrepoex);
} catch (SSOException ssoe) {
String[] data = { attributeValue, organization };
throw new AuthLoginException(amAuthWindowsDesktopSSO, "ssoSearch", data, ssoe);
}
if (debug.messageEnabled()) {
debug.message(classMethod + " No results were found !");
}
return null;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdRepoJAXRPCObjectImpl method getSpecialIdentities_idrepo.
public Map getSpecialIdentities_idrepo(String token, String type, String amOrgName) throws RemoteException, IdRepoException, SSOException {
SSOToken ssoToken = getSSOToken(token);
IdType idtype = IdUtils.getType(type);
IdSearchResults result = idServices.getSpecialIdentities(ssoToken, idtype, amOrgName);
return IdSearchResultsToMap(result);
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdCachedServicesImpl method search.
@Override
public IdSearchResults search(SSOToken token, IdType type, IdSearchControl ctrl, String orgName, CrestQuery crestQuery) throws IdRepoException, SSOException {
IdSearchResults answer = new IdSearchResults(type, orgName);
cacheStats.incrementSearchRequestCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchRqts(li);
}
//
if (crestQuery.hasQueryId()) {
String pattern = crestQuery.getQueryId();
//
if ((pattern.indexOf('*') == -1) && ServiceManager.isRealmEnabled()) {
// First check if the specific identity is in cache.
// If yes, get Attributes from cache.
// If not search in server.
AMIdentity uvid = new AMIdentity(token, pattern, type, orgName, null);
String universalID = uvid.getUniversalId().toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(universalID);
if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists() && (ctrl.getSearchModifierMap() == null)) {
// Check if search is for a specific identity
// Search is for a specific user, look in the cache
Map attributes;
try {
cacheStats.updateSearchHitCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchCacheHits(li);
}
if (ctrl.isGetAllReturnAttributesEnabled()) {
attributes = getAttributes(token, type, pattern, orgName, null);
} else {
Set attrNames = ctrl.getReturnAttributes();
attributes = getAttributes(token, type, pattern, attrNames, orgName, null, true);
}
// Construct IdSearchResults
AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
answer.addResult(id, attributes);
return answer;
} catch (IdRepoException ide) {
// Check if the exception is name not found
if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
// Throw the exception
throw (ide);
}
}
}
}
}
// Not in Cache. Do a search on the server.
return super.search(token, type, ctrl, orgName, crestQuery);
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdRepoSampleGetSpecialIds method getSpecialIds.
/*
* The special AMIdentities are for internal use only.
*/
public void getSpecialIds() {
try {
IdSearchResults isr = null;
Set isrSet = null;
Map isrMap = null;
/*
* get special role identities
*/
isr = idRepo.getSpecialIdentities(IdType.ROLE);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Roles");
/*
* get special user identities
*/
sampleUtils.waitForReturn("Hit <return> to get special users: ");
isr = idRepo.getSpecialIdentities(IdType.USER);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Users");
/*
* get special group identities
*/
sampleUtils.waitForReturn("Hit <return> to get special groups: ");
isr = idRepo.getSpecialIdentities(IdType.GROUP);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Groups");
/*
* get special agent identities
*/
sampleUtils.waitForReturn("Hit <return> to get special agents: ");
isr = idRepo.getSpecialIdentities(IdType.AGENT);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Agents");
/*
* get special realm identities
*/
sampleUtils.waitForReturn("Hit <return> to get special realms: ");
isr = idRepo.getSpecialIdentities(IdType.REALM);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Realms");
/*
* get special Filtered Role identities
*/
sampleUtils.waitForReturn("Hit <return> to get special filtered roles: ");
isr = idRepo.getSpecialIdentities(IdType.FILTEREDROLE);
isrSet = isr.getSearchResults();
isrMap = isr.getResultAttributes();
processSpecialIdentity(isrMap, isrSet, "Special Filtered Roles");
} catch (IdRepoException ire) {
System.err.println("idRepoProcessing:IdRepoException: " + ire.getMessage());
} catch (SSOException ssoe) {
System.err.println("idRepoProcessing:SSOException: " + ssoe.getMessage());
}
return;
}
use of com.sun.identity.idm.IdSearchResults in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method search.
@Override
public IdSearchResults search(SSOToken token, IdType type, IdSearchControl ctrl, String orgName, CrestQuery crestQuery) throws IdRepoException, SSOException {
IdSearchResults answer = new IdSearchResults(type, orgName);
// in legacy mode we must do search in order
// to get the AMSDKDN component added to AMIdentity's uvid.
// otherwise unix and anonymous login will fail.
cacheStats.incrementSearchRequestCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchRqts(li);
}
boolean isCached = false;
if (crestQuery.hasQueryId()) {
String pattern = crestQuery.getQueryId();
if ((pattern.indexOf('*') == -1) && ServiceManager.isRealmEnabled()) {
// First check if the specific identity is in cache.
// If yes, get Attributes from cache.
// If not search in server.
AMIdentity uvid = new AMIdentity(token, pattern, type, orgName, null);
String universalID = uvid.getUniversalId().toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(universalID);
if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists() && (ctrl.getSearchModifierMap() == null)) {
// Check if search is for a specific identity
// Search is for a specific user, look in the cache
Map attributes;
try {
cacheStats.updateSearchHitCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchCacheHits(li);
}
if (ctrl.isGetAllReturnAttributesEnabled()) {
attributes = getAttributes(token, type, pattern, orgName, null);
} else {
Set attrNames = ctrl.getReturnAttributes();
attributes = getAttributes(token, type, pattern, attrNames, orgName, null, true);
}
// Construct IdSearchResults
AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
answer.addResult(id, attributes);
isCached = true;
} catch (IdRepoException ide) {
// Check if the exception is name not found
if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
// Throw the exception
throw (ide);
}
}
}
}
}
if (!isCached) {
// Not in Cache. Do a search in server.
answer = super.search(token, type, ctrl, orgName, crestQuery);
}
return (answer);
}
Aggregations