10

i face a problem when i using spring cloud gateway

is if any dependency call spring-boot-starter-tomcat directly or recursively

it will not work because it will start the embedded tomcat server not the netty server that spring cloud gateway use

i started to solve this problem by excluding this dependency

        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>

the spring cloud gateway worked successfully

but sometimes i want to use spring-cloud-starter-oauth2 to use @EnableOAuth2Sso

i start to use

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

at that time i face the big issue that throw exception saying

Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration ......

Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter

ashraf revo
  • 767
  • 2
  • 12
  • 24
  • Did you find the solution? I am facing same issue – Ankur Raiyani Jun 08 '19 at 08:11
  • I am also facing the issue, and after spending almost 2 days unable to find anything ... just wanted to know if the issue is addressed in someway and is there some reference document that can be referred. – Rajas Gujarathi Aug 29 '19 at 09:44

3 Answers3

3

As you've seen, the Spring cloud gateway uses the reactive model and is based on netty rather than tomcat. The reactive change is a major shift and currently isn't supported by Spring Security but work is in progress on it and you can track it at https://github.com/spring-cloud/spring-cloud-gateway/issues/179

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
  • I am also facing the issue, and after spending almost 2 days unable to find anything ... just wanted to know if the issue is addressed in someway and is there some reference document that can be referred – Rajas Gujarathi Sep 01 '19 at 20:33
0

Use the following dependencies (I copied from my build.gradle)

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    implementation 'org.springframework.cloud:spring-cloud-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
}

Code your gateway app minimally as follows

@SpringBootApplication
public class App {

    @Bean
    public ForwardedHeaderTransformer forwardedHeaderTransformer() {
        return new ForwardedHeaderTransformer();
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

Configure in application.yml

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: XXX
            client-secret: YYY

I am actively building my stack that uses OAuth2 with Docker Swarm Discovery https://github.com/trajano/spring-cloud-demo.git so you can see how it would work in action.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
-2

spring boot 2.1 with spring security 5 have resolve this problem see this example

ashraf revo
  • 767
  • 2
  • 12
  • 24