Search in sources :

Example 1 with StoreSecretsRequest

use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest 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()));
    }
}
Also used : StoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse) GenerateAndStoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse) TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) GenerateAndStoreSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsRequest) StoreSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) TypedSecret(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 2 with StoreSecretsRequest

use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest in project open-smart-grid-platform by OSGP.

the class SecretManagementService method createStoreSecretsRequest.

private StoreSecretsRequest createStoreSecretsRequest(final String deviceIdentification, final TypedSecrets typedSecrets) {
    final StoreSecretsRequest request = new StoreSecretsRequest();
    request.setDeviceId(deviceIdentification);
    request.setTypedSecrets(typedSecrets);
    return request;
}
Also used : GenerateAndStoreSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsRequest) StoreSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest)

Example 3 with StoreSecretsRequest

use of org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest 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));
}
Also used : HashMap(java.util.HashMap) StoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse) GenerateAndStoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse) StoreSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) Test(org.junit.jupiter.api.Test)

Aggregations

StoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest)3 SecurityKeyType (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)2 GenerateAndStoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsRequest)2 GenerateAndStoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse)2 StoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 TypedSecret (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)1 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)1