-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from tw-mosip/release-0.9.x
[Release 01-08-2023] : Security Fixes, API Request Validation & Including App ID in the Loggers
- Loading branch information
Showing
14 changed files
with
168 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/io/mosip/mimoto/util/CommonExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.mosip.mimoto.util; | ||
|
||
|
||
import io.mosip.mimoto.dto.ErrorDTO; | ||
import io.mosip.mimoto.dto.resident.CredentialRequestResponseDTO; | ||
import io.mosip.mimoto.exception.InvalidInputException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import java.util.Collections; | ||
|
||
@ControllerAdvice | ||
public class CommonExceptionHandler{ | ||
@ExceptionHandler( value = InvalidInputException.class) | ||
public ResponseEntity<CredentialRequestResponseDTO> handleInvalidInput(InvalidInputException ex) { | ||
CredentialRequestResponseDTO credentialRequestResponseDTO = new CredentialRequestResponseDTO(); | ||
ErrorDTO errors = new ErrorDTO(ex.getErrorCode(), ex.getMessage()); | ||
credentialRequestResponseDTO.setVersion("1.0"); | ||
credentialRequestResponseDTO.setErrors(Collections.singletonList(errors)); | ||
return new ResponseEntity<>(credentialRequestResponseDTO, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.mosip.mimoto.util; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.mosip.mimoto.dto.mimoto.AppOTPRequestDTO; | ||
import io.mosip.mimoto.dto.mimoto.CredentialDownloadRequestDTO; | ||
import io.mosip.mimoto.exception.InvalidInputException; | ||
import io.mosip.mimoto.exception.PlatformErrorMessages; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.FieldError; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
@Component | ||
public class RequestValidator { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(RequestValidator.class); | ||
|
||
@Value("${mosip.notificationtype:EMAIL|PHONE}") | ||
private String notificationType; | ||
public void validateInputRequest(BindingResult result){ | ||
if(result.hasErrors()){ | ||
FieldError fieldError = result.getFieldError(); | ||
if(fieldError != null) { | ||
String errorMessage = fieldError.getField() + " " + fieldError.getDefaultMessage(); | ||
throw new InvalidInputException(errorMessage); | ||
} | ||
} | ||
} | ||
|
||
public void validateNotificationChannel(List<String> otpChannelList){ | ||
List<String> incorrectNotificationChannel = new ArrayList<String>(); | ||
logger.info("\n Notification Types from application-default.properties in mosip-config - > " + notificationType); | ||
incorrectNotificationChannel = otpChannelList | ||
.stream() | ||
.filter(otpChannel -> !notificationType.contains(otpChannel)) | ||
.collect(Collectors.toList()); | ||
if(incorrectNotificationChannel.size() > 0) { | ||
logger.error("Invalid Input is received in otpChannels " + String.join(",", incorrectNotificationChannel)); | ||
throw new InvalidInputException(PlatformErrorMessages.MIMOTO_PGS_INVALID_INPUT_PARAMETER.getMessage() + " - " + "otpChannels"); | ||
} | ||
} | ||
|
||
public void validateCredentialDownloadRequest(CredentialDownloadRequestDTO requestDTO, JsonNode requestedCredentialJSON) throws IOException, NoSuchFieldException { | ||
if(requestedCredentialJSON.has("response") && requestedCredentialJSON.get("response").has("id")) { | ||
String requestedIndividualId = requestedCredentialJSON.get("response").get("id").asText(); | ||
if (!requestDTO.getIndividualId().equals(requestedIndividualId)) { | ||
throw new InvalidInputException(PlatformErrorMessages.MIMOTO_PGS_INVALID_INPUT_PARAMETER.getMessage() + " - " + "individualId"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters