Как определить ip-адрес клиента в перехватчике Java для маршрута API в микрогейтвее WSO2 3.1.0? - PullRequest
0 голосов
/ 07 апреля 2020

Привет, я использую перехватчик java и хочу определить IP-адрес клиента, который вызвал API

Спецификация 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 голосов
/ 08 апреля 2020

Доступны две опции.

  1. Использовать X-Forwarded-For

В запросе вы можете найти значения заголовка [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

...