use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ObjectClassHelper method buildMay.
/**
* Build and check the MAY AT for this ObjectClass
*/
private static void buildMay(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
List<String> mayAttributeTypeOids = objectClass.getMayAttributeTypeOids();
if (mayAttributeTypeOids != null) {
objectClass.getMayAttributeTypes().clear();
for (String mayAttributeTypeName : mayAttributeTypeOids) {
try {
AttributeType attributeType = atRegistry.lookup(mayAttributeTypeName);
if (attributeType.isCollective()) {
// Collective Attributes are not allowed in MAY or MUST
String msg = I18n.err(I18n.ERR_13779_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, objectClass.getOid());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
if (objectClass.getMayAttributeTypes().contains(attributeType)) {
// Already registered : this is an error
String msg = I18n.err(I18n.ERR_13770_CANNOT_REGISTER_DUPLICATE_AT_IN_MAY, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
objectClass.getMayAttributeTypes().add(attributeType);
} catch (LdapException ne) {
// Cannot find the AT
String msg = I18n.err(I18n.ERR_13771_CANNOT_REGISTER_AT_IN_MAY_DOES_NOT_EXIST, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
}
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class QuirkySchemaTest method loadSchemaEntry.
private Entry loadSchemaEntry(String schemaFileName) {
LdifEntry ldifEntry = null;
try {
InputStream in = new FileInputStream(schemaFileName);
LdifReader ldifReader = new LdifReader(in);
if (ldifReader.hasNext()) {
ldifEntry = ldifReader.next();
}
ldifReader.close();
} catch (IOException e) {
throw new IllegalStateException("IO error with " + schemaFileName, e);
} catch (LdapException e) {
throw new IllegalStateException("LDAP error with " + schemaFileName, e);
}
if (ldifEntry == null) {
throw new IllegalStateException("No entry in LDIF " + schemaFileName);
}
return ldifEntry.getEntry();
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ValidatingPoolableLdapConnectionFactoryTest method testPoolWithBind.
@Test
public void testPoolWithBind() {
PoolTester tester = new PoolTester();
// no bind
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind()
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
connection.bind();
verify(connection, times(1)).bind();
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// anonymousBind()
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
connection.anonymousBind();
verify(connection, times(1)).anonymousBind();
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind( String )
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
connection.bind("");
verify(connection, times(1)).bind("");
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// admin bind( String, String )
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
connection.bind(ADMIN_DN, ADMIN_CREDENTIALS);
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind( String, String )
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
connection.bind("", "");
verify(connection, times(1)).bind("", "");
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind( Dn )
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
Dn dn = new Dn();
connection.bind(dn);
verify(connection, times(1)).bind(dn);
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind( Dn, String )
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
Dn dn = new Dn();
connection.bind(dn, "");
verify(connection, times(1)).bind(dn, "");
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
// bind( BindRequest );
tester.execute(new WithConnection() {
@Override
public void execute(LdapConnection connection, Counts counts) throws LdapException {
BindRequest bindRequest = new BindRequestImpl();
connection.bind(bindRequest);
verify(connection, times(1)).bind(bindRequest);
verifyAdminBind(connection, times(counts.adminBindCount));
}
});
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class AddAddRequestAttributeType method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
AddRequestDecorator addRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the type. It can't be null.
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04086);
LOG.error(msg);
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), null);
}
String type = Strings.utf8ToString(tlv.getValue().getData());
try {
addRequest.addAttributeType(type);
} catch (LdapException ne) {
String msg = I18n.err(I18n.ERR_04087);
LOG.error(msg);
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), ne);
}
if (IS_DEBUG) {
LOG.debug("Adding type {}", type);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class StoreModifyRequestAttributeValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
byte[] value = Strings.EMPTY_BYTES;
try {
if (tlv.getLength() == 0) {
modifyRequestDecorator.addAttributeValue("");
} else {
value = tlv.getValue().getData();
if (container.isBinary(modifyRequestDecorator.getCurrentAttributeType())) {
modifyRequestDecorator.addAttributeValue(value);
} else {
modifyRequestDecorator.addAttributeValue(Strings.utf8ToString((byte[]) value));
}
}
} catch (LdapException le) {
// Just swallow the exception, it can't occur here
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Value modified : {}", value);
}
}
Aggregations