use of com.iplanet.ums.SearchControl in project OpenAM by OpenRock.
the class AMSearchControl method setAllReturnAttributes.
/**
* Sets the specified boolean value to the variable. Boolean value is set to
* true, if all attributes of the entries need to be obtained as part of the
* search.
*
* NOTE: If this <code>getAllReturnAttributes</code> boolean is set to
* true as part of <code>AMSearchControl</code>, it overrides any other
* <code>setReturnAttributes</code> set as part of the
* <code>AMSearchControl</code>. This is similar to using a wildcard '*'
* in search.
*
* When the option for getting all attributes is set to true, the search
* results will return a Map, where the Key is the DN of the search results,
* and value is another Map of attribute names for keys and Sets for values
* of those attributes.
*
* @param getAllAttributes
* Boolean value set to true as part of the
* <code>AMSearchControl</code> to obtain all attributes as
* part of the search.
*
*
*/
public void setAllReturnAttributes(boolean getAllAttributes) {
SearchControl sc = getSearchControl();
sc.setAllReturnAttributes(getAllAttributes);
getAllAttributesEnabled = getAllAttributes;
}
use of com.iplanet.ums.SearchControl in project OpenAM by OpenRock.
the class DirectoryServicesImpl method search.
// RENAME from searchUsingSearchControl => search()
/**
* Search the Directory
*
* @param token
* SSOToken
* @param entryDN
* DN of the entry to start the search with
* @param searchFilter
* search filter
* @param searchControl
* search control defining the VLV indexes and search scope
* @param attrNames
* name of attributes
* @return Set set of matching DNs
*/
public AMSearchResults search(SSOToken token, String entryDN, String searchFilter, SearchControl searchControl, String[] attrNames) throws AMException {
AMSearchResults amResults = null;
try {
SortKey[] skeys = searchControl.getSortKeys();
SortKey skey = null;
if (skeys != null && skeys.length > 0 && skeys[0].attributeName != null) {
skey = skeys[0];
}
String userLocale = CommonUtils.getUserLocale(token);
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl.search() search with " + "searchcontrol locale = " + userLocale);
}
Collator collator = Collator.getInstance(Locale.getLocale(userLocale));
SearchControl sc;
if (skey != null) {
sc = new SearchControl();
sc.setMaxResults(searchControl.getMaxResults());
sc.setSearchScope(searchControl.getSearchScope());
sc.setTimeOut(searchControl.getTimeOut());
} else {
sc = searchControl;
}
PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
SearchResults results;
if (attrNames == null) {
if (skey == null) {
results = po.search(searchFilter, sc);
} else {
String[] tmpAttrNames = { skey.attributeName };
results = po.search(searchFilter, tmpAttrNames, sc);
}
} else {
if (skey == null) {
results = po.search(searchFilter, attrNames, sc);
} else {
String[] tmpAttrNames = new String[attrNames.length + 1];
System.arraycopy(attrNames, 0, tmpAttrNames, 0, attrNames.length);
tmpAttrNames[attrNames.length] = skey.attributeName;
results = po.search(searchFilter, tmpAttrNames, sc);
}
}
amResults = getSearchResults(results, skey, attrNames, collator, sc.isGetAllReturnAttributesEnabled());
} catch (UMSException ue) {
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.search() with search " + "control entryDN: " + entryDN + " Search Filter: " + searchFilter + " Error occurred: ", ue);
}
processInternalException(token, ue, "341");
}
return amResults;
}
use of com.iplanet.ums.SearchControl in project OpenAM by OpenRock.
the class AMRoleImpl method searchUsers.
/**
* Searches for users in this role using wildcards and attribute values.
* Wildcards can be specified such as a*, *, *a. To further refine the
* search, attribute-value pairs can be specifed so that DNs of users with
* matching attribute-value pairs will be returned.
*
* @param wildcard
* wildcard pattern to be used in the search
* @param avPairs
* attribute-value pairs to match when searching users
* @param searchControl
* specifies the search scope to be used, VLV ranges etc.,
*
* @return AMSearchResults which contains a Set DNs of Users matching the
* search
*
* @throws AMException
* if there is an internal error in the AM Store
* @throws SSOException
* if the sign on is no longer valid
*/
public AMSearchResults searchUsers(String wildcard, Map avPairs, AMSearchControl searchControl) throws AMException, SSOException {
int level = searchControl.getSearchScope();
if ((level != AMConstants.SCOPE_ONE) && (level != AMConstants.SCOPE_SUB))
throw new AMException(AMSDKBundle.getString("123", super.locale), "123");
if ((wildcard == null) || (wildcard.length() == 0))
throw new AMException(AMSDKBundle.getString("122", super.locale), "122");
String userFilter = "(&(" + AMNamingAttrManager.getNamingAttr(USER) + "=" + wildcard + ")" + getSearchFilter(AMObject.USER) + "(" + roleDNsAN + "=" + super.entryDN + "))";
String filter = null;
if (avPairs == null) {
filter = userFilter;
} else {
if (avPairs.isEmpty()) {
filter = userFilter;
} else {
StringBuilder filterSB = new StringBuilder();
filterSB.append("(&").append(userFilter).append("(|");
Iterator iter = avPairs.keySet().iterator();
while (iter.hasNext()) {
String attributeName = (String) (iter.next());
Iterator iter2 = ((Set) (avPairs.get(attributeName))).iterator();
while (iter2.hasNext()) {
String attributeValue = (String) iter2.next();
filterSB.append("(").append(attributeName).append("=").append(attributeValue).append(")");
}
}
filterSB.append("))");
filter = filterSB.toString();
}
}
SearchControl sc = searchControl.getSearchControl();
String[] returnAttrs = searchControl.getReturnAttributes();
return dsServices.search(super.token, getOrganizationDN(), filter, sc, returnAttrs);
}
use of com.iplanet.ums.SearchControl in project OpenAM by OpenRock.
the class AMGroupImpl method searchUsers.
/**
* Searches for users in this group using wildcards. Wildcards can be
* specified such as a*, *, *a.
*
* @param wildcard
* wildcard pattern to be used in the search
* @param avPairs
* attribute-value pairs to match when searching users
* @param searchControl
* specifies the size limit and time limit
*
* @return AMSearchResults which contains a Set DNs of Users matching the
* search
*
* @throws AMException
* if there is an internal error in the AM Store
* @throws SSOException
* if the sign on is no longer valid
*/
public AMSearchResults searchUsers(String wildcard, Map avPairs, AMSearchControl searchControl) throws AMException, SSOException {
int scope;
String base;
String gfilter;
if (profileType == DYNAMIC_GROUP || profileType == ASSIGNABLE_DYNAMIC_GROUP) {
String[] array = dsServices.getGroupFilterAndScope(token, entryDN, profileType);
scope = Integer.parseInt(array[0]);
base = array[1];
gfilter = array[2];
} else {
scope = AMConstants.SCOPE_SUB;
base = getOrganizationDN();
gfilter = "(iplanet-am-static-group-dn=" + entryDN + ")";
}
String userFilter = "(&" + gfilter + "(" + AMNamingAttrManager.getNamingAttr(USER) + "=" + wildcard + ")" + getSearchFilter(AMObject.USER) + ")";
String filter = null;
if (avPairs == null) {
filter = userFilter;
} else {
if (avPairs.isEmpty()) {
filter = userFilter;
} else {
StringBuilder filterSB = new StringBuilder();
filterSB.append("(&").append(userFilter).append("(|");
Iterator iter = avPairs.keySet().iterator();
while (iter.hasNext()) {
String attributeName = (String) (iter.next());
Iterator iter2 = ((Set) (avPairs.get(attributeName))).iterator();
while (iter2.hasNext()) {
String attributeValue = (String) iter2.next();
filterSB.append("(").append(attributeName).append("=").append(attributeValue).append(")");
}
}
filterSB.append("))");
filter = filterSB.toString();
}
}
searchControl.setSearchScope(scope);
SearchControl sc = searchControl.getSearchControl();
String[] returnAttrs = searchControl.getReturnAttributes();
return dsServices.search(super.token, base, filter, sc, returnAttrs);
}
use of com.iplanet.ums.SearchControl in project OpenAM by OpenRock.
the class DCTreeServicesImpl method updateCacheAndReturnDomain.
/**
* This is a private method to update cache
*/
private String updateCacheAndReturnDomain(SSOToken token, String canonOrgDN) throws AMException {
try {
DomainComponentTree dcTree = new DomainComponentTree(token, new Guid(DCTREE_START_DN));
SearchControl scontrol = new SearchControl();
scontrol.setSearchScope(SearchControl.SCOPE_SUB);
PersistentObject po = UMSObject.getObject(token, new Guid(DCTREE_START_DN));
String searchFilter = "(inetDomainBaseDN=" + canonOrgDN + ")";
if (debug.messageEnabled()) {
debug.message("DCTree.updateCache-> " + "searchFilter= " + searchFilter);
}
SearchResults results = po.search(searchFilter, null);
int count = 0;
String domainName = null;
String canonDomain = null;
while (results.hasMoreElements()) {
DomainComponent dcNode = (DomainComponent) results.next();
count++;
domainName = dcTree.mapDCToDomainName(dcNode);
if (debug.messageEnabled()) {
debug.message("DCTree:updateCache-> " + "domainName= " + domainName);
}
Attr isCanonical = dcNode.getAttribute(INET_CANONICAL_DOMAIN);
if (isCanonical != null) {
/*
* if (AMCacheManager.isCachingEnabled()) {
* synchronized(canonicalDomainMap) {
* canonicalDomainMap.put(canonOrgDN, domainName); } }
*/
canonDomain = domainName;
}
/*
* if (AMCacheManager.isCachingEnabled()) {
* synchronized(domainMap) { domainMap.put(canonOrgDN,
* domainName); } }
*/
}
results.abandon();
if (count == 1) {
canonDomain = domainName;
/*
* if (AMCacheManager.isCachingEnabled()) {
* canonicalDomainMap.put(canonOrgDN, domainName); }
*/
}
if (debug.messageEnabled()) {
debug.message("DCTree.updateCache-> " + "returning domain= " + canonDomain);
}
return canonDomain;
} catch (UMSException umse) {
debug.error("DCTree:updateCache: UMSException", umse);
return null;
}
}
Aggregations