diff options
author | Thomas <> | 2022-01-19 14:00:06 +0100 |
---|---|---|
committer | Thomas <> | 2022-01-19 14:00:06 +0100 |
commit | 122245400a8cbf72f65a206592eb15f70826ace9 (patch) | |
tree | dc2126cc95a3afb61771bc3c8b58337377d5652f | |
parent | 4932d6e3ef8b2347ecb0c66d5b8206fcfa54d77d (diff) | |
download | EAAF-Components-122245400a8cbf72f65a206592eb15f70826ace9.tar.gz EAAF-Components-122245400a8cbf72f65a206592eb15f70826ace9.tar.bz2 EAAF-Components-122245400a8cbf72f65a206592eb15f70826ace9.zip |
refactor(core): change API parameters from 'Date' to 'Instant'
7 files changed, 43 insertions, 36 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/AuthenticationData.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/AuthenticationData.java index 4fe22feb..e1646fb8 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/AuthenticationData.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/AuthenticationData.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.Date; import java.util.Map; import java.util.TimeZone; @@ -57,7 +58,7 @@ public class AuthenticationData implements IAuthData, Serializable { private final Map<String, Object> genericDataStorate = new HashedMap<>(); private String issuer; - private Date issueInstant; + private Instant issueInstant; @Deprecated private String identificationValue; @@ -82,14 +83,14 @@ public class AuthenticationData implements IAuthData, Serializable { private String eidasLoa = null; private boolean ssoSession = false; - private Date ssoSessionValidTo = null; + private Instant ssoSessionValidTo = null; private String sessionIndex = null; private String nameID = null; private String nameIdFormat = null; public AuthenticationData() { - this.issueInstant = new Date(); + this.issueInstant = Instant.now(); } @@ -109,7 +110,7 @@ public class AuthenticationData implements IAuthData, Serializable { } @Override - public Date getAuthenticationIssueInstant() { + public Instant getAuthenticationIssueInstant() { return getDateCopyOrNull(this.issueInstant); } @@ -127,7 +128,7 @@ public class AuthenticationData implements IAuthData, Serializable { * * @param date Authentication data */ - public void setAuthenticationIssueInstant(final Date date) { + public void setAuthenticationIssueInstant(final Instant date) { this.issueInstant = getDateCopyOrNull(date); } @@ -396,7 +397,7 @@ public class AuthenticationData implements IAuthData, Serializable { * @return the ssoSessionValidTo */ @Override - public Date getSsoSessionValidTo() { + public Instant getSsoSessionValidTo() { return getDateCopyOrNull(ssoSessionValidTo); } @@ -405,7 +406,7 @@ public class AuthenticationData implements IAuthData, Serializable { * * @param ssoSessionValidTo the ssoSessionValidTo to set */ - public void setSsoSessionValidTo(final Date ssoSessionValidTo) { + public void setSsoSessionValidTo(final Instant ssoSessionValidTo) { this.ssoSessionValidTo = getDateCopyOrNull(ssoSessionValidTo); } @@ -519,10 +520,12 @@ public class AuthenticationData implements IAuthData, Serializable { this.encSourceIdType = encSourceIdType; } - private Date getDateCopyOrNull(Date in) { + private Instant getDateCopyOrNull(Instant in) { if (in != null) { - return new Date(in.getTime()); + return Instant.from(in); + } else { + return null; } } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java index 368652be..383b4535 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java @@ -21,10 +21,12 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.data; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Map; import java.util.Map.Entry; -import java.util.TimeZone; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -54,8 +56,8 @@ public class AuthProcessDataWrapper } @Override - public Date getIssueInstant() { - return wrapStoredObject(VALUE_ISSUEINSTANT, null, Date.class); + public Instant getIssueInstant() { + return wrapStoredObject(VALUE_ISSUEINSTANT, null, Instant.class); } /* @@ -67,7 +69,7 @@ public class AuthProcessDataWrapper @Override public String getIssueInstantString() { return buildDateTimeUtcString( - wrapStoredObject(VALUE_ISSUEINSTANT, null, Date.class)); + wrapStoredObject(VALUE_ISSUEINSTANT, null, Instant.class)); } /* @@ -92,7 +94,7 @@ public class AuthProcessDataWrapper * java.lang.String) */ @Override - public void setIssueInstant(final Date issueInstant) { + public void setIssueInstant(final Instant issueInstant) { authProcessData.put(VALUE_ISSUEINSTANT, issueInstant); } @@ -347,16 +349,17 @@ public class AuthProcessDataWrapper * <code>yyyy-MM-dd'T'HH:mm:ss'Z'</code>, or <code>null</code> if {@link Date} was <code>null</code> */ @Nullable - public static String buildDateTimeUtcString(@Nullable final Date date) { + public static String buildDateTimeUtcString(@Nullable final Instant date) { if (date == null) { return null; } - - final SimpleDateFormat f = new SimpleDateFormat(PATTERN_ISSUE_INSTANT); - f.setTimeZone(TimeZone.getTimeZone("UTC")); - return f.format(date.getTime()); - + + return DateTimeFormatter + .ofPattern(PATTERN_ISSUE_INSTANT) + .withZone(ZoneId.of("UTC")) + .format(date); + } /** @@ -368,11 +371,11 @@ public class AuthProcessDataWrapper * if input parameter was <code>null</code> or invalid */ @Nullable - public static Date buildDateTimeUtcDate(@Nullable final String date) { + public static Instant buildDateTimeUtcDate(@Nullable final String date) { final SimpleDateFormat f = new SimpleDateFormat(PATTERN_ISSUE_INSTANT); try { - if (date != null) { - return f.parse(date); + if (date != null) { + return f.parse(date).toInstant(); } diff --git a/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/IAuthData.java b/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/IAuthData.java index f76e8d76..9c550819 100644 --- a/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/IAuthData.java +++ b/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/IAuthData.java @@ -19,7 +19,7 @@ package at.gv.egiz.eaaf.core.api.idp; -import java.util.Date; +import java.time.Instant; import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; @@ -51,7 +51,7 @@ public interface IAuthData { * * @return */ - Date getAuthenticationIssueInstant(); + Instant getAuthenticationIssueInstant(); /** * Get string formated timestamp of the authentication process. @@ -142,7 +142,7 @@ public interface IAuthData { * * @return */ - Date getSsoSessionValidTo(); + Instant getSsoSessionValidTo(); /** * SessionIndex, if it was an reauthentication on a service provider by using diff --git a/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/data/IAuthProcessDataContainer.java b/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/data/IAuthProcessDataContainer.java index cb9adbc8..ac235a8c 100644 --- a/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/data/IAuthProcessDataContainer.java +++ b/eaaf_core_api/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/data/IAuthProcessDataContainer.java @@ -19,6 +19,7 @@ package at.gv.egiz.eaaf.core.api.idp.auth.data; +import java.time.Instant; import java.util.Date; import java.util.Map; import java.util.Map.Entry; @@ -33,7 +34,7 @@ public interface IAuthProcessDataContainer { * * @return The issuing time of the AUTH-Block SAML assertion. */ - Date getIssueInstant(); + Instant getIssueInstant(); /** * Returns the issuing time of the AUTH-Block SAML assertion. @@ -58,7 +59,7 @@ public interface IAuthProcessDataContainer { * * @param issueInstant The issueInstant to set. */ - void setIssueInstant(Date issueInstant); + void setIssueInstant(Instant issueInstant); /** * Indicate if the authentication process is finished. diff --git a/eaaf_modules/eaaf_module_pvp2_idp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/idp/impl/builder/Pvp2AssertionBuilder.java b/eaaf_modules/eaaf_module_pvp2_idp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/idp/impl/builder/Pvp2AssertionBuilder.java index 88ff2206..733301be 100644 --- a/eaaf_modules/eaaf_module_pvp2_idp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/idp/impl/builder/Pvp2AssertionBuilder.java +++ b/eaaf_modules/eaaf_module_pvp2_idp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/idp/impl/builder/Pvp2AssertionBuilder.java @@ -363,8 +363,7 @@ public class Pvp2AssertionBuilder implements PvpConstants { final SubjectConfirmationData subjectConfirmationData = Saml2Utils.createSamlObject(SubjectConfirmationData.class); subjectConfirmationData.setInResponseTo(authnRequest.getID()); - subjectConfirmationData - .setNotOnOrAfter(Instant.ofEpochMilli(authData.getSsoSessionValidTo().getTime())); + subjectConfirmationData.setNotOnOrAfter(authData.getSsoSessionValidTo()); // set 'recipient' attribute in subjectConformationData subjectConfirmationData.setRecipient(assertionConsumerService.getLocation()); diff --git a/eaaf_modules/eaaf_module_pvp2_idp/src/test/java/at/gv/egiz/eaaf/modules/pvp2/idp/test/AuthenticationActionTest.java b/eaaf_modules/eaaf_module_pvp2_idp/src/test/java/at/gv/egiz/eaaf/modules/pvp2/idp/test/AuthenticationActionTest.java index cab14a5d..466bcf22 100644 --- a/eaaf_modules/eaaf_module_pvp2_idp/src/test/java/at/gv/egiz/eaaf/modules/pvp2/idp/test/AuthenticationActionTest.java +++ b/eaaf_modules/eaaf_module_pvp2_idp/src/test/java/at/gv/egiz/eaaf/modules/pvp2/idp/test/AuthenticationActionTest.java @@ -1,6 +1,6 @@ package at.gv.egiz.eaaf.modules.pvp2.idp.test; -import java.util.Date; +import java.time.Instant; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -104,7 +104,7 @@ public class AuthenticationActionTest { } @Override - public Date getSsoSessionValidTo() { + public Instant getSsoSessionValidTo() { return null; } @@ -208,8 +208,8 @@ public class AuthenticationActionTest { } @Override - public Date getAuthenticationIssueInstant() { - return new Date(); + public Instant getAuthenticationIssueInstant() { + return Instant.now(); } @Override diff --git a/eaaf_modules/eaaf_module_pvp2_sp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/sp/impl/utils/AssertionAttributeExtractor.java b/eaaf_modules/eaaf_module_pvp2_sp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/sp/impl/utils/AssertionAttributeExtractor.java index f87096fb..4d8c8993 100644 --- a/eaaf_modules/eaaf_module_pvp2_sp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/sp/impl/utils/AssertionAttributeExtractor.java +++ b/eaaf_modules/eaaf_module_pvp2_sp/src/main/java/at/gv/egiz/eaaf/modules/pvp2/sp/impl/utils/AssertionAttributeExtractor.java @@ -19,6 +19,7 @@ package at.gv.egiz.eaaf.modules.pvp2.sp.impl.utils; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -314,9 +315,9 @@ public class AssertionAttributeExtractor { * * @return Date, when the SAML2 assertion was issued, otherwise null */ - public Date getAssertionIssuingDate() { + public Instant getAssertionIssuingDate() { try { - return Date.from(getFullAssertion().getIssueInstant()); + return getFullAssertion().getIssueInstant(); } catch (final NullPointerException e) { return null; |