Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

Keycloak with Spring Cloud Gateway: how to exclude endpoint resources?

I am following the steps on https://blog.jdriven.com/2019/11/spring-cloud-gateway-with-openid-connect-and-token-relay/ , using a gateway and a microservice. Everything works fine, but when I try to exclude a resource (like for example "somepage.html") in the microservice, it does not work, I always get redirected to the keycloak login.

I tried to in the config part of the service to add

        http.authorizeRequests()
        .antMatchers("/index*")
            .permitAll();

but it did not work, I added this part to the config:

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/public/**");
    }

but it did not help either... This is the gateway config file:

server:
  port: 8080

spring:
  application:
    name: travel-spring-cloud-gateway
  security:
    oauth2:
      client:
        provider:
          keycloak:
            issuer-uri: http://localhost:8090/auth/realms/spring-cloud-gateway-realm
            user-name-attribute: preferred_username
        registration:
          keycloak:
            client-id: spring-cloud-gateway-client
            client-secret: 3a456790-c720-4208-9d4b-fb230ea03dc1

  cloud:
    gateway:
      default-filters:
      - TokenRelay

      routes:
      - id: front-service
        uri: http://127.0.0.1:8086/front
        predicates:
          - Path=/front/**

How can I make the gateway (or the microservice) prevent a request being redirected to the keycloak login ????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...