Search in sources :

Example 1 with CreateException

use of org.apache.directory.fortress.core.CreateException 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)

Example 2 with CreateException

use of org.apache.directory.fortress.core.CreateException in project directory-fortress-core by apache.

the class PermDAO method createPermissionAttribute.

/**
 * @param entity
 * @param attributeSetName
 * @return
 * @throws CreateException
 */
PermissionAttribute createPermissionAttribute(PermissionAttribute entity, String attributeSetName) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity, attributeSetName, entity.getContextId());
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_ATTR_OBJ_CLASS);
        // this will generate a new random, unique id on this entity:
        entity.setInternalId();
        // create the internal id:
        entry.add(GlobalIds.FT_IID, entity.getInternalId());
        entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE, entity.getAttributeName());
        entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET, attributeSetName);
        // description is optional
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        if (StringUtils.isNotEmpty(entity.getDataType())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_DATA_TYPE, entity.getDataType());
        }
        if (StringUtils.isNotEmpty(entity.getDefaultOperator())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_OPERATOR, entity.getDefaultOperator());
        }
        if (StringUtils.isNotEmpty(entity.getDefaultStrategy())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_STRATEGY, entity.getDefaultStrategy());
        }
        if (StringUtils.isNotEmpty(entity.getDefaultValue())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_VALUE, entity.getDefaultValue());
        }
        // add one to many valid values
        for (String validValue : entity.getValidValues()) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_VALID_VALUES, validValue);
        }
        // organizational name requires CN attribute:
        entry.add(SchemaConstants.CN_AT, entity.getAttributeName());
        // now add the new entry to directory:
        ld = getAdminConnection();
        add(ld, entry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "createPermissionAttribute name [" + entity.getAttributeName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PERM_ATTR_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 3 with CreateException

use of org.apache.directory.fortress.core.CreateException in project directory-fortress-core by apache.

the class PermDAO method createOperation.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
Permission createOperation(Permission 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_OP_OBJ_CLASS);
        entry.add(GlobalIds.POP_NAME, entity.getOpName());
        entry.add(GlobalIds.POBJ_NAME, entity.getObjName());
        entity.setAbstractName(entity.getObjName() + "." + entity.getOpName());
        // this will generate a new random, unique id on this entity:
        entity.setInternalId();
        // create the internal id:
        entry.add(GlobalIds.FT_IID, entity.getInternalId());
        // description is optional:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        // the abstract name is the human readable identifier:
        entry.add(PERM_NAME, entity.getAbstractName());
        // organizational name requires CN attribute:
        entry.add(SchemaConstants.CN_AT, entity.getAbstractName());
        // objectid is optional:
        if (StringUtils.isNotEmpty(entity.getObjId())) {
            entry.add(GlobalIds.POBJ_ID, entity.getObjId());
        }
        // type is optional:
        if (StringUtils.isNotEmpty(entity.getType())) {
            entry.add(GlobalIds.TYPE, entity.getType());
        }
        // These are multi-valued attributes, use the util function to load:
        // These items are optional as well.  The utility function will return quietly if no items are loaded into collection:
        loadAttrs(entity.getRoles(), entry, ROLES);
        loadAttrs(entity.getUsers(), entry, USERS);
        loadAttrs(entity.getPaSets(), entry, PERMISSION_ATTRIBUTE_SET);
        // 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 = "createOperation objName [" + entity.getObjName() + "] opName [" + entity.getOpName() + "] 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)

Example 4 with CreateException

use of org.apache.directory.fortress.core.CreateException in project directory-fortress-core by apache.

the class ConfigDAO method create.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
Properties create(String name, Properties props) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("create dn [{}]", dn);
    try {
        Entry myEntry = new DefaultEntry(dn);
        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, CONFIG_OBJ_CLASS);
        ld = getAdminConnection();
        myEntry.add(SchemaConstants.CN_AT, name);
        loadProperties(props, myEntry, GlobalIds.PROPS);
        add(ld, myEntry);
    } catch (LdapEntryAlreadyExistsException e) {
        String warning = "create config dn [" + dn + "] caught LdapEntryAlreadyExistsException=" + e.getMessage() + " msg=" + e.getMessage();
        throw new CreateException(GlobalErrIds.FT_CONFIG_ALREADY_EXISTS, warning, e);
    } catch (LdapException e) {
        String error;
        error = "create config dn [" + dn + "] caught LDAPException=" + e.getMessage();
        LOG.error(error, e);
        throw new CreateException(GlobalErrIds.FT_CONFIG_CREATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : LdapEntryAlreadyExistsException(org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException) 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) CreateException(org.apache.directory.fortress.core.CreateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 5 with CreateException

use of org.apache.directory.fortress.core.CreateException in project directory-fortress-core by apache.

the class GroupDAO method create.

/**
 * @param group
 * @throws org.apache.directory.fortress.core.CreateException
 */
Group create(Group group) throws CreateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    try {
        LOG.debug("create group dn [{}]", nodeDn);
        Entry myEntry = new DefaultEntry(nodeDn);
        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, GROUP_OBJ_CLASS);
        myEntry.add(SchemaConstants.CN_AT, group.getName());
        // protocol is required:
        myEntry.add(GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol());
        // type is required:
        myEntry.add(GlobalIds.TYPE, group.getType().toString());
        loadAttrs(group.getMembers(), myEntry, SchemaConstants.MEMBER_AT);
        loadProperties(group.getProperties(), myEntry, GROUP_PROPERTY_ATTR_IMPL, '=');
        if (StringUtils.isNotEmpty(group.getDescription())) {
            myEntry.add(SchemaConstants.DESCRIPTION_AT, group.getDescription());
        }
        ld = getAdminConnection();
        add(ld, myEntry);
    } catch (LdapException e) {
        String error = "create group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.GROUP_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return group;
}
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

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)16 CreateException (org.apache.directory.fortress.core.CreateException)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)15 Entry (org.apache.directory.api.ldap.model.entry.Entry)15 LdapEntryAlreadyExistsException (org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException)2 ArrayList (java.util.ArrayList)1 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)1 Modification (org.apache.directory.api.ldap.model.entry.Modification)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 PermissionAttribute (org.apache.directory.fortress.core.model.PermissionAttribute)1