use of org.apache.directory.api.ldap.model.name.Dn in project jackrabbit-oak by apache.
the class AbstractServer method loadLdif.
protected List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception {
List<LdifEntry> entries = new ArrayList<LdifEntry>();
for (LdifEntry ldifEntry : ldifReader) {
Dn dn = ldifEntry.getDn();
if (ldifEntry.isEntry()) {
org.apache.directory.api.ldap.model.entry.Entry items = ldifEntry.getEntry();
rootDSE.add(new DefaultEntry(directoryService.getSchemaManager(), items));
LOG.info("Added entry {}", dn);
entries.add(ldifEntry);
}
}
return entries;
}
use of org.apache.directory.api.ldap.model.name.Dn in project knox by apache.
the class SimpleLdapDirectoryServer method enabledPosixSchema.
private static void enabledPosixSchema(DirectoryService service) throws LdapException {
service.getSchemaManager().getLoadedSchema("nis").enable();
service.getAdminSession().modify(new Dn("cn=nis,ou=schema"), new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE"));
}
use of org.apache.directory.api.ldap.model.name.Dn in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method writeStringAttributes.
public void writeStringAttributes(final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().writeStringAttributes(entryDN, attributeValueProps, overwrite);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
for (final Map.Entry<String, String> entry : attributeValueProps.entrySet()) {
final String name = entry.getKey();
final String value = entry.getValue();
final Modification modification = new DefaultModification();
modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(name, value));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.name.Dn in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method replaceAttributeImpl.
private void replaceAttributeImpl(final String entryDN, final String attributeName, final Value oldValue, final Value newValue) throws ChaiOperationException {
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
{
final Modification modification = new DefaultModification();
modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, oldValue));
modifyRequest.addModification(modification);
}
{
final Modification modification = new DefaultModification();
modification.setOperation(ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, newValue));
modifyRequest.addModification(modification);
}
final ModifyResponse response = connection.modify(modifyRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.name.Dn in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method searchImpl.
private Map<String, Map<String, List<String>>> searchImpl(final String baseDN, final SearchHelper searchHelper, final boolean multivalued) throws ChaiUnavailableException, ChaiOperationException {
try {
final SearchRequest searchRequest = new SearchRequestImpl();
searchRequest.setBase(new Dn(baseDN));
searchRequest.setFilter(searchHelper.getFilter());
searchRequest.setScope(figureSearchScope(searchHelper.getSearchScope()));
searchRequest.setSizeLimit(searchHelper.getMaxResults());
searchRequest.setTimeLimit(searchHelper.getTimeLimit());
final SearchCursor searchCursor = connection.search(searchRequest);
final Map<String, Map<String, List<String>>> returnObj = new LinkedHashMap<String, Map<String, List<String>>>();
while (searchCursor.next()) {
final Entry entry = searchCursor.getEntry();
final String dnValue = entry.getDn().getName();
final Map<String, List<String>> entryMap = new HashMap<String, List<String>>();
for (Attribute returnAttr : entry) {
final String attrName = returnAttr.getId();
final List<String> valueList = new ArrayList<String>();
if (multivalued) {
for (Value value : returnAttr) {
valueList.add(value.getString());
}
} else {
final String value = returnAttr.iterator().next().getString();
valueList.add(value);
}
entryMap.put(attrName, Collections.unmodifiableList(valueList));
}
returnObj.put(dnValue, Collections.unmodifiableMap(entryMap));
}
return Collections.unmodifiableMap(returnObj);
} catch (CursorException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
Aggregations