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

[MOSIP-29801] Fixed less number of path parameters, api key expire error message. #1111

Merged
merged 1 commit into from
Oct 19, 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 @@ -465,6 +465,12 @@ protected String consumeResponse(ResettableStreamHttpServletRequest requestWrapp
String requestSignature = requestWrapper.getHeader(SIGNATURE);
String responseSignature = null;
if(isSigningRequired()) {
if (Objects.isNull(responseAsString) || responseAsString.trim().length() == 0) {
mosipLogger.error(IdAuthCommonConstants.SESSION_ID, EVENT_FILTER, BASE_IDA_FILTER,
" Response String is null or empty for response (JWT) signing");
throw new IdAuthenticationAppException(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorCode(),
IdAuthenticationErrorConstants.UNABLE_TO_PROCESS.getErrorMessage());
}
responseSignature = keyManager.signResponse(responseAsString);
responseWrapper.setHeader(EnvUtil.getSignResponse(), responseSignature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,19 +1119,28 @@ private Set<String> getAuthenticationFactors(PartnerPolicyResponseDTO partnerPol
* @param requestWrapper the request wrapper
* @return the auth part
*/
protected Map<String, String> getAuthPart(ResettableStreamHttpServletRequest requestWrapper) {
protected Map<String, String> getAuthPart(ResettableStreamHttpServletRequest requestWrapper) throws IdAuthenticationAppException{
Map<String, String> params = new HashMap<>();
String url = requestWrapper.getRequestURL().toString();
String contextPath = requestWrapper.getContextPath();
if ((Objects.nonNull(url) && !url.isEmpty()) && (Objects.nonNull(contextPath) && !contextPath.isEmpty())) {
String[] splitedUrlByContext = url.split(contextPath);
String[] paramsArray = Stream.of(splitedUrlByContext[1].split("/")).filter(str -> !str.isEmpty())
.toArray(size -> new String[size]);
.toArray(size -> new String[size]);
mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getCanonicalName(), "getAuthPart",
"List of Path Parameters received in url: " + Stream.of(paramsArray).collect(Collectors.joining(", ")));

if (paramsArray.length >= 3) {
params.put(MISPLICENSE_KEY, paramsArray[paramsArray.length - 3]);
params.put(PARTNER_ID, paramsArray[paramsArray.length - 2]);
params.put(API_KEY, paramsArray[paramsArray.length - 1]);
} else {
mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getCanonicalName(), "getAuthPart",
"Required Number of Path Parameters are not available in URL.");
throw new IdAuthenticationAppException(
IdAuthenticationErrorConstants.URI_PATH_PARAMS_MISSING.getErrorCode(),
IdAuthenticationErrorConstants.URI_PATH_PARAMS_MISSING.getErrorMessage());

}
}
return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ private void validatePartnerMappingDetails(Optional<PartnerMapping> partnerMappi
if (partnerMapping.getApiKeyData().getApiKeyCommenceOn().isAfter(DateUtils.getUTCCurrentDateTime())
|| partnerMapping.getApiKeyData().getApiKeyExpiresOn()
.isBefore(DateUtils.getUTCCurrentDateTime())) {
throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.PARTNER_NOT_REGISTERED.getErrorCode(),
IdAuthenticationErrorConstants.PARTNER_NOT_REGISTERED.getErrorMessage());
throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.PARTNER_API_EXPIRED.getErrorCode(),
IdAuthenticationErrorConstants.PARTNER_API_EXPIRED.getErrorMessage());
}
} else {
logger.info(IdAuthCommonConstants.IDA, this.getClass().getSimpleName(), "OIDC_client_validation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public void Test_validatePartnerMappingDetails_apikeyCommenceNotBefore() {
if (e.getUndeclaredThrowable() instanceof IdAuthenticationBaseException) {
IdAuthenticationBaseException idAuthenticationBaseException = (IdAuthenticationBaseException) e
.getUndeclaredThrowable();
assertEquals(IdAuthenticationErrorConstants.PARTNER_NOT_REGISTERED.getErrorCode(),
assertEquals(IdAuthenticationErrorConstants.PARTNER_API_EXPIRED.getErrorCode(),
idAuthenticationBaseException.getErrorCode());
}
}
Expand Down Expand Up @@ -898,7 +898,7 @@ public void Test_validatePartnerMappingDetails_apikeyExpiryNotAfter() {
if (e.getUndeclaredThrowable() instanceof IdAuthenticationBaseException) {
IdAuthenticationBaseException idAuthenticationBaseException = (IdAuthenticationBaseException) e
.getUndeclaredThrowable();
assertEquals(IdAuthenticationErrorConstants.PARTNER_NOT_REGISTERED.getErrorCode(),
assertEquals(IdAuthenticationErrorConstants.PARTNER_API_EXPIRED.getErrorCode(),
idAuthenticationBaseException.getErrorCode());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public enum IdAuthenticationErrorConstants {
UNAUTHORISED_VCI_EXCHANGE_PARTNER("IDA-MPA-036", "Partner is unauthorised for VCI-Exchange"),
VCI_EXCHANGE_NOT_ALLOWED("IDA-MPA-037", "%s not allowed as per policy",
"Please try after updating misp policy"),
URI_PATH_PARAMS_MISSING("IDA-MPA-038", "Required Number of Path parameters are missing in URI",
"Please try adding all the required path parameters."),
PARTNER_API_EXPIRED("IDA-MPA-039", "Partner API is expired or using before Commence Start Date."),


DATA_VALIDATION_FAILED("IDA-IDV-001", "Input Data Validation Failed"),
Expand Down