Search in sources :

Example 6 with ValidationException

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

the class PermP method validatePaSet.

/*
     * Ensure the paSet is present and name is safe.
     */
void validatePaSet(String paSetName, String contextId) throws ValidationException {
    try {
        PermissionAttributeSet paSet = new PermissionAttributeSet(paSetName);
        paSet.setContextId(contextId);
        read(paSet);
        VUtil.safeText(paSetName, GlobalIds.DESC_LEN);
    } catch (SecurityException e) {
        String error = "validatePaSet - paSetName not found with name [" + paSetName + "] caught SecurityException=" + e;
        throw new ValidationException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, error);
    }
}
Also used : PermissionAttributeSet(org.apache.directory.fortress.core.model.PermissionAttributeSet) ValidationException(org.apache.directory.fortress.core.ValidationException) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 7 with ValidationException

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

the class PermP method validate.

/**
 * Method will perform various validations to ensure the integrity of the Permission Object entity targeted for insertion
 * or updating in directory.  Data reasonability checks will be performed on all non-null attributes.
 *
 * @param pObj     Permission Object entity contains data targeted for insertion or update.
 * @param isUpdate if true update operation is being performed which specifies a different set of targeted attributes.
 * @throws org.apache.directory.fortress.core.ValidationException in the event of data validation error.
 */
void validate(PermObj pObj, boolean isUpdate) throws ValidationException {
    if (!isUpdate) {
        // Validate length
        VUtil.orgUnit(pObj.getOu());
        // ensure ou exists in the OS-P pool:
        OrgUnit ou = new OrgUnit(pObj.getOu(), OrgUnit.Type.PERM);
        ou.setContextId(pObj.getContextId());
        if (!orgUnitP.isValid(ou)) {
            String error = "validate detected invalid orgUnit name [" + pObj.getOu() + "] for object name [" + pObj.getObjName() + "]";
            // log.warn(error);
            throw new ValidationException(GlobalErrIds.PERM_OU_INVALID, error);
        }
        if (StringUtils.isNotEmpty(pObj.getObjName())) {
            VUtil.description(pObj.getObjName());
        }
        if (StringUtils.isNotEmpty(pObj.getOu())) {
            VUtil.orgUnit(pObj.getOu());
        }
        if (StringUtils.isNotEmpty(pObj.getDescription())) {
            VUtil.description(pObj.getDescription());
        }
    } else {
        if (StringUtils.isNotEmpty(pObj.getOu())) {
            VUtil.orgUnit(pObj.getOu());
            // ensure ou exists in the OS-P pool:
            OrgUnit ou = new OrgUnit(pObj.getOu(), OrgUnit.Type.PERM);
            ou.setContextId(pObj.getContextId());
            if (!orgUnitP.isValid(ou)) {
                String error = "validate detected invalid orgUnit name [" + pObj.getOu() + "] for object name [" + pObj.getObjName() + "]";
                throw new ValidationException(GlobalErrIds.PERM_OU_INVALID, error);
            }
        }
        if (StringUtils.isNotEmpty(pObj.getDescription())) {
            VUtil.description(pObj.getDescription());
        }
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) ValidationException(org.apache.directory.fortress.core.ValidationException)

Example 8 with ValidationException

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

the class PolicyP method validate.

/**
 * Method will perform simple validations to ensure the integrity of the OpenLDAP Password Policy entity targeted for insertion
 * or updating in directory.  Data reasonability checks will be performed on all non-null attributes.
 *
 * @param policy contains data targeted for insertion or update.
 * @throws ValidationException in the event of data validation error or DAO error on Org validation.
 */
private void validate(PwPolicy policy) throws ValidationException {
    int length = policy.getName().length();
    if (length < 1 || length > GlobalIds.PWPOLICY_NAME_LEN) {
        String error = "validate policy name [" + policy.getName() + "] INVALID LENGTH [" + length + "]";
        LOG.error(error);
        throw new ValidationException(GlobalErrIds.PSWD_NAME_INVLD_LEN, error);
    }
    if (policy.getCheckQuality() != null) {
        try {
            if (policy.getCheckQuality() < 0 || policy.getCheckQuality() > 2) {
                String error = "validate policy name [" + policy.getName() + "] value checkQuality [" + policy.getCheckQuality() + "] INVALID INT VALUE";
                LOG.error(error);
                throw new ValidationException(GlobalErrIds.PSWD_QLTY_INVLD, error);
            }
        } catch (java.lang.NumberFormatException nfe) {
            String error = "validate policy name [" + policy.getName() + "] value checkQuality [" + policy.getCheckQuality() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_QLTY_INVLD, error);
        }
    }
    if (policy.getMaxAge() != null) {
        if (policy.getMaxAge() > MAX_AGE) {
            String error = "validate policy name [" + policy.getName() + "] value maxAge [" + policy.getMaxAge() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_MAXAGE_INVLD, error);
        }
    }
    if (policy.getMinAge() != null) {
        // policy.minAge
        if (policy.getMinAge() > MAX_AGE) {
            String error = "validate policy name [" + policy.getName() + "] value minAge [" + policy.getMinAge() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_MINAGE_INVLD, error);
        }
    }
    if (policy.getMinLength() != null) {
        if (policy.getMinLength() > MIN_PW_LEN) {
            String error = "validate policy name [" + policy.getName() + "] value minLength [" + policy.getMinLength() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_MINLEN_INVLD, error);
        }
    }
    if (policy.getFailureCountInterval() != null) {
        if (policy.getFailureCountInterval() > MAX_AGE) {
            String error = "validate policy name [" + policy.getName() + "] value failureCountInterval [" + policy.getFailureCountInterval() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_INTERVAL_INVLD, error);
        }
    }
    if (policy.getMaxFailure() != null) {
        if (policy.getMaxFailure() > MAX_FAILURE) {
            String error = "validate policy name [" + policy.getName() + "] value maxFailure [" + policy.getMaxFailure() + "] INVALID INT VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_MAXFAIL_INVLD, error);
        }
    }
    if (policy.getInHistory() != null) {
        if (policy.getInHistory() > MAX_HISTORY) {
            String error = "validate policy name [" + policy.getName() + "] value inHistory [" + policy.getInHistory() + "] INVALID VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_HISTORY_INVLD, error);
        }
    }
    if (policy.getGraceLoginLimit() != null) {
        if (policy.getGraceLoginLimit() > MAX_GRACE_COUNT) {
            String error = "validate policy name [" + policy.getName() + "] value graceLoginLimit [" + policy.getGraceLoginLimit() + "] INVALID VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_GRACE_INVLD, error);
        }
    }
    if (policy.getLockoutDuration() != null) {
        if (policy.getLockoutDuration() > MAX_AGE) {
            String error = "validate policy name [" + policy.getName() + "] value lockoutDuration [" + policy.getLockoutDuration() + "] INVALID VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_LOCKOUTDUR_INVLD, error);
        }
    }
    if (policy.getExpireWarning() != null) {
        if (policy.getExpireWarning() > MAX_AGE) {
            String error = "validate policy name [" + policy.getName() + "] value expireWarning [" + policy.getExpireWarning() + "] INVALID VALUE";
            LOG.error(error);
            throw new ValidationException(GlobalErrIds.PSWD_EXPWARN_INVLD, error);
        }
    }
}
Also used : ValidationException(org.apache.directory.fortress.core.ValidationException)

Aggregations

ValidationException (org.apache.directory.fortress.core.ValidationException)8 Constraint (org.apache.directory.fortress.core.model.Constraint)3 SecurityException (org.apache.directory.fortress.core.SecurityException)2 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)2 UserRole (org.apache.directory.fortress.core.model.UserRole)2 ArrayList (java.util.ArrayList)1 AdminRole (org.apache.directory.fortress.core.model.AdminRole)1 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1 PermissionAttributeSet (org.apache.directory.fortress.core.model.PermissionAttributeSet)1 PwPolicy (org.apache.directory.fortress.core.model.PwPolicy)1 Role (org.apache.directory.fortress.core.model.Role)1 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)1 Time (org.apache.directory.fortress.core.util.time.Time)1 Validator (org.apache.directory.fortress.core.util.time.Validator)1