protected Handler createAppServlet(
     Server server,
     JerseyEnvironment jersey,
     ObjectMapper objectMapper,
     Validator validator,
     MutableServletContextHandler handler,
     @Nullable Servlet jerseyContainer,
     MetricRegistry metricRegistry) {
   configureSessionsAndSecurity(handler, server);
   handler
       .addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST))
       .setInitParameter(
           AllowedMethodsFilter.ALLOWED_METHODS_PARAM, Joiner.on(',').join(allowedMethods));
   handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
   serverPush.addFilter(handler);
   if (jerseyContainer != null) {
     if (jerseyRootPath.isPresent()) {
       jersey.setUrlPattern(jerseyRootPath.get());
     }
     jersey.register(new JacksonMessageBodyProvider(objectMapper));
     jersey.register(new HibernateValidationFeature(validator));
     if (registerDefaultExceptionMappers == null || registerDefaultExceptionMappers) {
       jersey.register(new LoggingExceptionMapper<Throwable>() {});
       jersey.register(new JerseyViolationExceptionMapper());
       jersey.register(new JsonProcessingExceptionMapper());
       jersey.register(new EarlyEofExceptionMapper());
     }
     handler.addServlet(new NonblockingServletHolder(jerseyContainer), jersey.getUrlPattern());
   }
   final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
   instrumented.setServer(server);
   instrumented.setHandler(handler);
   return instrumented;
 }
 private void registerResources(final JerseyEnvironment environment) {
   environment.register(new AggregateTickerResource());
   environment.register(new ExchangeResource());
   environment.register(new ExchangesResource());
   environment.register(new AssetsResource());
   environment.register(new MarketsResource());
   environment.register(DeploymentResource.getResource());
 }
Example #3
0
  @SuppressWarnings("unchecked")
  @Override
  public void run(KeywhizConfig config, Environment environment) throws Exception {
    if (injector == null) {
      logger.debug("No existing guice injector; creating new one");
      injector =
          Guice.createInjector(
              new ServiceModule(config, environment),
              new SecretGeneratorModule(secretGeneratorFactories, secretGenerators));
    }

    JerseyEnvironment jersey = environment.jersey();

    logger.debug("Registering resource filters");
    jersey.register(injector.getInstance(ClientCertificateFilter.class));

    logger.debug("Registering servlet filters");
    environment
        .servlets()
        .addFilter("security-headers-filter", injector.getInstance(SecurityHeadersFilter.class))
        .addMappingForUrlPatterns(
            null, /* Default is for requests */
            false /* Can be after other filters */,
            "/*" /* Every request */);
    jersey.register(injector.getInstance(CookieRenewingFilter.class));

    environment
        .servlets()
        .addFilter("xsrf-filter", injector.getInstance(XsrfServletFilter.class))
        .addMappingForUrlPatterns(
            null /* Default is for requests */,
            false /* Can be after other filters */,
            "/admin/*" /* Path to filter on */);

    logger.debug("Registering providers");
    jersey.register(
        new AuthResolver.Binder(
            injector.getInstance(ClientAuthFactory.class),
            injector.getInstance(AutomationClientAuthFactory.class),
            injector.getInstance(UserAuthFactory.class)));

    logger.debug("Registering resources");
    jersey.register(injector.getInstance(ClientResource.class));
    jersey.register(injector.getInstance(ClientsResource.class));
    jersey.register(injector.getInstance(GroupResource.class));
    jersey.register(injector.getInstance(GroupsResource.class));
    jersey.register(injector.getInstance(MembershipResource.class));
    jersey.register(injector.getInstance(SecretsDeliveryResource.class));
    jersey.register(injector.getInstance(SecretResource.class));
    jersey.register(injector.getInstance(SecretsResource.class));
    jersey.register(injector.getInstance(SecretGeneratorsResource.class));
    jersey.register(injector.getInstance(SecretDeliveryResource.class));
    jersey.register(injector.getInstance(SessionLoginResource.class));
    jersey.register(injector.getInstance(SessionLogoutResource.class));
    jersey.register(injector.getInstance(SessionMeResource.class));
    jersey.register(injector.getInstance(AutomationClientResource.class));
    jersey.register(injector.getInstance(AutomationGroupResource.class));
    jersey.register(injector.getInstance(AutomationSecretResource.class));
    jersey.register(injector.getInstance(AutomationEnrollClientGroupResource.class));
    jersey.register(injector.getInstance(AutomationSecretAccessResource.class));
    jersey.register(injector.getInstance(AutomationSecretGeneratorsResource.class));
    logger.debug("Keywhiz configuration complete");
  }
 private void registerProviders(final JerseyEnvironment environment) {
   environment.register(FormProvider.class);
 }