use of org.keycloak.models.map.client.MapClientEntityImpl in project keycloak by keycloak.
the class PerFieldDelegateProviderCacheTest method initEntities.
@Before
public void initEntities() {
upperEnt = new MapClientEntityImpl();
lowerEnt = new MapClientEntityImpl();
upperEnt.setProtocol("upper-protocol");
upperEnt.addRedirectUri("upper-redirectUri-1");
upperEnt.addRedirectUri("upper-redirectUri-2");
upperEnt.setClientId("upper-clientId-1");
upperEnt.setAttribute("attr1", Arrays.asList("upper-value-1"));
upperEnt.setAttribute("attr2", Arrays.asList("upper-value-2"));
upperEnt.setAttribute("attr3", Arrays.asList("upper-value-3"));
lowerEnt.setProtocol("lower-protocol");
lowerEnt.addRedirectUri("lower-redirectUri-1");
lowerEnt.addRedirectUri("lower-redirectUri-2");
lowerEnt.setClientId("lower-clientId-1");
lowerEnt.setAttribute("attr1", Arrays.asList("lower-value-1"));
lowerEnt.setAttribute("attr3", Arrays.asList("lower-value-3"));
lowerEnt.setAttribute("attr4", Arrays.asList("lower-value-4"));
upperNodeProperties = new HashMap<>();
upperCacheFor = new EnumMap<>(MapClientEntityFields.class);
upperCacheForExcluded = new EnumMap<>(MapClientEntityFields.class);
lowerNodeProperties = new HashMap<>();
lowerCacheFor = new EnumMap<>(MapClientEntityFields.class);
lowerCacheForExcluded = new EnumMap<>(MapClientEntityFields.class);
lowerEntSupplierCallCount.set(0);
}
use of org.keycloak.models.map.client.MapClientEntityImpl in project keycloak by keycloak.
the class PerFieldDelegateProviderPrimarySourceTest method initEntities.
@Before
public void initEntities() {
upperEnt = new MapClientEntityImpl();
lowerEnt = new MapClientEntityImpl();
upperEnt.setProtocol("upper-protocol");
upperEnt.addRedirectUri("upper-redirectUri-1");
upperEnt.addRedirectUri("upper-redirectUri-2");
upperEnt.setClientId("upper-clientId-1");
upperEnt.setAttribute("attr1", Arrays.asList("upper-value-1"));
upperEnt.setAttribute("attr2", Arrays.asList("upper-value-2"));
upperEnt.setAttribute("attr3", Arrays.asList("upper-value-3"));
lowerEnt.setProtocol("lower-protocol");
lowerEnt.addRedirectUri("lower-redirectUri-1");
lowerEnt.addRedirectUri("lower-redirectUri-2");
lowerEnt.setClientId("lower-clientId-1");
lowerEnt.setAttribute("attr1", Arrays.asList("lower-value-1"));
lowerEnt.setAttribute("attr3", Arrays.asList("lower-value-3"));
lowerEnt.setAttribute("attr4", Arrays.asList("lower-value-4"));
upperNodeProperties = new HashMap<>();
upperPrimarySourceFor = new EnumMap<>(MapClientEntityFields.class);
upperPrimarySourceForExcluded = new EnumMap<>(MapClientEntityFields.class);
lowerNodeProperties = new HashMap<>();
lowerPrimarySourceFor = new EnumMap<>(MapClientEntityFields.class);
lowerPrimarySourceForExcluded = new EnumMap<>(MapClientEntityFields.class);
lowerEntSupplierCallCount.set(0);
}
use of org.keycloak.models.map.client.MapClientEntityImpl in project keycloak by keycloak.
the class ConcurrentHashMapStorageTest method testStorageSeparation.
@Test
@SuppressWarnings("unchecked")
public <K, K1, K2> void testStorageSeparation() {
String component1Id = createMapStorageComponent("component1", "keyType", "ulong");
String component2Id = createMapStorageComponent("component2", "keyType", "string");
String[] ids = withRealm(realmId, (session, realm) -> {
ConcurrentHashMapStorage<K, MapClientEntity, ClientModel> storageMain = (ConcurrentHashMapStorage<K, MapClientEntity, ClientModel>) (MapStorage) session.getProvider(MapStorageProvider.class, ConcurrentHashMapStorageProviderFactory.PROVIDER_ID).getStorage(ClientModel.class);
ConcurrentHashMapStorage<K1, MapClientEntity, ClientModel> storage1 = (ConcurrentHashMapStorage<K1, MapClientEntity, ClientModel>) (MapStorage) session.getComponentProvider(MapStorageProvider.class, component1Id).getStorage(ClientModel.class);
ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel> storage2 = (ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel>) (MapStorage) session.getComponentProvider(MapStorageProvider.class, component2Id).getStorage(ClientModel.class);
// Assert that the map storage can be used both as a standalone store and a component
assertThat(storageMain, notNullValue());
assertThat(storage1, notNullValue());
assertThat(storage2, notNullValue());
final StringKeyConvertor<K> kcMain = storageMain.getKeyConvertor();
final StringKeyConvertor<K1> kc1 = storage1.getKeyConvertor();
final StringKeyConvertor<K2> kc2 = storage2.getKeyConvertor();
String idMain = kcMain.keyToString(kcMain.yieldNewUniqueKey());
String id1 = kc1.keyToString(kc1.yieldNewUniqueKey());
String id2 = kc2.keyToString(kc2.yieldNewUniqueKey());
assertThat(idMain, notNullValue());
assertThat(id1, notNullValue());
assertThat(id2, notNullValue());
// Assert that the stores do not contain the to-be-created clients
assertThat(storageMain.read(idMain), nullValue());
assertThat(storage1.read(id1), nullValue());
assertThat(storage2.read(id2), nullValue());
assertClientDoesNotExist(storageMain, id1, kc1, kcMain);
assertClientDoesNotExist(storageMain, id2, kc2, kcMain);
assertClientDoesNotExist(storage1, idMain, kcMain, kc1);
assertClientDoesNotExist(storage1, id2, kc2, kc1);
assertClientDoesNotExist(storage2, idMain, kcMain, kc2);
assertClientDoesNotExist(storage2, id1, kc1, kc2);
MapClientEntity clientMain = new MapClientEntityImpl();
clientMain.setId(idMain);
clientMain.setRealmId(realmId);
MapClientEntity client1 = new MapClientEntityImpl();
client1.setId(id1);
client1.setRealmId(realmId);
MapClientEntity client2 = new MapClientEntityImpl();
client2.setId(id2);
client2.setRealmId(realmId);
clientMain = storageMain.create(clientMain);
client1 = storage1.create(client1);
client2 = storage2.create(client2);
return new String[] { clientMain.getId(), client1.getId(), client2.getId() };
});
String idMain = ids[0];
String id1 = ids[1];
String id2 = ids[2];
LOG.debugf("Object IDs: %s, %s, %s", idMain, id1, id2);
assertClientsPersisted(component1Id, component2Id, idMain, id1, id2);
// Invalidate one component and check that the storage still contains what it should
getFactory().invalidate(ObjectType.COMPONENT, component1Id);
assertClientsPersisted(component1Id, component2Id, idMain, id1, id2);
// Invalidate whole realm and check that the storage still contains what it should
getFactory().invalidate(ObjectType.REALM, realmId);
assertClientsPersisted(component1Id, component2Id, idMain, id1, id2);
// Refresh factory (akin server restart) and check that the storage still contains what it should
reinitializeKeycloakSessionFactory();
assertClientsPersisted(component1Id, component2Id, idMain, id1, id2);
}
Aggregations