-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INJIWEB-665] : Error Handling in OVP Sharing (#363)
* [INJIWEB-665] : Handling Errors for OVP Data Sharing Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : enable cross origin for presentation controller Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : enable cross origin for presentation controller Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : enable cross origin for presentation controller Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : handle the errors in mimoto through redirect Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : handle the errors in mimoto through redirect (#345) Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : handle the errors in mimoto through redirect Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : fixing the failed test Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : fixing the failed test Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : update injiweb url redirection Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : add missing tests for datashare impl Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : handle mosip vc long redirect uri error handling. Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : handle mosip vc long redirect uri error handling. Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : fix instance creation in datashare object Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : apply server properties to bootstrap Signed-off-by: Vijay <[email protected]> * [INJIWEB-665] : fix pr review comments. Signed-off-by: Vijay <[email protected]> --------- Signed-off-by: Vijay <[email protected]>
- Loading branch information
1 parent
b2321ec
commit c67be19
Showing
21 changed files
with
364 additions
and
90 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
37 changes: 29 additions & 8 deletions
37
src/main/java/io/mosip/mimoto/controller/PresentationController.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 |
---|---|---|
@@ -1,39 +1,60 @@ | ||
package io.mosip.mimoto.controller; | ||
|
||
import io.mosip.mimoto.dto.openid.presentation.PresentationRequestDTO; | ||
import io.mosip.mimoto.exception.ApiNotAccessibleException; | ||
import io.mosip.mimoto.exception.InvalidCredentialResourceException; | ||
import io.mosip.mimoto.exception.InvalidVerifierException; | ||
import io.mosip.mimoto.exception.ErrorConstants; | ||
import io.mosip.mimoto.exception.VPNotCreatedException; | ||
import io.mosip.mimoto.service.PresentationService; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@RestController | ||
public class PresentationController { | ||
|
||
@Autowired | ||
PresentationService presentationService; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(PresentationController.class); | ||
|
||
@Value("${mosip.inji.ovp.error.redirect.url}") | ||
String injiOvpErrorRedirectUrl; | ||
|
||
@Value("${mosip.inji.web.redirect.url}") | ||
String injiWebRedirectUrl; | ||
|
||
@GetMapping("/authorize") | ||
public void performAuthorization(HttpServletResponse response, @ModelAttribute PresentationRequestDTO presentationRequestDTO) throws IOException, ApiNotAccessibleException { | ||
public void performAuthorization(HttpServletResponse response, @ModelAttribute PresentationRequestDTO presentationRequestDTO) throws IOException { | ||
try { | ||
logger.info("Started Presentation Authorization in the controller."); | ||
String redirectString = presentationService.authorizePresentation(presentationRequestDTO); | ||
logger.info("Completed Presentation Authorization in the controller."); | ||
response.sendRedirect(redirectString); | ||
} catch (VPNotCreatedException | IOException | ApiNotAccessibleException exception){ | ||
logger.error("Exception Occurred in Authorizing the presentation" + exception); | ||
throw exception; | ||
} catch( InvalidVerifierException exception){ | ||
sendRedirect(response, injiWebRedirectUrl, exception.getErrorCode(), exception.getErrorText()); | ||
} catch(VPNotCreatedException | InvalidCredentialResourceException exception){ | ||
sendRedirect(response, presentationRequestDTO.getRedirect_uri(), exception.getErrorCode(), exception.getErrorText()); | ||
} catch (Exception exception){ | ||
sendRedirect(response, presentationRequestDTO.getRedirect_uri(), ErrorConstants.INTERNAL_SERVER_ERROR.getErrorCode(), ErrorConstants.INTERNAL_SERVER_ERROR.getErrorMessage()); | ||
} | ||
} | ||
|
||
|
||
private void sendRedirect(HttpServletResponse response, String domain, String code, String message) throws IOException { | ||
logger.error("Exception Occurred in Authorizing the presentation"); | ||
String injiVerifyRedirectString = String.format(injiOvpErrorRedirectUrl, | ||
domain, | ||
code, | ||
URLEncoder.encode(message, StandardCharsets.UTF_8)); | ||
response.setStatus(302); | ||
response.sendRedirect(injiVerifyRedirectString); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseDTO.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
9 changes: 7 additions & 2 deletions
9
src/main/java/io/mosip/mimoto/dto/openid/datashare/DataShareResponseWrapperDTO.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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
package io.mosip.mimoto.dto.openid.datashare; | ||
|
||
import io.mosip.mimoto.dto.ErrorDTO; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class DataShareResponseWrapperDTO { | ||
private String id; | ||
private String version; | ||
private String responsetime; | ||
@NotNull | ||
private DataShareResponseDTO dataShare; | ||
|
||
private List<ErrorDTO> errors = new ArrayList<>(); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/mosip/mimoto/exception/ErrorConstants.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,24 @@ | ||
package io.mosip.mimoto.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorConstants { | ||
|
||
INVALID_REQUEST("invalid_request", "Some incorrect parameters in the request"), | ||
UNSUPPORTED_FORMAT("unsupported_format", "No VC of this format is found"), | ||
RESOURCE_NOT_FOUND("resource_not_found", "The requested resource doesn’t exist."), | ||
SERVER_UNAVAILABLE("server_unavailable", "The server is not reachable right now."), | ||
RESOURCE_EXPIRED("resource_expired", "The requested resource expired."), | ||
REQUEST_TIMED_OUT("request_timed_out", "We are unable to process your request right now"), | ||
URI_TOO_LONG("uri_too_long", "Resource URI is too long to be handled"), | ||
INVALID_CLIENT("invalid_client", "The requested client doesn’t match."), | ||
INVALID_REDIRECT_URI("invalid_redirect_uri", "The requested redirect uri doesn’t match."), | ||
INTERNAL_SERVER_ERROR("internal_server_error", "We are unable to process request now"); | ||
|
||
private final String errorCode; | ||
private final String errorMessage; | ||
|
||
} |
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
5 changes: 2 additions & 3 deletions
5
...osip/mimoto/service/VerifiersService.java → ...mosip/mimoto/service/VerifierService.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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package io.mosip.mimoto.service; | ||
|
||
import io.mosip.mimoto.dto.openid.VerifierDTO; | ||
import io.mosip.mimoto.dto.openid.VerifiersDTO; | ||
import io.mosip.mimoto.dto.openid.presentation.PresentationRequestDTO; | ||
import io.mosip.mimoto.exception.ApiNotAccessibleException; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
public interface VerifiersService { | ||
Optional<VerifierDTO> getVerifiersByClientId(String clientId) throws ApiNotAccessibleException, IOException; | ||
public interface VerifierService { | ||
Optional<VerifierDTO> getVerifierByClientId(String clientId) throws ApiNotAccessibleException, IOException; | ||
void validateVerifier(PresentationRequestDTO presentationRequestDTO) throws ApiNotAccessibleException, IOException; | ||
} |
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
Oops, something went wrong.