Search in sources :

Example 16 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.

the class StoreExtendedResponseName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ExtendedResponseDecorator<?>> container) throws DecoderException {
    // We can allocate the ExtendedResponse Object
    ExtendedResponse extendedResponse;
    // Get the Value and store it in the ExtendedResponse
    TLV tlv = container.getCurrentTLV();
    // OID
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04017);
        LOG.error(msg);
        throw new DecoderException(msg);
    } else {
        String responseName = Oid.fromString(Strings.asciiBytesToString(tlv.getValue().getData())).toString();
        extendedResponse = LdapApiServiceFactory.getSingleton().newExtendedResponse(responseName, container.getMessageId(), null);
        ((ExtendedResponseDecorator<?>) extendedResponse).setLdapResult((LdapResultDecorator) (container.getMessage().getLdapResult()));
        container.setMessage(LdapApiServiceFactory.getSingleton().decorate(extendedResponse));
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("OID read : {}", extendedResponse.getResponseName());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 17 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.

the class LdapNetworkConnection method startTls.

/**
 * Sends the StartTLS extended request to server and adds a security layer
 * upon receiving a response with successful result. Note that we will use
 * the default LDAP connection.
 *
 * @throws LdapException If the StartTLS operation failed
 */
public void startTls() throws LdapException {
    try {
        if (config.isUseSsl()) {
            throw new LdapException("Cannot use TLS when the useSsl flag is set true in the configuration");
        }
        // try to connect, if we aren't already connected.
        connect();
        checkSession();
        IoFilter sslFilter = ldapSession.getFilterChain().get(SSL_FILTER_KEY);
        if (sslFilter != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03222_LDAP_ALREADY_USING_START_TLS));
            }
            return;
        }
        ExtendedResponse resp = extended(new StartTlsRequestImpl());
        LdapResult result = resp.getLdapResult();
        if (result.getResultCode() == ResultCodeEnum.SUCCESS) {
            addSslFilter();
        } else {
            throw new LdapOperationException(result.getResultCode(), result.getDiagnosticMessage());
        }
    } catch (LdapException e) {
        throw e;
    } catch (Exception e) {
        throw new LdapException(e);
    }
}
Also used : LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) StartTlsRequestImpl(org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequestImpl) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) IoFilter(org.apache.mina.core.filterchain.IoFilter) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 18 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.

the class BatchResponseTest method testResponseWith2ExtendedResponse.

/**
 * Test parsing of a Response with the 2 ExtendedResponse
 */
@Test
public void testResponseWith2ExtendedResponse() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(BatchResponseTest.class.getResource("response_with_2_ExtendedResponse.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    BatchResponseDsml batchResponse = parser.getBatchResponse();
    assertEquals(2, batchResponse.getResponses().size());
    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
    if (response instanceof ExtendedResponse) {
        assertTrue(true);
    } else {
        fail();
    }
}
Also used : BatchResponseDsml(org.apache.directory.api.dsmlv2.response.BatchResponseDsml) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 19 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.

the class ExtendedResponseTest method testResponseWithResultCode.

/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ExtendedResponseTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = extendedResponse.getLdapResult();
    assertEquals(ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest) Test(org.junit.Test)

Example 20 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.

the class ExtendedResponseTest method testResponseWith1Referral.

/**
 * Test parsing of a response with a Referral
 */
@Test
public void testResponseWith1Referral() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ExtendedResponseTest.class.getResource("response_with_1_referral.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = extendedResponse.getLdapResult();
    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
    assertEquals(1, referrals.size());
    try {
        assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest) Test(org.junit.Test)

Aggregations

ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)30 DecoderException (org.apache.directory.api.asn1.DecoderException)22 Test (org.junit.Test)19 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)17 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)17 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)15 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)7 Control (org.apache.directory.api.ldap.model.message.Control)6 ByteBuffer (java.nio.ByteBuffer)4 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 BatchResponseDsml (org.apache.directory.api.dsmlv2.response.BatchResponseDsml)2