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