如何确定WSO2 microgatway 3.1.0中API路由的Java拦截器中的客户端ip地址?

时间:2020-04-07 15:15:43

标签: wso2 wso2-am wso2-mgw

您好,我正在使用Java拦截器,并想确定调用api的客户端ip地址

Open Api规范

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拦截器

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}
    }
}

1 个答案:

答案 0 :(得分:0)

有两个选项。

  1. 使用X-Forwarded-For

从请求中,您可以查找标头值[1]。

  1. 按如下所示使用呼叫者获取地址[2]

caller.getRemoteAddress()

芭蕾舞女演员方面似乎有一个问题,该问题未返回IP地址。

[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