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

Skip diagnostic logs publish for console app #5690

Merged
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 @@ -734,6 +734,7 @@ protected AuthenticationContext initializeFlow(HttpServletRequest request, HttpS
FrameworkConstants.LogConstants.AUTHENTICATION_FRAMEWORK,
FrameworkConstants.LogConstants.ActionIDs.INIT_AUTH_FLOW)
.inputParam(LogConstants.InputKeys.APPLICATION_NAME, context.getServiceProviderName())
.inputParam(LogConstants.InputKeys.CLIENT_ID, relyingParty)
.inputParam(LogConstants.InputKeys.CALLER_PATH, callerPath)
.inputParam(FrameworkConstants.LogConstants.TENANT_DOMAIN, tenantDomain)
.inputParam(FrameworkConstants.SESSION_DATA_KEY, callerSessionDataKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ protected void doAuthentication(HttpServletRequest request, HttpServletResponse
diagnosticLogBuilder.inputParam(LogConstants.InputKeys.IDP, idpName)
.inputParam("selected authenticator", authenticator.getName())
.inputParam(LogConstants.InputKeys.STEP, currentStep)
.inputParam(LogConstants.InputKeys.CLIENT_ID, context.getRelyingParty())
.resultMessage("Executing the authentication step.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public static class ApplicationManagement {
public static final String DELETE_OAUTH_APPLICATION_ACTION = "delete-oauth-application";
public static final String REGENERATE_CLIENT_SECRET_ACTION = "regenerate-client-secret";
public static final String UPDATE_APP_STATE_ACTION = "update-app-state";
public static final String CONSOLE_CLIENT_ID = "CONSOLE";
public static final String MY_ACCOUNT_CLIENT_ID = "MY_ACCOUNT";
public static final String CONSOLE_APP_NAME = "Console";
public static final String MY_ACCOUNT_APP_NAME = "My Account";
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2021-2024, 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
Expand All @@ -20,6 +20,7 @@

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -50,6 +51,10 @@
import java.util.Map;
import java.util.UUID;

import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.ApplicationManagement.CONSOLE_APP_NAME;
import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.ApplicationManagement.CONSOLE_CLIENT_ID;
import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.ApplicationManagement.MY_ACCOUNT_APP_NAME;
import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.ApplicationManagement.MY_ACCOUNT_CLIENT_ID;
import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.ENABLE_LOG_MASKING;
import static org.wso2.carbon.identity.central.log.mgt.utils.LogConstants.LOGGABLE_USER_CLAIMS;
import static org.wso2.carbon.identity.event.IdentityEventConstants.Event.PUBLISH_AUDIT_LOG;
Expand Down Expand Up @@ -168,6 +173,11 @@ public static void triggerDiagnosticLogEvent(DiagnosticLog.DiagnosticLogBuilder
try {
Map<String, Object> diagnosticLogProperties = new HashMap<>();
DiagnosticLog diagnosticLog = diagnosticLogBuilder.build();
/* As the Console and MyAccount application are managed by the identity server, the diagnostic logs are not
required to be emitted. */
if (isConsoleOrMyAccountApp(diagnosticLog)) {
return;
}
IdentityEventService eventMgtService =
CentralLogMgtServiceComponentHolder.getInstance().getIdentityEventService();
diagnosticLogProperties.put(CarbonConstants.LogEventConstants.DIAGNOSTIC_LOG, diagnosticLog);
Expand Down Expand Up @@ -381,4 +391,36 @@ public static List<String> getLoggableClaimURIs() {
}
return new ArrayList<>();
}

private static boolean isConsoleOrMyAccountApp(DiagnosticLog diagnosticLog) {

if (diagnosticLog.getInput() == null) {
return false;
}
String clientID;
List<?> clientIDs;
Object clientIDInputObj = diagnosticLog.getInput().get(LogConstants.InputKeys.CLIENT_ID);
if (clientIDInputObj instanceof String) {
return CONSOLE_CLIENT_ID.equals(clientIDInputObj) || MY_ACCOUNT_CLIENT_ID.equals(clientIDInputObj);
}
Object clientNameInputObj = diagnosticLog.getInput().get(LogConstants.InputKeys.APPLICATION_NAME);
if (clientNameInputObj instanceof String) {
return CONSOLE_APP_NAME.equals(clientNameInputObj) || MY_ACCOUNT_APP_NAME.equals(clientNameInputObj);
}
if (clientIDInputObj instanceof List<?>) {
clientIDs = (List<?>) diagnosticLog.getInput().get(LogConstants.InputKeys.CLIENT_ID);
if (CollectionUtils.isNotEmpty(clientIDs)) {
clientID = (String) clientIDs.get(0);
return CONSOLE_CLIENT_ID.equals(clientID) || MY_ACCOUNT_CLIENT_ID.equals(clientID);
}
}
if (diagnosticLog.getInput().get("client_id") instanceof List<?>) {
clientIDs = (List<?>) diagnosticLog.getInput().get("client_id");
if (CollectionUtils.isNotEmpty(clientIDs)) {
clientID = (String) clientIDs.get(0);
return CONSOLE_CLIENT_ID.equals(clientID) || MY_ACCOUNT_CLIENT_ID.equals(clientID);
}
}
return false;
}
}
Loading