Search in sources :

Example 11 with ModifyRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.

the class StoreModifyRequestAttributeValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the value. It can't be null
    byte[] value = Strings.EMPTY_BYTES;
    try {
        if (tlv.getLength() == 0) {
            modifyRequestDecorator.addAttributeValue("");
        } else {
            value = tlv.getValue().getData();
            if (container.isBinary(modifyRequestDecorator.getCurrentAttributeType())) {
                modifyRequestDecorator.addAttributeValue(value);
            } else {
                modifyRequestDecorator.addAttributeValue(Strings.utf8ToString((byte[]) value));
            }
        }
    } catch (LdapException le) {
    // Just swallow the exception, it can't occur here
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Value modified : {}", value);
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 12 with ModifyRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.

the class MessageDecorator method getDecorator.

/**
 * Gets the decorator associated with a given message
 *
 * @param codec The LdapApiService to use
 * @param decoratedMessage The message to decorate
 * @return The decorator instance
 */
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
    if (decoratedMessage instanceof MessageDecorator) {
        return (MessageDecorator<?>) decoratedMessage;
    }
    MessageDecorator<?> decorator;
    switch(decoratedMessage.getType()) {
        case ABANDON_REQUEST:
            decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
            break;
        case ADD_REQUEST:
            decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
            break;
        case ADD_RESPONSE:
            decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
            break;
        case BIND_REQUEST:
            decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
            break;
        case BIND_RESPONSE:
            decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
            break;
        case COMPARE_REQUEST:
            decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
            break;
        case COMPARE_RESPONSE:
            decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
            break;
        case DEL_REQUEST:
            decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
            break;
        case DEL_RESPONSE:
            decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
            break;
        case EXTENDED_REQUEST:
            decorator = codec.decorate((ExtendedRequest) decoratedMessage);
            break;
        case EXTENDED_RESPONSE:
            decorator = codec.decorate((ExtendedResponse) decoratedMessage);
            break;
        case INTERMEDIATE_RESPONSE:
            decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
            break;
        case MODIFY_REQUEST:
            decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
            break;
        case MODIFY_RESPONSE:
            decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
            break;
        case MODIFYDN_REQUEST:
            decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
            break;
        case MODIFYDN_RESPONSE:
            decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
            break;
        case SEARCH_REQUEST:
            decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
            break;
        case SEARCH_RESULT_DONE:
            decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
            break;
        case SEARCH_RESULT_ENTRY:
            decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
            break;
        case SEARCH_RESULT_REFERENCE:
            decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
            break;
        case UNBIND_REQUEST:
            decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
            break;
        default:
            return null;
    }
    Map<String, Control> controls = decoratedMessage.getControls();
    if (controls != null) {
        for (Control control : controls.values()) {
            decorator.addControl(control);
        }
    }
    return decorator;
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) DeleteRequestDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator) SearchResultEntryDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) DeleteResponseDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BindResponseDecorator(org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) AddResponseDecorator(org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator) AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) IntermediateResponseDecorator(org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) Control(org.apache.directory.api.ldap.model.message.Control) BindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator) UnbindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator) CompareRequestDecorator(org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator) ModifyDnRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) SearchResultReferenceDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) UnbindRequest(org.apache.directory.api.ldap.model.message.UnbindRequest) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) CompareResponseDecorator(org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModifyResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator) ModifyDnResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyDnResponseDecorator) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 13 with ModifyRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.

the class InitModifyRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
    // Now, we can allocate the ModifyRequest Object
    ModifyRequest internalModifyRequest = new ModifyRequestImpl();
    internalModifyRequest.setMessageId(container.getMessageId());
    ModifyRequestDecorator modifyRequestDecorator = new ModifyRequestDecorator(container.getLdapCodecService(), internalModifyRequest);
    container.setMessage(modifyRequestDecorator);
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest)

Example 14 with ModifyRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.

the class StoreModifyRequestObjectName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
    TLV tlv = container.getCurrentTLV();
    Dn object = Dn.EMPTY_DN;
    // Store the value.
    if (tlv.getLength() == 0) {
        (modifyRequestDecorator.getDecorated()).setName(object);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            object = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        modifyRequest.setName(object);
    }
    if (IS_DEBUG) {
        LOG.debug("Modification of Dn {}", modifyRequest.getName());
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) ModifyResponseImpl(org.apache.directory.api.ldap.model.message.ModifyResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 15 with ModifyRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.

the class StoreOperationType method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Decode the operation type
    int operation = 0;
    try {
        operation = IntegerDecoder.parse(tlv.getValue(), 0, 2);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04082, Strings.dumpBytes(tlv.getValue().getData()));
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg, ide);
    }
    // Store the current operation.
    modifyRequestDecorator.setCurrentOperation(operation);
    if (IS_DEBUG) {
        switch(operation) {
            case LdapCodecConstants.OPERATION_ADD:
                LOG.debug("Modification operation : ADD");
                break;
            case LdapCodecConstants.OPERATION_DELETE:
                LOG.debug("Modification operation : DELETE");
                break;
            case LdapCodecConstants.OPERATION_REPLACE:
                LOG.debug("Modification operation : REPLACE");
                break;
            default:
                LOG.debug("Modification operation : UNKNOWN");
        }
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)25 DecoderException (org.apache.directory.api.asn1.DecoderException)20 ByteBuffer (java.nio.ByteBuffer)19 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)19 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)19 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)19 Test (org.junit.Test)19 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)11 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)7 Modification (org.apache.directory.api.ldap.model.entry.Modification)7 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)4 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)4 ModifyResponseImpl (org.apache.directory.api.ldap.model.message.ModifyResponseImpl)4 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)1 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)1 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)1 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)1