This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #36 from UbiqueInnovation/develop
Created "/v2/onset" endpoint
- Loading branch information
Showing
9 changed files
with
352 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ public class AuthorizationCodeVerifyResponseDto { | |
|
||
private String accessToken; | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...admin/bag/covidcode/authcodegeneration/api/AuthorizationCodeVerifyResponseDtoWrapper.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,31 @@ | ||
package ch.admin.bag.covidcode.authcodegeneration.api; | ||
|
||
public class AuthorizationCodeVerifyResponseDtoWrapper { | ||
|
||
private AuthorizationCodeVerifyResponseDto dp3tAccessToken; | ||
private AuthorizationCodeVerifyResponseDto checkInAccessToken; | ||
|
||
public AuthorizationCodeVerifyResponseDtoWrapper(AuthorizationCodeVerifyResponseDto dp3tAccessToken, AuthorizationCodeVerifyResponseDto checkInAccessToken) { | ||
this.dp3tAccessToken = dp3tAccessToken; | ||
this.checkInAccessToken = checkInAccessToken; | ||
} | ||
|
||
public AuthorizationCodeVerifyResponseDtoWrapper() {} | ||
|
||
|
||
public AuthorizationCodeVerifyResponseDto getDP3TAccessToken() { | ||
return dp3tAccessToken; | ||
} | ||
|
||
public void setDP3TAccessToken(AuthorizationCodeVerifyResponseDto dp3tAccessToken) { | ||
this.dp3tAccessToken = dp3tAccessToken; | ||
} | ||
|
||
public AuthorizationCodeVerifyResponseDto getCheckInAccessToken() { | ||
return checkInAccessToken; | ||
} | ||
|
||
public void setCheckInAccessToken(AuthorizationCodeVerifyResponseDto checkInAccessToken) { | ||
this.checkInAccessToken = checkInAccessToken; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/ch/admin/bag/covidcode/authcodegeneration/api/TokenType.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,22 @@ | ||
package ch.admin.bag.covidcode.authcodegeneration.api; | ||
|
||
public enum TokenType { | ||
|
||
DP3T_TOKEN("dp3t", "exposed"), CHECKIN_USERUPLOAD_TOKEN("checkin", "userupload"); | ||
|
||
private final String scope; | ||
private final String audience; | ||
|
||
TokenType(String audience, String scope) { | ||
this.audience = audience; | ||
this.scope = scope; | ||
} | ||
|
||
public String getAudience() { | ||
return audience; | ||
} | ||
|
||
public String getScope() { | ||
return scope; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...min/bag/covidcode/authcodegeneration/web/controller/AuthCodeVerificationControllerV2.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,54 @@ | ||
package ch.admin.bag.covidcode.authcodegeneration.web.controller; | ||
|
||
import ch.admin.bag.covidcode.authcodegeneration.api.AuthorizationCodeVerificationDto; | ||
import ch.admin.bag.covidcode.authcodegeneration.api.AuthorizationCodeVerifyResponseDto; | ||
import ch.admin.bag.covidcode.authcodegeneration.api.AuthorizationCodeVerifyResponseDtoWrapper; | ||
import ch.admin.bag.covidcode.authcodegeneration.service.AuthCodeVerificationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.rest.webmvc.ResourceNotFoundException; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/v2/onset") | ||
@Slf4j | ||
public class AuthCodeVerificationControllerV2 { | ||
|
||
private final AuthCodeVerificationService authCodeVerificationService; | ||
private final Duration requestTime; | ||
|
||
public AuthCodeVerificationControllerV2(AuthCodeVerificationService authCodeVerificationService, @Value("${authcodegeneration.service.requestTime}") long requestTime) { | ||
this.authCodeVerificationService = authCodeVerificationService; | ||
this.requestTime = Duration.ofMillis(requestTime); | ||
} | ||
|
||
@Operation(summary = "Authorization code verification method") | ||
@PostMapping() | ||
public ResponseEntity<AuthorizationCodeVerifyResponseDtoWrapper> verify(@Valid @RequestBody AuthorizationCodeVerificationDto verificationDto) { | ||
var now = Instant.now().toEpochMilli(); | ||
log.debug("Call of Verify with authCode '{}'.", verificationDto.getAuthorizationCode()); | ||
final AuthorizationCodeVerifyResponseDtoWrapper accessTokenWrapper = authCodeVerificationService.verify(verificationDto.getAuthorizationCode(), verificationDto.getFake(), true); | ||
normalizeRequestTime(now); | ||
if (accessTokenWrapper.getDP3TAccessToken() == null || accessTokenWrapper.getCheckInAccessToken() == null) { | ||
throw new ResourceNotFoundException(null); | ||
} | ||
return ResponseEntity.ok().body(accessTokenWrapper); | ||
} | ||
|
||
private void normalizeRequestTime(long now) { | ||
long after = Instant.now().toEpochMilli(); | ||
long duration = after - now; | ||
try { | ||
Thread.sleep(Math.max(requestTime.minusMillis(duration).toMillis(), 0)); | ||
} catch (Exception ex) { | ||
log.error("Error during sleep", ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.