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


Java AuthHandler类代码示例

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


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

示例1: create

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
/**
 * Two mode for handler supported.
 *
 * @param cliffes
 * @return
 */
private AuthHandler create(final Set<Cliff> cliffes) {
    AuthHandler resultHandler = null;
    if (Values.ONE < cliffes.size()) {
        // 1 < handler
        final ChainAuthHandler chain = ChainAuthHandler.create();
        Observable.fromIterable(cliffes)
                .filter(Objects::nonNull)
                .map(this::get)
                .filter(Objects::nonNull)
                .subscribe(chain::append);
        resultHandler = chain;
    } else {
        // 1 = handler
        if (!cliffes.isEmpty()) {
            final Cliff cliff = cliffes.iterator().next();
            resultHandler = get(cliff);
        }
    }
    return resultHandler;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:27,代码来源:WallAxis.java

示例2: getAuthHandler

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
private static AuthHandler getAuthHandler(SwaggerAuthHandlerFactory authHandlerFactory, Swagger swagger, Operation operation) {
    AuthHandler authHandler = null;
    if(authHandlerFactory != null) {
        if(operation.getSecurity() != null) {
        	if(!operation.getSecurity().isEmpty()) {
        		authHandler = authHandlerFactory.createAuthHandler(operation.getSecurity());
        	}
        } else if(swagger.getSecurity() != null && !swagger.getSecurity().isEmpty()) {
            List<Map<String, List<String>>> security = swagger.getSecurity().stream()
                    .map(SecurityRequirement::getRequirements)
                    .collect(Collectors.toList());
            authHandler = authHandlerFactory.createAuthHandler(security);
        }
    }

    return authHandler;
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:18,代码来源:SwaggerRouter.java

示例3: getAuth

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
/**
 * Creates an auth handler of the type indicated in the `auth` section of config.
 *
 * @param vertx the vert.x instance
 * @param router the vert.x web router to protect
 * @param apimanConfig the apiman config
 * @return an auth handler
 */
public static AuthHandler getAuth(Vertx vertx, Router router, VertxEngineConfig apimanConfig) {
    String type = apimanConfig.getAuth().getString("type", "NONE");
    JsonObject authConfig = apimanConfig.getAuth().getJsonObject("config", new JsonObject());

    switch(AuthType.getType(type)) {
    case BASIC:
        return BasicAuth.create(authConfig);
    case NONE:
        return NoneAuth.create();
    case KEYCLOAK:
        return KeycloakOAuthFactory.create(vertx, router, apimanConfig, authConfig);
    default:
        return NoneAuth.create();
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:24,代码来源:AuthFactory.java

示例4: get

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
private AuthHandler get(final Cliff cliff) {
    return Fn.getJvm(() -> {
        JsonObject config = cliff.getConfig();
        config = null == config ? new JsonObject() : config;
        final Object reference = cliff.getAuthorizer().getAuthenticate().invoke(cliff.getProxy(), config);
        return null == reference ? null : (AuthHandler) reference;
    }, cliff, cliff.getProxy(), cliff.getAuthorizer(), cliff.getAuthorizer().getAuthenticate());
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:9,代码来源:WallAxis.java

示例5: configureAuthRoute

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
private static void configureAuthRoute(Router baseRouter, HttpMethod method, String path, Swagger swagger, Operation operation,
                                       SwaggerAuthHandlerFactory authHandlerFactory) {
    AuthHandler authHandler = getAuthHandler(authHandlerFactory, swagger, operation);
    if(authHandler != null) {
        ROUTE_BUILDERS.get(method).buildRoute(baseRouter, path).handler(authHandler);
    }
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:8,代码来源:SwaggerRouter.java

示例6: getAuthHandler

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
private AuthHandler getAuthHandler(String name) {
    AuthHandler authHandler = this.authHandlers.get(name);
    if (authHandler != null) {
        return authHandler;
    }

    AuthProvider authProvider = getAuthProviderFactory().getAuthProviderByName(name);
    if (authProvider == null) {
        return null;
    }

    SecuritySchemeDefinition securityScheme = this.securitySchemes.get(name);
    if(securityScheme != null) {
     switch (securityScheme.getType()) {
         case "apiKey":
             ApiKeyAuthDefinition apiKeyAuthDefinition = (ApiKeyAuthDefinition) securityScheme;
             Location apiKeyLocation = Location.valueOf(apiKeyAuthDefinition.getIn().name());
             authHandler = ApiKeyAuthHandler.create(authProvider, apiKeyLocation, apiKeyAuthDefinition.getName());
             break;
         case "basic":
             authHandler = BasicAuthHandler.create(authProvider);
             break;
         case "oauth2":
             vertxLogger.warn("OAuth2 authentication has not been implemented yet!");
             break;
         default:
             vertxLogger.warn("SecurityScheme is not authorized : " + securityScheme.getType());
             break;
     }
     
	
     if (authHandler != null) {
         this.authHandlers.put(name, authHandler);
     }
    } else {
        vertxLogger.warn("No securityScheme definition in swagger file for auth provider: " + name);
    }

    return authHandler;
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:41,代码来源:SwaggerAuthHandlerFactory.java

示例7: doStart

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();

    LOGGER.info("Start HTTP server for node management");

    // Start HTTP server
    Router mainRouter = Router.router(vertx).mountSubRouter(PATH, nodeRouter);

    AuthHandler authHandler = null;
    switch ( httpServerConfiguration.getAuthenticationType().toLowerCase() ) {
        case AUTHENTICATION_TYPE_NONE:
            break;
        case AUTHENTICATION_TYPE_BASIC:
            authHandler = BasicAuthHandler.create(authProvider, AUTHENTICATION_BASIC_REALM);
            break;
        default:
            throw new IllegalArgumentException("Unsupported Authentication type " + httpServerConfiguration.getAuthenticationType() + " for HTTP core services");
    }

    // Set security handler is defined
    if ( authHandler != null ) {
       mainRouter.route().handler(authHandler);
       nodeRouter.route().handler(authHandler);
    }


    // Set default handler
    mainRouter.route().handler(ctx -> ctx.fail(HttpStatusCode.NOT_FOUND_404));

    // Add request handler
    httpServer.requestHandler(mainRouter::accept).listen(event ->
            LOGGER.info("HTTP server for node management listening on port {}", event.result().actualPort()));

    // Set node handler
    NodeHandler nodeHandler = new NodeHandler();
    applicationContext.getAutowireCapableBeanFactory().autowireBean(nodeHandler);
    nodeRouter.get("/").handler(nodeHandler);
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:40,代码来源:HttpServer.java

示例8: main

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
public static void main(String[] args) {
    // TODO start a vertx instance
    // deploy verticles / one per resource in this case

    Json.mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    Vertx vertx = Vertx.vertx();

    HttpClientOptions clientOptions = new HttpClientOptions()
            .setSsl(true)
            .setTrustStoreOptions(new JksOptions()
                    .setPath(System.getProperty("javax.net.ssl.trustStore"))
                    .setPassword(System.getProperty("javax.net.ssl.trustStorePassword")));
    HttpClient httpClient = vertx.createHttpClient(clientOptions);

    Router router = Router.router(vertx);
    AuthHandler auth = new BearerAuthHandler(new FacebookOauthTokenVerifier(httpClient));
    router.route("/*").handler(auth);

    HelloResource helloResource = new HelloResource(httpClient);
    router.get("/hello").produces("text/plain").handler(helloResource::hello);

    CarRepository carRepository = new InMemoryCarRepository();
    CarsResource carsResource = new CarsResource(carRepository);
    router.route("/cars*").handler(BodyHandler.create());
    router.get("/cars").produces("application/json").handler(carsResource::all);
    router.post("/cars").consumes("application/json").handler(carsResource::create);

    CarResource carResource = new CarResource(carRepository);
    router.get("/cars/:id").produces("application/json").handler(carResource::byId);

    HttpServerOptions serverOptions = new HttpServerOptions()
            .setSsl(true)
            .setKeyStoreOptions(new JksOptions()
                    .setPath(System.getProperty("javax.net.ssl.keyStorePath"))
                    .setPassword(System.getProperty("javax.net.ssl.keyStorePassword")))
            .setPort(8090);
    HttpServer server = vertx.createHttpServer(serverOptions);
    server.requestHandler(router::accept).listen();
}
 
开发者ID:cdelmas,项目名称:microservices-comparison,代码行数:41,代码来源:Main.java

示例9: addAuthority

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Override
public AuthHandler addAuthority(String authority) {
  for (AuthHandler h : handlers) {
    h.addAuthority(authority);
  }
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:8,代码来源:ChainAuthHandlerImpl.java

示例10: addAuthorities

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Override
public AuthHandler addAuthorities(Set<String> authorities) {
  for (AuthHandler h : handlers) {
    h.addAuthorities(authorities);
  }
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:8,代码来源:ChainAuthHandlerImpl.java

示例11: iterate

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
private void iterate(final int idx, final RoutingContext ctx, HttpStatusException lastException, Handler<AsyncResult<JsonObject>> handler) {
  // stop condition
  if (idx >= handlers.size()) {
    // no more providers, means that we failed to find a provider capable of performing this operation
    handler.handle(Future.failedFuture(lastException));
    return;
  }

  // parse the request in order to extract the credentials object
  final AuthHandler authHandler = handlers.get(idx);

  authHandler.parseCredentials(ctx, res -> {
    if (res.failed()) {
      if (res.cause() instanceof HttpStatusException) {
        final HttpStatusException exception = (HttpStatusException) res.cause();
        switch (exception.getStatusCode()) {
          case 302:
          case 400:
          case 401:
          case 403:
            // try again with next provider since we know what kind of error it is
            iterate(idx + 1, ctx, exception, handler);
            return;
        }
      }
      handler.handle(Future.failedFuture(res.cause()));
      return;
    }

    // setup the desired auth provider if we can
    if (authHandler instanceof AuthHandlerImpl) {
      ctx.put(AuthHandlerImpl.AUTH_PROVIDER_CONTEXT_KEY, ((AuthHandlerImpl) authHandler).authProvider);
    }
    handler.handle(Future.succeededFuture(res.result()));
  });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:37,代码来源:ChainAuthHandlerImpl.java

示例12: create

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
public static AuthHandler create(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject authConfig) {
    OAuth2FlowType flowType = toEnum(authConfig.getString("flowType"));
    String role = authConfig.getString("requiredRole");

    Objects.requireNonNull(flowType, String.format("flowType must be specified and valid. Flows: %s.", Arrays.asList(OAuth2FlowType.values())));
    Objects.requireNonNull(role, "requiredRole must be non-null.");

    if (flowType != OAuth2FlowType.AUTH_CODE) {
        return directGrant(vertx, apimanConfig, authConfig, flowType, role);
    } else {
        return standardAuth(vertx, router, apimanConfig, authConfig, flowType);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:14,代码来源:KeycloakOAuthFactory.java

示例13: start

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) {
    Future<Void> superFuture = Future.future();
    Future<HttpServer> listenFuture = Future.future();
    super.start(superFuture);

    CompositeFuture.all(superFuture, listenFuture)
        .setHandler(compositeResult -> {
            if (compositeResult.succeeded()) {
                startFuture.complete(null);
            } else {
                startFuture.fail(compositeResult.cause());
            }
        });

    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.start();

    addResources(deployment.getRegistry(),
            new SystemResourceImpl(apimanConfig, engine),
            new ApiResourceImpl(apimanConfig, engine),
            new ClientResourceImpl(apimanConfig, engine),
            new OrgResourceImpl(apimanConfig, engine));

    deployment.getProviderFactory().register(RestExceptionMapper.class);

    VertxRequestHandler resteasyRh = new VertxRequestHandler(vertx, deployment);

    Router router = Router.router(vertx)
                .exceptionHandler(error -> log.error(error.getMessage(), error));

    // Ensure body handler is attached early so that if AuthHandler takes an external action
    // we don't end up losing the body (e.g OAuth2).
    router.route()
        .handler(BodyHandler.create());

    AuthHandler authHandler = AuthFactory.getAuth(vertx, router, apimanConfig);

    router.route("/*")
        .handler(authHandler);

    router.route("/*") // We did the previous stuff, now we call into JaxRS.
        .handler(context -> resteasyRh.handle(new Router2ResteasyRequestAdapter(context)));

    HttpServerOptions httpOptions = new HttpServerOptions();

    if (apimanConfig.isSSL()) {
        httpOptions.setSsl(true)
        .setKeyStoreOptions(
                new JksOptions()
                    .setPath(apimanConfig.getKeyStore())
                    .setPassword(apimanConfig.getKeyStorePassword())
                )
        .setTrustStoreOptions(
                new JksOptions()
                    .setPath(apimanConfig.getTrustStore())
                    .setPassword(apimanConfig.getTrustStorePassword())
                );
    } else {
        log.warn("API is running in plaintext mode. Enable SSL in config for production deployments.");
    }

    vertx.createHttpServer(httpOptions)
        .requestHandler(router::accept)
        .listen(apimanConfig.getPort(VERTICLE_TYPE),
                apimanConfig.getHostname(),
                listenFuture.completer());
}
 
开发者ID:apiman,项目名称:apiman,代码行数:69,代码来源:ApiVerticle.java

示例14: authenticate

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Authenticate
public AuthHandler authenticate(final JsonObject config) {
    return BasicOstium.create(
            MongoAuth.create(MongoInfix.getClient(), config)
    );
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:7,代码来源:MongoKeeper.java

示例15: addAuthority

import io.vertx.ext.web.handler.AuthHandler; //导入依赖的package包/类
@Override
public AuthHandler addAuthority(final String authority) {
    this.authorities.add(authority);
    return this;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:6,代码来源:AuthPhylum.java


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