use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse in project open-smart-grid-platform by OSGP.
the class SecretManagementEndpoint method storeSecrets.
public StoreSecretsResponse storeSecrets(final StoreSecretsRequest request) throws OsgpException {
final TypedSecrets soapTypedSecrets = request.getTypedSecrets();
final List<TypedSecret> typedSecretList = this.converter.convertToTypedSecrets(soapTypedSecrets);
this.secretManagementService.storeSecrets(request.getDeviceId(), typedSecretList);
return new StoreSecretsResponse();
}
use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse in project open-smart-grid-platform by OSGP.
the class SecretManagementService method storeNewKeys.
public void storeNewKeys(final MessageMetadata messageMetadata, final String deviceIdentification, final Map<SecurityKeyType, byte[]> keysByType) {
this.validateKeys(keysByType);
final TypedSecrets typedSecrets = new TypedSecrets();
final List<TypedSecret> typedSecretList = typedSecrets.getTypedSecret();
for (final Map.Entry<SecurityKeyType, byte[]> entry : keysByType.entrySet()) {
final TypedSecret ts = new TypedSecret();
ts.setType(entry.getKey().toSecretType());
ts.setSecret(this.encryptSoapSecret(entry.getValue(), true));
typedSecretList.add(ts);
}
final StoreSecretsRequest request = this.createStoreSecretsRequest(deviceIdentification, typedSecrets);
StoreSecretsResponse response = null;
try {
response = this.secretManagementClient.storeSecretsRequest(messageMetadata, request);
} catch (final RuntimeException exc) {
throw new IllegalStateException("Could not store keys: unexpected exception occured", exc);
}
if (response == null) {
throw new IllegalStateException("Could not store keys: NULL response");
} else if (!OsgpResultType.OK.equals(response.getResult())) {
throw new IllegalStateException(String.format("Could not store keys: result=%s; fault=%s", response.getResult(), response.getTechnicalFault()));
}
}
use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method testStoreNewKeys.
@Test
public void testStoreNewKeys() {
final Map<SecurityKeyType, byte[]> keys = new HashMap<>();
keys.put(KEY_TYPE, UNENCRYPTED_SECRET);
final StoreSecretsResponse response = new StoreSecretsResponse();
response.setResult(OsgpResultType.OK);
when(this.encrypterForSecretManagement.encrypt(UNENCRYPTED_SECRET)).thenReturn(SOAP_SECRET);
when(this.secretManagementClient.storeSecretsRequest(same(messageMetadata), any())).thenReturn(response);
// EXECUTE
this.secretManagementTestService.storeNewKeys(messageMetadata, DEVICE_IDENTIFICATION, keys);
// ASSERT
verify(this.secretManagementClient, times(1)).storeSecretsRequest(same(messageMetadata), any(StoreSecretsRequest.class));
}
Aggregations