use of io.vertigo.account.authorization.metamodel.SecurityDimension in project vertigo by KleeGroup.
the class SecuredEntityDeserializer method deserializeSecurityDimensions.
private static SecurityDimension deserializeSecurityDimensions(final DtDefinition entityDefinition, final JsonObject advancedDimension, final JsonDeserializationContext context) {
final String name = advancedDimension.get("name").getAsString();
final SecurityDimensionType type = SecurityDimensionType.valueOf(advancedDimension.get("type").getAsString());
final List<String> fieldNames = deserializeList(advancedDimension.get("fields"), String.class, context);
final List<DtField> fields = fieldNames.stream().map(fieldName -> deserializeDtField(entityDefinition, fieldName)).collect(Collectors.toList());
final List<String> values = deserializeList(advancedDimension.get("values"), String.class, context);
return new SecurityDimension(name, type, fields, values);
}
use of io.vertigo.account.authorization.metamodel.SecurityDimension in project vertigo by KleeGroup.
the class SecuredEntityDeserializer method deserialize.
/**
* {@inheritDoc}
*/
@Override
public SecuredEntity deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
final JsonObject jsonSecuredEntity = json.getAsJsonObject();
final DtDefinition entityDefinition = findDtDefinition(jsonSecuredEntity.get("entity").getAsString());
final List<DtField> securityFields = new ArrayList<>();
for (final JsonElement securityField : jsonSecuredEntity.get("securityFields").getAsJsonArray()) {
securityFields.add(deserializeDtField(entityDefinition, securityField.getAsString()));
}
final List<SecurityDimension> advancedDimensions = new ArrayList<>();
for (final JsonElement advancedDimension : jsonSecuredEntity.get("securityDimensions").getAsJsonArray()) {
// TODO if null ?
advancedDimensions.add(deserializeSecurityDimensions(entityDefinition, advancedDimension.getAsJsonObject(), context));
}
// on garde la map des operations pour resoudre les grants
final Map<String, Authorization> permissionPerOperations = new HashMap<>();
for (final JsonElement operation : jsonSecuredEntity.get("operations").getAsJsonArray()) {
// TODO if null ?
final Authorization permission = deserializeOperations(entityDefinition, operation.getAsJsonObject(), context, permissionPerOperations);
Assertion.checkArgument(!permissionPerOperations.containsKey(permission.getOperation().get()), "Operation {0} already declared on {1}", permission.getOperation().get(), entityDefinition.getName());
permissionPerOperations.put(permission.getOperation().get(), permission);
}
return new SecuredEntity(entityDefinition, securityFields, advancedDimensions, new ArrayList<>(permissionPerOperations.values()));
}
Aggregations