Search in sources :

Example 1 with InMemorySingleSignOnManager

use of io.undertow.security.impl.InMemorySingleSignOnManager 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 2 with InMemorySingleSignOnManager

use of io.undertow.security.impl.InMemorySingleSignOnManager in project wildfly by wildfly.

the class HostSingleSignOnServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    PathAddress hostAddress = address.getParent();
    PathAddress serverAddress = hostAddress.getParent();
    String hostName = hostAddress.getLastElement().getValue();
    String serverName = serverAddress.getLastElement().getValue();
    String domain = ModelNodes.optionalString(DOMAIN.resolveModelAttribute(context, model)).orElse(null);
    String path = PATH.resolveModelAttribute(context, model).asString();
    boolean secure = SECURE.resolveModelAttribute(context, model).asBoolean();
    boolean httpOnly = HTTP_ONLY.resolveModelAttribute(context, model).asBoolean();
    String cookieName = COOKIE_NAME.resolveModelAttribute(context, model).asString();
    ServiceName serviceName = UndertowService.ssoServiceName(serverName, hostName);
    ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, hostName);
    ServiceTarget target = context.getServiceTarget();
    ServiceName managerServiceName = serviceName.append("manager");
    if (DistributableHostSingleSignOnManagerBuilder.INSTANCE.isPresent()) {
        DistributableHostSingleSignOnManagerBuilder builder = DistributableHostSingleSignOnManagerBuilder.INSTANCE.get();
        builder.build(target, managerServiceName, context.getCapabilityServiceSupport(), serverName, hostName).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    } else {
        target.addService(managerServiceName, new ValueService<>(new ImmediateValue<>(new InMemorySingleSignOnManager()))).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    }
    SingleSignOnService service = new SingleSignOnService(domain, path, httpOnly, secure, cookieName);
    target.addService(serviceName, service).addDependency(virtualHostServiceName, Host.class, service.getHost()).addDependency(managerServiceName, SingleSignOnManager.class, service.getSingleSignOnSessionManager()).setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : InMemorySingleSignOnManager(io.undertow.security.impl.InMemorySingleSignOnManager) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) DistributableHostSingleSignOnManagerBuilder(org.wildfly.extension.undertow.security.sso.DistributableHostSingleSignOnManagerBuilder) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

InMemorySingleSignOnManager (io.undertow.security.impl.InMemorySingleSignOnManager)2 AuthenticationMechanism (io.undertow.security.api.AuthenticationMechanism)1 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 AuthenticationCallHandler (io.undertow.security.handlers.AuthenticationCallHandler)1 AuthenticationConstraintHandler (io.undertow.security.handlers.AuthenticationConstraintHandler)1 AuthenticationMechanismsHandler (io.undertow.security.handlers.AuthenticationMechanismsHandler)1 NotificationReceiverHandler (io.undertow.security.handlers.NotificationReceiverHandler)1 SecurityInitialHandler (io.undertow.security.handlers.SecurityInitialHandler)1 BasicAuthenticationMechanism (io.undertow.security.impl.BasicAuthenticationMechanism)1 FormAuthenticationMechanism (io.undertow.security.impl.FormAuthenticationMechanism)1 SingleSignOnAuthenticationMechanism (io.undertow.security.impl.SingleSignOnAuthenticationMechanism)1 HttpHandler (io.undertow.server.HttpHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)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 ArrayList (java.util.ArrayList)1 PathAddress (org.jboss.as.controller.PathAddress)1 ServiceName (org.jboss.msc.service.ServiceName)1