wso2 - 如何在 WSO2 microgatway 3.1.0 中的 API 路由的 Java 拦截器中确定客户端 IP 地址?
问题描述
嗨,我正在使用 java 拦截器,想确定调用 api 的客户端 IP 地址
开放 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}
}
}
解决方案
有两种选择。
- 使用 X-Forwarded-For
从请求中,您可以查找标头值 [1]。
- 如下使用调用者获取地址[2]
调用者.getRemoteAddress()
Ballerina 方面似乎存在不返回 IP 地址的问题。
推荐阅读
- java - 如何仅从 unix 时间戳获取月份和年份
- unity3d - CircleCollider2D 未注册与 TileMapCollider2D 中某些图块的碰撞
- javascript - 屏幕中间的 FlatList 不显示全部内容
- css - 侧柱没有达到整个高度
- javascript - 选定的维度转换为 div 表
- javascript - 在 req.body 中包含表
- spring-mvc - EL1007E: 在 null 上找不到属性或字段“fieldName”
- node-red - node-red 拆分、重新排序和连接输出字符串
- python - Python - 在 != 中使用多个单词
- go - 致命错误:所有 goroutine 都处于休眠状态 - 死锁!当通道没有缓冲时