Search in sources :

Example 71 with LdapException

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;
            }
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) AttributeTypeRegistry(org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry)

Example 72 with LdapException

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();
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) FileInputStream(java.io.FileInputStream)

Example 73 with LdapException

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));
        }
    });
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl) Test(org.junit.Test)

Example 74 with LdapException

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);
    }
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 75 with LdapException

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);
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)361 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)161 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)111 ArrayList (java.util.ArrayList)94 FinderException (org.apache.directory.fortress.core.FinderException)73 Modification (org.apache.directory.api.ldap.model.entry.Modification)70 Entry (org.apache.directory.api.ldap.model.entry.Entry)68 IOException (java.io.IOException)57 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)57 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)53 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)29 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)23 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22