diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-03-10 13:56:48 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-03-10 13:56:48 +0100 |
commit | 90705b721d49c61e6d7a698fd66aa951470e9dc0 (patch) | |
tree | e39ba49ab1d7cb94a97bf5000579cebbddef599f /eaaf_core/src/main/java/at | |
parent | d08a5df42ece34b58109d4cea3b88ca52e4bdb45 (diff) | |
download | EAAF-Components-90705b721d49c61e6d7a698fd66aa951470e9dc0.tar.gz EAAF-Components-90705b721d49c61e6d7a698fd66aa951470e9dc0.tar.bz2 EAAF-Components-90705b721d49c61e6d7a698fd66aa951470e9dc0.zip |
Change internal representation of IssuerInstant from String to Date
Diffstat (limited to 'eaaf_core/src/main/java/at')
-rw-r--r-- | eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/AuthenticationData.java | 3 | ||||
-rw-r--r-- | eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java | 85 |
2 files changed, 67 insertions, 21 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 a6fe5ff0..7b7aaa36 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 @@ -48,6 +48,7 @@ public class AuthenticationData implements IAuthData, Serializable { private static final long serialVersionUID = -1042697056735596866L; public static final String IDENTITY_LINK_DATE_FORMAT = "yyyy-MM-dd"; + public static final String ISSUE_INSTANT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private boolean isBaseIdTransferRestrication = true; private final Map<String, Object> genericDataStorate = new HashedMap<>(); @@ -112,7 +113,7 @@ public class AuthenticationData implements IAuthData, Serializable { @Override public String getAuthenticationIssueInstantString() { - final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + final SimpleDateFormat f = new SimpleDateFormat(ISSUE_INSTANT_DATE_FORMAT); f.setTimeZone(TimeZone.getTimeZone("UTC")); return f.format(this.issueInstant); 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 988a78b6..30144546 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 @@ -19,12 +19,15 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.data; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.TimeZone; +import javax.annotation.Nullable; + import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.api.idp.EaafAuthProcessDataConstants; import at.gv.egiz.eaaf.core.api.idp.auth.data.IAuthProcessDataContainer; @@ -39,6 +42,8 @@ public class AuthProcessDataWrapper implements IAuthProcessDataContainer, EaafAuthProcessDataConstants { private static final Logger log = LoggerFactory.getLogger(AuthProcessDataWrapper.class); + public final static String PATTERN_ISSUE_INSTANT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + protected Map<String, Object> authProcessData; public AuthProcessDataWrapper(final Map<String, Object> authProcessData) { @@ -46,6 +51,11 @@ public class AuthProcessDataWrapper } + @Override + public Date getIssueInstant() { + return wrapStoredObject(VALUE_ISSUEINSTANT, null, Date.class); + } + /* * (non-Javadoc) * @@ -53,8 +63,9 @@ public class AuthProcessDataWrapper * at.gv.egovernment.moa.id.auth.data.IAuthenticationSession#getIssueInstant() */ @Override - public String getIssueInstant() { - return wrapStringObject(VALUE_ISSUEINSTANT, null, String.class); + public String getIssueInstantString() { + return buildDateTimeUtcString( + wrapStoredObject(VALUE_ISSUEINSTANT, null, Date.class)); } /* @@ -66,7 +77,8 @@ public class AuthProcessDataWrapper */ @Override public void setIssueInstant(final String issueInstant) { - authProcessData.put(VALUE_ISSUEINSTANT, issueInstant); + authProcessData.put(VALUE_ISSUEINSTANT, + buildDateTimeUtcDate(issueInstant)); } @@ -79,7 +91,7 @@ public class AuthProcessDataWrapper */ @Override public void setIssueInstant(final Date issueInstant) { - authProcessData.put(VALUE_ISSUEINSTANT, buildDateTimeUtc(issueInstant)); + authProcessData.put(VALUE_ISSUEINSTANT, issueInstant); } @@ -91,7 +103,7 @@ public class AuthProcessDataWrapper */ @Override public boolean isAuthenticated() { - return wrapStringObject(FLAG_IS_AUTHENTICATED, false, Boolean.class); + return wrapStoredObject(FLAG_IS_AUTHENTICATED, false, Boolean.class); } @@ -116,7 +128,7 @@ public class AuthProcessDataWrapper */ @Override public IIdentityLink getIdentityLink() { - return wrapStringObject(VALUE_IDENTITYLINK, null, IIdentityLink.class); + return wrapStoredObject(VALUE_IDENTITYLINK, null, IIdentityLink.class); } @@ -141,7 +153,7 @@ public class AuthProcessDataWrapper */ @Override public boolean isMandateUsed() { - return wrapStringObject(FLAG_USE_MANDATE, false, Boolean.class); + return wrapStoredObject(FLAG_USE_MANDATE, false, Boolean.class); } /* @@ -164,7 +176,7 @@ public class AuthProcessDataWrapper */ @Override public String getQaaLevel() { - return wrapStringObject(VALUE_QAALEVEL, null, String.class); + return wrapStoredObject(VALUE_QAALEVEL, null, String.class); } /* @@ -187,7 +199,7 @@ public class AuthProcessDataWrapper */ @Override public boolean isForeigner() { - return wrapStringObject(FLAG_IS_FOREIGNER, false, Boolean.class); + return wrapStoredObject(FLAG_IS_FOREIGNER, false, Boolean.class); } /* @@ -209,7 +221,7 @@ public class AuthProcessDataWrapper */ @Override public boolean isOW() { - return wrapStringObject(FLAG_IS_ORGANWALTER, false, Boolean.class); + return wrapStoredObject(FLAG_IS_ORGANWALTER, false, Boolean.class); } /* @@ -225,7 +237,7 @@ public class AuthProcessDataWrapper @Override public boolean isEidProcess() { - return wrapStringObject(FLAG_IS_NEW_EID_PROCESS, false, Boolean.class); + return wrapStoredObject(FLAG_IS_NEW_EID_PROCESS, false, Boolean.class); } @Override @@ -242,7 +254,7 @@ public class AuthProcessDataWrapper */ @Override public Date getSessionCreated() { - return wrapStringObject(EaafConstants.AUTH_DATA_CREATED, null, Date.class); + return wrapStoredObject(EaafConstants.AUTH_DATA_CREATED, null, Date.class); } /* @@ -283,7 +295,7 @@ public class AuthProcessDataWrapper */ @Override public <T> T getGenericDataFromSession(final String key, final Class<T> clazz) { - return wrapStringObject(GENERIC_PREFIX + key, null, clazz); + return wrapStoredObject(GENERIC_PREFIX + key, null, clazz); } /* @@ -299,7 +311,7 @@ public class AuthProcessDataWrapper } - protected <T> T wrapStringObject(final String key, final Object defaultValue, + protected <T> T wrapStoredObject(final String key, final Object defaultValue, final Class<T> clazz) { if (StringUtils.isNotEmpty(key)) { final Object obj = authProcessData.get(key); @@ -322,16 +334,49 @@ public class AuthProcessDataWrapper } /** - * Builds a <code>dateTime</code> value in UTC from a <code>Calendar</code> value. + * Builds a {@link String} dateTime value in UTC from a {@link Date} value. * - * @param date the <code>Calendar</code> value - * @return the <code>dateTime</code> value + * @param date the {@link Date} that should be transformed + * @return The {@link String} representation of the date in + * <code>yyyy-MM-dd'T'HH:mm:ss'Z'</code>, or <code>null</code> if {@link Date} was <code>null</code> */ - public static String buildDateTimeUtc(final Date date) { + @Nullable + public static String buildDateTimeUtcString(@Nullable final Date date) { + if (date == null) { + return null; - final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - f.setTimeZone(TimeZone.getTimeZone("UTC")); + } + final SimpleDateFormat f = new SimpleDateFormat(PATTERN_ISSUE_INSTANT); + f.setTimeZone(TimeZone.getTimeZone("UTC")); return f.format(date.getTime()); + } + + /** + * Builds a {@link String} dateTime value in UTC from a {@link Date} value. + * + * @param date the {@link String} in <code>yyyy-MM-dd'T'HH:mm:ss'Z'</code> + * format that should be transformed + * @return The {@link Date} representation of the date, otherwise <code>null</code> + * if input parameter was <code>null</code> or invalid + */ + @Nullable + public static Date buildDateTimeUtcDate(@Nullable final String date) { + final SimpleDateFormat f = new SimpleDateFormat(PATTERN_ISSUE_INSTANT); + try { + if (date != null) { + return f.parse(date); + + } + + } catch (final ParseException e) { + log.error("Can NOT parse Date from String: {}", date, null, e); + + } + + return null; + + } + } |