Search in sources :

Example 11 with Referral

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

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

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

the class StoreReference method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultReferenceDecorator> container) throws DecoderException {
    SearchResultReference searchResultReference = container.getMessage();
    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();
    // Get the referral, or create it if not existing
    Referral referral = searchResultReference.getReferral();
    if (referral == null) {
        referral = new ReferralImpl();
        searchResultReference.setReferral(referral);
    }
    // We have to handle the special case of a 0 length list of referrals
    LdapUrl url = LdapUrl.EMPTY_URL;
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        String urlStr = Strings.utf8ToString(tlv.getValue().getData());
        try {
            url = new LdapUrl(urlStr);
            referral.addLdapUrl(urlStr);
        } catch (LdapURLEncodingException luee) {
            LOG.error(I18n.err(I18n.ERR_04021, urlStr, luee.getMessage()));
            throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
        }
    }
    if (IS_DEBUG) {
        LOG.debug("Search reference URL found : {}", url);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : 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) Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 14 with Referral

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

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

the class BindResponseImplTest method testHashCodeWithTheWorks.

/**
 * Tests for equal hashCode of two fully loaded identical BindResponse PDUs.
 */
@Test
public void testHashCodeWithTheWorks() throws LdapException {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResultImpl r1 = new LdapResultImpl();
    r0.setDiagnosticMessage("blah blah blah");
    r1.setDiagnosticMessage("blah blah blah");
    r0.setMatchedDn(new Dn("dc=example,dc=com"));
    r1.setMatchedDn(new Dn("dc=example,dc=com"));
    r0.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    r1.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    Referral refs0 = new ReferralImpl();
    refs0.addLdapUrl("ldap://someserver.com");
    refs0.addLdapUrl("ldap://anotherserver.org");
    Referral refs1 = new ReferralImpl();
    refs1.addLdapUrl("ldap://someserver.com");
    refs1.addLdapUrl("ldap://anotherserver.org");
    BindResponseImpl resp0 = new BindResponseImpl(1);
    BindResponseImpl resp1 = new BindResponseImpl(1);
    resp0.setServerSaslCreds(PASSWORD);
    resp1.setServerSaslCreds(PASSWORD);
    assertTrue(resp0.hashCode() == resp1.hashCode());
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) BindResponseImpl(org.apache.directory.api.ldap.model.message.BindResponseImpl) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) Test(org.junit.Test)

Aggregations

Referral (org.apache.directory.api.ldap.model.message.Referral)23 Test (org.junit.Test)16 ReferralImpl (org.apache.directory.api.ldap.model.message.ReferralImpl)11 Dn (org.apache.directory.api.ldap.model.name.Dn)10 DecoderException (org.apache.directory.api.asn1.DecoderException)9 LdapResultImpl (org.apache.directory.api.ldap.model.message.LdapResultImpl)9 EncoderException (org.apache.directory.api.asn1.EncoderException)8 ByteBuffer (java.nio.ByteBuffer)6 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)6 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)6 SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)5 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)3 SearchResultReferenceDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator)3 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)3 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)3 BufferOverflowException (java.nio.BufferOverflowException)2 HashSet (java.util.HashSet)2 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)2