如何在 wso2 apim 日志中显示调用某些 api 的用户的个人资料信息?

How to display profile info of the user that called certain api in wso2 apim log?

我正在尝试配置 wso2 apim (4.0.0) 的网关访问日志,以便它应该包含调用某些 [=24] 的用户的个人资料信息(例如:组织、电子邮件) =] 以及日志文件中 api 的所有者。我遵循了

的答案

我想要的结构是:

用户名 | user_organization | invoked_api_name | api_owner | api_url |请求 |回应

欢迎任何帮助!

通过使用以下属性,我们可以从自定义处理程序的消息上下文中提取 API PublisherUsernameTenant Domain

api.ut.apiPublisher: API Publisher
api.ut.userId: Username

Custom Handler 中的 handleRequestOutFlow(..) 方法执行以下增强以提取提到的数据

public boolean handleRequestOutFlow(..) {
    ...
    String username = (String) messageContext.getProperty("api.ut.userId");
    String apiCreator = (String) messageContext.getProperty("api.ut.apiPublisher");
    String apiContext = (String) messageContext.getProperty("api.ut.context");
    String tenantDomain = MultitenantUtils.getTenantDomainFromRequestURL(apiContext);
    if (tenantDomain == null) {
        tenantDomain = org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    ...
}

更新

如果你想通过自定义处理程序记录用户的organization,那么我可以想到两个选项来实现需求。

  • 选项 01:配置 OpenID 范围

    This option is applicable if you are having only a handful of applications that are needed for this function.

    通过 Carbon 管理控制台配置额外的 OpenID 范围映射到 organization 声明。并使 organization 声明成为每个服务提供商的强制声明,以生成包含 organization 声明的 JWT 访问令牌。

    当您尝试生成令牌时,您必须传递我们为 organization 创建的 OpenID 范围,以便服务提供商评估并将声明包含在令牌中。

    一旦令牌通过 Headers 到达网关,捕获令牌并从中提取声明。或者,将网关节点配置为生成 X-JWT-Assertion 令牌并捕获该令牌并提取声明。

  • 选项 02:自定义处理程序以检索声明

    我们可以增强处理程序实现以从 JWT 访问令牌中提取用户名,然后调用一组具有所需属性的密钥管理器端点来检索用户声明。您可以检查 Key Manager connector implementation 以找到相关端点以检索用户声明。

希望本次简报能帮助您选择一条道路。此外,我还针对第二个选项对 custom handler 实现添加了一些增强功能。