Search in sources :

Example 1 with AuthenticationConstraintHandler

use of io.undertow.security.handlers.AuthenticationConstraintHandler in project undertow by undertow-io.

the class AuthenticationTestBase method setAuthenticationChain.

@Before
public void setAuthenticationChain() {
    List<AuthenticationMechanism> testMechanisms = getTestMechanisms();
    if (testMechanisms == null) {
        return;
    }
    HttpHandler current = new ResponseHandler();
    current = new AuthenticationCallHandler(current);
    current = new AuthenticationConstraintHandler(current);
    current = new AuthenticationMechanismsHandler(current, testMechanisms);
    // Ensure empty on initialisation.
    auditReceiver.takeNotifications();
    current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
    if (cachingRequired()) {
        current = new CachedAuthenticatedSessionHandler(current);
    }
    current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
    setRootHandler(current);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) CachedAuthenticatedSessionHandler(io.undertow.security.handlers.CachedAuthenticatedSessionHandler) NotificationReceiverHandler(io.undertow.security.handlers.NotificationReceiverHandler) SecurityInitialHandler(io.undertow.security.handlers.SecurityInitialHandler) AuthenticationMechanismsHandler(io.undertow.security.handlers.AuthenticationMechanismsHandler) NotificationReceiver(io.undertow.security.api.NotificationReceiver) AuthenticationMechanism(io.undertow.security.api.AuthenticationMechanism) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) Before(org.junit.Before)

Example 2 with AuthenticationConstraintHandler

use of io.undertow.security.handlers.AuthenticationConstraintHandler in project syncany by syncany.

the class WebServer method addSecurity.

private static HttpHandler addSecurity(final HttpHandler toWrap, IdentityManager identityManager) {
    List<AuthenticationMechanism> mechanisms = Collections.<AuthenticationMechanism>singletonList(new BasicAuthenticationMechanism("Syncany"));
    HttpHandler handler = toWrap;
    handler = new AuthenticationCallHandler(handler);
    handler = new AuthenticationConstraintHandler(handler);
    handler = new AuthenticationMechanismsHandler(handler, mechanisms);
    handler = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, handler);
    return handler;
}
Also used : HttpHandler(io.undertow.server.HttpHandler) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) SecurityInitialHandler(io.undertow.security.handlers.SecurityInitialHandler) AuthenticationMechanismsHandler(io.undertow.security.handlers.AuthenticationMechanismsHandler) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism) AuthenticationMechanism(io.undertow.security.api.AuthenticationMechanism) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism)

Example 3 with AuthenticationConstraintHandler

use of io.undertow.security.handlers.AuthenticationConstraintHandler in project undertow by undertow-io.

the class SsoTestCase method setup.

@BeforeClass
public static void setup() {
    final SingleSignOnAuthenticationMechanism sso = new SingleSignOnAuthenticationMechanism(new InMemorySingleSignOnManager());
    final PathHandler path = new PathHandler();
    HttpHandler current = new ResponseHandler();
    current = new AuthenticationCallHandler(current);
    current = new AuthenticationConstraintHandler(current);
    List<AuthenticationMechanism> mechs = new ArrayList<>();
    mechs.add(sso);
    mechs.add(new BasicAuthenticationMechanism("Test Realm"));
    current = new AuthenticationMechanismsHandler(current, mechs);
    current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
    current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
    path.addPrefixPath("/test1", current);
    current = new ResponseHandler();
    current = new AuthenticationCallHandler(current);
    current = new AuthenticationConstraintHandler(current);
    mechs = new ArrayList<>();
    mechs.add(sso);
    mechs.add(new FormAuthenticationMechanism("form", "/login", "/error"));
    current = new AuthenticationMechanismsHandler(current, mechs);
    current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
    current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
    path.addPrefixPath("/test2", current);
    path.addPrefixPath("/login", new ResponseCodeHandler(StatusCodes.UNAUTHORIZED));
    DefaultServer.setRootHandler(new SessionAttachmentHandler(path, new InMemorySessionManager(""), new SessionCookieConfig()));
}
Also used : HttpHandler(io.undertow.server.HttpHandler) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) FormAuthenticationMechanism(io.undertow.security.impl.FormAuthenticationMechanism) SingleSignOnAuthenticationMechanism(io.undertow.security.impl.SingleSignOnAuthenticationMechanism) SingleSignOnAuthenticationMechanism(io.undertow.security.impl.SingleSignOnAuthenticationMechanism) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism) AuthenticationMechanism(io.undertow.security.api.AuthenticationMechanism) FormAuthenticationMechanism(io.undertow.security.impl.FormAuthenticationMechanism) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) ResponseCodeHandler(io.undertow.server.handlers.ResponseCodeHandler) SessionAttachmentHandler(io.undertow.server.session.SessionAttachmentHandler) InMemorySingleSignOnManager(io.undertow.security.impl.InMemorySingleSignOnManager) NotificationReceiverHandler(io.undertow.security.handlers.NotificationReceiverHandler) SecurityInitialHandler(io.undertow.security.handlers.SecurityInitialHandler) AuthenticationMechanismsHandler(io.undertow.security.handlers.AuthenticationMechanismsHandler) NotificationReceiver(io.undertow.security.api.NotificationReceiver) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) SessionCookieConfig(io.undertow.server.session.SessionCookieConfig) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism) InMemorySessionManager(io.undertow.server.session.InMemorySessionManager) BeforeClass(org.junit.BeforeClass)

Example 4 with AuthenticationConstraintHandler

use of io.undertow.security.handlers.AuthenticationConstraintHandler in project undertow by undertow-io.

the class BasicAuthServer method addSecurity.

private static HttpHandler addSecurity(final HttpHandler toWrap, final IdentityManager identityManager) {
    HttpHandler handler = toWrap;
    handler = new AuthenticationCallHandler(handler);
    handler = new AuthenticationConstraintHandler(handler);
    final List<AuthenticationMechanism> mechanisms = Collections.<AuthenticationMechanism>singletonList(new BasicAuthenticationMechanism("My Realm"));
    handler = new AuthenticationMechanismsHandler(handler, mechanisms);
    handler = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, handler);
    return handler;
}
Also used : HttpHandler(io.undertow.server.HttpHandler) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) SecurityInitialHandler(io.undertow.security.handlers.SecurityInitialHandler) AuthenticationMechanismsHandler(io.undertow.security.handlers.AuthenticationMechanismsHandler) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism) AuthenticationMechanism(io.undertow.security.api.AuthenticationMechanism) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) BasicAuthenticationMechanism(io.undertow.security.impl.BasicAuthenticationMechanism)

Example 5 with AuthenticationConstraintHandler

use of io.undertow.security.handlers.AuthenticationConstraintHandler in project wildfly by wildfly.

the class HttpInvokerHostService method secureAccess.

private static HttpHandler secureAccess(HttpHandler domainHandler, final HttpAuthenticationFactory httpAuthenticationFactory) {
    domainHandler = new AuthenticationCallHandler(domainHandler);
    domainHandler = new AuthenticationConstraintHandler(domainHandler);
    Supplier<List<HttpServerAuthenticationMechanism>> mechanismSupplier = () -> httpAuthenticationFactory.getMechanismNames().stream().map(s -> {
        try {
            return httpAuthenticationFactory.createMechanism(s);
        } catch (Exception e) {
            return null;
        }
    }).collect(Collectors.toList());
    domainHandler = ElytronContextAssociationHandler.builder().setNext(domainHandler).setMechanismSupplier(mechanismSupplier).setHttpExchangeSupplier(h -> new ElytronHttpExchange(h) {

        @Override
        public void authenticationComplete(SecurityIdentity securityIdentity, String mechanismName) {
            super.authenticationComplete(securityIdentity, mechanismName);
            h.putAttachment(ElytronIdentityHandler.IDENTITY_KEY, securityIdentity);
        }
    }).build();
    return domainHandler;
}
Also used : Service(org.jboss.msc.service.Service) StopContext(org.jboss.msc.service.StopContext) HttpServerExchange(io.undertow.server.HttpServerExchange) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) AttachmentKey(io.undertow.util.AttachmentKey) StartContext(org.jboss.msc.service.StartContext) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) HttpAuthenticationFactory(org.wildfly.security.auth.server.HttpAuthenticationFactory) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) HttpHandler(io.undertow.server.HttpHandler) List(java.util.List) PathHandler(io.undertow.server.handlers.PathHandler) ElytronContextAssociationHandler(org.wildfly.elytron.web.undertow.server.ElytronContextAssociationHandler) HttpServerAuthenticationMechanism(org.wildfly.security.http.HttpServerAuthenticationMechanism) ElytronHttpExchange(org.wildfly.elytron.web.undertow.server.ElytronHttpExchange) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) InjectedValue(org.jboss.msc.value.InjectedValue) StartException(org.jboss.msc.service.StartException) ElytronHttpExchange(org.wildfly.elytron.web.undertow.server.ElytronHttpExchange) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) AuthenticationConstraintHandler(io.undertow.security.handlers.AuthenticationConstraintHandler) AuthenticationCallHandler(io.undertow.security.handlers.AuthenticationCallHandler) List(java.util.List) StartException(org.jboss.msc.service.StartException)

Aggregations

AuthenticationCallHandler (io.undertow.security.handlers.AuthenticationCallHandler)5 AuthenticationConstraintHandler (io.undertow.security.handlers.AuthenticationConstraintHandler)5 HttpHandler (io.undertow.server.HttpHandler)5 AuthenticationMechanism (io.undertow.security.api.AuthenticationMechanism)4 AuthenticationMechanismsHandler (io.undertow.security.handlers.AuthenticationMechanismsHandler)4 SecurityInitialHandler (io.undertow.security.handlers.SecurityInitialHandler)4 BasicAuthenticationMechanism (io.undertow.security.impl.BasicAuthenticationMechanism)3 NotificationReceiver (io.undertow.security.api.NotificationReceiver)2 NotificationReceiverHandler (io.undertow.security.handlers.NotificationReceiverHandler)2 PathHandler (io.undertow.server.handlers.PathHandler)2 CachedAuthenticatedSessionHandler (io.undertow.security.handlers.CachedAuthenticatedSessionHandler)1 FormAuthenticationMechanism (io.undertow.security.impl.FormAuthenticationMechanism)1 InMemorySingleSignOnManager (io.undertow.security.impl.InMemorySingleSignOnManager)1 SingleSignOnAuthenticationMechanism (io.undertow.security.impl.SingleSignOnAuthenticationMechanism)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 ResponseCodeHandler (io.undertow.server.handlers.ResponseCodeHandler)1 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)1 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)1 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)1 AttachmentKey (io.undertow.util.AttachmentKey)1