Search in sources :

Example 1 with TooShortToken

use of org.structr.common.error.TooShortToken in project structr by structr.

the class ValidationHelper method isValidStringMinLength.

// ----- public static methods -----
/**
 * Checks whether the value for the given property key of the given node
 * has at least the given length.
 *
 * @param node the node
 * @param key the property key whose value should be checked
 * @param minLength the min length
 * @param errorBuffer the error buffer
 *
 * @return true if the condition is valid
 */
public static boolean isValidStringMinLength(final GraphObject node, final PropertyKey<String> key, final int minLength, final ErrorBuffer errorBuffer) {
    String value = node.getProperty(key);
    String type = node.getType();
    if (StringUtils.isNotBlank(value)) {
        if (value.length() >= minLength) {
            return true;
        }
        errorBuffer.add(new TooShortToken(type, key, minLength));
        return false;
    }
    errorBuffer.add(new EmptyPropertyToken(type, key));
    return false;
}
Also used : EmptyPropertyToken(org.structr.common.error.EmptyPropertyToken) TooShortToken(org.structr.common.error.TooShortToken)

Example 2 with TooShortToken

use of org.structr.common.error.TooShortToken in project structr by structr.

the class PasswordProperty method setProperty.

@Override
public Object setProperty(SecurityContext securityContext, GraphObject obj, String clearTextPassword) throws FrameworkException {
    if (clearTextPassword != null) {
        if (validationInfo != null) {
            String errorType = validationInfo.getErrorType();
            PropertyKey errorKey = validationInfo.getErrorKey();
            int minLength = validationInfo.getMinLength();
            if (minLength > 0 && clearTextPassword.length() < minLength) {
                throw new FrameworkException(422, "Validation of entity with ID " + obj.getUuid() + " failed", new TooShortToken(errorType, errorKey, minLength));
            }
        }
        String salt = RandomStringUtils.randomAlphanumeric(16);
        obj.setProperty(StructrApp.key(Principal.class, "salt"), salt);
        return super.setProperty(securityContext, obj, HashHelper.getHash(clearTextPassword, salt));
    } else {
        return super.setProperty(securityContext, obj, null);
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) TooShortToken(org.structr.common.error.TooShortToken) Principal(org.structr.core.entity.Principal)

Aggregations

TooShortToken (org.structr.common.error.TooShortToken)2 EmptyPropertyToken (org.structr.common.error.EmptyPropertyToken)1 FrameworkException (org.structr.common.error.FrameworkException)1 Principal (org.structr.core.entity.Principal)1