use of org.keycloak.userprofile.AttributeMetadata in project keycloak by keycloak.
the class AccountRestService method validationErrorParamsToString.
private String[] validationErrorParamsToString(Object[] messageParameters, Attributes userProfileAttributes) {
if (messageParameters == null)
return null;
String[] ret = new String[messageParameters.length];
int i = 0;
for (Object p : messageParameters) {
if (p != null) {
// first parameter is user profile attribute name, we have to take Display Name for it
if (i == 0) {
AttributeMetadata am = userProfileAttributes.getMetadata(p.toString());
if (am != null)
ret[i++] = am.getAttributeDisplayName();
else
ret[i++] = p.toString();
} else {
ret[i++] = p.toString();
}
} else {
i++;
}
}
return ret;
}
use of org.keycloak.userprofile.AttributeMetadata in project keycloak by keycloak.
the class AttributeRequiredByMetadataValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
AttributeContext attContext = UserProfileAttributeValidationContext.from(context).getAttributeContext();
AttributeMetadata metadata = attContext.getMetadata();
if (!metadata.isRequired(attContext)) {
return context;
}
if (metadata.isReadOnly(attContext)) {
return context;
}
@SuppressWarnings("unchecked") List<String> values = (List<String>) input;
if (values == null || values.isEmpty()) {
context.addError(new ValidationError(ID, inputHint, ERROR_USER_ATTRIBUTE_REQUIRED));
} else {
for (String value : values) {
if (Validation.isBlank(value)) {
context.addError(new ValidationError(ID, inputHint, ERROR_USER_ATTRIBUTE_REQUIRED));
return context;
}
}
}
return context;
}
Aggregations