Skip to content
Permalink
Browse files
Making acquisition of latest signatures easier through convenience fu…
…nction for use in provisioner.
  • Loading branch information
mifosio-04-04-2018 committed Apr 12, 2017
1 parent 333e131 commit 5d160e92b5e22398ea27a68b1c1f38348600dbd7
Showing 3 changed files with 47 additions and 0 deletions.
@@ -55,6 +55,11 @@ ApplicationSignatureSet createSignatureSet(@PathVariable("timestamp") @ValidKeyT
produces = {MediaType.ALL_VALUE})
ApplicationSignatureSet getSignatureSet(@PathVariable("timestamp") String timestamp);

@RequestMapping(value = "/signatures/_latest", method = RequestMethod.GET,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
ApplicationSignatureSet getLatestSignatureSet();

@RequestMapping(value = "/signatures/{timestamp}", method = RequestMethod.DELETE,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
@@ -65,6 +70,11 @@ ApplicationSignatureSet createSignatureSet(@PathVariable("timestamp") @ValidKeyT
produces = {MediaType.ALL_VALUE})
Signature getApplicationSignature(@PathVariable("timestamp") String timestamp);

@RequestMapping(value = "/signatures/_latest/application", method = RequestMethod.GET,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
Signature getLatestApplicationSignature();

@RequestMapping(value = "/initialize", method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
@@ -122,6 +122,11 @@ public void testKeyRotation()
Assert.assertTrue(signatureSets.contains(identityManagerKeyPair.getTimestamp()));
Assert.assertTrue(signatureSets.contains(identityManagerKeyPair2.getTimestamp()));
}
final ApplicationSignatureSet latestSignatureSet = anubis.getLatestSignatureSet();
Assert.assertEquals(identityManagerKeyPair2.getTimestamp(), latestSignatureSet.getTimestamp());

final Signature latestApplicationSignature = anubis.getLatestApplicationSignature();
Assert.assertEquals(latestSignatureSet.getApplicationSignature(), latestApplicationSignature);

//Get the newly created signature set, and test that it's contents are correct.
final ApplicationSignatureSet signatureSet2 = anubis.getSignatureSet(identityManagerKeyPair2.getTimestamp());
@@ -27,6 +27,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

/**
* @author Myrle Krantz
@@ -64,6 +65,19 @@ public SignatureRestController(final TenantSignatureRepository tenantSignatureRe
.orElseThrow(() -> ServiceException.notFound("Signature for timestamp '" + timestamp + "' not found."));
}

@Permittable(AcceptedTokenType.SYSTEM)
@RequestMapping(value = "/signatures/_latest", method = RequestMethod.GET,
consumes = {MediaType.ALL_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
public
@ResponseBody ResponseEntity<ApplicationSignatureSet> getLatestSignatureSet()
{
final Optional<String> timestamp = getMostRecentTimestamp();
return timestamp.flatMap(tenantSignatureRepository::getSignatureSet)
.map(ResponseEntity::ok)
.orElseThrow(() -> ServiceException.notFound("No valid signature found."));
}

@Permittable(AcceptedTokenType.SYSTEM)
@RequestMapping(value = "/signatures/{timestamp}", method = RequestMethod.DELETE,
consumes = {MediaType.ALL_VALUE},
@@ -86,4 +100,22 @@ public SignatureRestController(final TenantSignatureRepository tenantSignatureRe
.map(ResponseEntity::ok)
.orElseThrow(() -> ServiceException.notFound("Signature for timestamp '" + timestamp + "' not found."));
}

@Permittable(AcceptedTokenType.SYSTEM)
@RequestMapping(value = "/signatures/_latest/application", method = RequestMethod.GET,
consumes = {MediaType.ALL_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
public
@ResponseBody ResponseEntity<Signature> getLatestApplicationSignature()
{
final Optional<String> timestamp = getMostRecentTimestamp();
return timestamp.flatMap(tenantSignatureRepository::getApplicationSignature)
.map(ResponseEntity::ok)
.orElseThrow(() -> ServiceException.notFound("No valid signature found."));
}

private Optional<String> getMostRecentTimestamp() {
return tenantSignatureRepository.getAllSignatureSetKeyTimestamps().stream()
.max(String::compareTo);
}
}

0 comments on commit 5d160e9

Please sign in to comment.