use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method addGroup.
//------------------GROUP MODIFICATION METHODS-------------------------------
public void addGroup(Group group) 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("perunGroup");
// Add attributes
attributes.put(objClasses);
attributes.put("cn", group.getName());
attributes.put("perunGroupId", String.valueOf(group.getId()));
attributes.put("perunUniqueGroupName", new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
attributes.put("perunVoId", String.valueOf(group.getVoId()));
if (group.getDescription() != null && !group.getDescription().isEmpty())
attributes.put("description", group.getDescription());
if (group.getParentGroupId() != null) {
attributes.put("perunParentGroup", "perunGroupId=" + group.getParentGroupId().toString() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
attributes.put("perunParentGroupId", group.getParentGroupId().toString());
}
// Create the entry
try {
ldapTemplate.bind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())), null, attributes);
log.debug("New entry created in LDAP: Group {} in 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 createVo.
//--------------------------VO MODIFICATION METHODS---------------------------
public void createVo(Vo vo) throws InternalErrorException {
// Create a set of attributes for vo
Attributes voAttributes = new BasicAttributes();
// Create the objectclass to add
Attribute voObjClasses = new BasicAttribute("objectClass");
voObjClasses.add("top");
voObjClasses.add("organization");
voObjClasses.add("perunVO");
// Add attributes
voAttributes.put(voObjClasses);
voAttributes.put("o", vo.getShortName());
voAttributes.put("description", vo.getName());
voAttributes.put("perunVoId", String.valueOf(vo.getId()));
// Create the entires
try {
ldapTemplate.bind(getVoDNByVoId(String.valueOf(vo.getId())), null, voAttributes);
log.debug("New entry created in LDAP: Vo {}.", vo);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of javax.naming.directory.BasicAttribute in project perun by CESNET.
the class LdapConnectorImpl method addMemberToGroup.
//-----------------------------MEMBER MODIFICATION METHODS--------------------
public void addMemberToGroup(Member member, Group group) throws InternalErrorException {
//Add member to group
Attribute uniqueMember = new BasicAttribute("uniqueMember", "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
ModificationItem uniqueMemberItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, uniqueMember);
this.updateGroup(group, new ModificationItem[] { uniqueMemberItem });
//Add member to vo if this group is memebrsGroup
if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
//Add info to vo
this.updateVo(group.getVoId(), new ModificationItem[] { uniqueMemberItem });
//Add info also to user
Attribute memberOfPerunVo = new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
ModificationItem memberOfPerunVoItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOfPerunVo);
this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfPerunVoItem });
}
//Add group info to member
Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
ModificationItem memberOfItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOf);
this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfItem });
}
use of javax.naming.directory.BasicAttribute in project jackrabbit-oak by apache.
the class InternalLdapServer method addMembers.
public void addMembers(String groupDN, Iterable<String> memberDNs) throws Exception {
LdapContext ctxt = getWiredContext();
Attribute attr = new BasicAttribute("member");
for (String dn : memberDNs) {
attr.add(dn);
}
BasicAttributes attrs = new BasicAttributes();
attrs.put(attr);
ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs);
}
use of javax.naming.directory.BasicAttribute in project jmeter by apache.
the class LDAPExtSampler method getUserModAttributes.
/***************************************************************************
* 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 Modify test
*
* @return The BasicAttributes
**************************************************************************/
private ModificationItem[] getUserModAttributes() {
ModificationItem[] mods = new ModificationItem[getLDAPArguments().getArguments().size()];
BasicAttribute attr;
PropertyIterator iter = getLDAPArguments().iterator();
int count = 0;
while (iter.hasNext()) {
LDAPArgument item = (LDAPArgument) iter.next().getObjectValue();
if ((item.getValue()).length() == 0) {
attr = new BasicAttribute(item.getName());
} else {
attr = getBasicAttribute(item.getName(), item.getValue());
}
final String opcode = item.getOpcode();
if ("add".equals(opcode)) {
// $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
} else if (// $NON-NLS-1$
"delete".equals(opcode) || "remove".equals(opcode)) {
// $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
} else if ("replace".equals(opcode)) {
// $NON-NLS-1$
mods[count++] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
} else {
log.warn("Invalid opCode: " + opcode);
}
}
return mods;
}
Aggregations