我正在尝试使用rlm_rest针对RESTful API(由客户提供)对RADIUS请求进行身份验证。
我面临的问题是 (客户提供的REST API的)响应JSON格式与rlm_rest默认格式(在etc/raddb/mods-enabled/rest中表示)不同。
我的虚拟服务器配置如下:
authorize {
...
...
rest
if (ok) {
update control {
Auth-Type := rest
}
}
}
authorize {
uri = "https://3rd-party-API/auth"
method = 'post'
body = 'json'
chunk = 0
tls = ${..tls}
data = '{
"code": 1,
"identifier": %I,
"avps": {
"User-Name": ["%{User-Name}"],
"NAS-IP-Address": ["%{NAS-IP-Address}"],
"Called-Station-Id": ["%{Called-Station-Id}"],
"Calling-Station-Id": ["%{Calling-Station-Id}"],
"NAS-Identifier": ["%{NAS-Identifier}"]
}
}'
}
/ sbin / radiusd -Xxx
HTTP响应代码
200
JSON正文
{
"code": "2",
"identifier": "91",
"avps": {
"Customer-Attributes": "Hello"
...
...
"Acct-Interim-Interval": "300"
}
}
JSON结构与示例不同,并且xlat解析 “码” “标识符” “ avps”
当然,xlat找不到与字典匹配的属性,而找不到“ avps”并且不会更深入地研究。
所以我想知道无论如何
请告知是否有任何解决方法。谢谢!
答案 0 :(得分:0)
在FreeRADIUS版本4中,有一个rlm_json模块,该模块实现基于xpath(jpath)的自定义节点查询语言,它非常受限制,并且仅支持一些非常基本的查询(可以通过PR来增强它)。
下面是我从客户配置库中拉出的示例。您可以在此处看到它正在从JSON文档的根级别中提取两个密钥(externalID和macAddress),并将它们分配给几个自定义属性(Subscriber-ID和Provisioned-MAC)。
map json "%{rest_api:https://${modules.rest[rest_api].server}/admin/api/${modules.rest[rest_api].api_key}/external/getDeviceBySerialNumber?certificateSerialNumber=%{lpad:&TLS-Client-Cert-Serial 40 0}}" {
&Subscriber-ID := '$.externalId'
&Provisioned-MAC := '$.macAddress'
}
还可以修改xlat扩展以发送HTTP正文数据。只需在URL后面放置一个空格并传递您的自定义JSON Blob。