@Test public void storeSecrets() throws Exception { final TypedSecret typedSecret = new TypedSecret(); typedSecret.setSecretType(SecretType.E_METER_MASTER_KEY); typedSecret.setSecret(HexUtils.toHexString("$3cr3t".getBytes())); final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference(); keyReference.setEncryptionProviderType(EncryptionProviderType.JRE); keyReference.setReference("keyReferenceString"); final EncryptedSecret encryptedSecret = new EncryptedSecret(EncryptionProviderType.JRE, "$3cr3t".getBytes()); final DbEncryptedSecret dbEncryptedSecret = new DbEncryptedSecret(); when(this.secretRepository.findIdOfValidMostRecent(any(), any(), any())).thenReturn(null); when(this.keyRepository.findByTypeAndValid(any(), any(), any())).thenReturn( new PageImpl<>(Arrays.asList(keyReference))); when(this.encryptionDelegate.encrypt(any(), any(), anyString())).thenReturn(encryptedSecret); this.service.storeSecrets("SOME_DEVICE", Arrays.asList(typedSecret)); final ArgumentCaptor<DbEncryptedSecret> secretArgumentCaptor = ArgumentCaptor.forClass(DbEncryptedSecret.class); verify(this.secretRepository).save(secretArgumentCaptor.capture()); final DbEncryptedSecret savedSecret = secretArgumentCaptor.getValue(); assertThat(savedSecret).isNotNull(); assertThat(savedSecret.getDeviceIdentification()).isEqualTo("SOME_DEVICE"); assertThat(savedSecret.getSecretType()).isEqualTo(typedSecret.getSecretType()); assertThat(savedSecret.getEncodedSecret()).isEqualTo(HexUtils.toHexString(encryptedSecret.getSecret())); assertThat(savedSecret.getEncryptionKeyReference()).isEqualTo(keyReference); assertThat(savedSecret.getCreationTime()).isNotNull(); }
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);  }