0

Hi am using java interceptor and want to determine client ip address who invoked the api

Open Api Specification

paths:
  /test:
    get:
      description: ""
      operationId: PING
      x-wso2-disable-security: true
      x-wso2-throttling-tier: 6PerMin
      x-wso2-request-interceptor: java:org.mgw.interceptor.IDSAuthInterceptor
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PING"
            application/xml:
              schema:
                $ref: "#/components/schemas/PING"
      security:
        - basicAuthentication: []

Java Interceptor

public class IDSAuthInterceptor implements Interceptor {
    public boolean interceptRequest(Caller caller, Request request) {
       // How to determine client ip. Not able to fetch using {Caller caller, Request request}
    }
}
Umer Asir
  • 11
  • 4

1 Answers1

0

There are two options available.

  1. Use X-Forwarded-For

From the request, you can look for the header values [1].

  1. Use the caller as follows to get the address [2]

caller.getRemoteAddress()

It seems like there is an issue in the Ballerina side which does not return the IP address.

[1] - https://github.com/wso2/product-microgateway/blob/ba689b71e17cb36f77115eaee3334d305eecad28/components/micro-gateway-interceptor/src/main/java/org/wso2/micro/gateway/interceptor/Request.java#L162

[2] - https://github.com/Rajith90/MGW-demo/blob/master/mgwinterceptors/src/main/java/org/mgw/interceptor/SampleInterceptor.java#L40

Pubci
  • 3,834
  • 1
  • 13
  • 28
  • Actually i have tried both none of them works, Use X-Forwarded-For is not avalable as part of request and caller.getRemoteAddress() only returns port not host ip address – Umer Asir Apr 08 '20 at 08:56
  • Already created one issue https://github.com/wso2/product-microgateway/issues/1192 – Umer Asir Apr 08 '20 at 09:00