use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class DirectoryServicesImpl method createCOSDefinition.
/**
* Create a COS Definition based on serviceID & attribute set & type. For
* policy attribute, will set cosattribute to "override" For other
* attribute, will set cosattribute to "default"
*/
private DirectCOSDefinition createCOSDefinition(String serviceID, Set attrNames) throws UMSException {
// new attribute set
AttrSet attrs = new AttrSet();
// set naming attribute to the serviceID
Attr attr = new Attr(ICOSDefinition.DEFAULT_NAMING_ATTR, serviceID);
attrs.add(attr);
// add cosspecifier
attr = new Attr(ICOSDefinition.COSSPECIFIER, "nsrole");
attrs.add(attr);
// add cosattribute
attr = new Attr(ICOSDefinition.COSATTRIBUTE);
Iterator iter = attrNames.iterator();
while (iter.hasNext()) {
String attrName = (String) iter.next();
attr.addValue(attrName);
}
attrs.add(attr);
return new DirectCOSDefinition(attrs);
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class DirectoryServicesImpl method updateUserAttribute.
/**
* Adds or remove static group DN to or from member attribute
* 'iplanet-am-static-group-dn'
*
* @param token
* SSOToken
* @param members
* set of user DN's
* @param staticGroupDN
* DN of the static group
* @param toAdd
* true to add, false to remove
* @throws AMException
* if there is an internal problem with AM Store.
*/
public void updateUserAttribute(SSOToken token, Set members, String staticGroupDN, boolean toAdd) throws AMException {
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl.updateUserAttribute(): " + "groupDN:" + staticGroupDN + ", toAdd: " + toAdd + " members: " + members);
}
Attr attr = new Attr(STATIC_GROUP_DN_ATTRIBUTE, staticGroupDN);
Iterator itr = members.iterator();
while (itr.hasNext()) {
String userDN = (String) itr.next();
try {
PersistentObject po = UMSObject.getObjectHandle(token, new Guid(userDN));
if (toAdd) {
po.modify(attr, ModificationType.ADD);
} else {
po.modify(attr, ModificationType.DELETE);
}
po.save();
} catch (UMSException e) {
debug.error("DirectoryServicesImpl.updateUserAttribute(): " + "Failed while trying to set the static groupDN " + staticGroupDN + " for user: " + userDN, e);
throw new AMException(token, "351", e);
}
}
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class PersistentObject method addChild.
/**
* Adds a child object to the persistent object container. All persistent
* objects can add objects as a container. To override this behavior or
* impose restrictions override the add method in a subclass so that e.g.
* User.add( object ) is restricted or disallowed in certain ways.
*
* @param object Child object to be added to this persistent container.
* @throws AccessRightsException if an access rights exception occurs.
* @throws EntryAlreadyExistsException if the entry already exists.
* @throws UMSException if fail to add the given child object to the
* container. Possible causes include
* <code>EntryAlreadyExists</code>, <code>AccessRights</code>
* violation.
*
* @supported.api
*/
public void addChild(PersistentObject object) throws AccessRightsException, EntryAlreadyExistsException, UMSException {
if (object == null) {
String[] args = new String[1];
args[0] = this.toString();
String msg = i18n.getString(IUMSConstants.ADD_NULL_OBJ, args);
throw new IllegalArgumentException(msg);
}
String idAttr = object.getNamingAttribute();
String idValue = null;
Attr idAttrObj = object.getAttribute(idAttr);
if (idAttrObj != null) {
idValue = idAttrObj.getValue();
} else {
throw new UMSException(BAD_NAMING_ATTR + idAttr);
}
if (idAttr == null || idValue == null || idValue.length() == 0) {
String[] args = new String[1];
args[0] = object.toString();
String msg = i18n.getString(IUMSConstants.COMPOSE_GUID_FAILED, args);
throw new IllegalArgumentException(msg);
}
String childStr = null;
if (getGuid().getDn().length() > 0) {
childStr = idAttr + "=" + idValue + "," + getGuid().getDn();
} else {
childStr = idAttr + "=" + idValue;
}
Guid childGuid = new Guid(childStr);
object.setGuid(childGuid);
// Validation was done during the creation of the object
// Validation.validateAttributes( object.getAttrSet(),
// object.getClass(), this.getGUID() );
DataLayer.getInstance().addEntry(getPrincipal(), childGuid, object.getAttrSet());
object.setModSet(null);
object.setPrincipal(getPrincipal());
EntityManager em = EntityManager.getEntityManager();
try {
em.execute(getPrincipal(), object, m_guid);
} catch (UMSException e) {
// TODO - we should log error...
if (debug.messageEnabled()) {
debug.message("PersistentObject.addChild : UMSException : " + e.getMessage());
}
}
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class PersistentObject method addAttributeValue.
/**
* Adds value for an attribute and saves the change in the database.
*
* @param token Authenticated prinicpal's single sign on token.
* @param guid Identifiation of the entry to which to add the attribute
* value.
* @param name Name of the attribute to which value is being added.
* @param value Value to be added to the attribute.
* @throws UMSException if any exception from the data layer.
*
* @supported.api
*/
public static void addAttributeValue(SSOToken token, Guid guid, String name, String value) throws UMSException {
if (guid == null) {
throw new IllegalArgumentException(i18n.getString(IUMSConstants.NULL_GUIDS));
}
if (token == null) {
throw new IllegalArgumentException(i18n.getString(IUMSConstants.NULL_TOKEN));
}
try {
SSOTokenManager.getInstance().validateToken(token);
} catch (SSOException se) {
throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN), se);
}
Attr attr = new Attr(name, value);
attr = null;
Validation.validateAttribute(attr, UMSObject.getObject(token, guid).getClass(), guid);
try {
DataLayer.getInstance().addAttributeValue(token.getPrincipal(), guid, name, value);
} catch (SSOException se) {
throw new UMSException(i18n.getString(IUMSConstants.BAD_TOKEN_HDL), se);
}
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class StaticGroup method removeMember.
/**
* Removes a member from the group. The change is saved to persistent
* storage.
*
* @param guid
* Unique identifier for the member to be removed
* @exception UMSException
* on failure to save to persistent storage
* @supported.api
*/
public void removeMember(Guid guid) throws UMSException {
String dn = guid.getDn();
super.modify(new Attr(MEMBER_ATTR_NAME, dn), ModificationType.DELETE);
save();
}
Aggregations