Skip to content

Commit

Permalink
ES-429 (mosip#28)
Browse files Browse the repository at this point in the history
* config spring security and create endpoint to get csrf token

* add unit-test for new endpoint

* fix coding style

* register feature. connect to camdgc env

* update application-default reperty

* connect to uin, hashing password and add identity service. and write unit test

* remove git ignore and remove .idea

* resolve comment

* resolve comment

* remove hard code assign L1 to registrationType in Identity

* remove mock set transaction

* change RegistrationService dependency to private

* add validation on UserInfoMap field

* add validator on password in register request

* add exception message

* rename validator, remove consentType validator, change registrationId base on applicationID om RegistrationTrasaction

* ES-429

Signed-off-by: ase-101 <[email protected]>

---------

Signed-off-by: ase-101 <[email protected]>
Co-authored-by: Mengleang <[email protected]>
Signed-off-by: Sreang Rathanak <[email protected]>
  • Loading branch information
2 people authored and Sreang Rathanak committed Jan 15, 2024
1 parent a32a30c commit 79317d1
Show file tree
Hide file tree
Showing 35 changed files with 1,646 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.mosip.signup</groupId>
<artifactId>signup-parent</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>esignet-signup</name>
<description>Parent project of MOSIP e-Signet</description>
Expand Down
53 changes: 53 additions & 0 deletions signup-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
# Miscellaneous
*.java.hsp
*.sonarj
*.sw*
.DS_Store
build.sh
integration-repo
ivy-cache
argfile*
activemq-data/
classes/

# Log files
jxl.log
jmx.log
derby.log

# Gradle artifacts
.gradle
.gradletasknamecache
/build
buildSrc/build
/spring-*/build
/framework-*/build
/integration-tests/build
/src/asciidoc/build
spring-test/test-output/

# Maven artifacts
pom.xml
/target/

# Eclipse artifacts, including WTP generated manifests
bin
.classpath
.project
.settings
.springBeans
spring-*/src/main/java/META-INF/MANIFEST.MF

# IDEA artifacts and output dirs
*.iml
*.ipr
*.iws
.idea
out
test-output
atlassian-ide-plugin.xml

# VS Code
.vscode/

cached-antora-playbook.yml
# Compiled class file
*.class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, Ht

@ExceptionHandler(value = { Exception.class, RuntimeException.class })
public ResponseEntity handleExceptions(Exception ex, WebRequest request) {
log.error("Unhandled exception encountered in handler advice", ex);
log.error("Exception encountered while serving request {}: ", request.getDescription(false), ex);

if(ex instanceof MethodArgumentNotValidException) {
List<Error> errors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.mosip.signup.controllers;

import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/csrf")
public class CsrfController {

@GetMapping("/token")
public CsrfToken getCsrfToken(CsrfToken csrfToken) {
return csrfToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.mosip.signup.dto.GenerateChallengeRequest;
import io.mosip.signup.dto.GenerateChallengeResponse;
import io.mosip.signup.dto.RegistrationStatusResponse;
import io.mosip.signup.dto.RegisterRequest;
import io.mosip.signup.dto.RegisterResponse;
import io.mosip.signup.dto.VerifyChallengeRequest;
import io.mosip.signup.dto.VerifyChallengeResponse;
import io.mosip.signup.exception.SignUpException;
Expand All @@ -27,6 +29,15 @@ public class RegistrationController {
@Autowired
RegistrationService registrationService;

@PostMapping("/generate-challenge")
public ResponseWrapper<GenerateChallengeResponse> generateChallenge (
@Valid @RequestBody RequestWrapper<GenerateChallengeRequest> requestWrapper, @CookieValue(name = SignUpConstants.TRANSACTION_ID, defaultValue = "") String transactionId) throws SignUpException {
ResponseWrapper<GenerateChallengeResponse> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponse(registrationService.generateChallenge(requestWrapper.getRequest(), transactionId));
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime());
return responseWrapper;
}

@PostMapping("/verify-challenge")
public ResponseWrapper<VerifyChallengeResponse> verifyChallenge(@Valid @RequestBody RequestWrapper<VerifyChallengeRequest> requestWrapper,
@CookieValue(SignUpConstants.TRANSACTION_ID) String transactionId)
Expand All @@ -37,13 +48,14 @@ public ResponseWrapper<VerifyChallengeResponse> verifyChallenge(@Valid @RequestB
return responseWrapper;
}

@PostMapping("/generate-challenge")
public ResponseWrapper<GenerateChallengeResponse> generateChallenge (
@Valid @RequestBody RequestWrapper<GenerateChallengeRequest> requestWrapper, @CookieValue(name = SignUpConstants.TRANSACTION_ID, defaultValue = "") String transactionId) throws SignUpException {
ResponseWrapper<GenerateChallengeResponse> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponse(registrationService.generateChallenge(requestWrapper.getRequest(), transactionId));
@PostMapping("/register")
public ResponseWrapper<RegisterResponse> register(@Valid @RequestBody RequestWrapper<RegisterRequest> requestWrapper,
@CookieValue(SignUpConstants.TRANSACTION_ID) String transactionId)
throws SignUpException {
ResponseWrapper<RegisterResponse> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponse(registrationService.register(requestWrapper.getRequest(), transactionId));
responseWrapper.setResponseTime(IdentityProviderUtil.getUTCDateTime());
return responseWrapper;
return responseWrapper;
}

@GetMapping("/status")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mosip.signup.dto;

import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Size;
import java.io.Serializable;

@Data
public class AddIdentityRequest implements Serializable {

private String registrationId;
private Identity identity;
}
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 AddIdentityResponse {

private String status;
private String identity;
private String documents;
private String verifiedAttributes;
}
23 changes: 23 additions & 0 deletions signup-service/src/main/java/io/mosip/signup/dto/Identity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.mosip.signup.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class Identity implements Serializable {

@JsonProperty("UIN")
private String UIN;

@JsonProperty("IDSchemaVersion")
private float IDSchemaVersion;

private List<LanguageTaggedValue> fullName;
private String phone;
private String preferredLang;
private Password password;
private String registrationType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.mosip.signup.dto;

import io.mosip.signup.util.ErrorConstants;
import io.mosip.signup.validator.Language;
import lombok.AllArgsConstructor;
import lombok.Data;

import javax.validation.constraints.NotBlank;

@Data
@AllArgsConstructor
public class LanguageTaggedValue {

@Language
private String language;

@NotBlank(message = ErrorConstants.INVALID_VALUE)
private String value;
}
28 changes: 28 additions & 0 deletions signup-service/src/main/java/io/mosip/signup/dto/Password.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.mosip.signup.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Password {

private String hash;
private String salt;

@Data
@AllArgsConstructor
public static class PasswordPlaintext{
private String inputData;
}

@Data
public static class PasswordHash {
private String hashValue;
private String salt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.mosip.signup.dto;

import io.mosip.signup.util.ErrorConstants;
import io.mosip.signup.validator.Password;
import io.mosip.signup.validator.Username;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Data
public class RegisterRequest {

@Username
private String username;

@Password
private String password;

@NotBlank(message = ErrorConstants.INVALID_CONSENT)
@Pattern(message = ErrorConstants.INVALID_CONSENT, regexp = "^(DISAGREE)|(AGREE)$")
private String consent;

@NotNull(message = ErrorConstants.INVALID_USERINFO)
private @Valid UserInfoMap userInfo;
}
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 RegisterResponse {

private String status;
}
13 changes: 13 additions & 0 deletions signup-service/src/main/java/io/mosip/signup/dto/RestError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.mosip.signup.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class RestError {

private String errorCode;
private String message;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Data
public class RestRequestWrapper<T> implements Serializable {

private String id;
private String version;
private String requesttime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

@Data
public class RestResponseWrapper<T> implements Serializable {

private String id;
private String version;
private String responsetime;
private String metadata;
private T response;
private ArrayList<Error> errors;
private ArrayList<RestError> errors;
}
13 changes: 13 additions & 0 deletions signup-service/src/main/java/io/mosip/signup/dto/UINResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.mosip.signup.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class UINResponse implements Serializable {

@JsonProperty("uin")
private String UIN;
}
24 changes: 24 additions & 0 deletions signup-service/src/main/java/io/mosip/signup/dto/UserInfoMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.mosip.signup.dto;

import io.mosip.signup.util.ErrorConstants;
import io.mosip.signup.validator.PhoneNumber;
import io.mosip.signup.validator.Language;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Data
public class UserInfoMap {

@PhoneNumber
private String phone;

@NotEmpty(message = ErrorConstants.INVALID_FULLNAME)
private List<@Valid LanguageTaggedValue> fullName;

@Language
private String preferredLang;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.mosip.signup.exception;

import io.mosip.esignet.core.exception.EsignetException;
import io.mosip.signup.util.ErrorConstants;

public class SignUpException extends EsignetException {

public SignUpException() {super(ErrorConstants.UNKNOWN_ERROR);}

public SignUpException(String errorCode){
super(errorCode);
}
Expand Down
Loading

0 comments on commit 79317d1

Please sign in to comment.