当前位置: 首页>>代码示例>>Java>>正文


Java KeycloakAuth类代码示例

本文整理汇总了Java中io.vertx.ext.auth.oauth2.providers.KeycloakAuth的典型用法代码示例。如果您正苦于以下问题:Java KeycloakAuth类的具体用法?Java KeycloakAuth怎么用?Java KeycloakAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeycloakAuth类属于io.vertx.ext.auth.oauth2.providers包,在下文中一共展示了KeycloakAuth类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLoadJWK2

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
@Test
@Ignore
public void testLoadJWK2() {
  JsonObject config = new JsonObject("{\n" +
    "  \"realm\": \"master\",\n" +
    "  \"auth-server-url\": \"http://localhost:8080/auth\",\n" +
    "  \"ssl-required\": \"external\",\n" +
    "  \"resource\": \"test\",\n" +
    "  \"credentials\": {\n" +
    "    \"secret\": \"b0568625-a482-45d8-af8b-27beba502ed3\"\n" +
    "  }\n" +
    "}");

  OAuth2Auth oauth2 = KeycloakAuth.create(vertx, config);

  oauth2.loadJWK(load -> {
    assertFalse(load.failed());
    testComplete();
  });
  await();

}
 
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:23,代码来源:OAuth2KeyRotationTest.java

示例2: example13

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
public void example13(Vertx vertx) {
  // you would get this config from the keycloak admin console
  JsonObject keycloakJson = new JsonObject()
      .put("realm", "master")
      .put("realm-public-key", "MIIBIjANBgkqhk...wIDAQAB")
      .put("auth-server-url", "http://localhost:9000/auth")
      .put("ssl-required", "external")
      .put("resource", "frontend")
      .put("credentials", new JsonObject()
          .put("secret", "2fbf5e18-b923-4a83-9657-b4ebd5317f60"));

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

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

      // now check for permissions
      token.isAuthorised("account:manage-account", r -> {
        if (r.result()) {
          // this user is authorized to manage its account
        }
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:31,代码来源:AuthOAuth2Examples.java

示例3: loadUser

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
@Test
public void loadUser() {
  OAuth2Auth provider = KeycloakAuth.create(Vertx.vertx(), OAuth2FlowType.AUTH_CODE, keycloakConfig);
  OAuth2TokenImpl user = new OAuth2TokenImpl();
  System.out.println(keycloakToken.length());
  user.readFromBuffer(0, Buffer.buffer().appendInt(0).appendInt(keycloakToken.length()).appendString(keycloakToken));
  user.setAuthProvider(provider);
}
 
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:9,代码来源:OAuth2UserSerializationTest.java

示例4: keycloakTest

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
@Test
public void keycloakTest() throws Exception {
  super.setUp();
  oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakConfig);

  OAuth2TokenImpl token = new OAuth2TokenImpl((OAuth2AuthProviderImpl) oauth2, keycloakToken);

  assertNotNull(token.opaqueAccessToken());
  assertNotNull(token.opaqueRefreshToken());
  assertNull(token.accessToken());
  // trust it
  token.setTrustJWT(true);
  assertNotNull(token.accessToken());
}
 
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:15,代码来源:Oauth2TokenTest.java

示例5: standardAuth

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
private static OAuth2AuthHandler standardAuth(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject authConfig, OAuth2FlowType flowType)  {
    String proto = apimanConfig.isSSL() ? "https://" : "http://";
    int port = apimanConfig.getPort(ApiVerticle.VERTICLE_TYPE);
    String hostname = Optional.of(apimanConfig.getPublicEndpoint()).orElse(apimanConfig.getHostname());
    String redirect = proto + hostname + ":" + port; // Redirect back here to *after* auth.
    // Set up KC OAuth2 Authentication
    OAuth2AuthHandler auth = OAuth2AuthHandler.create(KeycloakAuth.create(vertx, flowType, authConfig), redirect);
    // Callback can be anything (as long as it's not already used by something else).
    auth.setupCallback(router.get("/callback"));
    return auth;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:12,代码来源:KeycloakOAuthFactory.java

示例6: authenticate

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, Handler<AsyncResult<Void>> resultHandler) {

    OAuth2FlowType flowType = getFlowType(config.get("flowType"));
    JsonObject params = new JsonObject();
    if (config.get("username") != null) {
        params.put("username", config.get("username"));
    }
    if (config.get("password") != null) {
        params.put("password", config.get("password"));
    }

    OAuth2Auth oauth2 = KeycloakAuth.create(vertx,  flowType, mapToJson(config));

    oauth2.getToken(params, tokenResult -> {
        if (tokenResult.succeeded()) {
            log.debug("OAuth2 Keycloak exchange succeeded.");
            AccessToken token = tokenResult.result();
            headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token"));
            resultHandler.handle(Future.succeededFuture());
        } else {
            log.error("Access Token Error: {0}.", tokenResult.cause().getMessage());
            resultHandler.handle(Future.failedFuture(tokenResult.cause()));
        }
      });
    return this;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:28,代码来源:KeycloakOAuth2.java

示例7: start

import io.vertx.ext.auth.oauth2.providers.KeycloakAuth; //导入依赖的package包/类
@Override
public void start(Future<Void> future) throws Exception {
  super.start();

  // get HTTP host and port from configuration, or use default value
  String host = config().getString("api.gateway.http.address", "localhost");
  int port = config().getInteger("api.gateway.http.port", DEFAULT_PORT);

  Router router = Router.router(vertx);
  // cookie and session handler
  enableLocalSession(router);

  // body handler
  router.route().handler(BodyHandler.create());

  // version handler
  router.get("/api/v").handler(this::apiVersion);

  // create OAuth 2 instance for Keycloak
  oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, config());

  router.route().handler(UserSessionHandler.create(oauth2));

  String hostURI = buildHostURI();

  // set auth callback handler
  router.route("/callback").handler(context -> authCallback(oauth2, hostURI, context));

  router.get("/uaa").handler(this::authUaaHandler);
  router.get("/login").handler(this::loginEntryHandler);
  router.post("/logout").handler(this::logoutHandler);

  // api dispatcher
  router.route("/api/*").handler(this::dispatchRequests);

  // static content
  router.route("/*").handler(StaticHandler.create());

  // enable HTTPS
  HttpServerOptions httpServerOptions = new HttpServerOptions()
    .setSsl(true)
    .setKeyStoreOptions(new JksOptions().setPath("server.jks").setPassword("123456"));

  // create http server
  vertx.createHttpServer(httpServerOptions)
    .requestHandler(router::accept)
    .listen(port, host, ar -> {
      if (ar.succeeded()) {
        publishApiGateway(host, port);
        future.complete();
        logger.info("API Gateway is running on port " + port);
        // publish log
        publishGatewayLog("api_gateway_init_success:" + port);
      } else {
        future.fail(ar.cause());
      }
    });
}
 
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:59,代码来源:APIGatewayVerticle.java


注:本文中的io.vertx.ext.auth.oauth2.providers.KeycloakAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。