use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class ManagedRole method addMember.
/**
* Adds a member to the role. The change is saved to persistent storage.
*
* @param member
* Object to be added as member
* @throws UMSException
* on failure to save to persistent storage
* @supported.api
*/
public void addMember(PersistentObject member) throws UMSException {
member.modify(new Attr(MEMBER_ATTR_NAME, this.getDN()), ModificationType.ADD);
this.getDN();
Principal principal = getPrincipal();
if (principal == null) {
throw new IllegalArgumentException(i18n.getString(IUMSConstants.BAD_PRINCIPAL_HDL));
}
DataLayer.getInstance().addAttributeValue(principal, member.getGuid(), MEMBER_ATTR_NAME, this.getDN());
// invalidate the cached computed role attribute
member.getAttrSet().remove(COMPUTED_MEMBER_ATTR_NAME);
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class PersistentObject method getACI.
/**
* Returns all the ACIs of this object.
*
* @return collecion of ACIs of this object.
* @throws ACIParseException if any error
*
* @supported.api
*/
public Collection getACI() throws ACIParseException, UMSException {
Collection acis = new ArrayList();
Attr aciAttr = getAttribute(ACI.ACI);
if (aciAttr != null) {
String[] aciTexts = aciAttr.getStringValues();
int size = aciTexts.length;
for (int i = 0; i < size; i++) {
acis.add(ACI.valueOf(aciTexts[i]));
}
}
return acis;
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class AMDCTree method splitAttrSet.
protected static AttrSet[] splitAttrSet(String orgDN, AttrSet attrSet) throws AMException {
AttrSet[] attrArray = new AttrSet[2];
attrArray[0] = new AttrSet();
attrArray[1] = new AttrSet();
if (attrSet == null) {
return (attrArray);
}
Set dcNodeAttrs = dcNodeAttributes();
Iterator it = dcNodeAttrs.iterator();
while (it.hasNext()) {
String aName = (String) it.next();
if (aName.indexOf("objectclass=") > -1) {
Attr attr = attrSet.getAttribute("objectclass");
String oc = aName.substring("objectclass=".length());
Attr dcAttr = new Attr("objectclass");
if (attr != null && attr.contains(oc)) {
attr.removeValue(oc);
dcAttr.addValue(oc);
attrSet.replace(attr);
attrArray[1].add(dcAttr);
}
} else {
Attr attr = attrSet.getAttribute(aName);
if (attr != null) {
attrArray[1].add(attr);
attrSet.remove(aName);
}
}
}
attrArray[0] = attrSet;
if (debug.messageEnabled()) {
debug.message("AMCompliance.splitAttrSet: " + "domain attrset = " + attrArray[1].toString());
debug.message("AMCompliance.splitAttrSet: " + "non-domain attrset = " + attrArray[0].toString());
}
return attrArray;
}
use of com.iplanet.services.ldap.Attr 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.Attr 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);
}
}
Aggregations