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;
}
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);
}
}
Aggregations