Search in sources :

Example 51 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 NameForm into an Entry
 *
 * @param nameForm The NameForm to convert
 * @param schema The schema containing this NameForm
 * @param schemaManager The SchemaManager
 * @return The converted NameForm
 */
public Entry convert(NameForm nameForm, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "");
    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 52 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 LdapComparator instance into an Entry
 *
 * @param oid The LdapComparator's OID
 * @param comparator The LdapComparator to convert
 * @param schema The schema containing this Comparator
 * @param schemaManager The SchemaManager
 * @return An Entry defining a LdapComparator
 */
public Entry convert(String oid, LdapComparator<? super Object> comparator, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC);
    entry.put(MetaSchemaConstants.M_OID_AT, oid);
    entry.put(MetaSchemaConstants.M_FQCN_AT, comparator.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 53 with DefaultEntry

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

the class LdifAttributesReader method parseEntry.

/**
 * Parse a ldif file. The following rules are processed :
 *
 * &lt;ldif-file&gt; ::= &lt;ldif-attrval-record&gt; &lt;ldif-attrval-records&gt; |
 * &lt;ldif-change-record&gt; &lt;ldif-change-records&gt; &lt;ldif-attrval-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;attrval-spec&gt; &lt;attrval-specs&gt; &lt;ldif-change-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt; &lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
 * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
 * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
 *
 * @param schemaManager The SchemaManager
 * @return The read entry
 * @throws LdapLdifException If the entry can't be read or is invalid
 */
private Entry parseEntry(SchemaManager schemaManager) throws LdapLdifException {
    if ((lines == null) || lines.isEmpty()) {
        LOG.debug(I18n.msg(I18n.MSG_13408_END_OF_LDIF));
        return null;
    }
    Entry entry = new DefaultEntry(schemaManager);
    // Now, let's iterate through the other lines
    for (String line : lines) {
        // Each line could start either with an OID, an attribute type, with
        // "control:" or with "changetype:"
        String lowerLine = Strings.toLowerCaseAscii(line);
        // 3) The first line after the Dn is anything else
        if (lowerLine.startsWith("control:")) {
            LOG.error(I18n.err(I18n.ERR_13401_CHANGE_NOT_ALLOWED));
            throw new LdapLdifException(I18n.err(I18n.ERR_13440_NO_CHANGE));
        } else if (lowerLine.startsWith("changetype:")) {
            LOG.error(I18n.err(I18n.ERR_13401_CHANGE_NOT_ALLOWED));
            throw new LdapLdifException(I18n.err(I18n.ERR_13440_NO_CHANGE));
        } else if (line.indexOf(':') > 0) {
            parseEntryAttribute(schemaManager, entry, line, lowerLine);
        } else {
            // Invalid attribute Value
            LOG.error(I18n.err(I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE));
            throw new LdapLdifException(I18n.err(I18n.ERR_13441_BAD_ATTRIBUTE));
        }
    }
    LOG.debug(I18n.msg(I18n.MSG_13405_READ_ATTR, entry));
    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 54 with DefaultEntry

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

the class LdifAttributesReader method parseEntry.

/**
 * A method which parses a ldif string and returns an Entry.
 *
 * @param schemaManager The SchemaManager
 * @param ldif The ldif string
 * @return An entry
 * @throws LdapLdifException If something went wrong
 */
public Entry parseEntry(SchemaManager schemaManager, String ldif) throws LdapLdifException {
    lines = new ArrayList<String>();
    position = 0;
    LOG.debug(I18n.msg(I18n.MSG_13407_STARTS_PARSING_LDIF));
    if (Strings.isEmpty(ldif)) {
        return new DefaultEntry(schemaManager);
    }
    StringReader strIn = new StringReader(ldif);
    reader = new BufferedReader(strIn);
    try {
        readLines();
        Entry entry = parseEntry(schemaManager);
        if (LOG.isDebugEnabled()) {
            if (entry == null) {
                LOG.debug(I18n.msg(I18n.MSG_13401_PARSED_NO_ENTRY));
            } else {
                LOG.debug(I18n.msg(I18n.MSG_13402_PARSED_ONE_ENTRY));
            }
        }
        return entry;
    } catch (LdapLdifException ne) {
        LOG.error(I18n.err(I18n.ERR_13403_CANNOT_PARSE_LDIF_BUFFER, ne.getLocalizedMessage()));
        throw new LdapLdifException(I18n.err(I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER), ne);
    } finally {
        try {
            reader.close();
        } catch (IOException ioe) {
            throw new LdapLdifException(I18n.err(I18n.ERR_13450_CANNOT_CLOSE_FILE), ioe);
        }
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) IOException(java.io.IOException)

Example 55 with DefaultEntry

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

the class PermDAO method createObject.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
PermObj createObject(PermObj entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_OBJ_OBJ_CLASS);
        entry.add(GlobalIds.POBJ_NAME, entity.getObjName());
        // this will generatre a new random, unique id on this entity:
        entity.setInternalId();
        // create the rDN:
        entry.add(GlobalIds.FT_IID, entity.getInternalId());
        // ou is required:
        entry.add(SchemaConstants.OU_AT, entity.getOu());
        // description is optional:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        // type is optional:
        if (StringUtils.isNotEmpty(entity.getType())) {
            entry.add(GlobalIds.TYPE, entity.getType());
        }
        // if the props is null don't try to load these attributes
        if (PropUtil.isNotEmpty(entity.getProperties())) {
            loadProperties(entity.getProperties(), entry, GlobalIds.PROPS);
        }
        // now add the new entry to directory:
        ld = getAdminConnection();
        add(ld, entry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "createObject perm obj [" + entity.getObjName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

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