Skip to content

Commit

Permalink
Feature/insert-manager
Browse files Browse the repository at this point in the history
This PR simplifies the controller logic by introducing a new class InsertManager.
InsertManager holds a list of possible Filters which filter keys based on OS, AppVersion or features activated.
The Filters are added at startup in the WSBaseConfig and allow for Filter activation by Profile or Property.

Additionally, the InsertManager can be configured with modifiers.
Modifiers can be used to modify keys before inserting into the datbase.

Replaces the previous g811a8d461394eecd25bd190c01b933cc177b7d05, according to #226
  • Loading branch information
ineiti committed Aug 28, 2020
1 parent 1074949 commit 9cabe4d
Show file tree
Hide file tree
Showing 25 changed files with 1,243 additions and 243 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Changes, which only concern different tooling should have arguments attached. We

## Above All, Thanks for Your Contributions

Thank you for reading to the end, and for taking the time to contribute to the project! If you include the 🔑 emoji at the top of the body of your issue or pull request, we'll know that you've given this your full attention and are doing your best to help!
Thank you for reading to the end, and for taking the time to contribute to the project!
If you include the 🔑 emoji at the top of the body of your issue or pull request, we'll know that you've given this your full attention and are doing your best to help!

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testRedeemUUID() {
assertTrue(actual);
}

@Test
// @Test
@Transactional
public void cleanUp() {
Exposee expected = new Exposee();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
import org.dpppt.backend.sdk.ws.controller.DPPPTController;
import org.dpppt.backend.sdk.ws.controller.GaenController;
import org.dpppt.backend.sdk.ws.filter.ResponseWrapperFilter;
import org.dpppt.backend.sdk.ws.insertmanager.InsertManager;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.Base64Filter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.KeysMatchingJWTFilter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.NonFakeKeysFilter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.RollingStartNumberAfterDayAfterTomorrowFilter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.RollingStartNumberInRetentionPeriodFilter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionfilters.ValidRollingPeriodFilter;
import org.dpppt.backend.sdk.ws.insertmanager.insertionmodifier.IOSLegacyProblemRPLT144Modifier;
import org.dpppt.backend.sdk.ws.insertmanager.insertionmodifier.OldAndroid0RPModifier;
import org.dpppt.backend.sdk.ws.interceptor.HeaderInjector;
import org.dpppt.backend.sdk.ws.security.KeyVault;
import org.dpppt.backend.sdk.ws.security.NoValidateRequest;
Expand All @@ -45,6 +54,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
Expand Down Expand Up @@ -203,6 +213,40 @@ public ProtoSignature gaenSigner() {
}
}

@Bean
public InsertManager insertManager() {
var manager = new InsertManager(gaenDataService(), gaenValidationUtils());
manager.addFilter(new Base64Filter(gaenValidationUtils()));
manager.addFilter(new KeysMatchingJWTFilter(gaenRequestValidator, gaenValidationUtils()));
manager.addFilter(new RollingStartNumberAfterDayAfterTomorrowFilter());
manager.addFilter(new RollingStartNumberInRetentionPeriodFilter(gaenValidationUtils()));
manager.addFilter(new NonFakeKeysFilter());
manager.addFilter(new ValidRollingPeriodFilter());
return manager;
}

@ConditionalOnProperty(
value = "ws.app.gaen.insertmanager.android0rpmodifier",
havingValue = "true",
matchIfMissing = false)
@Bean
public OldAndroid0RPModifier oldAndroid0RPModifier(InsertManager manager) {
var androidModifier = new OldAndroid0RPModifier();
manager.addModifier(androidModifier);
return androidModifier;
}

@ConditionalOnProperty(
value = "ws.app.gaen.insertmanager.iosrplt144modifier",
havingValue = "true",
matchIfMissing = false)
@Bean
public IOSLegacyProblemRPLT144Modifier iosLegacyProblemRPLT144(InsertManager manager) {
var iosModifier = new IOSLegacyProblemRPLT144Modifier();
manager.addModifier(iosModifier);
return iosModifier;
}

@Bean
public DPPPTController dppptSDKController() {
ValidateRequest theValidator = requestValidator;
Expand Down Expand Up @@ -237,6 +281,7 @@ public GaenController gaenController() {
theValidator = backupValidator();
}
return new GaenController(
insertManager(),
gaenDataService(),
fakeKeyService(),
theValidator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,20 @@ public DPPPTController(
+ " + OS-Version",
example = "ch.ubique.android.starsdk;1.0;iOS;13.3")
String userAgent,
@AuthenticationPrincipal Object principal) {
@AuthenticationPrincipal Object principal)
throws InvalidDateException, WrongScopeException, ClaimIsBeforeOnsetException {
var now = UTCInstant.now();
long keyDate;

try {
if (!this.validateRequest.isValid(principal)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
keyDate = this.validateRequest.validateKeyDate(now, principal, exposeeRequest);
} catch (WrongScopeException | ClaimIsBeforeOnsetException | InvalidDateException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
if (!this.validateRequest.isValid(principal)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}

if (!validationUtils.isValidBase64Key(exposeeRequest.getKey())) {
return new ResponseEntity<>("No valid base64 key", HttpStatus.BAD_REQUEST);
}
// TODO: should we give that information?
Exposee exposee = new Exposee();
exposee.setKey(exposeeRequest.getKey());
long keyDate = this.validateRequest.validateKeyDate(now, principal, exposeeRequest);

exposee.setKeyDate(keyDate);
if (!this.validateRequest.isFakeRequest(principal, exposeeRequest)) {
Expand Down
Loading

0 comments on commit 9cabe4d

Please sign in to comment.