Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -262,12 +262,14 @@ public AutnTxn build(EnvUtil env, IdaUinHashSaltRepo uinHashSaltRepo,
autnTxn.setAuthTknId(authTokenId);
autnTxn.setCrDTimes(DateUtils.getUTCCurrentDateTime());
LocalDateTime strUTCDate = DateUtils.getUTCCurrentDateTime();
try {
strUTCDate = DateUtils.parseToLocalDateTime(DateUtils.getUTCTimeFromDate(
DateUtils.parseToDate(reqTime, EnvUtil.getDateTimePattern())));
} catch (ParseException e) {
mosipLogger.warn(IdAuthCommonConstants.SESSION_ID, this.getClass().getName(), e.getMessage(),
"Invalid Request Time - setting to current date time");
if (reqTime != null && !reqTime.trim().isEmpty()) {
try {
strUTCDate = DateUtils.parseToLocalDateTime(DateUtils.getUTCTimeFromDate(
DateUtils.parseToDate(reqTime, EnvUtil.getDateTimePattern())));
} catch (ParseException e) {
mosipLogger.warn(IdAuthCommonConstants.SESSION_ID, this.getClass().getName(), e.getMessage(),
"Invalid Request Time - setting to current date time");
}
}
autnTxn.setRequestDTtimes(strUTCDate);
autnTxn.setResponseDTimes(DateUtils.getUTCCurrentDateTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.Temporal;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -221,7 +222,15 @@ private CharResponseWrapper sendErrorResponse(ServletResponse response, CharResp
boolean hasUnableToProcessError = errors.stream()
.anyMatch(err -> err.getErrorCode()
.equals(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorCode()));
if(!hasUnableToProcessError) {
// MOSIP-45564: id/version missing or invalid is already a specific, well-formed
// validation error (raised only by handleException() for id/version). Wrapping it
// here re-adds UNABLE_TO_PROCESS as a cause, and since BaseCheckedException copies
// the cause's info items into the wrapper, both error codes end up in the response.
boolean isIdOrVersionValidationError = errors.stream()
.anyMatch(err -> err.getErrorCode().equals(IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorCode())
|| err.getErrorCode().equals(IdAuthenticationErrorConstants.INVALID_INPUT_PARAMETER.getErrorCode())
|| err.getErrorCode().equals(IdAuthenticationErrorConstants.INVALID_ENCRYPTION.getErrorCode()));
if(!hasUnableToProcessError && !isIdOrVersionValidationError) {
exception = new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorCode(),
IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorMessage(), ex);
}
Expand Down Expand Up @@ -307,15 +316,23 @@ private void logTime(String timeInTheAllowedPattern, String type, Temporal actua
timeInTheAllowedPattern = IdaRequestResponsConsumerUtil.getResponseTime(null, dateTimePattern);
}
mosipLogger.info(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER, type + " at : " + timeInTheAllowedPattern);
long duration = Duration
.between(actualRequestTime,
LocalDateTime.parse(timeInTheAllowedPattern,
DateTimeFormatter
.ofPattern(dateTimePattern)))
.toMillis();
mosipLogger.info(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER,
"Time difference between request and response in millis:" + duration
+ ". Time difference between request and response in Seconds: " + ((double) duration / 1000));
// timeInTheAllowedPattern comes straight from the raw request body, ahead of
// (and independent of) request validation, so an invalid requestTime must not
// let this purely diagnostic duration calculation crash response processing.
try {
long duration = Duration
.between(actualRequestTime,
LocalDateTime.parse(timeInTheAllowedPattern,
DateTimeFormatter
.ofPattern(dateTimePattern)))
.toMillis();
mosipLogger.info(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER,
"Time difference between request and response in millis:" + duration
+ ". Time difference between request and response in Seconds: " + ((double) duration / 1000));
} catch (DateTimeParseException e) {
mosipLogger.warn(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER,
"Unable to compute request/response time difference - invalid requestTime: " + e.getMessage());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
}

protected boolean needStoreAuthTransaction() {
Expand Down Expand Up @@ -490,7 +507,14 @@ protected String consumeResponse(ResettableStreamHttpServletRequest requestWrapp
String inputReqTimeStr = inputRequestTime instanceof String? (String) inputRequestTime : null;
logTime(inputReqTimeStr, IdAuthCommonConstants.RESPONSE, actualRequestTime);
return responseAsString;
} catch (IdAuthenticationAppException e ) {
} catch (Exception e) {
// By this point responseAsString is already the fully-built response (success
// or a structured error already resolved by IdAuthExceptionHandler upstream).
// Everything in this try block past that is auxiliary post-processing (signing,
// storing the auth transaction, storing the anonymous profile) - a failure there
// (e.g. an unchecked DB/serialization exception, not just IdAuthenticationAppException)
// must not discard the already-correct response and fall through to the
// container's default error page.
mosipLogger.error(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER, e.getMessage());
return responseAsString;
}
Expand Down
Loading
Loading