-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ase-101 <[email protected]>
- Loading branch information
Showing
18 changed files
with
531 additions
and
9 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
27 changes: 27 additions & 0 deletions
27
signup-service/src/main/java/io/mosip/signup/config/WebSocketConfig.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,27 @@ | ||
package io.mosip.signup.config; | ||
|
||
import io.mosip.signup.services.IdentityVerificationHandshakeHandler; | ||
import io.mosip.signup.services.IdentityVerificationWebSocketHandler; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; | ||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; | ||
|
||
@Configuration | ||
@EnableWebSocket | ||
public class WebSocketConfig implements WebSocketConfigurer { | ||
|
||
@Autowired | ||
private IdentityVerificationWebSocketHandler identityVerificationWebSocketHandler; | ||
|
||
@Autowired | ||
private IdentityVerificationHandshakeHandler identityVerificationHandshakeHandler; | ||
|
||
@Override | ||
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) { | ||
webSocketHandlerRegistry.addHandler(identityVerificationWebSocketHandler,"/identity-verification") | ||
.setHandshakeHandler(identityVerificationHandshakeHandler); | ||
//By default, only same origin requests are allowed | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
signup-service/src/main/java/io/mosip/signup/controllers/IdentityVerificationController.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,73 @@ | ||
package io.mosip.signup.controllers; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.mosip.esignet.core.dto.RequestWrapper; | ||
import io.mosip.esignet.core.dto.ResponseWrapper; | ||
import io.mosip.esignet.core.util.IdentityProviderUtil; | ||
import io.mosip.signup.dto.*; | ||
import io.mosip.signup.exception.SignUpException; | ||
import io.mosip.signup.helper.AuditHelper; | ||
import io.mosip.signup.services.IdentityVerificationService; | ||
import io.mosip.signup.util.AuditEvent; | ||
import io.mosip.signup.util.AuditEventType; | ||
import io.mosip.signup.util.ErrorConstants; | ||
import io.mosip.signup.util.SignUpConstants; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
import static io.mosip.signup.util.SignUpConstants.EMTPY; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/identity-verification") | ||
public class IdentityVerificationController { | ||
|
||
@Autowired | ||
AuditHelper auditHelper; | ||
|
||
@Autowired | ||
IdentityVerificationService identityVerificationService; | ||
|
||
@PostMapping("/initiate") | ||
public ResponseWrapper<InitiateIdentityVerificationResponse> initiateIdentityVerification( | ||
@Valid @RequestBody RequestWrapper<InitiateIdentityVerificationRequest> requestWrapper, | ||
HttpServletResponse response){ | ||
ResponseWrapper<InitiateIdentityVerificationResponse> responseWrapper = new ResponseWrapper<>(); | ||
try{ | ||
responseWrapper.setResponse(identityVerificationService.initiateIdentityVerification(requestWrapper.getRequest(), response)); | ||
}catch (SignUpException signUpException){ | ||
auditHelper.sendAuditTransaction(AuditEvent.INITIATE_IDENTITY_VERIFICATION, AuditEventType.ERROR, null, signUpException); | ||
throw signUpException; | ||
} | ||
auditHelper.sendAuditTransaction(AuditEvent.INITIATE_IDENTITY_VERIFICATION, AuditEventType.SUCCESS, null, null); | ||
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime()); | ||
return responseWrapper; | ||
} | ||
|
||
@GetMapping("/identity-verifier/{id}") | ||
public ResponseWrapper<JsonNode> getIdentityVerifierDetails(@PathVariable String id, | ||
@Valid @NotBlank(message = ErrorConstants.INVALID_TRANSACTION) | ||
@CookieValue(value = SignUpConstants.IDV_TRANSACTION_ID, defaultValue = EMTPY) String transactionId) { | ||
ResponseWrapper<JsonNode> responseWrapper = new ResponseWrapper<>(); | ||
responseWrapper.setResponse(identityVerificationService.getIdentityVerifierDetails(transactionId, id)); | ||
auditHelper.sendAuditTransaction(AuditEvent.IDENTITY_VERIFIER, AuditEventType.SUCCESS, transactionId, null); | ||
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime()); | ||
return responseWrapper; | ||
} | ||
|
||
@PostMapping("/slot") | ||
public ResponseWrapper<SlotResponse> getSlot(@Valid @RequestBody RequestWrapper<SlotRequest> requestWrapper, | ||
@Valid @NotBlank(message = ErrorConstants.INVALID_TRANSACTION) | ||
@CookieValue(value = SignUpConstants.IDV_TRANSACTION_ID, defaultValue = EMTPY) String transactionId) { | ||
ResponseWrapper<SlotResponse> responseWrapper = new ResponseWrapper<>(); | ||
responseWrapper.setResponse(identityVerificationService.getSlot(transactionId, requestWrapper.getRequest())); | ||
auditHelper.sendAuditTransaction(AuditEvent.IDENTITY_VERIFICATION_SLOT, AuditEventType.SUCCESS, transactionId, null); | ||
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime()); | ||
return responseWrapper; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
signup-service/src/main/java/io/mosip/signup/dto/IdentityVerificationTransaction.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,14 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
@Data | ||
public class IdentityVerificationTransaction implements Serializable { | ||
|
||
private String individualId; | ||
private String slotId; | ||
private String verifierId; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
signup-service/src/main/java/io/mosip/signup/dto/IdentityVerifierDetail.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,18 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
@Data | ||
public class IdentityVerifierDetail implements Serializable { | ||
|
||
private String id; | ||
private Map<String, String> displayName; | ||
private String processType; | ||
private boolean active; | ||
private String logoUrl; | ||
private boolean retryOnFailure; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
signup-service/src/main/java/io/mosip/signup/dto/InitiateIdentityVerificationRequest.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,16 @@ | ||
package io.mosip.signup.dto; | ||
|
||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Data | ||
public class InitiateIdentityVerificationRequest { | ||
|
||
@NotBlank | ||
private String authorizationCode; | ||
|
||
@NotBlank | ||
private String state; | ||
} |
11 changes: 11 additions & 0 deletions
11
signup-service/src/main/java/io/mosip/signup/dto/InitiateIdentityVerificationResponse.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,11 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class InitiateIdentityVerificationResponse { | ||
|
||
IdentityVerifierDetail[] identityVerifiers; | ||
} |
12 changes: 12 additions & 0 deletions
12
signup-service/src/main/java/io/mosip/signup/dto/SlotRequest.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,12 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SlotRequest { | ||
|
||
private String verifierId; | ||
private String consent; | ||
private String disabilityType; | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
signup-service/src/main/java/io/mosip/signup/dto/SlotResponse.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,9 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SlotResponse { | ||
|
||
private String slotId; | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...-service/src/main/java/io/mosip/signup/services/IdentityVerificationHandshakeHandler.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,58 @@ | ||
package io.mosip.signup.services; | ||
|
||
import io.mosip.signup.dto.IdentityVerificationTransaction; | ||
import io.mosip.signup.util.ErrorConstants; | ||
import io.mosip.signup.util.SignUpConstants; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.server.ServerHttpRequest; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.socket.WebSocketHandler; | ||
import org.springframework.web.socket.server.HandshakeFailureException; | ||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
|
||
@Slf4j | ||
@Component | ||
public class IdentityVerificationHandshakeHandler extends DefaultHandshakeHandler { | ||
|
||
@Autowired | ||
CacheUtilService cacheUtilService; | ||
|
||
@Override | ||
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, | ||
Map<String, Object> attributes) { | ||
HttpHeaders headers = request.getHeaders(); | ||
|
||
String cookieName = SignUpConstants.IDV_TRANSACTION_ID+"="; | ||
Optional<String> transactionCookie = headers.getOrEmpty(HttpHeaders.COOKIE) | ||
.stream() | ||
.filter( cookie -> cookie.startsWith(cookieName)) | ||
.findFirst(); | ||
|
||
if(!transactionCookie.isPresent()) | ||
throw new HandshakeFailureException(ErrorConstants.INVALID_TRANSACTION); | ||
|
||
IdentityVerificationTransaction transaction = cacheUtilService.getIdentityVerificationTransaction( | ||
transactionCookie.get().substring(cookieName.length())); | ||
|
||
List<String> values = headers.getOrEmpty("SlotId"); | ||
if(values.isEmpty() || !values.get(0).equals(transaction.getSlotId())) { | ||
log.error("SlotId in the handshake header doesn't match the slotId in the transaction"); | ||
throw new HandshakeFailureException(ErrorConstants.INVALID_TRANSACTION); | ||
} | ||
|
||
return new Principal() { | ||
@Override | ||
public String getName() { | ||
return transaction.getSlotId(); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.