apache / servicecomb-java-chassis

ServiceComb Java Chassis is a Software Development Kit (SDK) for rapid development of microservices in Java, providing service registration, service discovery, dynamic routing, and service management features
Apache License 2.0
1.91k stars 813 forks source link

CommonHttpDispatcher does not invoke handler chain and Configured Auth handler is not triggered #3201

Open shri-arunraj opened 2 years ago

shri-arunraj commented 2 years ago

I have an issue in CommonHttpDispatcher in that the consumer auth handlers configured for the registered third party microservice are not triggered. Can you help here? Why handlers are not triggered on using this dispatcher?

This is my configuration. Here authClientGrant is a consumer auth handler configured for the registered third party service mfa-login-service . At run time after CommonHttpDispatcher picks the path for routing, the request is forwarded to the mfa-login-service . But none of the handlers are triggered before invocation.

servicecomb-config-order: 100
servicecomb:
  service:
    application: m1-services
    name: gateway
    properties:
      allowCrossApp: true #whether to allow calls across applications
    version: 0.0.4
    registry:
      # Default using local service center
      address: http://localhost:30100
      instance:
        watch: false
  edge:
    filter:
      addHeader:
        enabled: true
        allowedHeaders: xxx
  handler:
    chain:
      Consumer:
        default: loadbalance,tracing-consumer
        service:
         mfa-login-service: authClientGrant,loadbalance,tracing-consumer
      Provider:
           default: bizkeeper-provider,tracing-provider
  rest:
    address: 0.0.0.0:9091?sslEnabled=false
  tracing:
    enabled: true
  http:
    dispatcher:
      edge:
        http:
          enabled: true
          order: 1
          mappings:
           oauthAdmin:
              path: "/admin/oauth/.*"
              microserviceName: oauth-service
              prefixSegmentCount: 1
              versionRule: 0.0.0+
           mfaServices:
              path: "/a/mfa/login/.*"
              microserviceName: mfa-login-service
              prefixSegmentCount: 1
              versionRule: 0.0.0+
liubao68 commented 2 years ago

CommonHttpDispatcher is designed for common http request forwarding. e.g. Do not depend swagger, and can forward requests to non java chassis services. It does not execute handler( no Invocation)

shri-arunraj commented 2 years ago

Alternatively if I forward using URLMappedEdgeDispatcher to non java chassis service, the request headers in the original request are not getting received in the non java chassis service. Is there a way to configure URLMappedEdgeDispatcher to pass along http headers to the target recipient?

shri-arunraj commented 2 years ago

@liubao68 Please help answer! We are exploring this to use servicecomb for our migration to microservices infrastructure. Appreciate quick response on this thanks :)

liubao68 commented 2 years ago

You can look at EdgeAddHeaderClientFilter for reference. URLMappedEdgeDispatcher is designed for java chassis services and it follows Open API not HTTP proxy. So only headers defined in REST api are passed to backend services. You can add headers needed in invocation context.