use of javax.naming.directory.BasicAttribute in project OpenAM by OpenRock.
the class SMSEntry method addAttribute.
/**
* Adds the attribute value to the given attribute name. It is stored
* locally and is not written to the directory.
*/
public void addAttribute(String attrName, String value) throws SMSException {
Set attrValues = null;
if (attrSet == null) {
attrSet = new CaseInsensitiveHashMap();
} else if (attrSet.containsKey(attrName)) {
attrValues = (Set) attrSet.get(attrName);
if (attrValues.contains(value)) {
// Value is already present
if (debug.messageEnabled()) {
debug.message("SMSEntry: Duplicate value for addition");
}
throw (new SMSException(LdapException.newLdapException(ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, getBundleString(IUMSConstants.SMS_ATTR_OR_VAL_EXISTS)), "sms-ATTR_OR_VAL_EXISTS"));
}
}
// Add the attribute to attrset
if (attrValues == null) {
attrValues = new HashSet();
}
attrValues.add(value);
attrSet.put(attrName, attrValues);
// Check if the modification set exists, and add the attribute
if (modSet == null) {
modSet = new HashSet();
}
modSet.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attrName, value)));
}
use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method createUser.
//-----------------------USER MODIFICATION METHODS----------------------------
public void createUser(User user) throws InternalErrorException {
// Create a set of attributes
Attributes attributes = new BasicAttributes();
// Create the objectclass to add
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("person");
objClasses.add("organizationalPerson");
objClasses.add("inetOrgPerson");
objClasses.add("perunUser");
objClasses.add("tenOperEntry");
objClasses.add("inetUser");
String firstName = user.getFirstName();
String lastName = user.getLastName();
if (firstName == null)
firstName = "";
if (lastName == null || lastName.isEmpty())
lastName = "N/A";
// Add attributes
attributes.put(objClasses);
attributes.put("entryStatus", "active");
attributes.put("sn", lastName);
attributes.put("cn", firstName + " " + lastName);
if (!firstName.isEmpty())
attributes.put("givenName", firstName);
attributes.put("perunUserId", String.valueOf(user.getId()));
if (user.isServiceUser())
attributes.put("isServiceUser", "1");
else
attributes.put("isServiceUser", "0");
if (user.isSponsoredUser())
attributes.put("isSponsoredUser", "1");
else
attributes.put("isSponsoredUser", "0");
// Create the entry
try {
ldapTemplate.bind(getUserDN(String.valueOf(user.getId())), null, attributes);
log.debug("New entry created in LDAP: User {} in Group with Id=" + user.getId() + ".", user);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method removeGroup.
public void removeGroup(Group group) throws InternalErrorException {
List<String> uniqueUsersIds = new ArrayList<String>();
uniqueUsersIds = this.getAllUniqueMembersInGroup(group.getId(), group.getVoId());
for (String s : uniqueUsersIds) {
Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
this.updateUserWithUserId(s, new ModificationItem[] { memberOfItem });
}
try {
ldapTemplate.unbind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())));
log.debug("Entry deleted from LDAP: Group {} from Vo with ID=" + group.getVoId() + ".", group);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method removeMemberFromGroup.
public void removeMemberFromGroup(Member member, Group group) throws InternalErrorException {
//Remove member from group
Attribute uniqueMember = new BasicAttribute("uniqueMember", "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
ModificationItem uniqueMemberItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, uniqueMember);
this.updateGroup(group, new ModificationItem[] { uniqueMemberItem });
//Remove member from vo if this group is membersGroup
if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
//Remove info from vo
this.updateVo(group.getVoId(), new ModificationItem[] { uniqueMemberItem });
//Remove also information from user
Attribute memberOfPerunVo = new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
ModificationItem memberOfPerunVoItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOfPerunVo);
this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfPerunVoItem });
}
//Remove group info from member
Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfItem });
}
use of javax.naming.directory.BasicAttribute in project jmeter by apache.
the class LDAPSampler method getUserAttributes.
/**
* Collect all the value from the table (Arguments), using this create the
* basicAttributes. This will create the Basic Attributes for the User
* defined TestCase for Add Test.
*
* @return the BasicAttributes
*/
private BasicAttributes getUserAttributes() {
//$NON-NLS-1$
BasicAttribute basicattribute = new BasicAttribute("objectclass");
//$NON-NLS-1$
basicattribute.add("top");
//$NON-NLS-1$
basicattribute.add("person");
//$NON-NLS-1$
basicattribute.add("organizationalPerson");
//$NON-NLS-1$
basicattribute.add("inetOrgPerson");
BasicAttributes attrs = new BasicAttributes(true);
attrs.put(basicattribute);
BasicAttribute attr;
for (JMeterProperty jMeterProperty : getArguments()) {
Argument item = (Argument) jMeterProperty.getObjectValue();
attr = getBasicAttribute(item.getName(), item.getValue());
attrs.put(attr);
}
return attrs;
}
Aggregations