Search in sources :

Example 1 with ResultResponse

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

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

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

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

the class AbstractPasswordPolicyResponder method process.

/**
 * {@inheritDoc}
 */
@Override
public final PasswordWarning process(PasswordPolicyOperation operation) throws PasswordException {
    try {
        ResultResponse response = operation.process();
        PasswordPolicy passwordPolicy = getPasswordPolicy(response);
        ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
        if (resultCode == ResultCodeEnum.SUCCESS) {
            return success(passwordPolicy);
        } else {
            throw fail(response, passwordPolicy, resultCode);
        }
    } catch (LdapException e) {
        throw new PasswordException().setLdapException(e);
    }
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) PasswordException(org.apache.directory.ldap.client.template.exception.PasswordException) PasswordPolicy(org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum)

Example 5 with ResultResponse

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

Aggregations

ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)6 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)5 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)3 Referral (org.apache.directory.api.ldap.model.message.Referral)2 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)1 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)1 PasswordPolicy (org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)1 Message (org.apache.directory.api.ldap.model.message.Message)1 ReferralImpl (org.apache.directory.api.ldap.model.message.ReferralImpl)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)1 PasswordException (org.apache.directory.ldap.client.template.exception.PasswordException)1