Skip to content

Commit

Permalink
Use getUserId instead of getLoggableUserId
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Aug 7, 2023
1 parent 957c08e commit a3fada4
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.InvalidCredentialsException;
import org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
Expand Down Expand Up @@ -59,6 +60,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.RequestParams.RESTART_FLOW;
Expand Down Expand Up @@ -267,8 +269,9 @@ protected void processAuthenticationResponse(HttpServletRequest request, HttpSer
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
.resultStatus(DiagnosticLog.ResultStatus.SUCCESS)
.inputParam(LogConstants.InputKeys.STEP, context.getCurrentStep())
.inputParams(getApplicationDetails(context))
.inputParam(LogConstants.InputKeys.USER_ID, context.getSubject().getLoggableUserId());
.inputParams(getApplicationDetails(context));
Optional<String> optionalUserId = getUserId(context);
optionalUserId.ifPresent(userId -> diagnosticLogBuilder.inputParam(LogConstants.InputKeys.USER_ID, userId));
LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder);
}
}
Expand Down Expand Up @@ -548,4 +551,19 @@ private Map<String, String> getApplicationDetails(AuthenticationContext context)
applicationName));
return applicationDetailsMap;
}

private Optional<String> getUserId(AuthenticationContext context) {

if (context.getSubject() == null) {
return Optional.empty();
}
try {
return Optional.ofNullable(context.getSubject().getUserId());
} catch (UserIdNotFoundException e) {
if (log.isDebugEnabled()) {
log.debug("Error while getting the user id from the subject.", e);
}
return Optional.empty();
}
}
}

0 comments on commit a3fada4

Please sign in to comment.