use of org.keycloak.models.map.client.MapClientEntity in project keycloak by keycloak.
the class PerFieldDelegateProviderPrimarySourceTest method testGet_PrimarySourceFor.
@Test
public void testGet_PrimarySourceFor() {
//
// High-level perspective: only listed fields are available in upper entity, the rest is in lower one
//
// When there is are primary source in the node properties, only properties from those listed
// are considered as owned by this entity. Those not listed are obtained from the child entity.
// Thus there must be a single call to the child entity creator.
upperPrimarySourceFor.put(MapClientEntityFields.CLIENT_ID, null);
upperPrimarySourceFor.put(MapClientEntityFields.ATTRIBUTES, Arrays.asList("attr2", "attr3", "attr4"));
upperNodeProperties.put(NodeProperties.PRIMARY_SOURCE_FOR, upperPrimarySourceFor);
MapClientEntity ent = prepareEntityAndTreeNodeInstances();
assertThat(lowerEntSupplierCallCount.get(), is(0));
assertThat(ent.getClientId(), is("upper-clientId-1"));
assertThat(ent.getAttribute("attr2"), contains("upper-value-2"));
assertThat(ent.getAttribute("attr3"), contains("upper-value-3"));
assertThat(ent.getAttribute("attr4"), nullValue());
assertThat(lowerEntSupplierCallCount.get(), is(0));
assertThat(ent.getProtocol(), is("lower-protocol"));
assertThat(ent.getAttribute("attr1"), contains("lower-value-1"));
assertThat(lowerEntSupplierCallCount.get(), is(1));
assertThat(ent.getAttributes().keySet(), containsInAnyOrder("attr1", "attr2", "attr3"));
assertThat(ent.getAttributes(), hasEntry("attr1", Arrays.asList("lower-value-1")));
assertThat(ent.getAttributes(), hasEntry("attr2", Arrays.asList("upper-value-2")));
assertThat(ent.getAttributes(), hasEntry("attr3", Arrays.asList("upper-value-3")));
assertThat(lowerEntSupplierCallCount.get(), is(1));
}
use of org.keycloak.models.map.client.MapClientEntity in project keycloak by keycloak.
the class PerFieldDelegateProviderPrimarySourceTest method testSet_NoPrimarySource.
@Test
public void testSet_NoPrimarySource() {
// When there is no primary source (exclusion) in the node properties, all properties are considered as owned by this entity.
// Thus there is no call to the child entity creator.
MapClientEntity ent = prepareEntityAndTreeNodeInstances();
// When
// modification in: upper
ent.setProtocol("modified-protocol");
// modification in: upper
ent.setAttribute("attr1", Arrays.asList("modified-value-1"));
// modification in: upper
ent.setAttribute("attrX", Arrays.asList("modified-value-X"));
// modification in: upper
ent.addRedirectUri("added-redirectUri");
// modification in: upper
ent.removeRedirectUri("upper-redirectUri-2");
// modification in: upper
ent.removeRedirectUri("lower-redirectUri-2");
// Then
assertThat(lowerEntSupplierCallCount.get(), is(0));
assertThat(ent.getClientId(), is("upper-clientId-1"));
assertThat(upperEnt.getClientId(), is("upper-clientId-1"));
assertThat(lowerEnt.getClientId(), is("lower-clientId-1"));
assertThat(ent.getProtocol(), is("modified-protocol"));
assertThat(upperEnt.getProtocol(), is("modified-protocol"));
assertThat(lowerEnt.getProtocol(), is("lower-protocol"));
assertThat(ent.getRedirectUris(), containsInAnyOrder("upper-redirectUri-1", "added-redirectUri"));
assertThat(upperEnt.getRedirectUris(), containsInAnyOrder("upper-redirectUri-1", "added-redirectUri"));
assertThat(lowerEnt.getRedirectUris(), containsInAnyOrder("lower-redirectUri-1", "lower-redirectUri-2"));
assertThat(ent.getAttribute("attr1"), contains("modified-value-1"));
assertThat(upperEnt.getAttribute("attr1"), contains("modified-value-1"));
assertThat(lowerEnt.getAttribute("attr1"), contains("lower-value-1"));
assertThat(ent.getAttribute("attr3"), contains("upper-value-3"));
assertThat(upperEnt.getAttribute("attr3"), contains("upper-value-3"));
assertThat(lowerEnt.getAttribute("attr3"), contains("lower-value-3"));
assertThat(ent.getAttribute("attrX"), contains("modified-value-X"));
assertThat(upperEnt.getAttribute("attrX"), contains("modified-value-X"));
assertThat(lowerEnt.getAttribute("attrX"), nullValue());
assertThat(ent.getAttributes().keySet(), containsInAnyOrder("attr1", "attr2", "attr3", "attrX"));
assertThat(upperEnt.getAttributes().keySet(), containsInAnyOrder("attr1", "attr2", "attr3", "attrX"));
assertThat(lowerEnt.getAttributes().keySet(), containsInAnyOrder("attr1", "attr3", "attr4"));
}
use of org.keycloak.models.map.client.MapClientEntity in project keycloak by keycloak.
the class PerFieldDelegateProviderPrimarySourceTest method testSet_PrimarySourceFor.
@Test
public void testSet_PrimarySourceFor() {
//
// High-level perspective: only listed fields are available in upper entity, the rest is in lower one
//
// When there is are primary source in the node properties, only properties from those enumerated
// are considered as owned by this entity. Those not listed are obtained from the child entity.
// Thus there must be a single call to the child entity creator.
upperPrimarySourceFor.put(MapClientEntityFields.CLIENT_ID, null);
upperPrimarySourceFor.put(MapClientEntityFields.ATTRIBUTES, Arrays.asList("attr2", "attr3", "attr4"));
upperNodeProperties.put(NodeProperties.PRIMARY_SOURCE_FOR, upperPrimarySourceFor);
// When there is primary source in the node properties, named properties are considered as owned by this entity, and
// all other are considered as owned by child entity.
// Thus there is no call to the child entity creator.
MapClientEntity ent = prepareEntityAndTreeNodeInstances();
// When
// modification in: upper
ent.setClientId("modified-client-id");
// modification in: lower
ent.setProtocol("modified-protocol");
// modification in: lower
ent.setAttribute("attr1", Arrays.asList("modified-value-1"));
// modification in: lower
ent.setAttribute("attrX", Arrays.asList("modified-value-X"));
// modification in: lower
ent.addRedirectUri("added-redirectUri");
// modification in: lower
ent.removeRedirectUri("upper-redirectUri-2");
// modification in: lower
ent.removeRedirectUri("lower-redirectUri-2");
// Then
assertThat(lowerEntSupplierCallCount.get(), is(1));
assertThat(ent.getClientId(), is("modified-client-id"));
assertThat(upperEnt.getClientId(), is("modified-client-id"));
assertThat(lowerEnt.getClientId(), is("lower-clientId-1"));
assertThat(ent.getRedirectUris(), containsInAnyOrder("lower-redirectUri-1", "added-redirectUri"));
assertThat(upperEnt.getRedirectUris(), containsInAnyOrder("upper-redirectUri-1", "upper-redirectUri-2"));
assertThat(lowerEnt.getRedirectUris(), containsInAnyOrder("lower-redirectUri-1", "added-redirectUri"));
assertThat(ent.getProtocol(), is("modified-protocol"));
assertThat(upperEnt.getProtocol(), is("upper-protocol"));
assertThat(lowerEnt.getProtocol(), is("modified-protocol"));
assertThat(ent.getAttribute("attr1"), contains("modified-value-1"));
assertThat(upperEnt.getAttribute("attr1"), contains("upper-value-1"));
assertThat(lowerEnt.getAttribute("attr1"), contains("modified-value-1"));
assertThat(ent.getAttribute("attr3"), contains("upper-value-3"));
assertThat(upperEnt.getAttribute("attr3"), contains("upper-value-3"));
assertThat(lowerEnt.getAttribute("attr3"), contains("lower-value-3"));
assertThat(ent.getAttribute("attrX"), contains("modified-value-X"));
assertThat(upperEnt.getAttribute("attrX"), nullValue());
assertThat(lowerEnt.getAttribute("attrX"), contains("modified-value-X"));
assertThat(ent.getAttributes().keySet(), containsInAnyOrder(// From lower
"attr1", // From upper
"attr2", // From upper
"attr3", // From lower
"attrX"));
assertThat(upperEnt.getAttributes().keySet(), containsInAnyOrder("attr1", "attr2", "attr3"));
assertThat(lowerEnt.getAttributes().keySet(), containsInAnyOrder("attr1", "attr3", "attr4", "attrX"));
}
use of org.keycloak.models.map.client.MapClientEntity 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);
}
use of org.keycloak.models.map.client.MapClientEntity in project keycloak by keycloak.
the class DictTest method testDictClientFromEntity.
@Test
public void testDictClientFromEntity() {
MapClientEntity mce = Dict.clientDelegate();
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_NAME), nullValue());
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_ENABLED), nullValue());
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_LOGO), nullValue());
mce.setClientId("name");
mce.setEnabled(false);
mce.setAttribute("logo", Arrays.asList("thisShouldBeBase64Logo"));
mce.setAttribute("blah", Arrays.asList("thisShouldBeBase64Logofdas"));
assertThat(mce.getAttributes().keySet(), hasItems("logo"));
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_NAME), is("name"));
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_ENABLED), is(false));
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_LOGO), is("thisShouldBeBase64Logo"));
mce.setAttribute("logo", Arrays.asList("thisShouldBeAnotherBase64Logo"));
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_LOGO), is("thisShouldBeAnotherBase64Logo"));
mce.removeAttribute("logo");
assertThat(Dict.asDict(mce).get(Dict.CLIENT_FIELD_LOGO), nullValue());
}
Aggregations