Search in sources :

Example 1 with ImmutableServerConfig

use of com.nexblocks.authguard.rest.config.ImmutableServerConfig in project AuthGuard by AuthGuard.

the class JettyServerProviderTest method getNoSslEnabled.

@Test
void getNoSslEnabled() {
    final ImmutableServerConfig config = ImmutableServerConfig.builder().build();
    final JettyServerProvider provider = new JettyServerProvider(config);
    final Server server = provider.get();
    assertThat(server.getConnectors()).hasSize(1).allMatch(connector -> connector.getProtocols().size() == 1 && connector.getProtocols().get(0).equals("http/1.1"));
}
Also used : Server(org.eclipse.jetty.server.Server) ImmutableServerConfig(com.nexblocks.authguard.rest.config.ImmutableServerConfig) Test(org.junit.jupiter.api.Test)

Example 2 with ImmutableServerConfig

use of com.nexblocks.authguard.rest.config.ImmutableServerConfig in project AuthGuard by AuthGuard.

the class ServerRunner method run.

public void run(final ConfigContext configContext) {
    // class search
    final Collection<String> searchPackages = configContext.getSubContext("injection").getAsCollection("packages", String.class);
    final ClassSearch classSearch = new ClassSearch(searchPackages);
    // injectors
    final Injector injector = Guice.createInjector(new MappersBinder(), new ConfigBinder(configContext), new ExchangesBinder(configContext, searchPackages), new ApiKeysExchangeBinder(configContext, searchPackages), new ApiRoutesBinder(searchPackages, configContext), new ServicesBinder(configContext), new JwtBinder(configContext), new DalBinder(configContext, searchPackages), new EmbBinder(searchPackages), new ExternalProvidersBinder(configContext, searchPackages));
    log.info("Initialed injection binders");
    // run bootstraps
    new BootstrapRunner(classSearch, injector).runAll();
    log.info("Completed bootstrap");
    // run the server
    final ImmutableServerConfig serverConfig = Optional.ofNullable(configContext.getAsConfigBean("server", ImmutableServerConfig.class)).orElseGet(() -> ImmutableServerConfig.builder().port(3000).build());
    new AuthGuardServer(injector).start(Javalin.create(config -> {
        config.enforceSsl = serverConfig.enforceSsl();
        config.server(() -> new JettyServerProvider(serverConfig).get());
        config.accessManager(new RolesAccessManager());
    }));
}
Also used : com.nexblocks.authguard.bindings(com.nexblocks.authguard.bindings) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) BootstrapRunner(com.nexblocks.authguard.bootstrap.BootstrapRunner) JettyServerProvider(com.nexblocks.authguard.rest.server.JettyServerProvider) MappersBinder(com.nexblocks.authguard.rest.bindings.MappersBinder) Javalin(io.javalin.Javalin) AuthGuardServer(com.nexblocks.authguard.rest.server.AuthGuardServer) ClassSearch(com.nexblocks.authguard.injection.ClassSearch) Injector(com.google.inject.Injector) RolesAccessManager(com.nexblocks.authguard.rest.access.RolesAccessManager) Guice(com.google.inject.Guice) Optional(java.util.Optional) ConfigContext(com.nexblocks.authguard.config.ConfigContext) ImmutableServerConfig(com.nexblocks.authguard.rest.config.ImmutableServerConfig) AuthGuardServer(com.nexblocks.authguard.rest.server.AuthGuardServer) MappersBinder(com.nexblocks.authguard.rest.bindings.MappersBinder) RolesAccessManager(com.nexblocks.authguard.rest.access.RolesAccessManager) JettyServerProvider(com.nexblocks.authguard.rest.server.JettyServerProvider) Injector(com.google.inject.Injector) ImmutableServerConfig(com.nexblocks.authguard.rest.config.ImmutableServerConfig) ClassSearch(com.nexblocks.authguard.injection.ClassSearch) BootstrapRunner(com.nexblocks.authguard.bootstrap.BootstrapRunner)

Example 3 with ImmutableServerConfig

use of com.nexblocks.authguard.rest.config.ImmutableServerConfig in project AuthGuard by AuthGuard.

the class JettyServerProviderTest method getSslEnabledNoKeystore.

@Test
void getSslEnabledNoKeystore() {
    final ImmutableServerConfig config = ImmutableServerConfig.builder().enableSsl(true).build();
    final JettyServerProvider provider = new JettyServerProvider(config);
    assertThatThrownBy(provider::get).isInstanceOf(InitializationException.class);
}
Also used : ImmutableServerConfig(com.nexblocks.authguard.rest.config.ImmutableServerConfig) Test(org.junit.jupiter.api.Test)

Example 4 with ImmutableServerConfig

use of com.nexblocks.authguard.rest.config.ImmutableServerConfig in project AuthGuard by AuthGuard.

the class JettyServerProviderTest method getSslEnabled.

@Test
void getSslEnabled() {
    final ImmutableServerConfig config = ImmutableServerConfig.builder().enableSsl(true).keystorePath("src/test/resources/keystore").keystorePassword(// taken from the Jetty example
    "OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4").build();
    final JettyServerProvider provider = new JettyServerProvider(config);
    final Server server = provider.get();
    assertThat(server.getConnectors()).anyMatch(connector -> connector.getProtocols().stream().anyMatch("ssl"::equals));
}
Also used : Server(org.eclipse.jetty.server.Server) ImmutableServerConfig(com.nexblocks.authguard.rest.config.ImmutableServerConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableServerConfig (com.nexblocks.authguard.rest.config.ImmutableServerConfig)4 Test (org.junit.jupiter.api.Test)3 Server (org.eclipse.jetty.server.Server)2 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 com.nexblocks.authguard.bindings (com.nexblocks.authguard.bindings)1 BootstrapRunner (com.nexblocks.authguard.bootstrap.BootstrapRunner)1 ConfigContext (com.nexblocks.authguard.config.ConfigContext)1 ClassSearch (com.nexblocks.authguard.injection.ClassSearch)1 RolesAccessManager (com.nexblocks.authguard.rest.access.RolesAccessManager)1 MappersBinder (com.nexblocks.authguard.rest.bindings.MappersBinder)1 AuthGuardServer (com.nexblocks.authguard.rest.server.AuthGuardServer)1 JettyServerProvider (com.nexblocks.authguard.rest.server.JettyServerProvider)1 Javalin (io.javalin.Javalin)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1