Search in sources :

Example 76 with Dn

use of org.apache.directory.api.ldap.model.name.Dn 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 77 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class StoreMatchedDN method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    // Get the Value and store it in the BindResponse
    TLV tlv = container.getCurrentTLV();
    Dn matchedDn;
    ResultCodeEnum resultCode;
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    resultCode = ldapResult.getResultCode();
    // Dn
    if (tlv.getLength() == 0) {
        matchedDn = Dn.EMPTY_DN;
    } else {
        switch(resultCode) {
            case NO_SUCH_OBJECT:
            case ALIAS_PROBLEM:
            case INVALID_DN_SYNTAX:
            case ALIAS_DEREFERENCING_PROBLEM:
                byte[] dnBytes = tlv.getValue().getData();
                String dnStr = Strings.utf8ToString(dnBytes);
                try {
                    matchedDn = new Dn(dnStr);
                } catch (LdapInvalidDnException ine) {
                    // This is for the client side. We will never decode LdapResult on the server
                    String msg = I18n.err(I18n.ERR_04013, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
                    LOG.error(msg);
                    throw new DecoderException(I18n.err(I18n.ERR_04014, ine.getLocalizedMessage()), ine);
                }
                break;
            default:
                LOG.warn("The matched Dn should not be set when the result code is not one of NoSuchObject," + " AliasProblem, InvalidDNSyntax or AliasDreferencingProblem");
                matchedDn = Dn.EMPTY_DN;
                break;
        }
    }
    if (IS_DEBUG) {
        LOG.debug("The matchedDn is " + matchedDn);
    }
    ldapResult.setMatchedDn(matchedDn);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Dn(org.apache.directory.api.ldap.model.name.Dn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 78 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class StoreAddRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    AddRequestDecorator addRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the entry. It can't be null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04085);
        LOG.error(msg);
        AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
        // Not 100% sure though ...
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.NAMING_VIOLATION, Dn.EMPTY_DN, null);
    } else {
        Dn entryDn = null;
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entryDn = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        addRequest.setEntryDn(entryDn);
    }
    LOG.debug("Adding an entry with Dn : {}", addRequest.getEntry());
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 79 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class StoreModifyDnRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
    ModifyDnRequest modifyDnRequest = container.getMessage();
    // Get the Value and store it in the modifyDNRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length matched
    // Dn
    Dn entry;
    if (tlv.getLength() == 0) {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04089));
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entry = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        modifyDnRequest.setName(entry);
    }
    if (IS_DEBUG) {
        LOG.debug("Modifying Dn {}", entry);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyDnResponseImpl(org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 80 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class StoreModifyDnRequestNewRdn method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
    ModifyDnRequest modifyDnRequest = container.getMessage();
    // Get the Value and store it in the modifyDNRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length matched
    // newDN
    Rdn newRdn;
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04090);
        LOG.error(msg);
        ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), null);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            Dn dn = new Dn(dnStr);
            newRdn = dn.getRdn(dn.size() - 1);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid new Rdn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), ine);
        }
        modifyDnRequest.setNewRdn(newRdn);
    }
    if (IS_DEBUG) {
        LOG.debug("Modifying with new Rdn {}", newRdn);
    }
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) ModifyDnResponseImpl(org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) Rdn(org.apache.directory.api.ldap.model.name.Rdn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8