Skip to content

Commit

Permalink
Merge pull request #75 from pagopa/feature/PN-7164
Browse files Browse the repository at this point in the history
feature/PN-7164
  • Loading branch information
masciale89 authored Jul 11, 2023
2 parents d852004 + 3eea26c commit 159260f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {
}

allprojects {
version = '1.0.0-RC4'
version = '1.0.0-RC5'
group = 'it.pagopa.tech.lollipop-consumer-java-sdk'
sourceCompatibility = '11'
targetCompatibility = '11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class LollipopConsumerRequestConfig {

// assertion validation parameters
@Builder.Default private int assertionExpireInDays = 365;
@Builder.Default private String assertionNotBeforeDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
@Builder.Default private String assertionInstantDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

@Builder.Default
private String samlNamespaceAssertion = "urn:oasis:names:tc:SAML:2.0:assertion";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.xml.parsers.DocumentBuilder;
Expand All @@ -37,6 +33,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.wss4j.common.ext.WSSecurityException;
import org.apache.wss4j.common.saml.SAMLKeyInfo;
import org.joda.time.format.ISODateTimeFormat;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -150,10 +147,8 @@ protected boolean validateAssertionPeriod(Document assertionDoc)
long notBeforeMilliseconds;
try {
notBeforeMilliseconds =
new SimpleDateFormat(lollipopRequestConfig.getAssertionNotBeforeDateFormat())
.parse(notBefore)
.getTime();
} catch (ParseException e) {
ISODateTimeFormat.dateTimeParser().parseDateTime(notBefore).getMillis();
} catch (UnsupportedOperationException | IllegalArgumentException e) {
throw new AssertionPeriodException(
AssertionPeriodException.ErrorCode.ERROR_PARSING_ASSERTION_NOT_BEFORE_DATE,
e.getMessage(),
Expand Down Expand Up @@ -442,15 +437,15 @@ private String getPublicKey(String publicKey) {
}

private String parseInstantToMillis(String instant) {
String instantDateFormat = lollipopRequestConfig.getAssertionInstantDateFormat();
try {
instant =
Long.toString(new SimpleDateFormat(instantDateFormat).parse(instant).getTime());
} catch (ParseException e) {
Long.toString(
ISODateTimeFormat.dateTimeParser().parseDateTime(instant).getMillis());
} catch (UnsupportedOperationException | IllegalArgumentException e) {
String msg =
String.format(
"Retrieved instant %s does not match expected format %s",
instant, instantDateFormat);
"Retrieved instant %s does not match expected ISO datetime format",
instant);
log.debug(msg);
}
return instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TestUtils {
+ " xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\""
+ " ID=\"_6b9580aa-08b1-4f19-8fb6-8b670d070bad\""
+ " IssueInstant=\"2023-02-28T16:27:25.400Z\" Version=\"2.0\"><saml2:Conditions"
+ " NotBefore=\"2023-02-28\""
+ " NotBefore=\"2023-02-28Z\""
+ " NotOnOrAfter=\"2023-02-28T16:28:25.400Z\"><saml2:AudienceRestriction><saml2:Audience>https://app-backend.io.italia.it</saml2:Audience></saml2:AudienceRestriction></saml2:Conditions></saml2:Assertion></saml2p:Response>";
public static final String ASSERTION_XML_WITH_EXPIRED_PERIOD =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><saml2p:Response"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ void validateLollipopValidatePeriodSuccess() {
assertion.setAssertionData(VALID_ASSERTION_XML);

doReturn(365 * 20).when(lollipopRequestConfigMock).getAssertionExpireInDays();
doReturn("yyyy-MM-dd'T'HH:mm:ss'Z'")
.when(lollipopRequestConfigMock)
.getAssertionNotBeforeDateFormat();

doReturn(assertion).when(assertionServiceMock).getAssertion(anyString(), anyString());
doReturn(true)
Expand Down
2 changes: 1 addition & 1 deletion samples/servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {


group = 'it.pagopa.tech.lollipop.consumer.samples'
version = '1.0.0-RC4'
version = '1.0.0-RC5'
sourceCompatibility = '11'

application {
Expand Down
2 changes: 1 addition & 1 deletion samples/simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {


group = 'it.pagopa.tech.lollipop.consumer.samples'
version = '1.0.0-RC4'
version = '1.0.0-RC5'
sourceCompatibility = '11'

application {
Expand Down
2 changes: 1 addition & 1 deletion samples/simpleTypesafe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {


group = 'it.pagopa.tech.lollipop.consumer.samples'
version = '1.0.0-RC4'
version = '1.0.0-RC5'
sourceCompatibility = '11'

application {
Expand Down
2 changes: 1 addition & 1 deletion samples/spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'it.pagopa.tech.lollipop.consumer.samples'
version = '1.0.0-RC4'
version = '1.0.0-RC5'
sourceCompatibility = '11'

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ void testWithAValidRequestReturnsSuccess() throws IOException {
SimpleClientsTestUtils.createExpectationAssertionFound();
SimpleClientsTestUtils.createExpectationIdpFound();
lollipopConsumerRequestConfig.setAssertionExpireInDays(365);
lollipopConsumerRequestConfig.setAssertionNotBeforeDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
lollipopConsumerRequestConfig.setAssertionInstantDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

RestTemplate exec = restTemplate.getRestTemplate();
exec.getClientHttpRequestInitializers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public void startServer() {
void testWithValidRequestReturnsSuccess() throws IOException {
SimpleClientsTestUtils.createExpectationAssertionFound();
SimpleClientsTestUtils.createExpectationIdpFound();
springLollipopConsumerRequestConfig.setAssertionNotBeforeDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
springLollipopConsumerRequestConfig.setAssertionInstantDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");

RestTemplate exec = restTemplate.getRestTemplate();
exec.getClientHttpRequestInitializers()
Expand Down Expand Up @@ -202,10 +198,6 @@ void testWithInvalidURLRequestReturnsUnauthorized() throws IOException {
SimpleClientsTestUtils.createExpectationAssertionFound();
SimpleClientsTestUtils.createExpectationIdpFound();
springLollipopConsumerRequestConfig.setAssertionExpireInDays(365);
springLollipopConsumerRequestConfig.setAssertionNotBeforeDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
springLollipopConsumerRequestConfig.setAssertionInstantDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
idpCertSimpleClientConfig.setBaseUri("http://localhost:3001");

RestTemplate exec = restTemplate.getRestTemplate();
Expand Down

0 comments on commit 159260f

Please sign in to comment.