Search in sources :

Example 16 with AuthenticationMechanism

use of io.undertow.security.api.AuthenticationMechanism in project openremote by openremote.

the class SimpleKeycloakServletExtension method handleDeployment.

@Override
@SuppressWarnings("UseSpecificCatch")
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
    servletContext.setAttribute(AdapterDeploymentContext.class.getName(), deploymentContext);
    UndertowUserSessionManagement userSessionManagement = new UndertowUserSessionManagement();
    final NodesRegistrationManagement nodesRegistrationManagement = new NodesRegistrationManagement();
    final ServletKeycloakAuthMech mech = createAuthenticationMechanism(deploymentInfo, deploymentContext, userSessionManagement, nodesRegistrationManagement);
    UndertowAuthenticatedActionsHandler.Wrapper actions = new UndertowAuthenticatedActionsHandler.Wrapper(deploymentContext);
    // setup handlers
    deploymentInfo.addOuterHandlerChainWrapper(new ServletPreAuthActionsHandler.Wrapper(deploymentContext, userSessionManagement));
    deploymentInfo.addAuthenticationMechanism(AUTH_MECHANISM, new AuthenticationMechanismFactory() {

        @Override
        public AuthenticationMechanism create(String s, IdentityManager identityManager, FormParserFactory formParserFactory, Map<String, String> stringStringMap) {
            return mech;
        }
    });
    // authentication
    // handles authenticated actions and cors.
    deploymentInfo.addInnerHandlerChainWrapper(actions);
    deploymentInfo.setIdentityManager(new IdentityManager() {

        @Override
        public Account verify(Account account) {
            return account;
        }

        @Override
        public Account verify(String id, Credential credential) {
            throw new IllegalStateException("Should never be called in Keycloak flow");
        }

        @Override
        public Account verify(Credential credential) {
            throw new IllegalStateException("Should never be called in Keycloak flow");
        }
    });
    ServletSessionConfig cookieConfig = deploymentInfo.getServletSessionConfig();
    if (cookieConfig == null) {
        cookieConfig = new ServletSessionConfig();
    }
    if (cookieConfig.getPath() == null) {
        log.debug("Setting jsession cookie path to: " + deploymentInfo.getContextPath());
        cookieConfig.setPath(deploymentInfo.getContextPath());
        deploymentInfo.setServletSessionConfig(cookieConfig);
    }
    ChangeSessionId.turnOffChangeSessionIdOnLogin(deploymentInfo);
    deploymentInfo.addListener(new ListenerInfo(UndertowNodesRegistrationManagementWrapper.class, (InstanceFactory<UndertowNodesRegistrationManagementWrapper>) () -> {
        UndertowNodesRegistrationManagementWrapper listener = new UndertowNodesRegistrationManagementWrapper(nodesRegistrationManagement);
        return new ImmediateInstanceHandle<>(listener);
    }));
}
Also used : Account(io.undertow.security.idm.Account) IdentityManager(io.undertow.security.idm.IdentityManager) Credential(io.undertow.security.idm.Credential) NodesRegistrationManagement(org.keycloak.adapters.NodesRegistrationManagement) AuthenticationMechanism(io.undertow.security.api.AuthenticationMechanism) AdapterDeploymentContext(org.keycloak.adapters.AdapterDeploymentContext) FormParserFactory(io.undertow.server.handlers.form.FormParserFactory) ImmediateInstanceHandle(io.undertow.servlet.util.ImmediateInstanceHandle) AuthenticationMechanismFactory(io.undertow.security.api.AuthenticationMechanismFactory)

Aggregations

AuthenticationMechanism (io.undertow.security.api.AuthenticationMechanism)16 AuthenticationMechanismsHandler (io.undertow.security.handlers.AuthenticationMechanismsHandler)12 SecurityInitialHandler (io.undertow.security.handlers.SecurityInitialHandler)12 HttpHandler (io.undertow.server.HttpHandler)12 AuthenticationCallHandler (io.undertow.security.handlers.AuthenticationCallHandler)11 AuthenticationConstraintHandler (io.undertow.security.handlers.AuthenticationConstraintHandler)11 BasicAuthenticationMechanism (io.undertow.security.impl.BasicAuthenticationMechanism)10 DigestAuthenticationMechanism (io.undertow.security.impl.DigestAuthenticationMechanism)5 CachedAuthenticatedSessionMechanism (io.undertow.security.impl.CachedAuthenticatedSessionMechanism)4 ArrayList (java.util.ArrayList)4 NotificationReceiver (io.undertow.security.api.NotificationReceiver)3 NotificationReceiverHandler (io.undertow.security.handlers.NotificationReceiverHandler)3 IdentityManager (io.undertow.security.idm.IdentityManager)3 DigestQop (io.undertow.security.impl.DigestQop)3 SimpleNonceManager (io.undertow.security.impl.SimpleNonceManager)3 HttpServerExchange (io.undertow.server.HttpServerExchange)3 AuthenticationMechanismFactory (io.undertow.security.api.AuthenticationMechanismFactory)2 AuthenticationMode (io.undertow.security.api.AuthenticationMode)2 DigestAlgorithm (io.undertow.security.idm.DigestAlgorithm)2 FormAuthenticationMechanism (io.undertow.security.impl.FormAuthenticationMechanism)2