Search in sources :

Example 1 with PredefinedAliasPrivateKeyStrategy

use of won.cryptography.ssl.PredefinedAliasPrivateKeyStrategy in project webofneeds by researchstudio-sat.

the class LinkedDataRestClientHttps method createRestTemplateForReadingLinkedData.

private RestTemplate createRestTemplateForReadingLinkedData(String webID) {
    RestTemplate template = null;
    try {
        template = CryptographyUtils.createSslRestTemplate(this.keyStoreService.getUnderlyingKeyStore(), this.keyStoreService.getPassword(), new PredefinedAliasPrivateKeyStrategy(keyPairAliasDerivationStrategy.getAliasForNeedUri(webID)), this.trustStoreService.getUnderlyingKeyStore(), this.trustStrategy, readTimeout, connectionTimeout, true);
    } catch (Exception e) {
        throw new RuntimeException("Failed to create rest template for webID '" + webID + "'", e);
    }
    template.getMessageConverters().add(datasetConverter);
    return template;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) PredefinedAliasPrivateKeyStrategy(won.cryptography.ssl.PredefinedAliasPrivateKeyStrategy)

Example 2 with PredefinedAliasPrivateKeyStrategy

use of won.cryptography.ssl.PredefinedAliasPrivateKeyStrategy in project webofneeds by researchstudio-sat.

the class LinkedDataRestBridge method createRestTemplateForReadingLinkedData.

private RestTemplate createRestTemplateForReadingLinkedData(String webID) throws Exception {
    RestTemplate template = CryptographyUtils.createSslRestTemplate(this.keyStoreService.getUnderlyingKeyStore(), this.keyStoreService.getPassword(), new PredefinedAliasPrivateKeyStrategy(keyPairAliasDerivationStrategy.getAliasForNeedUri(webID)), this.trustStoreService.getUnderlyingKeyStore(), this.trustStrategy, readTimeout, connectionTimeout, true);
    // prevent the RestTemplate from throwing an exception when the server responds with 4xx or 5xx status
    // because we want to hand the orginal response back to the original caller in BridgeForLinkedDataController
    template.setErrorHandler(new DefaultResponseErrorHandler() {

        @Override
        protected boolean hasError(final HttpStatus statusCode) {
            return false;
        }
    });
    return template;
}
Also used : DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) HttpStatus(org.springframework.http.HttpStatus) RestTemplate(org.springframework.web.client.RestTemplate) PredefinedAliasPrivateKeyStrategy(won.cryptography.ssl.PredefinedAliasPrivateKeyStrategy)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)2 PredefinedAliasPrivateKeyStrategy (won.cryptography.ssl.PredefinedAliasPrivateKeyStrategy)2 HttpStatus (org.springframework.http.HttpStatus)1 DefaultResponseErrorHandler (org.springframework.web.client.DefaultResponseErrorHandler)1