Search in sources :

Example 46 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class AttributeUtilsTest method testApplyRemoveModificationFromEmptyEntry.

/**
 * Test the deletion of an attribute into an empty entry
 */
@Test
public void testApplyRemoveModificationFromEmptyEntry() throws LdapException {
    Entry entry = new DefaultEntry();
    Attribute attr = new DefaultAttribute("cn", "test");
    Modification modification = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attr);
    AttributeUtils.applyModification(entry, modification);
    assertNull(entry.get("cn"));
    assertEquals(0, entry.size());
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) 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) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 47 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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 48 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class AttributesFactory method convert.

/**
 * Converts a Schema to an Entry
 *
 * @param schema The Schema to convert
 * @param schemaManager The SchemaManager
 * @return An Entry containing the converted Schema
 * @throws LdapException If the conversion failed
 */
public Entry convert(Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC);
    entry.put(SchemaConstants.CN_AT, schema.getSchemaName());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    if (schema.isDisabled()) {
        entry.put(MetaSchemaConstants.M_DISABLED_AT, "TRUE");
    }
    String[] dependencies = schema.getDependencies();
    if (dependencies != null && dependencies.length > 0) {
        Attribute attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_DEPENDENCIES_AT));
        for (String dependency : dependencies) {
            attr.add(dependency);
        }
        entry.put(attr);
    }
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 49 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class AttributesFactory method convert.

/**
 * Convert a SyntaxChecker instance into an Entry
 *
 * @param syntaxChecker The SyntaxChecker to convert
 * @param schema The schema containing this SyntaxChecker
 * @param schemaManager The SchemaManager
 * @return An Entry containing the converted SyntaxChecker
 */
public Entry convert(SyntaxChecker syntaxChecker, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_CHECKER_OC);
    entry.put(MetaSchemaConstants.M_OID_AT, syntaxChecker.getOid());
    entry.put(MetaSchemaConstants.M_FQCN_AT, syntaxChecker.getClass().getName());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 50 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class AttributesFactory method convert.

/**
 * Converts a MatchingRule into an Entry
 *
 * @param matchingRule The MatchingRule to convert
 * @param schema The schema containing this ObjectClass
 * @param schemaManager The SchemaManager
 * @return The converted MatchingRule
 * @throws LdapException If the conversion failed
 */
public Entry convert(MatchingRule matchingRule, Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC);
    entry.put(MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    injectCommon(matchingRule, entry, schemaManager);
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4