diff --git a/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/AssertionVerifierServiceImpl.java b/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/AssertionVerifierServiceImpl.java index c53e6c5b..37fc3ffc 100644 --- a/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/AssertionVerifierServiceImpl.java +++ b/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/AssertionVerifierServiceImpl.java @@ -273,11 +273,7 @@ private String calculateThumbprint(String inResponseToAlgorithm, String publicKe throws AssertionThumbprintException { Base64URL thumbprint; try { - try { - publicKey = new String(Base64.getDecoder().decode(publicKey)); - } catch (Exception e) { - log.log(Level.FINE, "Key not in Base64"); - } + publicKey = getPublicKey(publicKey); thumbprint = ThumbprintUtils.compute(inResponseToAlgorithm, JWK.parse(publicKey)); } catch (JOSEException | ParseException e) { String errMsg = String.format("Can not calculate JwkThumbprint: %S", e.getMessage()); @@ -297,4 +293,13 @@ private String calculateThumbprint(String inResponseToAlgorithm, String publicKe } return calculatedThumbprint; } + + private String getPublicKey(String publicKey) { + try { + publicKey = new String(Base64.getDecoder().decode(publicKey)); + } catch (Exception e) { + log.log(Level.FINE, "Key not in Base64"); + } + return publicKey; + } } diff --git a/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/LollipopConsumerRequestValidationServiceImpl.java b/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/LollipopConsumerRequestValidationServiceImpl.java index e4712b83..9aeed6e2 100644 --- a/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/LollipopConsumerRequestValidationServiceImpl.java +++ b/core/src/main/java/it/pagopa/tech/lollipop/consumer/service/impl/LollipopConsumerRequestValidationServiceImpl.java @@ -14,8 +14,11 @@ import it.pagopa.tech.lollipop.consumer.service.LollipopConsumerRequestValidationService; import java.util.Base64; import java.util.Map; +import java.util.logging.Level; import java.util.regex.Pattern; +import lombok.extern.java.Log; +@Log public class LollipopConsumerRequestValidationServiceImpl implements LollipopConsumerRequestValidationService { @@ -52,7 +55,7 @@ private void validatePublicKey(String publicKey) try { publicKey = new String(Base64.getDecoder().decode(publicKey.getBytes())); } catch (Exception e) { - // + log.log(Level.FINE, "Key not in Base64"); } if (isNotValidPublicKey(publicKey, ECPublicKey.class) diff --git a/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/config/HttpVerifierConfiguration.java b/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/config/HttpVerifierConfiguration.java index a860d76e..a95dfa1b 100644 --- a/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/config/HttpVerifierConfiguration.java +++ b/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/config/HttpVerifierConfiguration.java @@ -10,7 +10,6 @@ import it.pagopa.tech.lollipop.consumer.service.LollipopConsumerRequestValidationService; import it.pagopa.tech.lollipop.consumer.service.impl.LollipopConsumerRequestValidationServiceImpl; import it.pagopa.tech.lollipop.consumer.spring.HttpVerifierHandlerInterceptor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -21,22 +20,22 @@ @Configuration public class HttpVerifierConfiguration { - @Autowired private SpringLollipopConsumerRequestConfig springLollipopConsumerRequestConfig; - @Bean public LollipopConsumerFactoryHelper lollipopConsumerFactoryHelper( HttpMessageVerifierFactory httpMessageVerifierFactory, IdpCertProviderFactory idpCertProviderFactory, - AssertionServiceFactory assertionServiceFactory) { + AssertionServiceFactory assertionServiceFactory, + LollipopConsumerRequestValidationService lollipopConsumerRequestValidationService) { return new LollipopConsumerFactoryHelper( httpMessageVerifierFactory, idpCertProviderFactory, assertionServiceFactory, - getLollipopConsumerRequestValidationService()); + lollipopConsumerRequestValidationService); } @Bean - public LollipopConsumerRequestValidationService getLollipopConsumerRequestValidationService() { + public LollipopConsumerRequestValidationService getLollipopConsumerRequestValidationService( + SpringLollipopConsumerRequestConfig springLollipopConsumerRequestConfig) { return new LollipopConsumerRequestValidationServiceImpl( springLollipopConsumerRequestConfig); } diff --git a/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/converter/LollipopConsumerRequestConverter.java b/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/converter/LollipopConsumerRequestConverter.java index 5245c351..ec517183 100644 --- a/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/converter/LollipopConsumerRequestConverter.java +++ b/spring-impl/src/main/java/it/pagopa/tech/lollipop/consumer/spring/converter/LollipopConsumerRequestConverter.java @@ -12,6 +12,8 @@ /** Class to be used for conversion of the http requests to be validated */ public class LollipopConsumerRequestConverter { + private LollipopConsumerRequestConverter() {} + /** * Utility method to be used to generate a LollipopConsumerRequest * diff --git a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java index 4be6c840..c89d6ea3 100644 --- a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java +++ b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java @@ -43,7 +43,7 @@ public static void startServer() { @Autowired private HttpVerifierHandlerInterceptor interceptor; @Test - public void testWithValidRequestReturnsSuccess() { + void testWithValidRequestReturnsSuccess() { AssertionSimpleClientTestUtils.createExpectationAssertionFound(); String signatureInput = @@ -93,7 +93,8 @@ public void testWithValidRequestReturnsSuccess() { Assertions.assertEquals(200, response.getStatusCodeValue()); } - public void testWithinvalidPayloadRequestReturnsUnauthorized() { + @Test + void testWithinvalidPayloadRequestReturnsUnauthorized() { AssertionSimpleClientTestUtils.createExpectationAssertionFound(); String signatureInput =