Search in sources :

Example 1 with ResultCodeEnum

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

the class Dsmlv2Engine method processRequest.

/**
 * Processes a single request
 *
 * @param request the request to process
 * @param respWriter The writer used to store the DSML response
 * @exception Exception If we had an error while processing the request
 */
protected void processRequest(DsmlDecorator<? extends Request> request, BufferedWriter respWriter) throws Exception {
    ResultCodeEnum resultCode = null;
    switch(request.getDecorated().getType()) {
        case ABANDON_REQUEST:
            connection.abandon((AbandonRequest) request);
            return;
        case ADD_REQUEST:
            AddResponse response = connection.add((AddRequest) request);
            resultCode = response.getLdapResult().getResultCode();
            AddResponseDsml addResponseDsml = new AddResponseDsml(connection.getCodecService(), response);
            writeResponse(respWriter, addResponseDsml);
            break;
        case BIND_REQUEST:
            BindResponse bindResponse = connection.bind((BindRequest) request);
            resultCode = bindResponse.getLdapResult().getResultCode();
            BindResponseDsml authResponseDsml = new BindResponseDsml(connection.getCodecService(), bindResponse);
            writeResponse(respWriter, authResponseDsml);
            break;
        case COMPARE_REQUEST:
            CompareResponse compareResponse = connection.compare((CompareRequest) request);
            resultCode = compareResponse.getLdapResult().getResultCode();
            CompareResponseDsml compareResponseDsml = new CompareResponseDsml(connection.getCodecService(), compareResponse);
            writeResponse(respWriter, compareResponseDsml);
            break;
        case DEL_REQUEST:
            DeleteResponse delResponse = connection.delete((DeleteRequest) request);
            resultCode = delResponse.getLdapResult().getResultCode();
            DelResponseDsml delResponseDsml = new DelResponseDsml(connection.getCodecService(), delResponse);
            writeResponse(respWriter, delResponseDsml);
            break;
        case EXTENDED_REQUEST:
            ExtendedResponse extendedResponse = connection.extended((ExtendedRequest) request);
            resultCode = extendedResponse.getLdapResult().getResultCode();
            ExtendedResponseDsml extendedResponseDsml = new ExtendedResponseDsml(connection.getCodecService(), extendedResponse);
            writeResponse(respWriter, extendedResponseDsml);
            break;
        case MODIFY_REQUEST:
            ModifyResponse modifyResponse = connection.modify((ModifyRequest) request);
            resultCode = modifyResponse.getLdapResult().getResultCode();
            ModifyResponseDsml modifyResponseDsml = new ModifyResponseDsml(connection.getCodecService(), modifyResponse);
            writeResponse(respWriter, modifyResponseDsml);
            break;
        case MODIFYDN_REQUEST:
            ModifyDnResponse modifyDnResponse = connection.modifyDn((ModifyDnRequest) request);
            resultCode = modifyDnResponse.getLdapResult().getResultCode();
            ModDNResponseDsml modDNResponseDsml = new ModDNResponseDsml(connection.getCodecService(), modifyDnResponse);
            writeResponse(respWriter, modDNResponseDsml);
            break;
        case SEARCH_REQUEST:
            SearchCursor searchResponses = connection.search((SearchRequest) request);
            SearchResponseDsml searchResponseDsml = new SearchResponseDsml(connection.getCodecService());
            if (respWriter != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("<searchResponse");
                if (request.getDecorated().getMessageId() > 0) {
                    sb.append(" requestID=\"");
                    sb.append(request.getDecorated().getMessageId());
                    sb.append('"');
                }
                sb.append('>');
                respWriter.write(sb.toString());
            }
            while (searchResponses.next()) {
                Response searchResponse = searchResponses.get();
                if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_ENTRY) {
                    SearchResultEntry searchResultEntry = (SearchResultEntry) searchResponse;
                    SearchResultEntryDsml searchResultEntryDsml = new SearchResultEntryDsml(connection.getCodecService(), searchResultEntry);
                    searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultEntryDsml);
                    if (respWriter != null) {
                        writeResponse(respWriter, searchResultEntryDsml);
                    } else {
                        searchResponseDsml.addResponse(searchResultEntryDsml);
                    }
                } else if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_REFERENCE) {
                    SearchResultReference searchResultReference = (SearchResultReference) searchResponse;
                    SearchResultReferenceDsml searchResultReferenceDsml = new SearchResultReferenceDsml(connection.getCodecService(), searchResultReference);
                    searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultReferenceDsml);
                    if (respWriter != null) {
                        writeResponse(respWriter, searchResultReferenceDsml);
                    } else {
                        searchResponseDsml.addResponse(searchResultReferenceDsml);
                    }
                }
            }
            SearchResultDone srDone = searchResponses.getSearchResultDone();
            if (srDone != null) {
                resultCode = srDone.getLdapResult().getResultCode();
                SearchResultDoneDsml srdDsml = new SearchResultDoneDsml(connection.getCodecService(), srDone);
                if (respWriter != null) {
                    writeResponse(respWriter, srdDsml);
                    respWriter.write("</searchResponse>");
                } else {
                    searchResponseDsml.addResponse(srdDsml);
                    batchResponse.addResponse(searchResponseDsml);
                }
            }
            break;
        case UNBIND_REQUEST:
            connection.unBind();
            break;
        default:
            throw new IllegalStateException("Unexpected request tpye " + request.getDecorated().getType());
    }
    if ((!continueOnError) && (resultCode != null) && (resultCode != ResultCodeEnum.SUCCESS) && (resultCode != ResultCodeEnum.COMPARE_TRUE) && (resultCode != ResultCodeEnum.COMPARE_FALSE) && (resultCode != ResultCodeEnum.REFERRAL)) {
        // Turning on Exit flag
        exit = true;
    }
}
Also used : DelResponseDsml(org.apache.directory.api.dsmlv2.response.DelResponseDsml) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) SearchResultDoneDsml(org.apache.directory.api.dsmlv2.response.SearchResultDoneDsml) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum) ModifyResponseDsml(org.apache.directory.api.dsmlv2.response.ModifyResponseDsml) CompareResponseDsml(org.apache.directory.api.dsmlv2.response.CompareResponseDsml) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) SearchResponseDsml(org.apache.directory.api.dsmlv2.response.SearchResponseDsml) SearchResultEntryDsml(org.apache.directory.api.dsmlv2.response.SearchResultEntryDsml) AddResponseDsml(org.apache.directory.api.dsmlv2.response.AddResponseDsml) SearchResultReferenceDsml(org.apache.directory.api.dsmlv2.response.SearchResultReferenceDsml) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) BindResponseDsml(org.apache.directory.api.dsmlv2.response.BindResponseDsml) ErrorResponse(org.apache.directory.api.dsmlv2.response.ErrorResponse) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Response(org.apache.directory.api.ldap.model.message.Response) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) ExtendedResponseDsml(org.apache.directory.api.dsmlv2.response.ExtendedResponseDsml) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModDNResponseDsml(org.apache.directory.api.dsmlv2.response.ModDNResponseDsml) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 2 with ResultCodeEnum

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

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

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

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

ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)6 DecoderException (org.apache.directory.api.asn1.DecoderException)3 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)3 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SaslClient (javax.security.sasl.SaslClient)1 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)1 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)1 AddResponseDsml (org.apache.directory.api.dsmlv2.response.AddResponseDsml)1 BindResponseDsml (org.apache.directory.api.dsmlv2.response.BindResponseDsml)1 CompareResponseDsml (org.apache.directory.api.dsmlv2.response.CompareResponseDsml)1