Search in sources :

Example 1 with LdapInvalidAttributeValueException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in project jackrabbit-oak by apache.

the class LdapIdentityProvider method createUser.

@Nonnull
private ExternalUser createUser(@Nonnull Entry entry, @CheckForNull String id) throws LdapInvalidAttributeValueException {
    ExternalIdentityRef ref = new ExternalIdentityRef(entry.getDn().getName(), this.getName());
    if (id == null) {
        String idAttribute = config.getUserConfig().getIdAttribute();
        Attribute attr = entry.get(idAttribute);
        if (attr == null) {
            throw new LdapInvalidAttributeValueException(ResultCodeEnum.CONSTRAINT_VIOLATION, "no value found for attribute '" + idAttribute + "' for entry " + entry);
        }
        id = attr.getString();
    }
    String path = config.getUserConfig().makeDnPath() ? createDNPath(entry.getDn()) : null;
    LdapUser user = new LdapUser(this, ref, id, path);
    Map<String, Object> props = user.getProperties();
    applyAttributes(props, entry);
    return user;
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Nonnull(javax.annotation.Nonnull)

Example 2 with LdapInvalidAttributeValueException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in project jackrabbit-oak by apache.

the class LdapIdentityProvider method createGroup.

@Nonnull
private ExternalGroup createGroup(@Nonnull Entry entry, @CheckForNull String name) throws LdapInvalidAttributeValueException {
    ExternalIdentityRef ref = new ExternalIdentityRef(entry.getDn().getName(), this.getName());
    if (name == null) {
        String idAttribute = config.getGroupConfig().getIdAttribute();
        Attribute attr = entry.get(idAttribute);
        if (attr == null) {
            throw new LdapInvalidAttributeValueException(ResultCodeEnum.CONSTRAINT_VIOLATION, "no value found for attribute '" + idAttribute + "' for entry " + entry);
        }
        name = attr.getString();
    }
    String path = config.getGroupConfig().makeDnPath() ? createDNPath(entry.getDn()) : null;
    LdapGroup group = new LdapGroup(this, ref, name, path);
    Map<String, Object> props = group.getProperties();
    applyAttributes(props, entry);
    return group;
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Nonnull(javax.annotation.Nonnull)

Example 3 with LdapInvalidAttributeValueException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in project directory-ldap-api by apache.

the class SchemaEntityFactory method getOid.

/**
 * Get an OID from an entry. Handles the bad cases (null OID,
 * not a valid OID, ...)
 */
private String getOid(Entry entry, String objectType, boolean strict) throws LdapInvalidAttributeValueException {
    // The OID
    Attribute mOid = entry.get(MetaSchemaConstants.M_OID_AT);
    if (mOid == null) {
        String msg = I18n.err(I18n.ERR_16011_NULL_ATTRIBUTE, objectType, MetaSchemaConstants.M_OID_AT);
        LOG.warn(msg);
        throw new IllegalArgumentException(msg);
    }
    String oid = mOid.getString();
    if (strict && !Oid.isOid(oid)) {
        String msg = I18n.err(I18n.ERR_16012_INVALID_COMPARATOR_OID, oid);
        LOG.warn(msg);
        throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg);
    }
    return oid;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)

Example 4 with LdapInvalidAttributeValueException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in project directory-ldap-api by apache.

the class SchemaAwareAttributeTest method testGetString.

/**
 * Test method getString()
 */
@Test
public void testGetString() throws LdapInvalidAttributeValueException {
    Attribute attr1 = new DefaultAttribute(atDC);
    assertEquals(1, attr1.add((String) null));
    Attribute attr2 = new DefaultAttribute(atDC);
    attr2.add("a");
    assertEquals("a", attr2.getString());
    Attribute attr3 = new DefaultAttribute(atPwd);
    attr3.add(BYTES1, BYTES2);
    try {
        attr3.getString();
        fail();
    } catch (LdapInvalidAttributeValueException ivae) {
        assertTrue(true);
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Test(org.junit.Test)

Example 5 with LdapInvalidAttributeValueException

use of org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testIsValid.

/**
 * Test the isValid method
 *
 * The SyntaxChecker does not accept values longer than 5 chars.
 */
@Test
public void testIsValid() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    new Value(attribute, (byte[]) null);
    new Value(attribute, Strings.EMPTY_BYTES);
    new Value(attribute, new byte[] { 0x01, 0x02 });
    try {
        new Value(attribute, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
        fail();
    } catch (LdapInvalidAttributeValueException liave) {
        assertTrue(true);
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Test(org.junit.Test)

Aggregations

LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)28 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)12 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)7 Test (org.junit.Test)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 Value (org.apache.directory.api.ldap.model.entry.Value)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)3 Modification (org.apache.directory.api.ldap.model.entry.Modification)3 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)3 Nonnull (javax.annotation.Nonnull)2 ModificationOperation (org.apache.directory.api.ldap.model.entry.ModificationOperation)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)2 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)2 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)2 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1