只暴露特定的 Jmix 实体使用 Jmix Rest。

huangapple go评论109阅读模式
英文:

Expose only specific jmixentities wit Jmix Rest

问题

我们的项目中使用了Jmix-Rest API,并通过JMixEntity注解公开了实体以供Rest调用。然而,默认情况下,这会暴露所有的JmixEntities。JmixEntity注解既用于CRUD Rest API,也用于模板等。虽然对于模板等用途来说这样做没问题,但在CRUD Rest API中,默认情况下不应该暴露所有的实体。
我们正在寻找一种方法,只暴露其中几个特定的实体,而不让它们默认可通过Rest访问。
在JMix中是否有相应的属性、设置或注解可以实现这一点呢?我知道Jmix是建立在Spring之上的。也许在Spring配置或注解中有相关的方法吗?
提前谢谢!

英文:

in our project we use the Jmix-Rest API and expose the Entities annotated with JMixEntity for Rest calls. This however exposes all JmixEntities per default. The JmixEntity-Annotation is used for both, the CRUD rest api and for templating etc. While the later is ok for the templating etc the former is not supposed to expose all entities per CRUD per default.
However we are looking for a way to expose only a few select entities like that and not make them accessible via Rest per default.

Is there a property, setting or annotation that lets you do that in JMix?
I know that Jmix is built ontop of Spring. Is there maybe a way with Spring config or anntotations?

Thank you in advance!

答案1

得分: 2

你可以使用 REST API 通过 资源角色 限制可用的实体数量。

该角色必须具有 "API" 范围:

@ResourceRole(name = "新角色", code = "new-role", scope = "API")

对于此角色,您可以限制用户可以访问的实体数量,例如:

@EntityAttributePolicy(entityClass = MyEntity.class,
attributes = "*",
action = EntityAttributePolicyAction.MODIFY)
@EntityPolicy(entityClass = MyEntity.class,
actions = EntityPolicyAction.ALL)
void myEntity();

如果将此角色分配给用户,用户将无法仅使用 REST API 读取指定的实体。

英文:

You can limit the number of entities available with REST API with resource role.

The role must have the "API" scope:

@ResourceRole(name = "New role", code = "new-role", scope = "API")

For this role you can limit the number of entities the user can access, e.g. like this:

    @EntityAttributePolicy(entityClass = MyEntity.class,
        attributes = "*",
        action = EntityAttributePolicyAction.MODIFY)
    @EntityPolicy(entityClass = MyEntity.class,
        actions = EntityPolicyAction.ALL)
    void myEntity();

If you assign this role to a user, the user won't be able to read only specified entities with the REST API.

huangapple
  • 本文由 发表于 2023年4月17日 15:49:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032809.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定