use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class AMCommonUtils method combineAttrSets.
/**
* Combines 2 AttrSets and returns the result set. The original sets are not
* modified.
*
* @param attrSet1
* the first AttrSet
* @param attrSet2
* the second AttrSet
* @return an AttrSet which has combined values of attrSet1 & attrSet2
*/
protected static AttrSet combineAttrSets(AttrSet attrSet1, AttrSet attrSet2) {
AttrSet retAttrSet = new AttrSet();
if (attrSet1 != null) {
int count = attrSet1.size();
for (int i = 0; i < count; i++) {
Attr attr = attrSet1.elementAt(i);
retAttrSet.add(attr);
}
}
if (attrSet2 != null) {
int count = attrSet2.size();
for (int i = 0; i < count; i++) {
Attr attr = attrSet2.elementAt(i);
retAttrSet.add(attr);
}
}
return retAttrSet;
}
use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class EmailNotificationHelper method sendUserModifyNotification.
// TODO: Refactor this method.
/**
* The proper setUser<>NotificationList method should be called before
* calling this method.
*
* @param token
* a valid single sign on token
* @param attributes
* the attribues of the user
* @param oldAttributes
* the previous attributes of the user
*/
public void sendUserModifyNotification(SSOToken token, Map attributes, Map oldAttributes) {
if (modifyNotifyList == null || modifyNotifyList.isEmpty()) {
return;
}
// TODO: Refactor code to use maps directly
AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
AttrSet oldAttrSet = CommonUtils.mapToAttrSet(oldAttributes);
try {
String self = AMSDKBundle.getString("504");
Iterator iter = modifyNotifyList.iterator();
while (iter.hasNext()) {
String val = (String) iter.next();
StringTokenizer stz = new StringTokenizer(val);
int toLen = stz.countTokens();
if (toLen > 0) {
String attrName = stz.nextToken().toLowerCase();
boolean valuesChanged = false;
Attr newAttrVal = null;
Attr oldAttrVal = null;
StringBuilder newSB = new StringBuilder();
StringBuilder oldSB = new StringBuilder();
if (attrSet.contains(attrName)) {
newAttrVal = attrSet.getAttribute(attrName);
if (newAttrVal != null) {
String[] newvalues = newAttrVal.getStringValues();
for (int i = 0; i < newvalues.length; i++) {
newSB.append(newvalues[i]);
}
}
}
if (oldAttrSet.contains(attrName)) {
oldAttrVal = oldAttrSet.getAttribute(attrName);
if (oldAttrVal != null) {
String[] oldvalues = oldAttrVal.getStringValues();
for (int i = 0; i < oldvalues.length; i++) {
oldSB.append(oldvalues[i]);
}
}
}
String newStr = newSB.toString();
String oldStr = oldSB.toString();
valuesChanged = !newStr.equalsIgnoreCase(oldStr);
if (valuesChanged) {
while (stz.hasMoreTokens()) {
StringTokenizer stz2 = new StringTokenizer(stz.nextToken(), "|");
String email = stz2.nextToken();
String[] to;
if (email.equals(self)) {
Set attrNamesSet = new HashSet(1);
attrNamesSet.add(EMAIL_ATTRIBUTE);
Map emailAttrMap = DirectoryServicesFactory.getInstance().getAttributes(token, entryDN, attrNamesSet, AMObject.USER);
Set emails = (Set) emailAttrMap.get(EMAIL_ATTRIBUTE);
if (emails == null || emails.isEmpty()) {
continue;
} else {
to = (String[]) emails.toArray(new String[emails.size()]);
}
} else if (email.startsWith(self + ":")) {
String emailAttrName = email.substring((self + ":").length());
if (emailAttrName == null || emailAttrName.length() == 0) {
continue;
}
Set attrNamesSet = new HashSet(1);
attrNamesSet.add(emailAttrName);
Map emailAttrMap = DirectoryServicesFactory.getInstance().getAttributes(token, entryDN, attrNamesSet, AMObject.USER);
Set emails = (Set) emailAttrMap.get(emailAttrName);
if (emails == null || emails.isEmpty()) {
continue;
} else {
to = (String[]) emails.toArray(new String[emails.size()]);
}
} else {
to = new String[1];
to[0] = email;
}
String locale = null;
String charset = null;
if (stz2.hasMoreTokens()) {
locale = stz2.nextToken();
if (stz2.hasMoreTokens()) {
charset = stz2.nextToken();
}
}
Attr oldAttr = oldAttrSet.getAttribute(attrName);
Attr newAttr = attrSet.getAttribute(attrName);
String sub = AMSDKBundle.getString("492", locale);
StringBuilder msgSB = new StringBuilder();
msgSB.append(AMSDKBundle.getString("495", locale)).append(" ").append(entryDN).append("\n").append(AMSDKBundle.getString("496", locale)).append(" ").append(attrName).append("\n").append(AMSDKBundle.getString("502", locale)).append("\n");
if (oldAttr != null) {
String[] values = oldAttr.getStringValues();
for (int i = 0; i < values.length; i++) {
msgSB.append(" ").append(values[i]).append("\n");
}
}
msgSB.append(AMSDKBundle.getString("503", locale)).append("\n");
if (newAttr != null) {
String[] values = newAttr.getStringValues();
for (int i = 0; i < values.length; i++) {
msgSB.append(" ").append(values[i]).append("\n");
}
}
String from = AMSDKBundle.getString("497", locale);
mailer.postMail(to, sub, msgSB.toString(), from, charset);
}
}
}
}
} catch (MessagingException me) {
if (debug.warningEnabled()) {
debug.warning("EmailNotificationHelper." + "sendUserModifyNotification() Unable to send " + "email for user: " + entryDN, me);
}
} catch (SSOException e) {
debug.error("EmailNotificationHelper.sendUserModifyNotification() " + "Error occured while trying to send email for user: " + entryDN, e);
} catch (AMException ex) {
debug.error("EmailNotificationHelper.sendUserModifyNotification() " + "Error occured while trying to send email for user: " + entryDN, ex);
}
}
use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class DirectoryServicesImpl method createDynamicGroup.
private void createDynamicGroup(SSOToken token, PersistentObject parentObj, Map attributes, String profileName) throws UMSException, AMException {
// Invoke the Pre Process plugin
String orgDN = getOrganizationDN(internalToken, parentObj.getDN());
String entryDN = getNamingAttribute(AMObject.GROUP) + "=" + profileName + "," + parentObj.getDN();
attributes = callBackHelper.preProcess(token, entryDN, orgDN, null, attributes, CallBackHelper.CREATE, AMObject.DYNAMIC_GROUP, false);
AttrSet attrSet = CommonUtils.mapToAttrSet(attributes);
makeNamingFirst(attrSet, getNamingAttribute(AMObject.DYNAMIC_GROUP), profileName);
TemplateManager tempMgr = TemplateManager.getTemplateManager();
CreationTemplate creationTemp = tempMgr.getCreationTemplate("BasicDynamicGroup", new Guid(orgDN), TemplateManager.SCOPE_ANCESTORS);
attrSet = combineOCs(creationTemp, attrSet);
com.iplanet.ums.DynamicGroup dgroup = new com.iplanet.ums.DynamicGroup(creationTemp, attrSet);
String filter = dgroup.getSearchFilter();
if ("(objectClass=*)".equalsIgnoreCase(filter)) {
dgroup.setSearchFilter(SearchFilterManager.getSearchFilter(AMObject.USER, orgDN));
}
dgroup.setSearchScope(SearchScope.WHOLE_SUBTREE.intValue());
dgroup.setSearchBase(new Guid(orgDN));
parentObj.addChild(dgroup);
// Invoke Post processing impls
callBackHelper.postProcess(token, dgroup.getDN(), orgDN, null, attributes, CallBackHelper.CREATE, AMObject.DYNAMIC_GROUP, false);
}
use of com.iplanet.services.ldap.AttrSet 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.services.ldap.AttrSet in project OpenAM by OpenRock.
the class COSManager method removeDirectCOSAssignment.
/**
* Removes a Direct COS assignment from a target persistent object. The COS
* target persistent object could be a user, group, organization,
* organizationalunit, etc. The COS target object must be persistent before
* this method can be used.
*
* @param pObject
* The COS target persistent object.
* @param cosDef
* A COS definition.
* @param sMgr
* A SchemaManager object, which is used to determine object
* classes for attributes.
*
* @throws UMSException
* The exception thrown if any of the following occur: o an
* exception occurs determining the object class for the COS
* specifier. o an exception occurs determining the object class
* for the COS attributes. o there is an exception thrown rom
* the data layer.
*/
private void removeDirectCOSAssignment(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
ArrayList aList;
AttrSet attrSet = new AttrSet();
try {
//
if (pObject.getAttribute(cosDef.getCOSSpecifier()) != null)
attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
// Get cosSpecifier object class - should only be one.
// Include the cosSpecifier object class in the attribute
// set for removal (only if itt exists).
//
aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
String cosSpecObjectClass = (String) aList.get(0);
if (objectClassExists(cosSpecObjectClass, pObject)) {
attrSet.add(new Attr("objectclass", cosSpecObjectClass));
}
// Get the cos attributes from the definition (ex. mailquota).
// For each of the attributes, get the objectclass. Include the
// object classes in the attribute set for removal (if they exist).
//
String[] cosAttributes = cosDef.getCOSAttributes();
String cosAttribute = null;
for (int i = 0; i < cosAttributes.length; i++) {
// Only get the attribute - not the qualifier
//
StringTokenizer st = new StringTokenizer(cosAttributes[i]);
cosAttribute = st.nextToken();
aList = (ArrayList) sMgr.getObjectClasses(cosAttribute);
String cosAttributeObjectClass = (String) aList.get(0);
if (objectClassExists(cosAttributeObjectClass, pObject)) {
attrSet.add(new Attr("objectclass", cosAttributeObjectClass));
}
}
if (attrSet.size() > 0) {
pObject.modify(toModifications(ModificationType.DELETE, attrSet));
pObject.save();
}
} catch (UMSException e) {
LdapException le = (LdapException) e.getRootCause();
// Ignore anything that is not a COS generated attribute's object class
if (!ResultCode.OBJECTCLASS_VIOLATION.equals(le.getResult().getResultCode())) {
throw e;
}
}
}
Aggregations