use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-fortress-core by apache.
the class LdapDataProvider method loadProperties.
/**
* Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap modification set in preparation for ldap add.
*
* @param props contains {@link java.util.Properties} targeted for adding to ldap.
* @param entry contains ldap entry to push attrs into.
* @param attrName contains the name of the ldap attribute to be added.
* @param separator contains the char value used to separate name and value in ldap raw format.
* @throws LdapException If we weren't able to add the properies into the entry
*/
protected void loadProperties(Properties props, Entry entry, String attrName, char separator) throws LdapException {
if ((props != null) && (props.size() > 0)) {
Attribute attr = null;
for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) {
// This LDAP attr is stored as a name-value pair separated by a ':'.
String key = (String) e.nextElement();
String val = props.getProperty(key);
String prop = key + separator + val;
if (attr == null) {
attr = new DefaultAttribute(attrName);
} else {
attr.add(prop);
}
}
if (attr != null) {
entry.add(attr);
}
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project structr by structr.
the class StructrLDAPWrapper method matches.
private boolean matches(final LDAPNode node, final ExprNode filter) throws FrameworkException, LdapInvalidAttributeValueException {
if (filter instanceof SimpleNode) {
return evaluateSimpleNode(node, (SimpleNode) filter);
} else if (filter instanceof SubstringNode) {
return evaluateSubstringNode(node, (SubstringNode) filter);
} else if (filter instanceof PresenceNode) {
final PresenceNode presence = (PresenceNode) filter;
final Attribute attribute = new DefaultAttribute(presence.getAttributeType());
return findAttribute(node, attribute.getId()) != null;
} else if (filter instanceof OrNode) {
final OrNode orNode = (OrNode) filter;
for (final ExprNode child : orNode.getChildren()) {
if (matches(node, child)) {
return true;
}
}
return false;
} else if (filter instanceof AndNode) {
final AndNode andNode = (AndNode) filter;
boolean result = true;
for (final ExprNode child : andNode.getChildren()) {
result &= matches(node, child);
}
return result;
} else {
System.out.println("Unsupported filter type " + filter.getClass());
}
return false;
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project structr by structr.
the class StructrLDAPWrapper method evaluateSubstringNode.
private boolean evaluateSubstringNode(final LDAPNode node, final SubstringNode substringNode) throws FrameworkException, LdapInvalidAttributeValueException {
final Attribute attribute = new DefaultAttribute(substringNode.getAttributeType());
final String oid = attribute.getId();
final String initialPart = substringNode.getInitial();
final String finalPart = substringNode.getFinal();
final List<String> any = new LinkedList<>();
final List<String> fromNode = substringNode.getAny();
// add fragments from substring node (if present)
if (fromNode != null) {
any.addAll(fromNode);
}
final Pattern pattern = SubstringNode.getRegex(initialPart, any.toArray(new String[0]), finalPart);
for (final LDAPAttribute attr : node.getAttributes()) {
if (oid.equals(attr.getOid())) {
for (final LDAPValue value : attr.getValues()) {
final String stringValue = value.getStringValue().toLowerCase();
final Matcher matcher = pattern.matcher(stringValue);
if (matcher.matches()) {
return true;
}
}
}
}
return false;
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project structr by structr.
the class StructrLDAPWrapper method getAttribute.
public Attribute getAttribute(final LDAPAttribute src) throws LdapInvalidAttributeValueException {
final AttributeType type = schemaManager.getAttributeType(src.getOid());
final Attribute attribute = new DefaultAttribute(type);
final String name = src.getUserProvidedId();
if (name != null) {
attribute.setUpId(name);
}
for (final LDAPValue value : src.getValues()) {
attribute.add(value.getStringValue());
}
return attribute;
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method deleteStringAttributeValue.
public void deleteStringAttributeValue(final String entryDN, final String attributeName, final String value) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().deleteStringAttributeValue(entryDN, attributeName, value);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
if (value == null) {
final Modification modification = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attributeName);
modifyRequest.addModification(modification);
} else {
final Modification modification = new DefaultModification();
modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, value));
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
Aggregations