Uploaded image for project: 'Keycloak'
  1. Keycloak
  2. KEYCLOAK-5098

Spring Boot 2 Adapter

    XMLWordPrintable

    Details

    • Sprint:
      Keycloak Sprint 2, Keycloak Sprint 3, Keycloak Sprint 4, Keycloak Sprint 5
    • Story Points:
      13
    • Docs QE Status:
      NEW
    • QE Status:
      NEW

      Description

      If you try to use the spring boot 1.x adapter in a spring boot 2 app you get a NoClassDefFoundError for EmbeddedServletContainerCustomizer. To use spring boot 2 a separate adapter would be required. The approach taken in the KeycloakAutoConfiguration class needs a bit of tweaking for spring boot 2 (just a mapping from the boot 1 set of classes to the boot 2 set of classes, no logic changes) so the new adapter would need to have a different implementation.

      The getKeycloakContainerCustomizer method of KeycloakAutoConfiguration.java in the spring boot 1 adapter returns a EmbeddedServletContainerCustomizer (https://github.com/keycloak/keycloak/blob/master/adapters/oidc/spring-boot/src/main/java/org/keycloak/adapters/springboot/KeycloakAutoConfiguration.java). For a spring boot 2 adapter the equivalent implementation would be be this:

      @Bean
      public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> getKeycloakContainerCustomizer() {
      return new WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>() {
      @Override
      public void customize(ConfigurableServletWebServerFactory configurableServletWebServerFactory) {
      if(configurableServletWebServerFactory instanceof TomcatServletWebServerFactory)

      { TomcatServletWebServerFactory container = (TomcatServletWebServerFactory)configurableServletWebServerFactory; container.addContextValves(new KeycloakAuthenticatorValve()); container.addContextCustomizers(tomcatKeycloakContextCustomizer()); }

      else if (configurableServletWebServerFactory instanceof UndertowServletWebServerFactory)

      { UndertowServletWebServerFactory container = (UndertowServletWebServerFactory)configurableServletWebServerFactory; container.addDeploymentInfoCustomizers(undertowKeycloakContextCustomizer()); }

      else if (configurableServletWebServerFactory instanceof JettyServletWebServerFactory)

      { JettyServletWebServerFactory container = (JettyServletWebServerFactory)configurableServletWebServerFactory; container.addServerCustomizers(jettyKeycloakServerCustomizer()); }

      }

      };
      }

      Otherwise the spring boot 2 adapter would be a copy of the existing spring boot adapter (https://github.com/keycloak/keycloak/tree/master/adapters/oidc/spring-boot) but with a reference to a version 2 spring boot dependency. Currently only milestones are available so the spring boot milestone repository would have to be added.

        Attachments

          Activity

            People

            Assignee:
            sebastienblanc Sebastien Blanc
            Reporter:
            ryandawson Ryan Dawson (Inactive)
            Votes:
            6 Vote for this issue
            Watchers:
            13 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: