@Test public void storeSecrets_existingIdenticalSecret() { final TypedSecret newTypedSecret = new TypedSecret(); newTypedSecret.setSecretType(SecretType.E_METER_MASTER_KEY); newTypedSecret.setSecret(HexUtils.toHexString("$3cr3t".getBytes())); final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference(); keyReference.setEncryptionProviderType(EncryptionProviderType.JRE); keyReference.setReference("keyReferenceString"); final EncryptedSecret newEncryptedSecret = new EncryptedSecret(EncryptionProviderType.JRE, "$3cr3t".getBytes()); final DbEncryptedSecret existingDbSecret = new DbEncryptedSecret(); existingDbSecret.setCreationTime(new Date()); existingDbSecret.setSecretType(SecretType.E_METER_MASTER_KEY); existingDbSecret.setEncodedSecret("1234567890ABCDEF"); existingDbSecret.setDeviceIdentification("SOME_DEVICE"); existingDbSecret.setEncryptionKeyReference(keyReference); when(this.secretRepository.findIdOfValidMostRecent(any(), any(), any())).thenReturn(1L); when(this.secretRepository.findById(1L)).thenReturn(Optional.of(existingDbSecret)); when(this.encryptionDelegate.decrypt(any(), any())).thenReturn( new Secret(HexUtils.fromHexString(newTypedSecret.getSecret()))); assertThatIllegalArgumentException().isThrownBy( () -> this.service.storeSecrets("SOME_DEVICE", Arrays.asList(newTypedSecret))).withMessageContaining( "identical to current"); }
public void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets) { secrets.stream() .map(t -> this.validateSecret(deviceIdentification, t)) .map(s -> this.createEncrypted(deviceIdentification, s, this.getKey())) .forEach(this.secretRepository::save); }
SecretManagementService { public void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets) { secrets.stream() .map(t -> this.validateSecret(deviceIdentification, t)) .map(s -> this.createEncrypted(deviceIdentification, s, this.getKey())) .forEach(this.secretRepository::save); } }
SecretManagementService { public void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets) { secrets.stream() .map(t -> this.validateSecret(deviceIdentification, t)) .map(s -> this.createEncrypted(deviceIdentification, s, this.getKey())) .forEach(this.secretRepository::save); } SecretManagementService(
            @Qualifier("DefaultEncryptionDelegate") final EncryptionDelegate defaultEncryptionDelegate,
            final EncryptionProviderType encryptionProviderType, final DbEncryptedSecretRepository secretRepository,
            final DbEncryptionKeyRepository keyRepository); }
SecretManagementService { public void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets) { secrets.stream() .map(t -> this.validateSecret(deviceIdentification, t)) .map(s -> this.createEncrypted(deviceIdentification, s, this.getKey())) .forEach(this.secretRepository::save); } SecretManagementService(
            @Qualifier("DefaultEncryptionDelegate") final EncryptionDelegate defaultEncryptionDelegate,
            final EncryptionProviderType encryptionProviderType, final DbEncryptedSecretRepository secretRepository,
            final DbEncryptionKeyRepository keyRepository); void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets); List<TypedSecret> retrieveSecrets(final String deviceIdentification, final List<SecretType> secretTypes); Optional<TypedSecret> retrieveSecret(final String deviceIdentification, final SecretType secretType); }
SecretManagementService { public void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets) { secrets.stream() .map(t -> this.validateSecret(deviceIdentification, t)) .map(s -> this.createEncrypted(deviceIdentification, s, this.getKey())) .forEach(this.secretRepository::save); } SecretManagementService(
            @Qualifier("DefaultEncryptionDelegate") final EncryptionDelegate defaultEncryptionDelegate,
            final EncryptionProviderType encryptionProviderType, final DbEncryptedSecretRepository secretRepository,
            final DbEncryptionKeyRepository keyRepository); void storeSecrets(final String deviceIdentification, final List<TypedSecret> secrets); List<TypedSecret> retrieveSecrets(final String deviceIdentification, final List<SecretType> secretTypes); Optional<TypedSecret> retrieveSecret(final String deviceIdentification, final SecretType secretType);  }