use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class MiscUtils 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
*/
public 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 ComplianceServicesImpl method verifyAndLinkRoleToGroup.
/**
* Method which verifies if the <code>roleDN</code> corresponds to an
* admin role. If true the <code>memberOf</code> and
* <code>adminRole</code> attributes of each member/user are set to the
* corresponding administration <code>groupDN</code> and administration
* <code>groupRDN</code> respectively. Each of the members/users are also
* added to the corresponding admin group.
*
* @param token
* single sign on token.
* @param membersGuid
* Guid array of members to be operated on.
* @param roleDN
* distinguished name of the role.
*
* @exception AMException
* if unsuccessful in adding the members to the corresponding
* admin group. As a result of which the memberOf and
* adminRole attributes are also not updated.
*/
protected void verifyAndLinkRoleToGroup(SSOToken token, Guid[] membersGuid, String roleDN) throws AMException {
// Obtain the group corresponding to roleDN
DN dn = DN.valueOf(roleDN);
String groupName = getGroupFromRoleDN(dn);
if (groupName != null) {
// roleDN corresponds to an admin role
String orgDN = dn.parent().toString();
String groupDN = NamingAttributeManager.getNamingAttribute(AMObject.GROUP) + "=" + groupName + ",ou=Groups," + orgDN;
String groupRDN = NamingAttributeManager.getNamingAttribute(AMObject.GROUP) + "=" + groupName;
try {
// Add the members to corresponding group.
AssignableDynamicGroup group = (AssignableDynamicGroup) UMSObject.getObject(token, new Guid(groupDN));
group.addMembers(membersGuid);
Attr[] attrs = new Attr[1];
attrs[0] = new Attr("adminrole", groupRDN);
AttrSet attrSet = new AttrSet(attrs);
int numMembers = membersGuid.length;
for (int i = 0; i < numMembers; i++) {
addAttributesToEntry(token, membersGuid[i].getDn(), attrSet);
}
} catch (EntryNotFoundException ex) {
debug.error("Compliance.verifyAndLinkRoleToGroup: " + "Admin groups are missing");
} catch (UMSException ue) {
debug.error("Compliance." + "verifyAndLinkRoleToGroup(): ", ue);
throw new AMException(AMSDKBundle.getString("771"), "771");
}
}
}
use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class CommonUtils method mapToAttrSet.
/**
* Method to convert a Map to AttrSet.
*
* @param map
* a map contaning attribute names as keys and a Set of attribute
* values corresponding to each map key.
* @param byteValues
* if true then values are bytes otherwise strings
* @return an AttrSet having the contents of the supplied map
*/
protected static AttrSet mapToAttrSet(Map map, boolean byteValues) {
AttrSet attrSet = new AttrSet();
if (map == null) {
return attrSet;
}
if (!byteValues) {
Iterator itr = map.keySet().iterator();
while (itr.hasNext()) {
String attrName = (itr.next()).toString();
Set set = (Set) (map.get(attrName));
String[] attrValues = (set == null) ? null : (String[]) set.toArray(new String[set.size()]);
if (attrValues != null) {
attrSet.replace(new Attr(attrName, attrValues));
}
}
} else {
Iterator itr = map.keySet().iterator();
while (itr.hasNext()) {
String attrName = (itr.next()).toString();
byte[][] attrValues = (byte[][]) (map.get(attrName));
if (attrValues != null) {
attrSet.replace(new Attr(attrName, attrValues));
}
}
}
return attrSet;
}
use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class PCMappingTable method getAttrSetFromFilter.
/**
* Gets the attribute set correspondent to the filter string. Only accepts
* filter string with the following format:
*
* <PRE>
*
* <filter> ::= <and> | <item> <and> ::= '(' '&'
* <itemlist> ')' <itemlist> ::= <item> | <item>
* <itemlist> <item> ::= '(' <attr> '=' <value> ')'
*
* </PRE>
*
* @param filter
* filter string to parse
* @return the attribute set correspondent to the filter string
*/
private AttrSet getAttrSetFromFilter(String filter) {
AttrSet attrSet = new AttrSet();
String f = filter;
f.trim();
if (f.startsWith("(") && f.endsWith(")")) {
f = f.substring(1, f.length() - 1);
}
if (f.startsWith("|") || f.startsWith("!")) {
// TODO: should throw an exception: invalid pc filter
return null;
}
if (f.startsWith("&")) {
int level = 0;
int start = 0;
int end = 0;
for (int i = 0; i < f.length(); i++) {
if (f.charAt(i) == '(') {
if (level == 0) {
start = i;
}
level++;
}
if (f.charAt(i) == ')') {
level--;
if (level == 0) {
end = i;
String subf = f.substring(start, end + 1);
if (subf.startsWith("(") && subf.endsWith(")")) {
subf = subf.substring(1, subf.length() - 1);
}
int idx = subf.indexOf('=');
if (idx == -1) {
return null;
}
String type = subf.substring(0, idx).trim();
String value = subf.substring(idx + 1).trim();
attrSet.add(new Attr(type, value));
}
}
}
} else {
int idx = f.indexOf('=');
if (idx == -1) {
return null;
}
String type = f.substring(0, idx).trim();
String value = f.substring(idx + 1).trim();
attrSet.add(new Attr(type, value));
}
return attrSet;
}
use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.
the class PCMappingTable method getPeopleContainer.
/**
* Gets People Container associated with the user
*
* @param user
* user object to look up
* @return guid identifying People Container associated with the user, null
* if no match found and default has not been set
* @exception UMSException
* Failure
*/
public String getPeopleContainer(User user) throws UMSException {
PersistentObject po = UMSObject.getObject(_principal, _mappingGuid);
AttrSet attrSet = po.getAttrSet();
String defaultPC = getDefault(attrSet);
for (int j = 0; j < ATTRNAMESTOSKIP.length; j++) {
attrSet.remove(ATTRNAMESTOSKIP[j]);
}
Enumeration e1 = attrSet.getAttributes();
while (e1.hasMoreElements()) {
Attr attr = (Attr) e1.nextElement();
String guid = attr.getName();
String[] filters = attr.getStringValues();
for (int j = 0; j < filters.length; j++) {
AttrSet filterAttrSet = getAttrSetFromFilter(filters[j]);
// loop through filterAttrSet and compare each one to the
// user's AttrSet
Enumeration e2 = filterAttrSet.getAttributes();
while (e2.hasMoreElements()) {
Attr filterAttr = (Attr) e2.nextElement();
Attr userAttr = user.getAttribute(filterAttr.getName());
if (userAttr != null) {
String[] filterAttrValues = filterAttr.getStringValues();
for (int i = 0; i < filterAttrValues.length; i++) {
if (userAttr.contains(filterAttrValues[i])) {
return guid;
}
}
}
}
}
}
return defaultPC;
}
Aggregations