Search in sources :

Example 31 with LdapResult

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

the class SearchResultDoneTest method testResponseWith1EmptyReferral.

/**
 * Test parsing of a response with an empty Referral
 */
@Test
public void testResponseWith1EmptyReferral() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultDoneTest.class.getResource("response_with_1_empty_referral.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
    LdapResult ldapResult = searchResultDone.getLdapResult();
    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
    assertEquals(0, referrals.size());
}
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 32 with LdapResult

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

the class LdapResultImplTest method testEqualsDiffImpl.

/**
 * Tests for equality when the lockable parent is the same.
 */
@Test
public void testEqualsDiffImpl() {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResult r1 = new LdapResult() {

        public ResultCodeEnum getResultCode() {
            return ResultCodeEnum.SUCCESS;
        }

        public void setResultCode(ResultCodeEnum a_resultCode) {
        }

        public Dn getMatchedDn() {
            return null;
        }

        public void setMatchedDn(Dn dn) {
        }

        public String getDiagnosticMessage() {
            return null;
        }

        public void setDiagnosticMessage(String diagnosticMessage) {
        }

        public boolean isReferral() {
            return false;
        }

        public Referral getReferral() {
            return null;
        }

        public void setReferral(Referral referral) {
        }

        public boolean isDefaultSuccess() {
            return false;
        }
    };
    assertTrue("r0 equals should see other impl r1 as equal", r0.equals(r1));
    assertFalse("r1 impl uses Object.equals() so it should not see " + "r0 as the same object", r1.equals(r0));
}
Also used : LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Referral(org.apache.directory.api.ldap.model.message.Referral) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum) Test(org.junit.Test)

Example 33 with LdapResult

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

the class InitReferrals method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // If we hae a Referrals sequence, then it should not be empty
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04011);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    Referral referral = new ReferralImpl();
    ldapResult.setReferral(referral);
    if (IS_DEBUG) {
        LOG.debug("Initialising a referrals list");
    }
}
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) Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 34 with LdapResult

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

the class StoreErrorMessage 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();
    String errorMessage;
    // message
    if (tlv.getLength() == 0) {
        errorMessage = "";
    } else {
        errorMessage = Strings.utf8ToString(tlv.getValue().getData());
    }
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    ldapResult.setDiagnosticMessage(errorMessage);
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("The error message is : " + errorMessage);
    }
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 35 with LdapResult

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

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