Search in sources :

Example 1 with ApplicationKeyConfiguration

use of org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationKeyConfiguration in project open-smart-grid-platform by OSGP.

the class GetKeys method anApplicationKeyIsConfigured.

@Given("^an application key is configured$")
public void anApplicationKeyIsConfigured(final Map<String, String> settings) throws Throwable {
    final ApplicationDataLookupKey applicationDataLookupKey = new ApplicationDataLookupKey(settings.get(PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION), this.applicationName);
    final ApplicationKeyConfiguration applicationKeyConfiguration = new ApplicationKeyConfiguration(applicationDataLookupKey, "/etc/osp/smartmetering/keys/application/smartmetering-rsa-public.key");
    this.applicationKeyConfigurationRepository.save(applicationKeyConfiguration);
}
Also used : ApplicationDataLookupKey(org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey) ApplicationKeyConfiguration(org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationKeyConfiguration) Given(io.cucumber.java.en.Given)

Example 2 with ApplicationKeyConfiguration

use of org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationKeyConfiguration in project open-smart-grid-platform by OSGP.

the class SmartMeteringConfigurationEndpoint method getRsaEncrypterForApplication.

private RsaEncrypter getRsaEncrypterForApplication(final String organisationIdentification) throws OsgpException {
    final ApplicationKeyConfiguration applicationKeyConfiguration = this.applicationKeyConfigurationRepository.findById(new ApplicationDataLookupKey(organisationIdentification, this.webserviceNotificationApplicationName)).orElseThrow(() -> new OsgpException(ComponentType.WS_SMART_METERING, "No public key found for application " + this.webserviceNotificationApplicationName + " and organisation " + organisationIdentification));
    final String publicKeyLocation = applicationKeyConfiguration.getPublicKeyLocation();
    try {
        final Resource keyResource = new FileSystemResource(publicKeyLocation);
        final RsaEncrypter applicationRsaEncrypter = new RsaEncrypter();
        applicationRsaEncrypter.setPublicKeyStore(keyResource.getFile());
        return applicationRsaEncrypter;
    } catch (final IOException e) {
        throw new OsgpException(ComponentType.WS_SMART_METERING, "Could not get public key file for application " + this.webserviceNotificationApplicationName + " and organisation " + organisationIdentification);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ApplicationKeyConfiguration(org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationKeyConfiguration) ApplicationDataLookupKey(org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResource(org.springframework.core.io.FileSystemResource) RsaEncrypter(org.opensmartgridplatform.shared.security.RsaEncrypter) IOException(java.io.IOException)

Aggregations

ApplicationDataLookupKey (org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey)2 ApplicationKeyConfiguration (org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationKeyConfiguration)2 Given (io.cucumber.java.en.Given)1 IOException (java.io.IOException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 RsaEncrypter (org.opensmartgridplatform.shared.security.RsaEncrypter)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 Resource (org.springframework.core.io.Resource)1