use of io.undertow.security.handlers.SecurityInitialHandler in project droolsjbpm-integration by kiegroup.
the class KieServerRouter method start.
public void start(String host, Integer port, Integer portTls, ConfigurationListener... listeners) {
System.setProperty(ROUTER_HOST, host);
System.setProperty(ROUTER_PORT, port.toString());
System.setProperty(ROUTER_PORT_TLS, portTls.toString());
boolean isHttpEnabled = environment().isHttpEnabled();
configurationManager = new ConfigurationManager(environment(), repository, executorService);
Configuration configuration = configurationManager.getConfiguration();
for (ConfigurationListener listener : listeners) {
configurationManager.getConfiguration().addListener(listener);
}
// setup config file watcher to be updated when changes are discovered
if (environment().isConfigFileWatcherEnabled()) {
configurationManager.startWatcher();
}
AdminHttpHandler adminHandler = new AdminHttpHandler(configurationManager);
final KieServerProxyClient proxyClient = new KieServerProxyClient(configurationManager);
Map<String, List<String>> perContainer = configuration.getHostsPerContainer();
for (Map.Entry<String, List<String>> entry : perContainer.entrySet()) {
Set<String> uniqueUrls = new LinkedHashSet<>(entry.getValue());
uniqueUrls.forEach(url -> {
proxyClient.addContainer(entry.getKey(), URI.create(url));
});
}
HttpHandler notFoundHandler = ResponseCodeHandler.HANDLE_404;
ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(proxyClient).setMaxRequestTime(-1).setRewriteHostHeader(true).setReuseXForwarded(false).setNext(new OptionsHttpHandler(notFoundHandler, configurationManager)).build();
PathHandler pathHandler = Handlers.path(proxyHandler);
pathHandler.addPrefixPath("/queries/definitions", new QueriesDataHttpHandler(notFoundHandler, configurationManager));
pathHandler.addPrefixPath("/queries", new QueriesHttpHandler(notFoundHandler, configurationManager));
pathHandler.addPrefixPath("/jobs", new JobsHttpHandler(proxyHandler, configurationManager));
pathHandler.addPrefixPath("/documents", new DocumentsHttpHandler(notFoundHandler, configurationManager));
pathHandler.addExactPath("/containers", new ContainersHttpHandler(notFoundHandler, configurationManager));
if (environment().isManagementSecured()) {
IdentityManager idm = getIdentityService();
HttpHandler authenticationCallHandler = new AuthenticationCallHandler(adminHandler);
HttpHandler authenticationConstraintHandler = new AuthenticationConstraintHandler(authenticationCallHandler);
List<AuthenticationMechanism> mechanisms = Collections.singletonList(new BasicAuthenticationMechanism("KieServerRouterRealm"));
AuthenticationMechanismsHandler authenticationMechanismsHandler = new AuthenticationMechanismsHandler(authenticationConstraintHandler, mechanisms);
SecurityInitialHandler securityInitialHandler = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, idm, authenticationMechanismsHandler);
pathHandler.addPrefixPath("/mgmt", securityInitialHandler);
} else {
pathHandler.addPrefixPath("/mgmt", adminHandler);
}
pathHandler.addExactPath("/", new KieServerInfoHandler(environment()));
HttpHandler blockingHandler = new BlockingHandler(pathHandler);
// main server configuration
Undertow.Builder undertowBuilder = Undertow.builder();
if (isHttpEnabled) {
undertowBuilder.addHttpListener(port, host);
}
if (environment().isTlsEnabled()) {
SSLContext sslContext = SSLContextBuilder.builder().setKeyStorePath(environment().getKeystorePath()).setKeyStorePassword(environment().getKeystorePassword()).setKeyAlias(environment().getKeystoreKey()).build();
undertowBuilder = undertowBuilder.addHttpsListener(portTls, host, sslContext);
}
if (!isHttpEnabled && !environment().isTlsEnabled()) {
throw new IllegalStateException("HTTP listener was disabled (by setting HTTP port to 0 or lower ) and TLS wasn't configured, no listener is available to handle requests");
}
server = undertowBuilder.setHandler(blockingHandler).build();
server.start();
if (log.isInfoEnabled()) {
logServerInfo("KieServerRouter started on: ", host, port, portTls);
}
connectToController(configurationManager);
}
use of io.undertow.security.handlers.SecurityInitialHandler in project hermes by allegro.
the class HandlersChainFactory method createAuthenticationHandlersChain.
private HttpHandler createAuthenticationHandlersChain(HttpHandler next, AuthenticationConfiguration authConfig) {
HttpHandler authenticationCallHandler = new AuthenticationCallHandler(next);
HttpHandler constraintHandler = new AuthenticationPredicateAwareConstraintHandler(authenticationCallHandler, authConfig.getIsAuthenticationRequiredPredicate());
HttpHandler mechanismsHandler = new AuthenticationMechanismsHandler(constraintHandler, authConfig.getAuthMechanisms());
AuthenticationMode authenticationMode = AuthenticationMode.valueOf(configFactory.getStringProperty(Configs.FRONTEND_AUTHENTICATION_MODE).toUpperCase());
return new SecurityInitialHandler(authenticationMode, authConfig.getIdentityManager(), mechanismsHandler);
}
use of io.undertow.security.handlers.SecurityInitialHandler in project light-oauth2 by networknt.
the class PathHandlerProvider method addFormSecurity.
private static HttpHandler addFormSecurity(final HttpHandler toWrap, final IdentityManager identityManager) {
HttpHandler handler = toWrap;
handler = new AuthenticationCallHandler(handler);
handler = new AuthenticationConstraintHandler(handler);
final List<AuthenticationMechanism> mechanisms = new ArrayList<>();
mechanisms.add(new CachedAuthenticatedSessionMechanism());
mechanisms.add(new FormAuthenticationMechanism("oauth2", "/login", "/error", "/oauth2/authorize"));
handler = new AuthenticationMechanismsHandler(handler, mechanisms);
handler = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, handler);
handler = new SessionAttachmentHandler(handler, new InMemorySessionManager("oauth2"), new SessionCookieConfig());
return handler;
}
use of io.undertow.security.handlers.SecurityInitialHandler in project light-oauth2 by networknt.
the class PathHandlerProvider method addBasicSecurity.
private static HttpHandler addBasicSecurity(final HttpHandler toWrap, final IdentityManager identityManager) {
HttpHandler handler = toWrap;
handler = new AuthenticationCallHandler(handler);
handler = new AuthenticationConstraintHandler(handler);
final List<AuthenticationMechanism> mechanisms = Collections.singletonList(new BasicAuthenticationMechanism("oauth2"));
handler = new AuthenticationMechanismsHandler(handler, mechanisms);
handler = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, handler);
return handler;
}
use of io.undertow.security.handlers.SecurityInitialHandler in project mangooio by svenkubiak.
the class RequestUtils method wrapBasicAuthentication.
/**
* Adds a Wrapper to the handler when the request requires authentication
*
* @param httpHandler The Handler to wrap
* @param username The username to use
* @param password The password to use
* @return An HttpHandler wrapped through BasicAuthentication
*/
public static HttpHandler wrapBasicAuthentication(HttpHandler httpHandler, String username, String password) {
Objects.requireNonNull(httpHandler, Required.HTTP_HANDLER.toString());
Objects.requireNonNull(username, Required.USERNAME.toString());
Objects.requireNonNull(password, Required.PASSWORD.toString());
HttpHandler wrap = new AuthenticationCallHandler(httpHandler);
wrap = new AuthenticationConstraintHandler(wrap);
wrap = new AuthenticationMechanismsHandler(wrap, Collections.singletonList(new BasicAuthenticationMechanism("Authentication required")));
return new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, new Identity(username, password), wrap);
}
Aggregations