Search in sources :

Example 46 with UserModel

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;
}
Also used : UserModel(org.keycloak.models.UserModel) AttributeContext(org.keycloak.userprofile.AttributeContext) UserProfileAttributeValidationContext(org.keycloak.userprofile.UserProfileAttributeValidationContext) List(java.util.List) ValidationError(org.keycloak.validate.ValidationError)

Example 47 with UserModel

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;
}
Also used : UserModel(org.keycloak.models.UserModel) RealmModel(org.keycloak.models.RealmModel) AttributeContext(org.keycloak.userprofile.AttributeContext) List(java.util.List) ValidationError(org.keycloak.validate.ValidationError)

Example 48 with UserModel

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();
}
Also used : UserModel(org.keycloak.models.UserModel)

Example 49 with UserModel

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();
}
Also used : UserModel(org.keycloak.models.UserModel)

Example 50 with UserModel

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();
}
Also used : UserModel(org.keycloak.models.UserModel)

Aggregations

UserModel (org.keycloak.models.UserModel)383 RealmModel (org.keycloak.models.RealmModel)220 Test (org.junit.Test)126 ClientModel (org.keycloak.models.ClientModel)86 KeycloakSession (org.keycloak.models.KeycloakSession)81 CachedUserModel (org.keycloak.models.cache.CachedUserModel)52 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)43 List (java.util.List)41 UserSessionModel (org.keycloak.models.UserSessionModel)40 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)40 RoleModel (org.keycloak.models.RoleModel)39 ComponentModel (org.keycloak.component.ComponentModel)31 HashMap (java.util.HashMap)30 Response (javax.ws.rs.core.Response)29 Path (javax.ws.rs.Path)28 UserManager (org.keycloak.models.UserManager)28 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)27 Map (java.util.Map)25 GroupModel (org.keycloak.models.GroupModel)24 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)24