Skip to content

Commit

Permalink
Update diagnostic logs according to new builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Jul 17, 2023
1 parent b6a70cb commit 8102ac1
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,13 @@ private Response handleResponseFromConsent(OAuthMessage oAuthMessage) throws OAu
if (oAuthMessage.getRequest() != null && MapUtils.isNotEmpty(oAuthMessage.getRequest().getParameterMap())) {
oAuthMessage.getRequest().getParameterMap().forEach((key, value) -> {
if (ArrayUtils.isNotEmpty(value)) {
diagnosticLogBuilder.putParams(key, Arrays.asList(value));
diagnosticLogBuilder.inputParam(key, Arrays.asList(value));
}
});
}
diagnosticLogBuilder.resultMessage("Successfully received consent response.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logLevel(DiagnosticLog.LogLevel.ADVANCED);
.logDetailLevel(DiagnosticLog.LogDetailLevel.INTERNAL_SYSTEM);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}

Expand Down Expand Up @@ -991,13 +991,13 @@ private Response handleAuthenticationResponse(OAuthMessage oAuthMessage)
if (oAuthMessage.getRequest() != null && MapUtils.isNotEmpty(oAuthMessage.getRequest().getParameterMap())) {
oAuthMessage.getRequest().getParameterMap().forEach((key, value) -> {
if (ArrayUtils.isNotEmpty(value)) {
diagnosticLogBuilder.putParams(key, Arrays.asList(value));
diagnosticLogBuilder.inputParam(key, Arrays.asList(value));
}
});
}
diagnosticLogBuilder.resultMessage("Received authentication response from Framework.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logLevel(DiagnosticLog.LogLevel.ADVANCED);
.logDetailLevel(DiagnosticLog.LogDetailLevel.INTERNAL_SYSTEM);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}

Expand Down Expand Up @@ -1032,18 +1032,19 @@ private Response handleAuthenticationResponse(OAuthMessage oAuthMessage)
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "validate-authn-status");
diagnosticLogBuilder.putParams("ApplicationName", oauth2Params.getApplicationName())
.putParams("clientId", oAuthMessage.getClientId())
.putParams("tenantDomain", tenantDomain);
diagnosticLogBuilder.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("client id", oAuthMessage.getClientId())
.inputParam("tenant domain", tenantDomain)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
if (userIdentifier != null) {
diagnosticLogBuilder.putParams("authenticatedUserId", userIdentifier);
diagnosticLogBuilder.inputParam("authenticated user id", userIdentifier);
if (LoggerUtils.isLogMaskingEnable) {
diagnosticLogBuilder.putParams("authenticatedUserMasked",
diagnosticLogBuilder.inputParam("authenticated user (masked)",
LoggerUtils.getMaskedContent(authnResult.getSubject().getUserName()));
}
}
if (oAuthMessage.getAuthorizationGrantCacheEntry() != null) {
diagnosticLogBuilder.putParams("Authentication Method Reference",
diagnosticLogBuilder.inputParam("authentication method reference",
oAuthMessage.getAuthorizationGrantCacheEntry().getAmrList());
}
diagnosticLogBuilder.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
Expand Down Expand Up @@ -1271,15 +1272,16 @@ private Response handleInitialAuthorizationRequest(OAuthMessage oAuthMessage) th
if (oAuthMessage.getRequest() != null && MapUtils.isNotEmpty(oAuthMessage.getRequest().getParameterMap())) {
oAuthMessage.getRequest().getParameterMap().forEach((key, value) -> {
if (ArrayUtils.isNotEmpty(value)) {
diagnosticLogBuilder.putParams(key, Arrays.asList(value));
diagnosticLogBuilder.inputParam(key, Arrays.asList(value));
}
});
}
UserAgent userAgent = new UserAgent(oAuthMessage.getRequest().getHeader("User-Agent"));
diagnosticLogBuilder.putParams("Login browser", userAgent.getBrowser())
.putParams("Login Device", userAgent.getDevice())
diagnosticLogBuilder.inputParam("login browser", userAgent.getBrowser())
.inputParam("login device", userAgent.getDevice())
.resultMessage("Successfully received OAuth2 Authorize request.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS);
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
String redirectURL = handleOAuthAuthorizationRequest(oAuthMessage);
Expand Down Expand Up @@ -1533,13 +1535,14 @@ private String handleServerErrorAuthorization(OAuthMessage oAuthMessage, OIDCSes
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "handle-authorization");
if (oauth2Params != null) {
diagnosticLogBuilder.putParams("client_id", oauth2Params.getClientId())
.putParams("ApplicationName", oauth2Params.getApplicationName())
.putParams("redirect_uri", oauth2Params.getRedirectURI())
.putParams("scope", oauth2Params.getScopes())
.putParams("ResponseType", oauth2Params.getResponseType());
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("redirect uri", oauth2Params.getRedirectURI())
.inputParam("scope", oauth2Params.getScopes())
.inputParam("response type", oauth2Params.getResponseType());
}
diagnosticLogBuilder.resultStatus(DiagnosticLog.ResultStatus.FAILED)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
.resultMessage(errorMsg);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
Expand Down Expand Up @@ -1567,14 +1570,15 @@ private String handleFailureAuthorization(OAuthMessage oAuthMessage, OIDCSession
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "handle-authorization");
if (oauth2Params != null) {
diagnosticLogBuilder.putParams("clientId", oauth2Params.getClientId())
.putParams("Application Name", oauth2Params.getApplicationName())
.putParams("redirectUri", oauth2Params.getRedirectURI())
.putParams("scope", oauth2Params.getScopes())
.putParams("ResponseType", oauth2Params.getResponseType());
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("redirect uri", oauth2Params.getRedirectURI())
.inputParam("scope", oauth2Params.getScopes())
.inputParam("response type", oauth2Params.getResponseType());
}
diagnosticLogBuilder.resultStatus(DiagnosticLog.ResultStatus.FAILED)
.resultMessage("Error occurred while processing the authorization: " + errorMsg);
.resultMessage("Error occurred while processing the authorization: " + errorMsg)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
return EndpointUtil.getErrorRedirectURL(oAuthMessage.getRequest(), oauthProblemException, oauth2Params);
Expand All @@ -1590,12 +1594,13 @@ private String handleAuthorizationFailureBeforeConsent(OAuthMessage oAuthMessage
: "Error occurred while processing authorization request.";
OAuthProblemException oauthProblemException = OAuthProblemException.error(
authzRespDTO.getErrorCode(), errorMsg);
diagnosticLogBuilder.putParams("clientId", oauth2Params.getClientId())
.putParams("ApplicationName", oauth2Params.getApplicationName())
.putParams("RedirectURI", authzRespDTO.getCallbackURI())
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("redirect uri", authzRespDTO.getCallbackURI())
.resultMessage("Error occurred when processing the authorization request before consent. " +
authzRespDTO.getErrorMsg())
.resultStatus(DiagnosticLog.ResultStatus.FAILED);
.resultStatus(DiagnosticLog.ResultStatus.FAILED)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
return EndpointUtil.getErrorRedirectURL(oAuthMessage.getRequest(), oauthProblemException, oauth2Params);
}

Expand Down Expand Up @@ -1654,13 +1659,14 @@ private OAuthResponse handleSuccessAuthorization(OAuthMessage oAuthMessage, OIDC
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "generate-response");
diagnosticLogBuilder.putParams("clientId", oauth2Params.getClientId())
.putParams("Application Name", oauth2Params.getApplicationName())
.putParams("redirectUri", redirectURL)
.putParams("responseMode", oauth2Params.getResponseMode())
.putParams("AuthorizedScopes", authzRespDTO.getScope())
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("redirect uri", redirectURL)
.inputParam("response mode", oauth2Params.getResponseMode())
.inputParam("authorized scopes", authzRespDTO.getScope())
.resultMessage("Successfully generated oauth response.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS);
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
sessionState.setAuthenticated(true);
Expand Down Expand Up @@ -2734,22 +2740,24 @@ private String doUserAuthorization(OAuthMessage oAuthMessage, String sessionData
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "validate-scopes-before-consent");
diagnosticLogBuilder.putParams("clientId", oauth2Params.getClientId())
.putParams("ApplicationName", oauth2Params.getApplicationName())
.putParams("ScopesToBeValidate", oauth2Params.getScopes())
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("scopes to be validate", oauth2Params.getScopes())
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.resultMessage("Scope validation started.");
.resultMessage("Scope validation started.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
validateScopesBeforeConsent(oAuthMessage, oauth2Params, authzReqDTO);
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "validate-scopes-before-consent");
diagnosticLogBuilder.putParams("clientId", oauth2Params.getClientId())
.putParams("ApplicationName", oauth2Params.getApplicationName())
.putParams("ScopesAfterValidation", oauth2Params.getScopes())
diagnosticLogBuilder.inputParam("client id", oauth2Params.getClientId())
.inputParam("application name", oauth2Params.getApplicationName())
.inputParam("scopes after validation", oauth2Params.getScopes())
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.resultMessage("Scope validation completed.");
.resultMessage("Scope validation completed.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
} catch (IdentityOAuth2UnauthorizedScopeException e) {
Expand Down Expand Up @@ -3649,8 +3657,8 @@ private Response handleAuthFlowThroughFramework(OAuthMessage oAuthMessage, Strin
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "hand-over-to-framework")
.resultMessage("Forward authorization request to framework for user authentication.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.putParams("clientId", oAuthMessage.getClientId())
.logLevel(DiagnosticLog.LogLevel.ADVANCED);
.inputParam("client id", oAuthMessage.getClientId())
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ public Response issueAccessToken(@Context HttpServletRequest request, String pay
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "receive-token-request");
if (MapUtils.isNotEmpty(paramMap) && paramMap.containsKey("client_id")) {
diagnosticLogBuilder.putParams("clientId", paramMap.get("client_id"));
diagnosticLogBuilder.inputParam("client id", paramMap.get("client_id"));
}
diagnosticLogBuilder.resultMessage("Successfully received token request.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS);
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
} catch (TokenEndpointBadRequestException e) {
triggerOnTokenExceptionListeners(e, request, null);
Expand All @@ -126,10 +127,11 @@ public Response issueAccessToken(@Context HttpServletRequest request,
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "receive-token-request");
if (MapUtils.isNotEmpty(paramMap) && paramMap.containsKey("client_id")) {
diagnosticLogBuilder.putParams("clientId", paramMap.getFirst("client_id"));
diagnosticLogBuilder.inputParam("client id", paramMap.getFirst("client_id"));
}
diagnosticLogBuilder.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.resultMessage("Successfully received token request.");
.resultMessage("Successfully received token request.")
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
return issueAccessToken(request, (Map<String, List<String>>) paramMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,13 +1078,13 @@ public static void storeOAuthScopeConsent(AuthenticatedUser user, OAuth2Paramete
if (LoggerUtils.isDiagnosticLogsEnabled()) {
DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog.DiagnosticLogBuilder(
OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, "persist-oauth-scope-consent");
diagnosticLogBuilder.putParams("clientId", params.getClientId())
.putParams("approvedScopes", userApprovedScopes)
.putParams("user", userId)
.putParams("overrideExistingConsent", overrideExistingConsent)
diagnosticLogBuilder.inputParam("clientId", params.getClientId())
.inputParam("approved scopes", userApprovedScopes)
.inputParam("user", userId)
.inputParam("override existing consent", overrideExistingConsent)
.resultMessage("Successfully persisted oauth scopes.")
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.logLevel(DiagnosticLog.LogLevel.ADVANCED);
.logDetailLevel(DiagnosticLog.LogDetailLevel.INTERNAL_SYSTEM);
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
}
Expand Down
Loading

0 comments on commit 8102ac1

Please sign in to comment.