Search in sources :

Example 1 with BerValue

use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.

the class StoredProcedureRequestImpl method getParameterValueString.

/**
 * Get a parameter value
 *
 * @param index The position of the parameter in the list of parameters
 * @return The paremeter's value
 */
public Object getParameterValueString(int index) {
    if (!"java".equals(language)) {
        Object obj = parameters.get(index).getValue();
        if (obj instanceof byte[]) {
            String str = Strings.utf8ToString((byte[]) obj);
            String type = (String) getParameterTypeString(index);
            if ("int".equals(type)) {
                try {
                    return IntegerDecoder.parse(new BerValue((byte[]) obj));
                } catch (IntegerDecoderException e) {
                    throw new RuntimeException("Failed to decode INTEGER: " + Strings.dumpBytes((byte[]) obj), e);
                }
            } else {
                return str;
            }
        }
    }
    return getJavaParameterValue(index);
}
Also used : BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)

Example 2 with BerValue

use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.

the class DefaultLdapCodecService method toJndi.

/**
 * {@inheritDoc}
 */
@Override
public javax.naming.ldap.ExtendedRequest toJndi(final ExtendedRequest modelRequest) throws EncoderException {
    final String oid = modelRequest.getRequestName();
    final byte[] value;
    if (modelRequest instanceof ExtendedRequestDecorator) {
        ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) modelRequest;
        value = decorator.getRequestValue();
    } else {
        // have to ask the factory to decorate for us - can't do it ourselves
        ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(modelRequest.getRequestName());
        ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) extendedRequestFactory.decorate(modelRequest);
        value = decorator.getRequestValue();
    }
    return new javax.naming.ldap.ExtendedRequest() {

        private static final long serialVersionUID = -4160980385909987475L;

        @Override
        public String getID() {
            return oid;
        }

        @Override
        public byte[] getEncodedValue() {
            return value;
        }

        @Override
        public javax.naming.ldap.ExtendedResponse createExtendedResponse(String id, byte[] berValue, int offset, int length) throws NamingException {
            ExtendedOperationFactory factory = extendedOperationFactories.get(modelRequest.getRequestName());
            try {
                final ExtendedResponseDecorator<?> resp = (ExtendedResponseDecorator<?>) factory.newResponse(berValue);
                return new javax.naming.ldap.ExtendedResponse() {

                    private static final long serialVersionUID = -7686354122066100703L;

                    @Override
                    public String getID() {
                        return oid;
                    }

                    @Override
                    public byte[] getEncodedValue() {
                        return resp.getResponseValue();
                    }
                };
            } catch (DecoderException de) {
                NamingException ne = new NamingException("Unable to decode encoded response value: " + Strings.dumpBytes(berValue));
                ne.setRootCause(de);
                throw ne;
            }
        }
    };
}
Also used : ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) NamingException(javax.naming.NamingException)

Example 3 with BerValue

use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.

the class InitAbandonRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AbandonRequestDecorator> container) throws DecoderException {
    // Create the AbandonRequest LdapMessage instance and store it in the container
    AbandonRequest internalAbandonRequest = new AbandonRequestImpl();
    internalAbandonRequest.setMessageId(container.getMessageId());
    AbandonRequestDecorator abandonRequest = new AbandonRequestDecorator(container.getLdapCodecService(), internalAbandonRequest);
    container.setMessage(abandonRequest);
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    if ((value == null) || (value.getData() == null)) {
        String msg = I18n.err(I18n.ERR_04075);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    try {
        int abandonnedMessageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
        abandonRequest.setAbandoned(abandonnedMessageId);
        if (IS_DEBUG) {
            LOG.debug("AbandonMessage Id has been decoded : {}", Integer.valueOf(abandonnedMessageId));
        }
        container.setGrammarEndAllowed(true);
        return;
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04076, Strings.dumpBytes(value.getData()), ide.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(ide.getMessage(), ide);
    }
}
Also used : IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) AbandonRequestImpl(org.apache.directory.api.ldap.model.message.AbandonRequestImpl) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 4 with BerValue

use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.

the class StoreModifyDnRequestDeleteOldRdn method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
    ModifyDnRequest modifyDnRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // We get the value. If it's a 0, it's a FALSE. If it's
    // a FF, it's a TRUE. Any other value should be an error,
    // but we could relax this constraint. So if we have
    // something
    // which is not 0, it will be interpreted as TRUE, but we
    // will generate a warning.
    BerValue value = tlv.getValue();
    try {
        modifyDnRequest.setDeleteOldRdn(BooleanDecoder.parse(value));
    } catch (BooleanDecoderException bde) {
        LOG.error(I18n.err(I18n.ERR_04091, Strings.dumpBytes(value.getData()), bde.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(bde.getMessage(), bde);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        if (modifyDnRequest.getDeleteOldRdn()) {
            LOG.debug(" Old Rdn attributes will be deleted");
        } else {
            LOG.debug(" Old Rdn attributes will be retained");
        }
    }
}
Also used : BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 5 with BerValue

use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.

the class StoreSearchRequestDerefAlias method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We have to check that this is a correct derefAliases
    BerValue value = tlv.getValue();
    int derefAliases = 0;
    try {
        derefAliases = IntegerDecoder.parse(value, LdapCodecConstants.NEVER_DEREF_ALIASES, LdapCodecConstants.DEREF_ALWAYS);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04102, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setDerefAliases(AliasDerefMode.getDerefMode(derefAliases));
    if (IS_DEBUG) {
        switch(derefAliases) {
            case LdapCodecConstants.NEVER_DEREF_ALIASES:
                LOG.debug("Handling object strategy : NEVER_DEREF_ALIASES");
                break;
            case LdapCodecConstants.DEREF_IN_SEARCHING:
                LOG.debug("Handling object strategy : DEREF_IN_SEARCHING");
                break;
            case LdapCodecConstants.DEREF_FINDING_BASE_OBJ:
                LOG.debug("Handling object strategy : DEREF_FINDING_BASE_OBJ");
                break;
            case LdapCodecConstants.DEREF_ALWAYS:
                LOG.debug("Handling object strategy : DEREF_ALWAYS");
                break;
            default:
                LOG.debug("Handling object strategy : UNKNOWN");
        }
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) 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)

Aggregations

BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)22 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)19 DecoderException (org.apache.directory.api.asn1.DecoderException)18 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)11 BooleanDecoderException (org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException)5 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)5 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 StoredProcedureContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer)2 StoredProcedureDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder)2 StoredProcedureRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator)2 Control (org.apache.directory.api.ldap.model.message.Control)2 Test (org.junit.Test)2 NamingException (javax.naming.NamingException)1 CheckNotNullLength (org.apache.directory.api.asn1.actions.CheckNotNullLength)1 LongDecoderException (org.apache.directory.api.asn1.ber.tlv.LongDecoderException)1 ExtendedOperationFactory (org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)1 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)1