use of org.keycloak.validate.ValidationError in project keycloak by keycloak.
the class ReadOnlyAttributeUnchangedValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
AttributeContext attributeContext = UserProfileAttributeValidationContext.from(context).getAttributeContext();
Map.Entry<String, List<String>> attribute = attributeContext.getAttribute();
String key = attribute.getKey();
Pattern pattern = (Pattern) config.get(CFG_PATTERN);
if (!pattern.matcher(key).find()) {
return context;
}
@SuppressWarnings("unchecked") List<String> values = (List<String>) input;
if (values == null) {
return context;
}
UserModel user = attributeContext.getUser();
List<String> existingAttrValues = user == null ? null : user.getAttribute(key);
String existingValue = null;
if (existingAttrValues != null && !existingAttrValues.isEmpty()) {
existingValue = existingAttrValues.get(0);
}
String value = null;
if (!values.isEmpty()) {
value = values.get(0);
}
if (!isUnchanged(existingValue, value)) {
logger.warnf("Attempt to edit denied attribute '%s' of user '%s'", pattern, user == null ? "new user" : user.getFirstAttribute(UserModel.USERNAME));
context.addError(new ValidationError(ID, key, UPDATE_READ_ONLY_ATTRIBUTES_REJECTED_MSG));
}
return context;
}
use of org.keycloak.validate.ValidationError in project keycloak by keycloak.
the class RegistrationEmailAsUsernameUsernameValueValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
RealmModel realm = context.getSession().getContext().getRealm();
if (!realm.isRegistrationEmailAsUsername()) {
return context;
}
@SuppressWarnings("unchecked") List<String> values = (List<String>) input;
if (values == null || values.isEmpty()) {
return context;
}
String value = values.get(0);
if (value != null && Validation.isBlank(value)) {
context.addError(new ValidationError(ID, inputHint, Messages.MISSING_USERNAME));
}
return context;
}
use of org.keycloak.validate.ValidationError in project keycloak by keycloak.
the class UsernameHasValueValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
@SuppressWarnings("unchecked") List<String> values = (List<String>) input;
String value = null;
if (values != null && !values.isEmpty()) {
value = values.get(0);
}
if (Validation.isBlank(value)) {
context.addError(new ValidationError(ID, inputHint, Messages.MISSING_USERNAME));
}
return context;
}
Aggregations