use of org.apache.directory.api.ldap.model.exception.LdapException in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method readStringAttribute.
public String readStringAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().readStringAttribute(entryDN, attribute);
try {
final EntryCursor entries = connection.search(entryDN, ChaiConstant.FILTER_OBJECTCLASS_ANY, org.apache.directory.api.ldap.model.message.SearchScope.OBJECT, attribute);
final Entry entry = entries.iterator().next();
final Attribute attr = entry.get(attribute);
return attr == null ? null : attr.getString();
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method writeStringAttribute.
public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
try {
final ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(new Dn(entryDN));
{
final Modification modification = new DefaultModification();
modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
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.exception.LdapException in project jackrabbit-oak by apache.
the class LdapIdentityProvider method getGroup.
@Override
public ExternalGroup getGroup(@Nonnull String name) throws ExternalIdentityException {
DebugTimer timer = new DebugTimer();
LdapConnection connection = connect();
timer.mark("connect");
try {
Entry entry = getEntry(connection, config.getGroupConfig(), name, config.getCustomAttributes());
timer.mark("lookup");
if (log.isDebugEnabled()) {
log.debug("getGroup({}) {}", name, timer.getString());
}
if (entry != null) {
return createGroup(entry, name);
} else {
return null;
}
} catch (LdapException | CursorException e) {
throw lookupFailedException(e, timer);
} finally {
disconnect(connection);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project syncope by apache.
the class LdifInputStreamLoader method execute.
/**
* Opens the LDIF file and loads the entries into the context.
*
* @return The count of entries created.
*/
public int execute() {
try {
try {
for (LdifEntry ldifEntry : new LdifReader(ldif)) {
Dn dn = ldifEntry.getDn();
if (ldifEntry.isEntry()) {
Entry entry = ldifEntry.getEntry();
try {
coreSession.lookup(dn);
LOG.debug("Found {}, will not create.", dn);
} catch (Exception e) {
try {
coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), entry));
count++;
LOG.debug("Created {}.", dn);
} catch (LdapException e1) {
LOG.error("Could not create entry " + entry, e1);
}
}
} else {
// modify
List<Modification> items = ldifEntry.getModifications();
try {
coreSession.modify(dn, items);
LOG.debug("Modified: " + dn + " with modificationItems: " + items);
} catch (LdapException e) {
LOG.debug("Could not modify: " + dn + " with modificationItems: " + items, e);
}
}
}
} finally {
ldif.close();
}
} catch (Exception ioe) {
LOG.error(I18n.err(I18n.ERR_174), ioe);
}
return count;
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class SchemaEntityFactory method getLdapComparator.
/**
* {@inheritDoc}
*/
@Override
public LdapComparator<?> getLdapComparator(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
checkEntry(entry, SchemaConstants.COMPARATOR);
// The Comparator OID
String oid = getOid(entry, SchemaConstants.COMPARATOR, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested Comparator
String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, entry.getDn().getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is disabled. We still have to update the backend
String msg = I18n.err(I18n.ERR_16023_CANNOT_ADD_CMP_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
// The FQCN
String fqcn = getFqcn(entry, SchemaConstants.COMPARATOR);
// The ByteCode
Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
try {
// Class load the comparator
LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(comparator, entry, schema);
// return the resulting comparator
return comparator;
} catch (Exception e) {
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
}
}
Aggregations