Search in sources :

Example 11 with CreateException

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

the class PermDAO method createPermissionAttributeSet.

/**
 * @param entity
 * @return
 * @throws CreateException
 */
PermissionAttributeSet createPermissionAttributeSet(PermissionAttributeSet 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_ATTR_SET_OBJ_CLASS);
        entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET, entity.getName());
        // 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());
        }
        if (StringUtils.isNotEmpty(entity.getType())) {
            entry.add(GlobalIds.FT_PERMISSION_ATTRIBUTE_SET_TYPE, entity.getType());
        }
        // organizational name requires CN attribute:
        entry.add(SchemaConstants.CN_AT, entity.getName());
        // now add the new entry to directory:
        ld = getAdminConnection();
        add(ld, entry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "createPermissionAttributeSet name [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    // add each ftPA
    for (PermissionAttribute pa : entity.getAttributes()) {
        pa.setContextId(entity.getContextId());
        this.createPermissionAttribute(pa, entity.getName());
    }
    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) PermissionAttribute(org.apache.directory.fortress.core.model.PermissionAttribute) 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 12 with CreateException

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

the class PolicyDAO method create.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
PwPolicy create(PwPolicy entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity);
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, PWPOLICY_OBJ_CLASS);
        entry.add(PW_PWD_ID, entity.getName());
        entry.add(PW_ATTRIBUTE, PW_POLICY_EXTENSION);
        if (entity.getMinAge() != null) {
            entry.add(PW_MIN_AGE, entity.getMinAge().toString());
        }
        if (entity.getMaxAge() != null) {
            entry.add(PW_MAX_AGE, entity.getMaxAge().toString());
        }
        if (entity.getInHistory() != null) {
            entry.add(PW_IN_HISTORY, entity.getInHistory().toString());
        }
        if (entity.getCheckQuality() != null) {
            entry.add(PW_CHECK_QUALITY, entity.getCheckQuality().toString());
        }
        if (entity.getMinLength() != null) {
            entry.add(PW_MIN_LENGTH, entity.getMinLength().toString());
        }
        if (entity.getExpireWarning() != null) {
            entry.add(PW_EXPIRE_WARNING, entity.getExpireWarning().toString());
        }
        if (entity.getGraceLoginLimit() != null) {
            entry.add(PW_GRACE_LOGIN_LIMIT, entity.getGraceLoginLimit().toString());
        }
        if (entity.getLockout() != null) {
            /**
             * OpenLDAP requires the pwdLockout boolean value to be upper case:
             */
            entry.add(PW_LOCKOUT, entity.getLockout().toString().toUpperCase());
        }
        if (entity.getLockoutDuration() != null) {
            entry.add(PW_LOCKOUT_DURATION, entity.getLockoutDuration().toString());
        }
        if (entity.getMaxFailure() != null) {
            entry.add(PW_MAX_FAILURE, entity.getMaxFailure().toString());
        }
        if (entity.getFailureCountInterval() != null) {
            entry.add(PW_FAILURE_COUNT_INTERVAL, entity.getFailureCountInterval().toString());
        }
        if (entity.getMustChange() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            entry.add(PW_MUST_CHANGE, entity.getMustChange().toString().toUpperCase());
        }
        if (entity.getAllowUserChange() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            entry.add(PW_ALLOW_USER_CHANGE, entity.getAllowUserChange().toString().toUpperCase());
        }
        if (entity.getSafeModify() != null) {
            entry.add(PW_SAFE_MODIFY, entity.getSafeModify().toString().toUpperCase());
        }
        ld = getAdminConnection();
        add(ld, entry, entity);
    } catch (LdapException e) {
        String error = "create name [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PSWD_CREATE_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 13 with CreateException

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

the class AdminRoleDAO method create.

/**
 * Create a new AdminRole entity using supplied data.  Required attribute is {@link org.apache.directory.fortress.core.model.AdminRole#name}.
 * This data will be stored in the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
 *
 * @param entity record contains AdminRole data.  Null attributes will be ignored.
 * @return input record back to client.
 * @throws org.apache.directory.fortress.core.CreateException in the event LDAP errors occur.
 */
AdminRole create(AdminRole entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity);
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, ADMIN_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));
        loadAttrs(entity.getOsPSet(), entry, ROLE_OSP);
        loadAttrs(entity.getOsUSet(), entry, ROLE_OSU);
        String szRaw = entity.getRoleRangeRaw();
        if (StringUtils.isNotEmpty(szRaw)) {
            entry.add(ROLE_RANGE, szRaw);
        }
        // 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 role [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.ARLE_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 14 with CreateException

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

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

the class GroupDAO method add.

Group add(Group group, String key, String value) throws FinderException, CreateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    try {
        LOG.debug("add group property dn [{}], key [{}], value [{}]", nodeDn, key, value);
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, GROUP_PROPERTY_ATTR_IMPL, key + "=" + value));
        ld = getAdminConnection();
        modify(ld, nodeDn, mods, group);
    } catch (LdapException e) {
        String error = "update group property node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.GROUP_ADD_PROPERTY_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return get(group);
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) 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