简体   繁体   English

来自vertx RoutingContext的KeycloakSecurityContext

[英]KeycloakSecurityContext from vertx RoutingContext

Actually I'm using Vertx Routher, and I have a request with Authorization in headers and want to find more information about token, so I've tried to create KeycloakSecurityContext form Vert.x RoutingContext by using code like these: 实际上,我使用的是Vertx Routher,并且我在标头中有一个带有Authorization的请求,并且想要查找有关令牌的更多信息,因此我尝试通过使用类似以下代码的形式从Vert.x RoutingContext创建KeycloakSecurityContext

KeycloakSecurityContext securityContext = (KeycloakSecurityContext) routingContext.session().get(KeycloakSecurityContext.class.getName());

But it failed. 但是失败了。 (NPE, empty seesion.data) (NPE,空seesion.data)

Can anyone prompt me, how can I create that Keycloak Context from Vertx route? 谁能提示我,如何从Vertx路由创建该Keycloak上下文? In future I want to terminate that token, so extra tips are welcome. 将来我想终止该令牌,因此欢迎您提供其他提示。

Thanks, 谢谢,

There is no Keycloak security context in Vert.x Web. Vert.x Web中没有Keycloak安全上下文。 All interactions between Vert.x and Keycloak are done over the OAuth2 protocol which is independent of the vendor you're using eg: Keycloak, Facebook, Google, Twitter, Linkedin, etc... Vert.x和Keycloak之间的所有交互均通过OAuth2协议完成,该协议独立于您使用的供应商,例如:Keycloak,Facebook,Google,Twitter,Linkedin等。

As of version 3.3.0 you will be able to use keycloak grants as encoded in the OAuth2 token as Vert.x auth authorities so you can do not just authentication but also authorization. 从3.3.0版开始,您将可以使用OAuth2令牌中编码的密钥斗篷授予作为Vert.x身份验证授权,因此您不仅可以进行身份​​验证,还可以进行授权。

Here an example: 这里是一个例子:

// Initialize the OAuth2 Library
    OAuth2Auth oauth2 = OAuth2Auth.createKeycloak(vertx, OAuth2FlowType.PASSWORD, keycloakJson);

    // first get a token (authenticate)
    oauth2.getToken(new JsonObject().put("username", "user").put("password", "secret"), res -> {
      if (res.failed()) {
        // error handling...
      } else {
        AccessToken token = res.result();

        // now check for permissions
        token.isAuthorised("account:manage-account", r -> {
          if (r.result()) {
            // this user is authorized to manage its account
          }
        });
      }
});

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

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