Search in sources :

Example 11 with AddRequest

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

the class LdapNetworkConnection method addAsync.

/**
 * {@inheritDoc}
 */
@Override
public AddFuture addAsync(Entry entry) throws LdapException {
    if (entry == null) {
        String msg = "Cannot add null entry";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry(entry);
    return addAsync(addRequest);
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl)

Example 12 with AddRequest

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

the class LdapNetworkConnection method add.

// ------------------------ The LDAP operations ------------------------//
// Add operations                                                      //
// ---------------------------------------------------------------------//
/**
 * {@inheritDoc}
 */
@Override
public void add(Entry entry) throws LdapException {
    if (entry == null) {
        String msg = "Cannot add an empty entry";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry(entry);
    AddResponse addResponse = add(addRequest);
    processResponse(addResponse);
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse)

Example 13 with AddRequest

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

the class QuirkySchemaTest method createFakeConnection.

private LdapConnection createFakeConnection(final String schemaFileName) {
    return new LdapConnection() {

        @Override
        public void unBind() throws LdapException {
        }

        @Override
        public void setTimeOut(long timeOut) {
        }

        @Override
        public void setSchemaManager(SchemaManager schemaManager) {
        }

        @Override
        public void setBinaryAttributeDetector(BinaryAttributeDetector binaryAttributeDetecter) {
        }

        @Override
        public SearchCursor search(SearchRequest searchRequest) throws LdapException {
            return null;
        }

        @Override
        public EntryCursor search(String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
            return null;
        }

        @Override
        public EntryCursor search(Dn baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
            return null;
        }

        @Override
        public void rename(Dn entryDn, Rdn newRdn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void rename(String entryDn, String newRdn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void rename(Dn entryDn, Rdn newRdn) throws LdapException {
        }

        @Override
        public void rename(String entryDn, String newRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(String entryDn, String newDn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(Dn entryDn, Dn newDn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(String entryDn, String newDn) throws LdapException {
        }

        @Override
        public void moveAndRename(Dn entryDn, Dn newDn) throws LdapException {
        }

        @Override
        public void move(Dn entryDn, Dn newSuperiorDn) throws LdapException {
        }

        @Override
        public void move(String entryDn, String newSuperiorDn) throws LdapException {
        }

        @Override
        public ModifyDnResponse modifyDn(ModifyDnRequest modDnRequest) throws LdapException {
            return null;
        }

        @Override
        public ModifyResponse modify(ModifyRequest modRequest) throws LdapException {
            return null;
        }

        @Override
        public void modify(Entry entry, ModificationOperation modOp) throws LdapException {
        }

        @Override
        public void modify(String dn, Modification... modifications) throws LdapException {
        }

        @Override
        public void modify(Dn dn, Modification... modifications) throws LdapException {
        }

        @Override
        public Entry lookup(String dn, Control[] controls, String... attributes) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(String dn, String... attributes) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(Dn dn, Control[] controls, String... attributes) throws LdapException {
            return lookup(dn);
        }

        @Override
        public Entry lookup(Dn dn, String... attributes) throws LdapException {
            return lookup(dn);
        }

        @Override
        public Entry lookup(String dn) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(Dn dn) throws LdapException {
            if (dn.isRootDse()) {
                Entry entry = new DefaultEntry(dn);
                entry.add(SchemaConstants.SUBSCHEMA_SUBENTRY_AT, SCHEMA_DN);
                return entry;
            } else if (dn.toString().equals(SCHEMA_DN)) {
                Entry entry = loadSchemaEntry(schemaFileName);
                return entry;
            } else {
                throw new UnsupportedOperationException("Unexpected DN " + dn);
            }
        }

        @Override
        public void loadSchemaRelaxed() throws LdapException {
        }

        @Override
        public void loadSchema() throws LdapException {
        }

        @Override
        public boolean isRequestCompleted(int messageId) {
            return true;
        }

        @Override
        public boolean isControlSupported(String controlOID) throws LdapException {
            return true;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isAuthenticated() {
            return false;
        }

        @Override
        public List<String> getSupportedControls() throws LdapException {
            return null;
        }

        @Override
        public SchemaManager getSchemaManager() {
            return null;
        }

        @Override
        public Entry getRootDse(String... attributes) throws LdapException {
            return lookup(Dn.ROOT_DSE);
        }

        @Override
        public Entry getRootDse() throws LdapException {
            return lookup(Dn.ROOT_DSE);
        }

        @Override
        public LdapApiService getCodecService() {
            return null;
        }

        @Override
        public BinaryAttributeDetector getBinaryAttributeDetector() {
            return null;
        }

        @Override
        public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(Oid oid, byte[] value) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(Oid oid) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(String oid, byte[] value) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(String oid) throws LdapException {
            return null;
        }

        @Override
        public boolean exists(Dn dn) throws LdapException {
            return false;
        }

        @Override
        public boolean exists(String dn) throws LdapException {
            return false;
        }

        @Override
        public boolean doesFutureExistFor(int messageId) {
            return false;
        }

        @Override
        public DeleteResponse delete(DeleteRequest deleteRequest) throws LdapException {
            return null;
        }

        @Override
        public void delete(Dn dn) throws LdapException {
        }

        @Override
        public void delete(String dn) throws LdapException {
        }

        @Override
        public boolean connect() throws LdapException {
            return true;
        }

        @Override
        public CompareResponse compare(CompareRequest compareRequest) throws LdapException {
            return null;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, byte[] value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, String value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(String dn, String attributeName, byte[] value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(String dn, String attributeName, String value) throws LdapException {
            return false;
        }

        @Override
        public void close() throws IOException {
        }

        @Override
        public BindResponse bind(BindRequest bindRequest) throws LdapException {
            return null;
        }

        @Override
        public void bind(Dn name, String credentials) throws LdapException {
        }

        @Override
        public void bind(Dn name) throws LdapException {
        }

        @Override
        public void bind(String name, String credentials) throws LdapException {
        }

        @Override
        public void bind(String name) throws LdapException {
        }

        @Override
        public void bind() throws LdapException {
        }

        @Override
        public void anonymousBind() throws LdapException {
        }

        @Override
        public AddResponse add(AddRequest addRequest) throws LdapException {
            return null;
        }

        @Override
        public void add(Entry entry) throws LdapException {
        }

        @Override
        public void abandon(AbandonRequest abandonRequest) {
        }

        @Override
        public void abandon(int messageId) {
        }

        @Override
        public boolean compare(String dn, String attributeName, Value value) throws LdapException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, Value value) throws LdapException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public BindResponse bind(SaslRequest saslRequest) throws LdapException {
            // TODO Auto-generated method stub
            return null;
        }
    };
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) Modification(org.apache.directory.api.ldap.model.entry.Modification) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) Oid(org.apache.directory.api.asn1.util.Oid) BinaryAttributeDetector(org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector) AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ModificationOperation(org.apache.directory.api.ldap.model.entry.ModificationOperation) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) SearchScope(org.apache.directory.api.ldap.model.message.SearchScope) Value(org.apache.directory.api.ldap.model.entry.Value) Rdn(org.apache.directory.api.ldap.model.name.Rdn) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest)

Example 14 with AddRequest

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

the class InitAddRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    // Now, we can allocate the AddRequest Object
    int messageId = container.getMessageId();
    AddRequest internalAddRequest = new AddRequestImpl();
    internalAddRequest.setMessageId(messageId);
    AddRequestDecorator addRequest = new AddRequestDecorator(container.getLdapCodecService(), internalAddRequest);
    container.setMessage(addRequest);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04084);
        LOG.error(msg);
        // Will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DecoderException(org.apache.directory.api.asn1.DecoderException) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 15 with AddRequest

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

the class AddRequestDecorator method computeLength.

// -------------------------------------------------------------------------
// The Decorator methods
// -------------------------------------------------------------------------
/**
 * Compute the AddRequest length
 * <br>
 * AddRequest :
 * <pre>
 * 0x68 L1
 *  |
 *  +--&gt; 0x04 L2 entry
 *  +--&gt; 0x30 L3 (attributes)
 *        |
 *        +--&gt; 0x30 L4-1 (attribute)
 *        |     |
 *        |     +--&gt; 0x04 L5-1 type
 *        |     +--&gt; 0x31 L6-1 (values)
 *        |           |
 *        |           +--&gt; 0x04 L7-1-1 value
 *        |           +--&gt; ...
 *        |           +--&gt; 0x04 L7-1-n value
 *        |
 *        +--&gt; 0x30 L4-2 (attribute)
 *        |     |
 *        |     +--&gt; 0x04 L5-2 type
 *        |     +--&gt; 0x31 L6-2 (values)
 *        |           |
 *        |           +--&gt; 0x04 L7-2-1 value
 *        |           +--&gt; ...
 *        |           +--&gt; 0x04 L7-2-n value
 *        |
 *        +--&gt; ...
 *        |
 *        +--&gt; 0x30 L4-m (attribute)
 *              |
 *              +--&gt; 0x04 L5-m type
 *              +--&gt; 0x31 L6-m (values)
 *                    |
 *                    +--&gt; 0x04 L7-m-1 value
 *                    +--&gt; ...
 *                    +--&gt; 0x04 L7-m-n value
 * </pre>
 */
@Override
public int computeLength() {
    AddRequest addRequest = getDecorated();
    Entry entry = addRequest.getEntry();
    if (entry == null) {
        throw new IllegalArgumentException(I18n.err(I18n.ERR_04481_ENTRY_NULL_VALUE));
    }
    dnBytes = Strings.getBytesUtf8(entry.getDn().getName());
    int dnLen = dnBytes.length;
    // The entry Dn
    addRequestLength = 1 + TLV.getNbBytes(dnLen) + dnLen;
    // The attributes sequence
    entryLength = 0;
    if (entry.size() != 0) {
        attributesLength = new LinkedList<>();
        attributeIds = new LinkedList<>();
        valuesLength = new LinkedList<>();
        // Compute the attributes length
        for (Attribute attribute : entry) {
            int localAttributeLength;
            int localValuesLength;
            // Get the type length
            byte[] attributeIdBytes = Strings.getBytesUtf8(attribute.getUpId());
            attributeIds.add(attributeIdBytes);
            int idLength = attributeIdBytes.length;
            localAttributeLength = 1 + TLV.getNbBytes(idLength) + idLength;
            // The values
            if (attribute.size() != 0) {
                localValuesLength = 0;
                for (Value value : attribute) {
                    if (value.getBytes() == null) {
                        localValuesLength += 1 + 1;
                    } else {
                        int valueLength = value.getBytes().length;
                        localValuesLength += 1 + TLV.getNbBytes(valueLength) + valueLength;
                    }
                }
                localAttributeLength += 1 + TLV.getNbBytes(localValuesLength) + localValuesLength;
            } else {
                // No value : we still have to store the encapsulating Sequence
                localValuesLength = 1 + 1;
                localAttributeLength += 1 + 1 + localValuesLength;
            }
            // add the attribute length to the attributes length
            entryLength += 1 + TLV.getNbBytes(localAttributeLength) + localAttributeLength;
            attributesLength.add(localAttributeLength);
            valuesLength.add(localValuesLength);
        }
    }
    addRequestLength += 1 + TLV.getNbBytes(entryLength) + entryLength;
    // Return the result.
    return 1 + TLV.getNbBytes(addRequestLength) + addRequestLength;
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue)

Aggregations

AddRequest (org.apache.directory.api.ldap.model.message.AddRequest)26 Test (org.junit.Test)19 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)16 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)16 Entry (org.apache.directory.api.ldap.model.entry.Entry)12 Value (org.apache.directory.api.ldap.model.entry.Value)11 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 Control (org.apache.directory.api.ldap.model.message.Control)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 AddRequestImpl (org.apache.directory.api.ldap.model.message.AddRequestImpl)4 ByteBuffer (java.nio.ByteBuffer)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)3 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)3