首页 > 解决方案 > 创建 WSO2 自定义用户存储监听器

问题描述

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

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

如何注册事件监听器 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 调用此侦听器的任何位置。

标签: wso2listenercustomization

解决方案


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

脚步:

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

./wso2server.sh -DosginConsole

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

SS SOA安全

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

b {捆绑ID}

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

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

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

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

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


推荐阅读