boolean getBoolean(String path, boolean defaultValue);
@Override public boolean getBoolean(String path, boolean defaultValue) { final String value = getTags().get(path); if ( value == null ) return fallback.getBoolean(path, defaultValue); return Boolean.valueOf(value); }
void setupHttp2( Config config, Undertow.Builder server ){ if ( config.getBoolean("http2-mode") ) { log.info( "Enabling HTTP/2" ); server.setServerOption( ENABLE_HTTP2, true ); } } }
@Override public Config enrich(Config originalConfig) { if ( !originalConfig.getBoolean( "server.aws.ec2.tag-as-config-enabled" ) ) return originalConfig; log.info( "Using the tags associated with this EC2 instance as configuration entries." ); return new AmazonEC2Config( this::getInstanceTagsAsMap, originalConfig ); }
@Override public void load( final Builder server, final DeploymentContext context ) throws IOException { if ( !config.getBoolean( "server.health-check.enabled" ) ) return; if ( healthChecks.isEmpty() ) throw new UnsupportedOperationException( "The health-check module is enabled, but no HealthCheck found on Class Path." ); deployHealthChecks(); deployHealthCheckEndpoint( context ); }
@PostConstruct public void loadConfig(){ List<Config> configs = config.getConfigList("server.smart-routes.rewrite"); rewriteRoutes = configs.stream().map( c-> SmartRouteRule.from(c) ).collect(Collectors.toList()); configs = config.getConfigList("server.smart-routes.reverse"); reverseRoutes = configs.stream().map( c-> SmartRouteRule.from(c) ).collect(Collectors.toList()); isHttp2EnabledForProxy = config.getBoolean( "server.smart-routes.reverse-with-http2", true ); }
void loadJvmMetrics(){ final Config config = this.config.getConfig(JVM_METRICS); for (String key : config.getKeys()) { if ( config.getBoolean( key ) ) { jvmMetrics.get(key).accept(key); } } }
@Override public void load(Undertow.Builder server, DeploymentContext context) { Config httpConfig = config.getConfig("server.http"); if ( httpConfig.getBoolean("enabled") ) loadHttpListener( httpConfig, server ); }
@PostConstruct @SuppressWarnings("unchecked") public void loadConfig(){ metricConfiguration = new MetricConfiguration( (Class<? extends ReporterConfiguration>) config.getClass( REPORTER_CONFIGURATION_CLASS ), (Class<? extends MetricRegistryListener>) config.getClass( REPORTER_LISTENER_CLASS ), (Class<? extends MetricFilter>) config.getClass( REPORTER_FILTER_CLASS ), (Class<? extends MetricStore>) config.getClass( REPORTER_STORE_CLASS ), config.getBoolean( SHOULD_STORE_INDIVIDUAL_WEB_METRICS ), config.getBoolean( SHOULD_STORE_SUMMARIZED_WEB_METRICS ), config.getBoolean( IS_MODULE_ENABLED ), config.getLong( REPORTER_INTERVAL ), cdi ); }
void deployHttpToHttps(Config config, DeploymentContext context) { if ( config.getBoolean("redirect-http-to-https") ) { log.info("Automatically redirecting HTTP requests to HTTPS"); context.rootHandler(new AutoHTTPSRedirectHandler(context.rootHandler())); } }
@PostConstruct public void configureEndpointContext(){ isRestEnabled = config.getBoolean( "server.uworkers.rest-api.enabled" ); restApiPrefix = config.getString( "server.uworkers.rest-api.base-endpoint" ); maxTaskPoolSize = config.getInteger( "server.uworkers.rest-api.max-task-pool-size" ); defaultEndpointConfig = createEndpointConfig( "default" ); }
CORSConfig loadCorsConfig(){ final List<String> allowedOrigins = config.getStringList("server.smart-routes.cors.allowed-origins"); return new CORSConfig( config.getBoolean("server.smart-routes.cors.always-allow-origin"), config.getBoolean("server.smart-routes.cors.always-allow-credentials"), asSet(config.getStringList("server.smart-routes.cors.allowed-methods")), asSet( allowedOrigins ), asMatcherSet( allowedOrigins )); }
private void configureGracefulShutdown( final DeploymentContext context ){ final boolean isGracefulShutdownEnabled = config.getBoolean("server.modules.enable-graceful-shutdown"); if ( isGracefulShutdownEnabled ) { gracefulShutdownHandler = new GracefulShutdownHandler( context.rootHandler() ); context.rootHandler( gracefulShutdownHandler ); } }
@Override public void load(Undertow.Builder server, DeploymentContext context) throws IOException { if ( !config.getBoolean("server.smart-routes.cors.enabled") ) return; final CORSConfig corsConfig = loadCorsConfig(); final HttpHandler rootHandler = context.rootHandler(); final CORSFilterHttpHandler httpHandler = new CORSFilterHttpHandler( corsConfig, rootHandler, notFoundHandler); log.info( "Deploying CORS Smart Route: " + corsConfig ); context.rootHandler( httpHandler ); }
private AuthenticationRule convertConfToRule( final Config ruleConf ) { final List<String> defaultIdentityManagersAndAuthMechanisms = Collections.singletonList("default"); final List<String> defaultExcludedPatterns = authConfig.getStringList("default-excluded-patterns"); final List<IdentityManager> identityManagers = getIdentityManagerFor( ruleConf, defaultIdentityManagersAndAuthMechanisms ); final List<AuthenticationMechanism> mechanisms = extractNeededMechanisms( ruleConf.getStringList("auth-mechanisms", defaultIdentityManagersAndAuthMechanisms) ); final List<String> excludedPatterns = ruleConf.getStringList("exclude-patterns", new ArrayList<>()); final boolean authenticationRequired = ruleConf.getBoolean( "authentication-required", true ); excludedPatterns.addAll( defaultExcludedPatterns ); return new AuthenticationRule( ruleConf.getString( "pattern" ), identityManagers, mechanisms, ruleConf.getStringList( "expected-roles", Collections.emptyList() ), excludedPatterns, authenticationRequired ); }
@Override public void load(Undertow.Builder server, DeploymentContext context) throws IOException { Config httpConfig = config.getConfig("server.https"); if ( httpConfig.getBoolean("enabled") ) { loadHttpsListener(httpConfig, server); deployHttpToHttps(httpConfig, context); setupHttp2( httpConfig, server ); } }
@Override public void load(Undertow.Builder server, DeploymentContext context) throws IOException { final Config staticConfig = config.getConfig("server.static"); if ( staticConfig.getBoolean("enabled") ) { deployWelcomeFile(staticConfig, context); deployDefaultStaticRouting(staticConfig, context); deployWebJarStaticRouting(staticConfig, context); } }
/** * Create a SSLContext. * * @return * @throws IOException */ public SSLContext createSSLContext() throws IOException { if ( !httpsConfig.getBoolean("enabled") ) return null; return createSSLContext( httpsConfig.getString("keystore"), httpsConfig.getString("truststore"), httpsConfig.getString("password") ); }
@Override public void load( Builder server, DeploymentContext context ) throws IOException { final boolean defaultEnabledState = config.getBoolean( "server.smart-routes.auth.enabled" ); if ( !isEmpty( authenticationEndpoints.getLoginPage() ) && config.getBoolean( "server.smart-routes.auth.login-form-enabled", defaultEnabledState ) ) context.register( authenticationEndpoints.getLoginPage(), "GET", loginHttpHandler ); if ( !isEmpty( authenticationEndpoints.getLogoutUrl() ) && config.getBoolean( "server.smart-routes.auth.logout-url-enabled", defaultEnabledState ) ) { context.register( authenticationEndpoints.getLogoutUrl(), authenticationEndpoints.getLogoutUrlMethod(), logoutHttpHandler ); } if ( !isEmpty( authenticationEndpoints.getCallbackUrl() ) && config.getBoolean( "server.smart-routes.auth.callback-url-enabled", defaultEnabledState )) { context.register( authenticationEndpoints.getCallbackUrl(), authenticationEndpoints.getCallbackUrlMethod(), authCallbackVerificationHttpHandler ); } }
private void deployWebJarStaticRouting(Config staticConfig, DeploymentContext context) { if ( staticConfig.getBoolean("webjar-enabled" ) ) { final String urlPrefix = staticConfig.getString("webjar-url-prefix").replaceFirst( "/$", "" ); log.info( "Enabling static routing for webjars at '" + urlPrefix + "'" ); final String webJarInternalLocation = staticConfig.getString("webjar-location", DEFAULT_WEBJAR_LOCATION); final ResourceManager resourceManager = SystemResource.loadResourceManagerFor( webJarInternalLocation ); final HttpHandler webjarHandler = new WebJarHttpHandler( new ResourceHandler(resourceManager, new WebJarNotFound( context.fallbackHandler() ) ), URLMatcher.compile( urlPrefix + "/{path}" ), context.fallbackHandler()); context.fallbackHandler( webjarHandler ); } }