【问题标题】:Create WSO2 Custom User Store Listener创建 WSO2 自定义用户存储监听器
【发布时间】:2019-07-17 14:56:38
【问题描述】:

未调用自定义用户存储侦听器。

遵循有关如何创建自定义用户存储侦听器的文档。

如何注册事件监听器 https://docs.wso2.com/display/IS560/Writing+a+Custom+Password+Validator

用户存储监听器 https://docs.wso2.com/display/IS560/User+Store+Listeners

自定义监听器示例代码 https://svn.wso2.org/repos/wso2/people/asela/user-mgt/custom-listener/

事件监听器 org.wso2.carbon.identity.governance.store.JDBCIdentityDataStore

    <!-- Enable this listener to call DeleteEventRecorders. -->
    <EventListener type="org.wso2.carbon.user.core.listener.UserOperationEventListener"
                   name="org.wso2.carbon.user.mgt.listeners.UserDeletionEventListener"
                   orderId="98" enable="false"/>
    <EventListener type="org.wso2.carbon.identity.core.handler.AbstractIdentityHandler"
                   name="org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.ConsentMgtPostAuthnHandler"
                   orderId="110" enable="true"/>

    <!-- Audit Loggers -->

    <!-- Old Audit Logger -->
    <EventListener type="org.wso2.carbon.user.core.listener.UserOperationEventListener"
                   name="org.wso2.carbon.user.mgt.listeners.UserMgtAuditLogger"
                   orderId="0" enable="false"/>

    <!-- New Audit Loggers-->
    <EventListener type="org.wso2.carbon.user.core.listener.UserOperationEventListener"
                   name="org.wso2.carbon.user.mgt.listeners.UserManagementAuditLogger"
                   orderId="1" enable="true"/>
    <EventListener type="org.wso2.carbon.user.core.listener.UserManagementErrorEventListener"
                   name="org.wso2.carbon.user.mgt.listeners.UserMgtFailureAuditLogger"
                   orderId="0" enable="true"/>

    <!-- OS Custom event handler-->
    <EventListener type="org.wso2.carbon.user.core.listener.UserOperationEventListener"
                   name="org.wso2.carbon.sample.user.operation.event.listener.SampleUserOperationEventListener"
                   orderId="49" enable="true"/>
</EventListeners>

这里是 SampleUserOperationEventListener 代码。

公共类 SampleUserOperationEventListener 扩展 AbstractUserOperationEventListener {

//private static Log log = LogFactory.getLog(SampleUserOperationEventListener.class);

private static final Log audit = CarbonConstants.AUDIT_LOG;
private static String AUDIT_MESSAGE = "Initiator : %s | Action : %s | Target : %s ";

@Override
public int getExecutionOrderId() {

    //This listener should execute before the IdentityMgtEventListener
    //Hence the number should be < 1357 (Execution order ID of IdentityMgtEventListener)
    return 49;
}

我希望它会在 WSO2 管理控制台中发生用户活动以及用户登录服务提供商时调用自定义侦听器并记录信息。

我没有找到 WSO2 调用此侦听器的任何位置。

【问题讨论】:

    标签: wso2 listener customization


    【解决方案1】:

    我希望您将此自定义侦听器部署为 OSGI 包。如果此捆绑包成功激活,则应在发出用户创建请求时调用它。您无需在 EventListners 下添加它,添加到 dropins 文件夹即可完成这项工作。首先检查捆绑包是否被 OSGI 控制台激活。

    步骤:

    1. 使用 -DosgiConsole 启动 wso2 身份服务器

    ./wso2server.sh -DosginConsole

    1. 服务器启动后输入以下命令。

    ss 安全性

    3 这将给出一个带有包的工件名称的包 ID。

    b {捆绑 ID}

    这将给出捆绑包的状态,无论它是否已激活。如果没有激活。发生这种情况的原因很少。

    1. IS-5.6.0 中使用的 carbon 内核版本是 4.4.32。但是在您的听众中,您使用的是 4.2.0。
    2. 检查您的捆绑清单文件以获取正确的导入包和导出包详细信息

    请参阅此博客及其参考以获取更多信息

    https://medium.com/@inthiraj1994/user-operation-event-listener-for-wso2-server-8ce4765b8c95

    如果您仍然遇到此问题,请告诉我。

    【讨论】:

    • 我可以启动并运行它并检查 OSGi 捆绑包是否处于活动状态。日志记录仍然没有发生。在 POM 文件中使用 slf4j 并重构记录器后,我现在可以在审计文件中看到自定义日志。 -pom 更改 org.slf4jslf4j-api1.7.13 -logger 使用在 java 代码中 private static Logger log = LoggerFactory.getLogger(SampleUserOperationEventListener.class)
    • 现在我需要在审核日志中打印客户端 IP 地址。是否有 API 可以访问客户端 IP 侦听器。
    • 没有这样的 API 可以得到它。但是您可以使用 log4j 配置来实现。没有这样的 API 可以做到这一点。但是您可以使用 log4j 配置来实现。您需要将以下配置添加到 {IS-HOME}/repository/conf/log4j.properties 。 log4j.appender.CARBON_SAMPLE.layout.ConversionPattern=TID:租户 ID:[%T] 服务器名称:[%S] 主机名/地址:[%H] 实例 ID:[%I] 应用程序名称:[% A] [%d] %P%5p {%c} - %x %m %n
    猜你喜欢
    • 1970-01-01
    • 2011-10-19
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多