use of javax.naming.directory.ModificationItem 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.ModificationItem 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.ModificationItem 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.ModificationItem in project camel by apache.
the class SpringLdapProducer method process.
/**
* Performs the LDAP operation defined in SpringLdapEndpoint that created
* this producer. The in-message in the exchange must be a map, containing
* the following entries:
*
* <pre>
* key: "dn" - base DN for the LDAP operation
* key: "filter" - necessary for the search operation only; LDAP filter for the search operation,
* see <a http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol>http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol</a>
* key: "attributes" - necessary for the bind operation only; an instance of javax.naming.directory.Attributes,
* containing the information necessary to create an LDAP node.
* key: "password" - necessary for the authentication operation only;
* key: "modificationItems" - necessary for the modify_attributes operation only;
* key: "function" - necessary for the function_driven operation only; provides a flexible hook into the {@link LdapTemplate} to call any method
* key: "request" - necessary for the function_driven operation only; passed into the "function" to enable the client to bind parameters that need to be passed into the {@link LdapTemplate}
* </pre>
*
* The keys are defined as final fields above.
*/
@Override
public void process(Exchange exchange) throws Exception {
@SuppressWarnings("unchecked") Map<String, Object> body = exchange.getIn().getBody(Map.class);
LdapOperation operation = endpoint.getOperation();
if (null == operation) {
throw new UnsupportedOperationException("LDAP operation must not be empty, but you provided an empty operation");
}
String dn = (String) body.get(DN);
if (operation != LdapOperation.FUNCTION_DRIVEN && (StringUtils.isBlank(dn))) {
throw new UnsupportedOperationException("DN must not be empty, but you provided an empty DN");
}
LdapOperations ldapTemplate = endpoint.getLdapTemplate();
switch(operation) {
case SEARCH:
String filter = (String) body.get(FILTER);
exchange.getIn().setBody(ldapTemplate.search(dn, filter, endpoint.scopeValue(), mapper));
break;
case BIND:
Attributes attributes = (Attributes) body.get(ATTRIBUTES);
ldapTemplate.bind(dn, null, attributes);
break;
case UNBIND:
ldapTemplate.unbind(dn);
break;
case AUTHENTICATE:
ldapTemplate.authenticate(LdapQueryBuilder.query().base(dn).filter((String) body.get(FILTER)), (String) body.get(PASSWORD));
break;
case MODIFY_ATTRIBUTES:
ModificationItem[] modificationItems = (ModificationItem[]) body.get(MODIFICATION_ITEMS);
ldapTemplate.modifyAttributes(dn, modificationItems);
break;
case FUNCTION_DRIVEN:
BiFunction<LdapOperations, Object, ?> ldapOperationFunction = (BiFunction<LdapOperations, Object, ?>) body.get(FUNCTION);
Object ldapOperationRequest = body.get(REQUEST);
exchange.getIn().setBody(ldapOperationFunction.apply(ldapTemplate, ldapOperationRequest));
break;
default:
throw new UnsupportedOperationException("Bug in the Spring-LDAP component. Despite of all assertions, you managed to call an unsupported operation '" + operation + "'");
}
}
use of javax.naming.directory.ModificationItem in project fess by codelibs.
the class LdapManager method modifyDeleteEntry.
protected void modifyDeleteEntry(final List<ModificationItem> modifyList, final String name, final Object value) {
final Attribute attr = new BasicAttribute(name, value);
final ModificationItem mod = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
modifyList.add(mod);
}
Aggregations