Search in sources :

Example 1 with StoreSecretsResponse

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();
}
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) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)

Example 2 with 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()));
    }
}
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 3 with StoreSecretsResponse

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));
}
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

GenerateAndStoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse)3 StoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse)3 SecurityKeyType (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)2 StoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest)2 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)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.secretmanagement.application.domain.TypedSecret)1 GenerateAndStoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsRequest)1 TypedSecret (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)1