Search in sources :

Example 86 with DefaultEntry

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

the class RoleDAO method create.

/**
 * @param entity
 * @return
 * @throws CreateException
 */
Role create(Role entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity.getName(), entity.getContextId());
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, ROLE_OBJ_CLASS);
        entity.setId();
        entry.add(GlobalIds.FT_IID, entity.getId());
        entry.add(ROLE_NM, entity.getName());
        // description field is optional on this object class:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        // CN attribute is required for this object class:
        entry.add(SchemaConstants.CN_AT, entity.getName());
        entry.add(GlobalIds.CONSTRAINT, ConstraintUtil.setConstraint(entity));
        // These multi-valued attributes are optional.  The utility function will return quietly if items are not loaded into collection:
        loadAttrs(entity.getParents(), entry, GlobalIds.PARENT_NODES);
        ld = getAdminConnection();
        add(ld, entry, entity);
    } catch (LdapException e) {
        String error = "create role [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.ROLE_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)

Example 87 with DefaultEntry

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

the class OrgUnitDAO method create.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
OrgUnit create(OrgUnit entity) throws CreateException {
    LdapConnection ld = null;
    Dn dn = getDn(entity);
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, ORGUNIT_OBJ_CLASS);
        entity.setId();
        entry.add(GlobalIds.FT_IID, entity.getId());
        String description = entity.getDescription();
        if (!Strings.isEmpty(description)) {
            entry.add(SchemaConstants.DESCRIPTION_AT, description);
        }
        // organizational name requires OU attribute:
        entry.add(SchemaConstants.OU_AT, entity.getName());
        // These multi-valued attributes are optional.  The utility function will return quietly if no items are loaded into collection:
        loadAttrs(entity.getParents(), entry, GlobalIds.PARENT_NODES);
        ld = getAdminConnection();
        add(ld, entry, entity);
    } catch (LdapException e) {
        String error = "create orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] root [" + dn + "] caught LdapException=" + e;
        int errCode;
        if (entity.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_ADD_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_ADD_FAILED_USER;
        }
        throw new CreateException(errCode, 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) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 88 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 Syntax instance into an Entry
 *
 * @param syntax The LdapSytax to convert
 * @param schema The schema containing this Syntax
 * @param schemaManager The SchemaManager
 * @return And entry defining a LdapSyntax
 * @throws LdapException If the conversion failed
 */
public Entry convert(LdapSyntax syntax, Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC);
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    injectCommon(syntax, 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)

Example 89 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 MatchingRuleUse into an Entry
 *
 * @param matchingRuleUse The MatchingRuleUse to convert
 * @param schema The schema containing this MatchingRuleUse
 * @param schemaManager The SchemaManager
 * @return The converted MatchingRuleUse
 */
public Entry convert(MatchingRuleUse matchingRuleUse, 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 90 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 Normalizer instance into an Entry
 *
 * @param oid The Normalizer's OID
 * @param normalizer The Normalizer to convert
 * @param schema The schema containing this Normalizer
 * @param schemaManager The SchemaManager
 * @return An Entry defining a Normalizer
 */
public Entry convert(String oid, Normalizer normalizer, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC);
    entry.put(MetaSchemaConstants.M_OID_AT, oid);
    entry.put(MetaSchemaConstants.M_FQCN_AT, normalizer.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)

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