Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagnostic logs when handling notification #200

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
<artifactId>org.wso2.carbon.identity.branding.preference.management.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.central.log.mgt</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -175,6 +179,7 @@
org.wso2.carbon.event.publisher.core.*; version="${carbon.analytics.common.version.range}",
org.wso2.carbon.databridge.commons.*; version="${carbon.analytics.common.version.range}",
org.wso2.carbon.email.mgt.*; version="${identity.event.handler.notification.imp.pkg.version.range}",
org.wso2.carbon.identity.central.log.mgt.*; version="${carbon.identity.framework.imp.pkg.version.range}",
org.wso2.carbon.identity.governance.*; version="${identity.governance.imp.pkg.version.range}",
org.wso2.carbon.identity.branding.preference.management.core.*; version="${identity.branding.preference.management.version.range}",
org.wso2.carbon.identity.organization.management.service;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* Copyright (c) 2016, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Expand Down Expand Up @@ -107,4 +107,36 @@ public static class SMSNotification {
public static final String STREAM_VERSION = "1.0.0";
public static final String DEFAULT_SMS_NOTIFICATION_LOCALE = "en_US";
}

/**
* Define logging constants.
*/
public static class LogConstants {

private LogConstants() {
}
public static final String NOTIFICATION_HANDLER_SERVICE = "notification-handler-service";

/**
* Define action IDs for diagnostic logs.
*/
public static class ActionIDs {

private ActionIDs() {
}

public static final String HANDLE_EVENT = "handle-event";
}

/**
* Define common and reusable Input keys for diagnostic logs.
*/
public static class InputKeys {

private InputKeys() {
}
public static final String EVENT_NAME = "event name";
public static final String TENANT_DOMAIN = "tenant domain";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Expand All @@ -21,19 +21,16 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.email.mgt.util.I18nEmailUtil;
import org.wso2.carbon.event.stream.core.EventStreamService;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.core.handler.InitConfig;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.event.IdentityEventConstants;
import org.wso2.carbon.identity.event.IdentityEventException;
import org.wso2.carbon.identity.event.event.Event;
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;
import org.wso2.carbon.identity.event.handler.notification.email.bean.Notification;
import org.wso2.carbon.identity.event.handler.notification.internal.NotificationHandlerDataHolder;
import org.wso2.carbon.identity.event.handler.notification.util.NotificationUtil;
import org.wso2.carbon.email.mgt.util.I18nEmailUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.DiagnosticLog;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -50,6 +47,7 @@ public class NotificationHandler extends DefaultNotificationHandler {

@Override
public void handleEvent(Event event) throws IdentityEventException {

//We can set the notification template from the identity-even.properties file as a property of the subscription
//property. Then it will get the first priority.
String notificationTemplate = getNotificationTemplate(event);
Expand All @@ -63,9 +61,24 @@ public void handleEvent(Event event) throws IdentityEventException {
arbitraryDataMap.put(entry.getKey(), (String) entry.getValue());
}
}
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
NotificationConstants.LogConstants.NOTIFICATION_HANDLER_SERVICE,
NotificationConstants.LogConstants.ActionIDs.HANDLE_EVENT);
diagnosticLogBuilder
.inputParam(NotificationConstants.LogConstants.InputKeys.EVENT_NAME,
arbitraryDataMap.get(NotificationConstants.TEMPLATE_TYPE))
.inputParam(NotificationConstants.LogConstants.InputKeys.TENANT_DOMAIN,
arbitraryDataMap.get(NotificationConstants.TENANT_DOMAIN))
.resultMessage("Notification will be handled.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logDetailLevel(DiagnosticLog.LogDetailLevel.INTERNAL_SYSTEM);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}

Notification notification = NotificationUtil.buildNotification(event, arbitraryDataMap);

//Stream definition will be read from the the identity-even.properties file as a property of the subscription
//Stream definition will be read from the identity-even.properties file as a property of the subscription
//property. Then it will get the first priority.
String streamDefinitionID = getStreamDefinitionID(event);
//This stream-id was set to the map to pass to the publishToStream method only to avoid API change.
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
<version>${carbon.identity.framework.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.central.log.mgt</artifactId>
<version>${carbon.identity.framework.version}</version>
</dependency>

<!--Carbon Analytics Common Dependencies-->
<dependency>
Expand Down Expand Up @@ -404,8 +409,8 @@
<commons-lang.version.range>[2.6.0,3.0.0)</commons-lang.version.range>

<!--Carbon Kernel Version-->
<carbon.kernel.version>4.7.0</carbon.kernel.version>
<carbon.kernel.feature.version>4.7.0</carbon.kernel.feature.version>
<carbon.kernel.version>4.9.10</carbon.kernel.version>
<carbon.kernel.feature.version>4.9.10</carbon.kernel.feature.version>
<carbon.kernel.imp.pkg.version.range>[4.5.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>

<carbon.user.api.imp.pkg.version.range>[1.0.1, 2.0.0)</carbon.user.api.imp.pkg.version.range>
Expand All @@ -418,7 +423,7 @@
<carbon.commons.imp.pkg.version>[4.7.11, 5.0.0)</carbon.commons.imp.pkg.version>

<!--Carbon Identity Framework Version-->
<carbon.identity.framework.version>5.25.167</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.328</carbon.identity.framework.version>
<carbon.identity.framework.imp.pkg.version.range>[5.14.67, 7.0.0)</carbon.identity.framework.imp.pkg.version.range>

<!-- Organization management Version -->
Expand Down
Loading