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);
}
}
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);
}
}
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);
}
}
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;
}
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));
}
}
Aggregations