use of org.keycloak.models.UserModel in project keycloak by keycloak.
the class ImmutableAttributeValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
UserProfileAttributeValidationContext ac = (UserProfileAttributeValidationContext) context;
AttributeContext attributeContext = ac.getAttributeContext();
if (!isReadOnly(attributeContext)) {
return context;
}
UserModel user = attributeContext.getUser();
if (user == null) {
return context;
}
List<String> currentValue = user.getAttributeStream(inputHint).collect(Collectors.toList());
List<String> values = (List<String>) input;
if (!CollectionUtil.collectionEquals(currentValue, values)) {
if (currentValue.isEmpty() && !notBlankValidator().validate(values).isValid()) {
return context;
}
context.addError(new ValidationError(ID, inputHint, DEFAULT_ERROR_MESSAGE));
}
return context;
}
use of org.keycloak.models.UserModel in project keycloak by keycloak.
the class UsernameMutationValidator method validate.
@Override
public ValidationContext validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config) {
@SuppressWarnings("unchecked") List<String> values = (List<String>) input;
if (values.isEmpty()) {
return context;
}
String value = values.get(0);
if (Validation.isBlank(value)) {
return context;
}
AttributeContext attributeContext = UserProfileAttributeValidationContext.from(context).getAttributeContext();
UserModel user = attributeContext.getUser();
RealmModel realm = context.getSession().getContext().getRealm();
if (!realm.isEditUsernameAllowed() && user != null && !value.equals(user.getFirstAttribute(UserModel.USERNAME))) {
if (realm.isRegistrationEmailAsUsername() && UserProfileContext.UPDATE_PROFILE.equals(attributeContext.getContext())) {
// it is expected that username changes when attributes are normalized by the provider
return context;
}
context.addError(new ValidationError(ID, inputHint, Messages.READ_ONLY_USERNAME));
}
return context;
}
use of org.keycloak.models.UserModel in project keycloak by keycloak.
the class FailableHardcodedStorageProvider method searchForUserStream.
@Override
public Stream<UserModel> searchForUserStream(RealmModel realm, String search) {
checkForceFail();
if (!search.equals(username))
return Stream.empty();
UserModel model = getUserByUsername(realm, username);
return model != null ? Stream.of(model) : Stream.empty();
}
use of org.keycloak.models.UserModel in project keycloak by keycloak.
the class FailableHardcodedStorageProvider method searchForUserStream.
@Override
public Stream<UserModel> searchForUserStream(RealmModel realm, Map<String, String> params, Integer firstResult, Integer maxResults) {
checkForceFail();
if (!username.equals(params.get("username")))
return Stream.empty();
UserModel model = getUserByUsername(realm, username);
return model != null ? Stream.of(model) : Stream.empty();
}
use of org.keycloak.models.UserModel in project keycloak by keycloak.
the class PassThroughAuthenticator method authenticate.
@Override
public void authenticate(AuthenticationFlowContext context) {
UserModel user = KeycloakModelUtils.findUserByNameOrEmail(context.getSession(), context.getRealm(), username);
if (user == null) {
context.failure(AuthenticationFlowError.UNKNOWN_USER);
return;
}
context.setUser(user);
context.success();
}
Aggregations