Skip to content
Permalink
Browse files
Adjusting createSignature return value to be more palatable for provi…
…sioner.
  • Loading branch information
mifosio-04-04-2018 committed Apr 12, 2017
1 parent 075b2b9 commit 323650e08e563452c974ab9170d65c2337206c2c
Showing 5 changed files with 26 additions and 13 deletions.
@@ -15,6 +15,7 @@
*/
package io.mifos.identity.api.v1.client;

import io.mifos.anubis.api.v1.domain.ApplicationSignatureSet;
import io.mifos.core.api.annotation.ThrowsException;
import io.mifos.core.api.util.CustomFeignClientsConfiguration;
import io.mifos.identity.api.v1.domain.*;
@@ -128,5 +129,5 @@ public interface IdentityManager {
@RequestMapping(value = "/signatures", method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
String createSignatureSet();
ApplicationSignatureSet createSignatureSet();
}
@@ -38,7 +38,7 @@ public void testKeyRotation() throws InterruptedException {

try (final AutoSeshat ignored1 = new AutoSeshat(systemToken)) {
//Create a signature set then test that it is listed.
final String timestamp = getTestSubject().createSignatureSet();
final String timestamp = getTestSubject().createSignatureSet().getTimestamp();
{
final List<String> signatureSets = anubis.getAllSignatureSets();
Assert.assertTrue(signatureSets.contains(timestamp));
@@ -60,7 +60,7 @@ public void testKeyRotation() throws InterruptedException {
TimeUnit.SECONDS.sleep(2); //Timestamp has resolution at seconds level -- Make sure that second signature set has different timestamp from the first one.

//Create a second signature set and test that it and the previous signature set are listed.
final String timestamp2 = getTestSubject().createSignatureSet();
final String timestamp2 = getTestSubject().createSignatureSet().getTimestamp();
{
final List<String> signatureSets = anubis.getAllSignatureSets();
Assert.assertTrue(signatureSets.contains(timestamp));
@@ -81,7 +81,7 @@ public void buildTable() {
cassandraSessionProvider.getTenantSession().execute(createValidIndex);
}

public void add(final RsaKeyPairFactory.KeyPairHolder keys)
public SignatureEntity add(final RsaKeyPairFactory.KeyPairHolder keys)
{
//There will only be one entry in this table.
final BoundStatement tenantCreationStatement =
@@ -103,6 +103,14 @@ public void add(final RsaKeyPairFactory.KeyPairHolder keys)
tenantCreationStatement.setVarint(PUBLIC_KEY_EXP_COLUMN, keys.getPublicKeyExp());

cassandraSessionProvider.getTenantSession().execute(tenantCreationStatement);

final SignatureEntity ret = new SignatureEntity();
ret.setKeyTimestamp(keys.getTimestamp());
ret.setPublicKeyMod(keys.getPublicKeyMod());
ret.setPublicKeyExp(keys.getPublicKeyExp());
ret.setValid(true);

return ret;
}

public Optional<SignatureEntity> getSignature(final String keyTimestamp) {
@@ -57,11 +57,7 @@ public List<String> getAllSignatureSetKeyTimestamps() {
@Override
public Optional<ApplicationSignatureSet> getSignatureSet(final String keyTimestamp) {
final Optional<SignatureEntity> signatureEntity = signatures.getSignature(keyTimestamp);
return signatureEntity.map(x ->
new ApplicationSignatureSet(
x.getKeyTimestamp(),
new Signature(x.getPublicKeyMod(), x.getPublicKeyExp()),
new Signature(x.getPublicKeyMod(), x.getPublicKeyExp())));
return signatureEntity.map(this::mapSignatureEntityToApplicationSignatureSet);
}

@Override
@@ -85,9 +81,16 @@ public boolean tenantAlreadyProvisioned() {
}
}

public String createSignatureSet() {
public ApplicationSignatureSet createSignatureSet() {
final RsaKeyPairFactory.KeyPairHolder keys = RsaKeyPairFactory.createKeyPair();
signatures.add(keys);
return keys.getTimestamp();
final SignatureEntity signatureEntity = signatures.add(keys);
return mapSignatureEntityToApplicationSignatureSet(signatureEntity);
}

private ApplicationSignatureSet mapSignatureEntityToApplicationSignatureSet(final SignatureEntity signatureEntity) {
return new ApplicationSignatureSet(
signatureEntity.getKeyTimestamp(),
new Signature(signatureEntity.getPublicKeyMod(), signatureEntity.getPublicKeyExp()),
new Signature(signatureEntity.getPublicKeyMod(), signatureEntity.getPublicKeyExp()));
}
}
@@ -17,6 +17,7 @@

import io.mifos.anubis.annotation.AcceptedTokenType;
import io.mifos.anubis.annotation.Permittable;
import io.mifos.anubis.api.v1.domain.ApplicationSignatureSet;
import io.mifos.identity.internal.command.handler.Provisioner;
import io.mifos.identity.internal.service.TenantService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -69,7 +70,7 @@ public class InitializeRestController {
consumes = {MediaType.ALL_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
@Permittable(AcceptedTokenType.SYSTEM)
public @ResponseBody ResponseEntity<String> createSignatureSet() {
public @ResponseBody ResponseEntity<ApplicationSignatureSet> createSignatureSet() {
return ResponseEntity.ok(tenantService.createSignatureSet());
}
}

0 comments on commit 323650e

Please sign in to comment.