Search in sources :

Example 21 with StorageId

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

the class GroupStorageTest method testGetGroupById.

@Test
public void testGetGroupById() {
    String providerId = this.providerId;
    testingClient.server().run(session -> {
        RealmModel realm = session.realms().getRealmByName("test");
        StorageId storageId = new StorageId(providerId, "hardcoded-group");
        GroupModel hardcoded = session.groups().getGroupById(realm, storageId.getId());
        assertNotNull(hardcoded);
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) GroupModel(org.keycloak.models.GroupModel) StorageId(org.keycloak.storage.StorageId) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 22 with StorageId

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

the class ClientScopeStorageTest method testGetClientScopeById.

@Test
public void testGetClientScopeById() {
    getParameters(ClientScopeStorageProviderModel.class).forEach(fs -> inComittedTransaction(fs, (session, federatedStorage) -> {
        Assume.assumeThat("Cannot handle more than 1 client scope federation provider", clientScopeFederationId, Matchers.nullValue());
        RealmModel realm = session.realms().getRealm(realmId);
        federatedStorage.setParentId(realmId);
        federatedStorage.setEnabled(true);
        federatedStorage.getConfig().putSingle(HardcodedClientScopeStorageProviderFactory.SCOPE_NAME, HardcodedClientScopeStorageProviderFactory.SCOPE_NAME);
        ComponentModel res = realm.addComponentModel(federatedStorage);
        clientScopeFederationId = res.getId();
        log.infof("Added %s client scope federation provider: %s", federatedStorage.getName(), clientScopeFederationId);
        return null;
    }));
    inComittedTransaction(1, (session, i) -> {
        final RealmModel realm = session.realms().getRealm(realmId);
        StorageId storageId = new StorageId(clientScopeFederationId, "scope_name");
        ClientScopeModel hardcoded = session.clientScopes().getClientScopeById(realm, storageId.getId());
        Assert.assertNotNull(hardcoded);
        return null;
    });
}
Also used : ClientScopeStorageProviderModel(org.keycloak.storage.clientscope.ClientScopeStorageProviderModel) HardcodedClientScopeStorageProviderFactory(org.keycloak.testsuite.federation.HardcodedClientScopeStorageProviderFactory) ClientScopeModel(org.keycloak.models.ClientScopeModel) RealmModel(org.keycloak.models.RealmModel) Constants(org.keycloak.models.Constants) Matchers(org.hamcrest.Matchers) KeycloakSession(org.keycloak.models.KeycloakSession) Test(org.junit.Test) StorageId(org.keycloak.storage.StorageId) ClientScopeStorageProviderModel(org.keycloak.storage.clientscope.ClientScopeStorageProviderModel) RealmProvider(org.keycloak.models.RealmProvider) ComponentModel(org.keycloak.component.ComponentModel) Assume(org.junit.Assume) Assert(org.junit.Assert) ClientScopeStorageProvider(org.keycloak.storage.clientscope.ClientScopeStorageProvider) RealmModel(org.keycloak.models.RealmModel) ComponentModel(org.keycloak.component.ComponentModel) ClientScopeModel(org.keycloak.models.ClientScopeModel) StorageId(org.keycloak.storage.StorageId) Test(org.junit.Test)

Example 23 with StorageId

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

the class LDAPStorageProvider method addUser.

@Override
public UserModel addUser(RealmModel realm, String username) {
    if (!synchronizeRegistrations()) {
        return null;
    }
    UserModel user = null;
    if (model.isImportEnabled()) {
        user = session.userLocalStorage().addUser(realm, username);
        user.setFederationLink(model.getId());
    } else {
        user = new InMemoryUserAdapter(session, realm, new StorageId(model.getId(), username).getId());
        user.setUsername(username);
    }
    LDAPObject ldapUser = LDAPUtils.addUserToLDAP(this, realm, user);
    LDAPUtils.checkUuid(ldapUser, ldapIdentityStore.getConfig());
    user.setSingleAttribute(LDAPConstants.LDAP_ID, ldapUser.getUuid());
    user.setSingleAttribute(LDAPConstants.LDAP_ENTRY_DN, ldapUser.getDn().toString());
    // Add the user to the default groups and add default required actions
    UserModel proxy = proxy(realm, user, ldapUser, true);
    proxy.grantRole(realm.getDefaultRole());
    realm.getDefaultGroupsStream().forEach(proxy::joinGroup);
    realm.getRequiredActionProvidersStream().filter(RequiredActionProviderModel::isEnabled).filter(RequiredActionProviderModel::isDefaultAction).map(RequiredActionProviderModel::getAlias).forEachOrdered(proxy::addRequiredAction);
    return proxy;
}
Also used : CachedUserModel(org.keycloak.models.cache.CachedUserModel) UserModel(org.keycloak.models.UserModel) RequiredActionProviderModel(org.keycloak.models.RequiredActionProviderModel) InMemoryUserAdapter(org.keycloak.storage.adapter.InMemoryUserAdapter) LDAPObject(org.keycloak.storage.ldap.idm.model.LDAPObject) StorageId(org.keycloak.storage.StorageId)

Example 24 with StorageId

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

the class LDAPStorageProvider method getUserById.

@Override
public UserModel getUserById(RealmModel realm, String id) {
    UserModel alreadyLoadedInSession = userManager.getManagedProxiedUser(id);
    if (alreadyLoadedInSession != null)
        return alreadyLoadedInSession;
    StorageId storageId = new StorageId(id);
    return getUserByUsername(realm, storageId.getExternalId());
}
Also used : CachedUserModel(org.keycloak.models.cache.CachedUserModel) UserModel(org.keycloak.models.UserModel) StorageId(org.keycloak.storage.StorageId)

Example 25 with StorageId

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

the class RealmCacheSession method validateCache.

protected ClientModel validateCache(RealmModel realm, CachedClient cached) {
    if (!realm.getId().equals(cached.getRealm())) {
        return null;
    }
    StorageId storageId = new StorageId(cached.getId());
    if (!storageId.isLocal()) {
        ComponentModel component = realm.getComponent(storageId.getProviderId());
        ClientStorageProviderModel model = new ClientStorageProviderModel(component);
        // its also hard to test stuff
        if (model.shouldInvalidate(cached)) {
            registerClientInvalidation(cached.getId(), cached.getClientId(), realm.getId());
            return getClientDelegate().getClientById(realm, cached.getId());
        }
    }
    ClientAdapter adapter = new ClientAdapter(realm, cached, this);
    return adapter;
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) StorageId(org.keycloak.storage.StorageId)

Aggregations

StorageId (org.keycloak.storage.StorageId)44 UserModel (org.keycloak.models.UserModel)7 RealmModel (org.keycloak.models.RealmModel)6 ComponentModel (org.keycloak.component.ComponentModel)5 ClientModel (org.keycloak.models.ClientModel)5 ClientScopeModel (org.keycloak.models.ClientScopeModel)5 List (java.util.List)3 Objects (java.util.Objects)3 Stream (java.util.stream.Stream)3 Test (org.junit.Test)3 KeycloakSession (org.keycloak.models.KeycloakSession)3 ModelException (org.keycloak.models.ModelException)3 UserConsentModel (org.keycloak.models.UserConsentModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2