简体   繁体   English

Helidon MP 授权

[英]Authorization in Helidon MP

Helidon uses annotations like @RoleValidator.Roles({“my_admins”, “test”}) to do the authorization. Helidon 使用 @RoleValidator.Roles({“my_admins”, “test”}) 之类的注释来进行授权。 I am wondering if there is a way to do authorization differently using configuration settings for paths, for example.例如,我想知道是否有一种方法可以使用路径的配置设置以不同方式进行授权。

Basically, the question is.基本上,问题是。 Is there a way to use configuration instead of annotation to authorize requests to particular endpoints?有没有办法使用配置而不是注释来授权对特定端点的请求?

If yes, would it be possible to get the SecurityContext like in a case of annotation?如果是,是否可以像在注释的情况下那样获取 SecurityContext? Example with multiple roles for one endpoint would be helpful一个端点具有多个角色的示例会有所帮助

I am successfully using annotations but in some cases it is not convenient我成功地使用了注释,但在某些情况下并不方便

You should be able to do what you want using configuration instead of annotations.你应该能够使用配置而不是注释来做你想做的事。 It would look similar to what our documentation describes here: https://helidon.io/docs/latest/index.html#/se/guides/security-oidc#Restrict-access-to-a-specific-role它看起来类似于我们的文档在此处描述的内容: https://helidon.io/docs/latest/index.html#/se/guides/security-oidc#Restrict-access-to-a-specific-role

You might not even use the annotations given your use case.您甚至可能不会使用给定用例的注释。

You would define the user-to-roles mapping however makes sense for you (Helidon config would work as would some other provider) and then use Helidon config to set up each endpoint's roles-allowed setting as needed.您可以定义用户到角色的映射,但对您来说有意义(Helidon 配置可以像其他一些提供者一样工作),然后使用 Helidon 配置根据需要设置每个端点的roles-allowed设置。

As you are using Helidon MP, you could for example add something like this to your META-INF/microprofile-config.properties file:当您使用 Helidon MP 时,您可以将类似这样的内容添加到您的META-INF/microprofile-config.properties文件中:

web-server.paths.0.path=/greet
web-server.paths.0.methods=get
web-server.paths.0.roles-allowed=admin,dev
web-server.paths.0.authenticate=true

(These particular settings are drawn from Helidon's MP QuickStart example but you get the idea.) (这些特定设置取自 Helidon 的 MP QuickStart 示例,但您明白了。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM