parent
05f8f3038f
commit
ddeab744d0
5 changed files with 34 additions and 32 deletions
|
@ -23,6 +23,7 @@ import org.keycloak.common.util.reflections.Types;
|
||||||
import org.keycloak.component.ComponentModel;
|
import org.keycloak.component.ComponentModel;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.LegacyRealmModel;
|
||||||
import org.keycloak.models.ModelException;
|
import org.keycloak.models.ModelException;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
|
@ -71,9 +72,8 @@ public class RoleStorageManager implements RoleProvider {
|
||||||
return getStorageProviderInstance(session, storageModel, factory);
|
return getStorageProviderInstance(session, storageModel, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T> Stream<RoleStorageProviderModel> getStorageProviders(RealmModel realm, KeycloakSession session, Class<T> type) {
|
public static <T> Stream<RoleStorageProviderModel> getStorageProviders(RealmModel realm, KeycloakSession session, Class<T> type) {
|
||||||
return realm.getRoleStorageProvidersStream()
|
return ((LegacyRealmModel) realm).getRoleStorageProvidersStream()
|
||||||
.filter(model -> {
|
.filter(model -> {
|
||||||
RoleStorageProviderFactory factory = getRoleStorageProviderFactory(model, session);
|
RoleStorageProviderFactory factory = getRoleStorageProviderFactory(model, session);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
|
@ -162,9 +162,9 @@ public class RoleStorageManager implements RoleProvider {
|
||||||
/**
|
/**
|
||||||
* Obtaining roles from an external role storage is time-bounded. In case the external role storage
|
* Obtaining roles from an external role storage is time-bounded. In case the external role storage
|
||||||
* isn't available at least roles from a local storage are returned. For this purpose
|
* isn't available at least roles from a local storage are returned. For this purpose
|
||||||
* the {@link org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used.
|
* the <code>org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()</code> property is used.
|
||||||
* Default value is 3000 milliseconds and it's configurable.
|
* Default value is 3000 milliseconds and it's configurable.
|
||||||
* See {@link org.keycloak.services.DefaultKeycloakSessionFactory} for details.
|
* See <code>org.keycloak.services.DefaultKeycloakSessionFactory</code> for details.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Stream<RoleModel> searchForRolesStream(RealmModel realm, String search, Integer first, Integer max) {
|
public Stream<RoleModel> searchForRolesStream(RealmModel realm, String search, Integer first, Integer max) {
|
||||||
|
@ -229,9 +229,9 @@ public class RoleStorageManager implements RoleProvider {
|
||||||
/**
|
/**
|
||||||
* Obtaining roles from an external role storage is time-bounded. In case the external role storage
|
* Obtaining roles from an external role storage is time-bounded. In case the external role storage
|
||||||
* isn't available at least roles from a local storage are returned. For this purpose
|
* isn't available at least roles from a local storage are returned. For this purpose
|
||||||
* the {@link org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used.
|
* the <code>org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used.
|
||||||
* Default value is 3000 milliseconds and it's configurable.
|
* Default value is 3000 milliseconds and it's configurable.
|
||||||
* See {@link org.keycloak.services.DefaultKeycloakSessionFactory} for details.
|
* See <code>org.keycloak.services.DefaultKeycloakSessionFactory</code> for details.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Stream<RoleModel> searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max) {
|
public Stream<RoleModel> searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max) {
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.keycloak.models;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.storage.client.ClientStorageProvider;
|
import org.keycloak.storage.client.ClientStorageProvider;
|
||||||
import org.keycloak.storage.client.ClientStorageProviderModel;
|
import org.keycloak.storage.client.ClientStorageProviderModel;
|
||||||
|
import org.keycloak.storage.role.RoleStorageProvider;
|
||||||
|
import org.keycloak.storage.role.RoleStorageProviderModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -47,4 +49,24 @@ public interface LegacyRealmModel extends RealmModel {
|
||||||
.map(ClientStorageProviderModel::new)
|
.map(ClientStorageProviderModel::new)
|
||||||
.sorted(ClientStorageProviderModel.comparator);
|
.sorted(ClientStorageProviderModel.comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #getRoleStorageProvidersStream() getRoleStorageProvidersStream} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
default List<RoleStorageProviderModel> getRoleStorageProviders() {
|
||||||
|
return getRoleStorageProvidersStream().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns sorted {@link RoleStorageProviderModel RoleStorageProviderModel} as a stream.
|
||||||
|
* It should be used with forEachOrdered if the ordering is required.
|
||||||
|
* @return Sorted stream of {@link RoleStorageProviderModel}. Never returns {@code null}.
|
||||||
|
*/
|
||||||
|
default Stream<RoleStorageProviderModel> getRoleStorageProvidersStream() {
|
||||||
|
return getComponentsStream(getId(), RoleStorageProvider.class.getName())
|
||||||
|
.map(RoleStorageProviderModel::new)
|
||||||
|
.sorted(RoleStorageProviderModel.comparator);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ import org.keycloak.component.ComponentModel;
|
||||||
import org.keycloak.provider.Provider;
|
import org.keycloak.provider.Provider;
|
||||||
import org.keycloak.provider.ProviderEvent;
|
import org.keycloak.provider.ProviderEvent;
|
||||||
import org.keycloak.storage.SearchableModelField;
|
import org.keycloak.storage.SearchableModelField;
|
||||||
import org.keycloak.storage.role.RoleStorageProvider;
|
|
||||||
import org.keycloak.storage.role.RoleStorageProviderModel;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -658,25 +656,6 @@ public interface RealmModel extends RoleContainerModel {
|
||||||
|
|
||||||
ComponentModel getComponent(String id);
|
ComponentModel getComponent(String id);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #getRoleStorageProvidersStream() getRoleStorageProvidersStream} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default List<RoleStorageProviderModel> getRoleStorageProviders() {
|
|
||||||
return getRoleStorageProvidersStream().collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns sorted {@link RoleStorageProviderModel RoleStorageProviderModel} as a stream.
|
|
||||||
* It should be used with forEachOrdered if the ordering is required.
|
|
||||||
* @return Sorted stream of {@link RoleStorageProviderModel}. Never returns {@code null}.
|
|
||||||
*/
|
|
||||||
default Stream<RoleStorageProviderModel> getRoleStorageProvidersStream() {
|
|
||||||
return getComponentsStream(getId(), RoleStorageProvider.class.getName())
|
|
||||||
.map(RoleStorageProviderModel::new)
|
|
||||||
.sorted(RoleStorageProviderModel.comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns stream of ComponentModels that represent StorageProviders for class storageProviderClass in this realm.
|
* Returns stream of ComponentModels that represent StorageProviders for class storageProviderClass in this realm.
|
||||||
* @param storageProviderClass {@code Class<? extends Provider>}
|
* @param storageProviderClass {@code Class<? extends Provider>}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.keycloak.events.Details;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.models.LegacyRealmModel;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.cache.infinispan.ClientAdapter;
|
import org.keycloak.models.cache.infinispan.ClientAdapter;
|
||||||
import org.keycloak.representations.AccessToken;
|
import org.keycloak.representations.AccessToken;
|
||||||
|
@ -341,7 +342,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
|
ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get();
|
||||||
Calendar eviction = Calendar.getInstance();
|
Calendar eviction = Calendar.getInstance();
|
||||||
eviction.add(Calendar.HOUR, 1);
|
eviction.add(Calendar.HOUR, 1);
|
||||||
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_DAILY);
|
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_DAILY);
|
||||||
|
@ -366,7 +367,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findAny().get();
|
ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findAny().get();
|
||||||
Calendar eviction = Calendar.getInstance();
|
Calendar eviction = Calendar.getInstance();
|
||||||
eviction.add(Calendar.HOUR, 4 * 24);
|
eviction.add(Calendar.HOUR, 4 * 24);
|
||||||
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_WEEKLY);
|
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_WEEKLY);
|
||||||
|
@ -394,7 +395,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
|
ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get();
|
||||||
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN);
|
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN);
|
||||||
model.setMaxLifespan(1 * 60 * 60 * 1000);
|
model.setMaxLifespan(1 * 60 * 60 * 1000);
|
||||||
realm.updateComponent(model);
|
realm.updateComponent(model);
|
||||||
|
@ -446,7 +447,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
|
ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get();
|
||||||
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.NO_CACHE);
|
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.NO_CACHE);
|
||||||
realm.updateComponent(model);
|
realm.updateComponent(model);
|
||||||
});
|
});
|
||||||
|
@ -466,7 +467,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
private void setDefaultCachePolicy() {
|
private void setDefaultCachePolicy() {
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
RealmModel realm = session.realms().getRealmByName("test");
|
RealmModel realm = session.realms().getRealmByName("test");
|
||||||
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
|
ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get();
|
||||||
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.DEFAULT);
|
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.DEFAULT);
|
||||||
realm.updateComponent(model);
|
realm.updateComponent(model);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue