use of org.keycloak.models.map.client.MapClientEntityFields in project keycloak by keycloak.
the class JpaClientDelegateProvider method getDelegate.
@Override
public MapClientEntity getDelegate(boolean isRead, Enum<? extends EntityField<MapClientEntity>> field, Object... parameters) {
if (getDelegate().isMetadataInitialized())
return getDelegate();
if (isRead) {
if (field instanceof MapClientEntityFields) {
switch((MapClientEntityFields) field) {
case ID:
case REALM_ID:
case CLIENT_ID:
case PROTOCOL:
case ENABLED:
return getDelegate();
case ATTRIBUTES:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<JpaClientEntity> query = cb.createQuery(JpaClientEntity.class);
Root<JpaClientEntity> root = query.from(JpaClientEntity.class);
root.fetch("attributes", JoinType.LEFT);
query.select(root).where(cb.equal(root.get("id"), UUID.fromString(getDelegate().getId())));
setDelegate(em.createQuery(query).getSingleResult());
break;
default:
setDelegate(em.find(JpaClientEntity.class, UUID.fromString(getDelegate().getId())));
}
} else {
throw new IllegalStateException("Not a valid client field: " + field);
}
} else {
setDelegate(em.find(JpaClientEntity.class, UUID.fromString(getDelegate().getId())));
}
return getDelegate();
}
use of org.keycloak.models.map.client.MapClientEntityFields in project keycloak by keycloak.
the class TreeStorageNodePrescriptionTest method testPrimarySourceForBasicSetId.
/**
* Test a node that has PRIMARY_SOURCE_FOR set to only ID field with no specialization (i.e. {@code null}),
* and no PRIMARY_SOURCE_FOR_EXCLUDED is set.
* <p>
* Represents e.g. a node in the tree that stores only ID (maintains existence check of an object)
*/
@Test
public void testPrimarySourceForBasicSetId() {
Map<String, Object> nodeProperties = new HashMap<>();
EnumMap<MapClientEntityFields, Collection<String>> primarySourceFor = new EnumMap<>(MapClientEntityFields.class);
nodeProperties.put(NodeProperties.PRIMARY_SOURCE_FOR, primarySourceFor);
primarySourceFor.put(MapClientEntityFields.ID, null);
TreeStorageNodePrescription n = new TreeStorageNodePrescription(nodeProperties, null, null);
for (MapClientEntityFields field : MapClientEntityFields.values()) {
assertThat(n.isPrimarySourceFor(field, null), is(field == MapClientEntityFields.ID ? FieldContainedStatus.FULLY : FieldContainedStatus.NOT_CONTAINED));
}
}
use of org.keycloak.models.map.client.MapClientEntityFields in project keycloak by keycloak.
the class TreeStorageNodePrescriptionTest method testPrimarySourceForBasicSet.
/**
* Test a node that has PRIMARY_SOURCE_FOR set to all fields with no specialization (i.e. {@code null}),
* and no PRIMARY_SOURCE_FOR_EXCLUDED is set.
* <p>
* Represents e.g. a node in the tree that stores all fields.
*/
@Test
public void testPrimarySourceForBasicSet() {
Map<String, Object> nodeProperties = new HashMap<>();
EnumMap<MapClientEntityFields, Collection<String>> primarySourceFor = new EnumMap<>(MapClientEntityFields.class);
for (MapClientEntityFields field : MapClientEntityFields.values()) {
primarySourceFor.put(field, null);
}
nodeProperties.put(NodeProperties.PRIMARY_SOURCE_FOR, primarySourceFor);
TreeStorageNodePrescription n = new TreeStorageNodePrescription(nodeProperties, null, null);
for (MapClientEntityFields field : MapClientEntityFields.values()) {
assertThat("Field " + field + " has primary source in this node", n.isPrimarySourceFor(field, null), is(FieldContainedStatus.FULLY));
}
}
use of org.keycloak.models.map.client.MapClientEntityFields in project keycloak by keycloak.
the class TreeStorageNodePrescriptionTest method testPrimarySourceForWithExcluded.
/**
* Test a node that has no PRIMARY_SOURCE_FOR set,
* and PRIMARY_SOURCE_FOR_EXCLUDED is set to ATTRIBUTES field with no specialization (i.e. {@code null}).
* <p>
* Represents e.g. a node in the tree that stores all attributes apart from attributes
*/
@Test
public void testPrimarySourceForWithExcluded() {
Map<String, Object> nodeProperties = new HashMap<>();
EnumMap<MapClientEntityFields, Collection<String>> primarySourceForExcluded = new EnumMap<>(MapClientEntityFields.class);
nodeProperties.put(NodeProperties.PRIMARY_SOURCE_FOR_EXCLUDED, primarySourceForExcluded);
primarySourceForExcluded.put(MapClientEntityFields.ATTRIBUTES, null);
// node is primary for all fields apart from all attributes
TreeStorageNodePrescription n = new TreeStorageNodePrescription(nodeProperties, null, null);
for (MapClientEntityFields field : MapClientEntityFields.values()) {
assertThat(n.isPrimarySourceFor(field, null), is(field == MapClientEntityFields.ATTRIBUTES ? FieldContainedStatus.NOT_CONTAINED : FieldContainedStatus.FULLY));
}
}
use of org.keycloak.models.map.client.MapClientEntityFields in project keycloak by keycloak.
the class TreeStorageNodePrescriptionTest method testPrimarySourceForBasicUnset.
/**
* Test a node that has neither PRIMARY_SOURCE_FOR nor PRIMARY_SOURCE_FOR_EXCLUDED set.
* <p>
* Represents e.g. a node in the tree that stores all fields.
*/
@Test
public void testPrimarySourceForBasicUnset() {
Map<String, Object> nodeProperties = new HashMap<>();
TreeStorageNodePrescription n = new TreeStorageNodePrescription(nodeProperties, null, null);
for (MapClientEntityFields field : MapClientEntityFields.values()) {
assertThat("Field " + field + " has primary source in this node", n.isPrimarySourceFor(field, null), is(FieldContainedStatus.FULLY));
}
}
Aggregations