use of com.iplanet.ums.PersistentObject in project OpenAM by OpenRock.
the class DirectoryServicesImpl method getAttributesFromDS.
/**
* Gets the specific attributes corresponding to the entryDN. This method
* obtains the DC Tree node attributes and also performs compliance related
* verification checks in compliance mode. Note: In compliance mode you can
* skip the compliance checks by setting ignoreCompliance to "false".
*
* @param token
* a valid SSOToken
* @param entryDN
* the DN of the entry whose attributes need to retrieved
* @param attrNames
* a Set of names of the attributes that need to be retrieved.
* The attrNames should not be null.
* @param ignoreCompliance
* a boolean value specificying if compliance related entries
* need to ignored or not. Ignored if true.
* @return a Map containing attribute names as keys and Set of values
* corresponding to each key.
* @throws AMException
* if an error is encountered in fetching the attributes
*/
public Map getAttributesFromDS(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
if (attrNames == null) {
return getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
}
try {
// Convert the attrNames to String[]
String[] names = (String[]) attrNames.toArray(new String[attrNames.size()]);
PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
// Perform compliance related checks
AttrSet attrSet;
if (!ignoreCompliance && ComplianceServicesImpl.isComplianceUserDeletionEnabled()) {
// check for deleted user by getting complaince attributes
attrSet = complianceImpl.verifyAndGetAttributes(po, names);
} else {
attrSet = po.getAttributes(names);
}
AMHashMap attributes = (AMHashMap) CommonUtils.attrSetToMap(attrSet, byteValues);
// Obtain DC tree attributes if applicable
Map dcAttributes = getDCTreeAttributes(token, entryDN, attrNames, byteValues, profileType);
attributes.copy(dcAttributes);
return attributes;
} catch (UMSException e) {
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.getAttributes(): " + "Unable to get attributes: ", e);
}
// Extract the ldap error code from Exception
throw new AMException(token, "330", e);
}
}
use of com.iplanet.ums.PersistentObject 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.PersistentObject in project OpenAM by OpenRock.
the class DirectoryServicesImpl method getSearchResults.
/**
* convert search results to a AMSearchResults object TODO: Refactor code
*/
private AMSearchResults getSearchResults(SearchResults results, SortKey skey, String[] attrNames, Collator collator, boolean getAllAttrs) throws UMSException {
TreeMap tm = null;
TreeSet tmpTreeSet = null;
if (skey != null) {
tm = new TreeMap(collator);
tmpTreeSet = new TreeSet();
}
Set set = new OrderedSet();
Map map = new HashMap();
int errorCode = AMSearchResults.SUCCESS;
try {
if (results != null) {
while (results.hasMoreElements()) {
PersistentObject po = results.next();
String dn = po.getGuid().toString();
if (tm != null) {
Attr attr = po.getAttribute(skey.attributeName);
if (attr != null) {
String attrValue = attr.getStringValues()[0];
Object obj = tm.get(attrValue);
if (obj == null) {
tm.put(attrValue, dn);
} else if (obj instanceof java.lang.String) {
TreeSet tmpSet = new TreeSet();
tmpSet.add(obj);
tmpSet.add(dn);
tm.put(attrValue, tmpSet);
} else {
((TreeSet) obj).add(dn);
}
} else {
tmpTreeSet.add(dn);
}
} else {
set.add(dn);
}
AttrSet attrSet = new AttrSet();
if (attrNames != null) {
// Support for multiple return values
attrSet = po.getAttributes(attrNames, true);
} else {
/*
* Support for multiple return values when attribute
* names are not passed as part of the return
* attributes. This boolean check is to make sure user
* has set the setAllReturnAttributes flag in
* AMSearchControl in order to get all attributes or
* not.
*/
if (getAllAttrs) {
attrSet = po.getAttributes(po.getAttributeNames(), true);
}
}
map.put(dn, CommonUtils.attrSetToMap(attrSet));
}
}
} catch (SizeLimitExceededException slee) {
errorCode = AMSearchResults.SIZE_LIMIT_EXCEEDED;
} catch (TimeLimitExceededException tlee) {
errorCode = AMSearchResults.TIME_LIMIT_EXCEEDED;
}
Integer count = (Integer) results.get(SearchResults.VLVRESPONSE_CONTENT_COUNT);
int countValue;
if (count == null) {
countValue = AMSearchResults.UNDEFINED_RESULT_COUNT;
} else {
countValue = count.intValue();
}
if (tm != null) {
Object[] values = tm.values().toArray();
int len = values.length;
if (skey.reverse) {
for (int i = len - 1; i >= 0; i--) {
Object obj = values[i];
if (obj instanceof java.lang.String) {
set.add(obj);
} else {
set.addAll((Collection) obj);
}
}
} else {
for (int i = 0; i < len; i++) {
Object obj = values[i];
if (obj instanceof java.lang.String) {
set.add(obj);
} else {
set.addAll((Collection) obj);
}
}
}
Iterator iter = tmpTreeSet.iterator();
while (iter.hasNext()) {
set.add(iter.next());
}
}
AMSearchResults searchResults = new AMSearchResults(countValue, set, errorCode, map);
return searchResults;
}
use of com.iplanet.ums.PersistentObject in project OpenAM by OpenRock.
the class COSManager method updateDefinition.
/**
* Updates the contents of a COS definition with the new contents. The COS
* definition must already exist in the persistent layer, before its
* contents can be replaced.
*
* @param cosDef
* The COS definition containing new contents, which will replace
* the same definition in the persistent layer.
*
* @throws UMSException
* The exception thrown from the data layer.
* @supported.api
*/
public void updateDefinition(ICOSDefinition cosDef) throws UMSException {
PersistentObject pObject = (PersistentObject) cosDef;
if (pObject.getGuid() == null) {
String msg = i18n.getString(IUMSConstants.REPLACE_DEFINITION_NOT_PERSISTENT);
throw new UMSException(msg);
}
pObject.save();
}
use of com.iplanet.ums.PersistentObject in project OpenAM by OpenRock.
the class COSManager method addDefinition.
/**
* This method adds a COS definition to the persistent store. The definition
* is added under the specified "guid" parameter.
*
* @param cosDef
* The COS definition to be added.
*
* @throws UMSException
* The exception thrown from the data layer.
* @supported.api
*/
public void addDefinition(ICOSDefinition cosDef) throws UMSException {
if (!(cosDef instanceof DirectCOSDefinition)) {
String msg = i18n.getString(IUMSConstants.INVALID_COSDEFINITION);
throw new UMSException(msg);
}
String[] cosAttributes = cosDef.getCOSAttributes();
AbstractCollection aList = (AbstractCollection) Arrays.asList(ICOSDefinition.qualifiers);
for (int i = 0; i < cosAttributes.length; i++) {
String cosAttribute = null;
String qualifier = null;
StringTokenizer st = new StringTokenizer(cosAttributes[i]);
if (st.hasMoreTokens()) {
cosAttribute = st.nextToken();
}
if (cosAttribute == null) {
String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
throw new UMSException(msg);
}
if (st.hasMoreTokens())
qualifier = st.nextToken();
if (qualifier == null) {
qualifier = ICOSDefinition.qualifiers[ICOSDefinition.DEFAULT];
cosDef.removeCOSAttribute(cosAttribute);
cosDef.addCOSAttribute(cosAttribute, ICOSDefinition.DEFAULT);
}
if (!aList.contains(qualifier)) {
String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
throw new UMSException(msg);
}
}
PersistentObject po = (PersistentObject) cosDef;
_parentObject.addChild(po);
}
Aggregations