Search in sources :

Example 36 with LdapResult

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

the class StoreResultCode method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
    try {
        resultCode = ResultCodeEnum.getResultCode(IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED.getResultCode()));
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage()));
        throw new DecoderException(ide.getMessage(), ide);
    }
    if (IS_DEBUG) {
        LOG.debug("The result code is set to " + resultCode);
    }
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    ldapResult.setResultCode(resultCode);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum)

Example 37 with LdapResult

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

the class AddReferral method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    Message response = container.getMessage();
    LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
    Referral referral = ldapResult.getReferral();
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
            try {
                String url = Strings.utf8ToString(tlv.getValue().getData());
                referral.addLdapUrl(new LdapUrl(url).toString());
            } catch (LdapURLEncodingException luee) {
                String badUrl = Strings.utf8ToString(tlv.getValue().getData());
                LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
                throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
            }
        } else {
            LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
            referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
        }
    }
    if (IS_DEBUG) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (String url : ldapResult.getReferral().getLdapUrls()) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(", ");
            }
            sb.append(url);
        }
        LOG.debug("The referral error message is set to " + sb.toString());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Message(org.apache.directory.api.ldap.model.message.Message) Referral(org.apache.directory.api.ldap.model.message.Referral) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 38 with LdapResult

use of org.apache.directory.api.ldap.model.message.LdapResult 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 39 with LdapResult

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

the class SearchResultDoneTest method testResponseWithMatchedDNAttribute.

/**
 * Test parsing of a response with MatchedDN attribute
 */
@Test
public void testResponseWithMatchedDNAttribute() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultDoneTest.class.getResource("response_with_matchedDN_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
    LdapResult ldapResult = searchResultDone.getLdapResult();
    assertTrue(ldapResult.getMatchedDn().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 40 with LdapResult

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

the class SearchResultDoneTest method testResponseWithResultCode.

/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultDoneTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
    LdapResult ldapResult = searchResultDone.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) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)71 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)65 Test (org.junit.Test)65 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)64 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)64 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)23 DecoderException (org.apache.directory.api.asn1.DecoderException)13 ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)9 SearchResponse (org.apache.directory.api.dsmlv2.response.SearchResponse)8 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)8 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)8 CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)8 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)8 ModifyDnResponse (org.apache.directory.api.ldap.model.message.ModifyDnResponse)8 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)8 SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)8 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)5 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)5 Referral (org.apache.directory.api.ldap.model.message.Referral)3 ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)3