Search in sources :

Example 6 with LdapInvalidAttributeValueException

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

the class StringValueAttributeTypeTest 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.getIA5StringAttributeType();
    new Value(attribute, (String) null);
    new Value(attribute, "");
    new Value(attribute, "TEST");
    try {
        new Value(attribute, "testlong");
        fail();
    } catch (LdapInvalidAttributeValueException liave) {
        assertTrue(true);
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Test(org.junit.Test)

Example 7 with LdapInvalidAttributeValueException

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

the class DeepTrimNormalizer method normalize.

/**
 * {@inheritDoc}
 */
@Override
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
    if (value == null) {
        return null;
    }
    String normValue = null;
    try {
        // Transcoding is useless
        // Map
        String mapped = PrepareString.mapCaseSensitive(value);
        // Normalize
        String normalized = PrepareString.normalize(mapped);
        char[] chars = normalized.toCharArray();
        // Prohibit
        PrepareString.checkProhibited(chars);
        // Insignificant Characters Handling
        switch(assertionType) {
            case ATTRIBUTE_VALUE:
                normValue = PrepareString.insignificantSpacesStringValue(chars);
                break;
            case SUBSTRING_INITIAL:
                normValue = PrepareString.insignificantSpacesStringInitial(chars);
                break;
            case SUBSTRING_ANY:
                normValue = PrepareString.insignificantSpacesStringAny(chars);
                break;
            case SUBSTRING_FINAL:
                normValue = PrepareString.insignificantSpacesStringFinal(chars);
                break;
            default:
                // Do nothing
                break;
        }
        return normValue;
    } catch (IOException ioe) {
        throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13724_INVALID_VALUE, value), ioe);
    }
}
Also used : PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) IOException(java.io.IOException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)

Example 8 with LdapInvalidAttributeValueException

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

the class DeepTrimToLowerNormalizer method normalize.

/**
 * {@inheritDoc}
 */
@Override
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
    if (value == null) {
        return null;
    }
    String normValue = null;
    try {
        // Transcoding is useless
        // Map
        String mapped = PrepareString.mapIgnoreCase(value);
        // Normalize
        String normalized = PrepareString.normalize(mapped);
        char[] chars = normalized.toCharArray();
        // Prohibit
        PrepareString.checkProhibited(chars);
        // Insignificant Characters Handling
        switch(assertionType) {
            case ATTRIBUTE_VALUE:
                normValue = PrepareString.insignificantSpacesStringValue(chars);
                break;
            case SUBSTRING_INITIAL:
                normValue = PrepareString.insignificantSpacesStringInitial(chars);
                break;
            case SUBSTRING_ANY:
                normValue = PrepareString.insignificantSpacesStringAny(chars);
                break;
            case SUBSTRING_FINAL:
                normValue = PrepareString.insignificantSpacesStringFinal(chars);
                break;
            default:
                // Do nothing
                break;
        }
        return normValue;
    } catch (IOException ioe) {
        throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13724_INVALID_VALUE, value), ioe);
    }
}
Also used : PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) IOException(java.io.IOException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)

Example 9 with LdapInvalidAttributeValueException

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

the class WrappedPartialResultException method wrap.

/**
 * Wraps a LDAP exception into a NaingException
 *
 * @param t The original exception
 * @throws NamingException The wrapping JNDI exception
 */
public static void wrap(Throwable t) throws NamingException {
    if (t instanceof NamingException) {
        throw (NamingException) t;
    }
    NamingException ne;
    if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
        ne = new NamingException(t.getLocalizedMessage());
    } else if (t instanceof LdapAttributeInUseException) {
        ne = new AttributeInUseException(t.getLocalizedMessage());
    } else if (t instanceof LdapAuthenticationException) {
        ne = new AuthenticationException(t.getLocalizedMessage());
    } else if (t instanceof LdapAuthenticationNotSupportedException) {
        ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
    } else if (t instanceof LdapContextNotEmptyException) {
        ne = new ContextNotEmptyException(t.getLocalizedMessage());
    } else if (t instanceof LdapEntryAlreadyExistsException) {
        ne = new NameAlreadyBoundException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidAttributeTypeException) {
        ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidAttributeValueException) {
        ne = new InvalidAttributeValueException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidDnException) {
        ne = new InvalidNameException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidSearchFilterException) {
        ne = new InvalidSearchFilterException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoPermissionException) {
        ne = new NoPermissionException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoSuchAttributeException) {
        ne = new NoSuchAttributeException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoSuchObjectException) {
        ne = new NameNotFoundException(t.getLocalizedMessage());
    } else if (t instanceof LdapProtocolErrorException) {
        ne = new CommunicationException(t.getLocalizedMessage());
    } else if (t instanceof LdapReferralException) {
        ne = new WrappedReferralException((LdapReferralException) t);
    } else if (t instanceof LdapPartialResultException) {
        ne = new WrappedPartialResultException((LdapPartialResultException) t);
    } else if (t instanceof LdapSchemaViolationException) {
        ne = new SchemaViolationException(t.getLocalizedMessage());
    } else if (t instanceof LdapServiceUnavailableException) {
        ne = new ServiceUnavailableException(t.getLocalizedMessage());
    } else if (t instanceof LdapTimeLimitExceededException) {
        ne = new TimeLimitExceededException(t.getLocalizedMessage());
    } else if (t instanceof LdapUnwillingToPerformException) {
        ne = new OperationNotSupportedException(t.getLocalizedMessage());
    } else {
        ne = new NamingException(t.getLocalizedMessage());
    }
    ne.setRootCause(t);
    throw ne;
}
Also used : LdapEntryAlreadyExistsException(org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException) LdapOperationErrorException(org.apache.directory.api.ldap.model.exception.LdapOperationErrorException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) AuthenticationException(javax.naming.AuthenticationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) LdapInvalidAttributeTypeException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) LdapAliasException(org.apache.directory.api.ldap.model.exception.LdapAliasException) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) LdapPartialResultException(org.apache.directory.api.ldap.model.exception.LdapPartialResultException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) LdapLoopDetectedException(org.apache.directory.api.ldap.model.exception.LdapLoopDetectedException) InvalidNameException(javax.naming.InvalidNameException) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapReferralException(org.apache.directory.api.ldap.model.exception.LdapReferralException) NamingException(javax.naming.NamingException) SchemaViolationException(javax.naming.directory.SchemaViolationException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) LdapAliasDereferencingException(org.apache.directory.api.ldap.model.exception.LdapAliasDereferencingException) InvalidAttributeIdentifierException(javax.naming.directory.InvalidAttributeIdentifierException) CommunicationException(javax.naming.CommunicationException) InvalidSearchFilterException(javax.naming.directory.InvalidSearchFilterException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) NameNotFoundException(javax.naming.NameNotFoundException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapAffectMultipleDsaException(org.apache.directory.api.ldap.model.exception.LdapAffectMultipleDsaException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvalidAttributeValueException(javax.naming.directory.InvalidAttributeValueException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoPermissionException(javax.naming.NoPermissionException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) TimeLimitExceededException(javax.naming.TimeLimitExceededException) AttributeInUseException(javax.naming.directory.AttributeInUseException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 10 with LdapInvalidAttributeValueException

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

the class DefaultEntry method createEntry.

// -------------------------------------------------------------------------
// Helper methods
// -------------------------------------------------------------------------
private Entry createEntry(SchemaManager schemaManager, Object... elements) throws LdapInvalidAttributeValueException, LdapLdifException {
    StringBuilder sb = new StringBuilder();
    int pos = 0;
    boolean valueExpected = false;
    for (Object element : elements) {
        if (!valueExpected) {
            if (!(element instanceof String)) {
                throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13233_ATTRIBUTE_ID_MUST_BE_A_STRING, pos + 1));
            }
            String attribute = (String) element;
            sb.append(attribute);
            if (attribute.indexOf(':') != -1) {
                sb.append('\n');
            } else {
                valueExpected = true;
            }
        } else {
            if (element instanceof String) {
                sb.append(": ").append((String) element).append('\n');
            } else if (element instanceof byte[]) {
                sb.append(":: ");
                sb.append(new String(Base64.encode((byte[]) element)));
                sb.append('\n');
            } else {
                throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13234_ATTRIBUTE_VAL_STRING_OR_BYTE, pos + 1));
            }
            valueExpected = false;
        }
    }
    if (valueExpected) {
        throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_12087));
    }
    try (LdifAttributesReader reader = new LdifAttributesReader()) {
        return reader.parseEntry(schemaManager, sb.toString());
    } catch (IOException e) {
        throw new LdapLdifException(I18n.err(I18n.ERR_13248_CANNOT_READ_ENTRY));
    }
}
Also used : LdapLdifException(org.apache.directory.api.ldap.model.ldif.LdapLdifException) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) IOException(java.io.IOException)

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