Search in sources :

Example 21 with UserStorageProviderModel

use of org.keycloak.storage.UserStorageProviderModel in project keycloak by keycloak.

the class TestLDAPResource method removeLDAPUser.

/**
 * Remove specified user directly just from the LDAP server
 */
@DELETE
@Path("/remove-ldap-user")
@Consumes(MediaType.APPLICATION_JSON)
public void removeLDAPUser(@QueryParam("username") String ldapUsername) {
    ComponentModel ldapCompModel = LDAPTestUtils.getLdapProviderModel(realm);
    UserStorageProviderModel ldapModel = new UserStorageProviderModel(ldapCompModel);
    LDAPStorageProvider ldapProvider = LDAPTestUtils.getLdapProvider(session, ldapModel);
    LDAPTestUtils.removeLDAPUserByUsername(ldapProvider, realm, ldapProvider.getLdapIdentityStore().getConfig(), ldapUsername);
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 22 with UserStorageProviderModel

use of org.keycloak.storage.UserStorageProviderModel in project keycloak by keycloak.

the class UserCredentialStoreManager method updateCredential.

@Override
public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) {
    String providerId = StorageId.isLocalStorage(user) ? user.getFederationLink() : StorageId.resolveProviderId(user);
    if (!StorageId.isLocalStorage(user))
        throwExceptionIfInvalidUser(user);
    if (providerId != null) {
        UserStorageProviderModel model = getStorageProviderModel(realm, providerId);
        if (model == null || !model.isEnabled())
            return false;
        CredentialInputUpdater updater = getStorageProviderInstance(model, CredentialInputUpdater.class);
        if (updater != null && updater.supportsCredentialType(input.getType())) {
            if (updater.updateCredential(realm, user, input))
                return true;
        }
    }
    return getCredentialProviders(session, CredentialInputUpdater.class).filter(updater -> updater.supportsCredentialType(input.getType())).anyMatch(updater -> updater.updateCredential(realm, user, input));
}
Also used : Arrays(java.util.Arrays) RealmModel(org.keycloak.models.RealmModel) Types(org.keycloak.common.util.reflections.Types) UserStorageProvider(org.keycloak.storage.UserStorageProvider) KeycloakSession(org.keycloak.models.KeycloakSession) CachedUserModel(org.keycloak.models.cache.CachedUserModel) OnUserCache(org.keycloak.models.cache.OnUserCache) AbstractStorageManager(org.keycloak.storage.AbstractStorageManager) StorageId(org.keycloak.storage.StorageId) Objects(java.util.Objects) List(java.util.List) UserModel(org.keycloak.models.UserModel) Stream(java.util.stream.Stream) UserCache(org.keycloak.models.cache.UserCache) UserCredentialManager(org.keycloak.models.UserCredentialManager) CredentialValidationOutput(org.keycloak.models.CredentialValidationOutput) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) LinkedList(java.util.LinkedList) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 23 with UserStorageProviderModel

use of org.keycloak.storage.UserStorageProviderModel in project keycloak by keycloak.

the class UserCredentialStoreManager method isConfiguredThroughUserStorage.

private UserStorageCredentialConfigured isConfiguredThroughUserStorage(RealmModel realm, UserModel user, String type) {
    String providerId = StorageId.isLocalStorage(user) ? user.getFederationLink() : StorageId.resolveProviderId(user);
    if (providerId != null) {
        UserStorageProviderModel model = getStorageProviderModel(realm, providerId);
        if (model == null || !model.isEnabled())
            return UserStorageCredentialConfigured.USER_STORAGE_DISABLED;
        CredentialInputValidator validator = getStorageProviderInstance(model, CredentialInputValidator.class);
        if (validator != null && validator.supportsCredentialType(type) && validator.isConfiguredFor(realm, user, type)) {
            return UserStorageCredentialConfigured.CONFIGURED;
        }
    }
    return UserStorageCredentialConfigured.NOT_CONFIGURED;
}
Also used : UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 24 with UserStorageProviderModel

use of org.keycloak.storage.UserStorageProviderModel in project keycloak by keycloak.

the class UserCredentialStoreManager method getDisableableCredentialTypesStream.

@Override
public Stream<String> getDisableableCredentialTypesStream(RealmModel realm, UserModel user) {
    Stream<String> types = Stream.empty();
    String providerId = StorageId.isLocalStorage(user) ? user.getFederationLink() : StorageId.resolveProviderId(user);
    if (providerId != null) {
        UserStorageProviderModel model = getStorageProviderModel(realm, providerId);
        if (model == null || !model.isEnabled())
            return types;
        CredentialInputUpdater updater = getStorageProviderInstance(model, CredentialInputUpdater.class);
        if (updater != null)
            types = updater.getDisableableCredentialTypesStream(realm, user);
    }
    return Stream.concat(types, getCredentialProviders(session, CredentialInputUpdater.class).flatMap(updater -> updater.getDisableableCredentialTypesStream(realm, user))).distinct();
}
Also used : UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 25 with UserStorageProviderModel

use of org.keycloak.storage.UserStorageProviderModel in project keycloak by keycloak.

the class UserCredentialStoreManager method isValid.

@Override
public boolean isValid(RealmModel realm, UserModel user, List<CredentialInput> inputs) {
    if (!isValid(user)) {
        return false;
    }
    List<CredentialInput> toValidate = new LinkedList<>(inputs);
    String providerId = StorageId.isLocalStorage(user) ? user.getFederationLink() : StorageId.resolveProviderId(user);
    if (providerId != null) {
        UserStorageProviderModel model = getStorageProviderModel(realm, providerId);
        if (model == null || !model.isEnabled())
            return false;
        CredentialInputValidator validator = getStorageProviderInstance(model, CredentialInputValidator.class);
        if (validator != null) {
            validate(realm, user, toValidate, validator);
        }
    }
    if (toValidate.isEmpty())
        return true;
    getCredentialProviders(session, CredentialInputValidator.class).forEach(validator -> validate(realm, user, toValidate, validator));
    return toValidate.isEmpty();
}
Also used : UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) LinkedList(java.util.LinkedList)

Aggregations

UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)40 ComponentModel (org.keycloak.component.ComponentModel)19 RealmModel (org.keycloak.models.RealmModel)17 UserStorageProvider (org.keycloak.storage.UserStorageProvider)12 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)8 Test (org.junit.Test)7 UserStorageSyncManager (org.keycloak.services.managers.UserStorageSyncManager)7 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)6 LinkedList (java.util.LinkedList)5 UserModel (org.keycloak.models.UserModel)5 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)5 HashMap (java.util.HashMap)4 KeycloakSession (org.keycloak.models.KeycloakSession)4 UserStorageProviderFactory (org.keycloak.storage.UserStorageProviderFactory)4 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)4 Path (javax.ws.rs.Path)3 CachedUserModel (org.keycloak.models.cache.CachedUserModel)3 ProviderConfigurationBuilder (org.keycloak.provider.ProviderConfigurationBuilder)3 Arrays (java.util.Arrays)2 List (java.util.List)2