Skip to content

Commit

Permalink
Merge pull request #31 from pagopa/core-sprint-3-fixes
Browse files Browse the repository at this point in the history
[core-sprint3-fixes] Fixing sonar smells
  • Loading branch information
alessio-cialini authored Apr 19, 2023
2 parents 944bb0b + 31bece5 commit c73e80f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void startServer() {
@Autowired private HttpVerifierHandlerInterceptor interceptor;

@Test
public void testWithValidRequestReturnsSuccess() {
void testWithValidRequestReturnsSuccess() {
AssertionSimpleClientTestUtils.createExpectationAssertionFound();

String signatureInput =
Expand Down Expand Up @@ -93,7 +93,8 @@ public void testWithValidRequestReturnsSuccess() {
Assertions.assertEquals(200, response.getStatusCodeValue());
}

public void testWithinvalidPayloadRequestReturnsUnauthorized() {
@Test
void testWithinvalidPayloadRequestReturnsUnauthorized() {
AssertionSimpleClientTestUtils.createExpectationAssertionFound();

String signatureInput =
Expand Down

0 comments on commit c73e80f

Please sign in to comment.