Spring + Keycloak: Gateway Docker container returns 404

27 Views Asked by At

Note: all requests works perfectly on localhost. I have this problem, only when I'm running all containers with the help of docker-compose.

My application-docker.yml for Gateway:

  security:
    oauth2:
      client:
        provider:
          keycloak:
            token-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/token
            authorization-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/auth
            user-name-attribute: preferred_username
            user-info-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/userinfo
            jwk-set-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/certs
            user-info-authentication-method: header
        registration:
          keycloak:
            provider: keycloak
            client-id: taxi-realm
            client-secret: DqTwdhwq0yYPt0qClZBWhJq6PNnxulxE
            authorization-grant-type: authorization_code
            redirect-uri: "{baseUrl}/login/oauth2/code/keycloak"
            scope: openid
      resourceserver:
        jwt:
          jwk-set-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/certs

My docker-compose configuration for keycloak and gateway:

  api-gateway:
    image: api-gateway:latest
    container_name: api-gateway
    ports:
      - "8080:8080"
    expose:
      - "8080"
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY=TRACE
      - MANAGEMENT_ZIPKIN_TRACING_ENDPOINT=http://zipkin:9411/api/v2/spans
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_ISSUER_URI=http://keycloak:8080/realms/taxi-realm
    depends_on:
      - discovery-server
      - broker
      - keycloak
    restart: always

  keycloak:
    image: quay.io/keycloak/keycloak:18.0.2
    container_name: keycloak
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    volumes:
      - ./keycloak/themes:/opt/keycloak/themes/custom/login
    command:
      - start-dev
    ports:
      - "8181:8080"

My Keycloak-Client configuration: My Keycloak-Client configuration

And Logs from Gateway:

2024-03-19 22:40:38 2024-03-19T19:40:38.469Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/logout', method=POST}
2024-03-19 22:40:38 2024-03-19T19:40:38.470Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] athPatternParserServerWebExchangeMatcher : Request 'GET /api/v1/passengers' doesn't match 'POST /logout'
2024-03-19 22:40:38 2024-03-19T19:40:38.471Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : No matches found
2024-03-19 22:40:38 2024-03-19T19:40:38.473Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/actuator/**', method=GET}
2024-03-19 22:40:38 2024-03-19T19:40:38.474Z DEBUG 1 --- [API-GATEWAY] [     parallel-3] [] athPatternParserServerWebExchangeMatcher : Request 'GET /api/v1/passengers' doesn't match 'GET /actuator/**'
2024-03-19 22:40:38 2024-03-19T19:40:38.475Z DEBUG 1 --- [API-GATEWAY] [     parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : No matches found
2024-03-19 22:40:38 2024-03-19T19:40:38.476Z DEBUG 1 --- [API-GATEWAY] [     parallel-3] [] a.DelegatingReactiveAuthorizationManager : Checking authorization on '/api/v1/passengers' using org.springframework.security.authorization.AuthenticatedReactiveAuthorizationManager@4a7f5d63
2024-03-19 22:40:38 2024-03-19T19:40:38.478Z DEBUG 1 --- [API-GATEWAY] [     parallel-3] [] o.s.s.w.s.a.AuthorizationWebFilter       : Authorization successful

Response for all requests:

EDIT NOTE: If I making request with Wrong token, I get 401 error (=> authorization works)

0

There are 0 best solutions below