summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at
diff options
context:
space:
mode:
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.java70
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java10
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BirthdateAttributeBuilder.java10
3 files changed, 49 insertions, 41 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 00324a9a..4fe22feb 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
@@ -26,6 +26,9 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
+import java.util.regex.Pattern;
+
+import javax.annotation.Nullable;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
@@ -47,6 +50,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 IDENTITY_LINK_DATE_REGEX = "([0-9]{4})-([0-9]{2})-([0-9]{2})";
public static final String ISSUE_INSTANT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private boolean isBaseIdTransferRestrication = true;
@@ -64,7 +68,7 @@ public class AuthenticationData implements IAuthData, Serializable {
private String familyName;
private String givenName;
- private Date dateOfBirth;
+ private String dateOfBirth;
private String encSourceId;
private String encSourceIdType;
@@ -147,22 +151,36 @@ public class AuthenticationData implements IAuthData, Serializable {
}
@Override
- public Date getDateOfBirth() {
- return getDateCopyOrNull(this.dateOfBirth);
+ public String getDateOfBirth() {
+ return this.dateOfBirth;
}
@Override
- public String getFormatedDateOfBirth() {
- final DateFormat pvpDateFormat = new SimpleDateFormat(IDENTITY_LINK_DATE_FORMAT);
- if (getDateOfBirth() != null) {
- return pvpDateFormat.format(getDateOfBirth());
- } else {
- return "2999-12-31";
- }
-
+ public String getDateOfBirthFormated(String pattern) {
+ if (StringUtils.isNotEmpty(getDateOfBirth())) {
+ try {
+ final DateFormat dateFormat = new SimpleDateFormat(IDENTITY_LINK_DATE_FORMAT);
+ Date parsedDate = dateFormat.parse(getDateOfBirth());
+ final String dateString = dateFormat.format(parsedDate);
+ if (getDateOfBirth().equals(dateString)) {
+ final DateFormat destDateFormat = new SimpleDateFormat(pattern);
+ return destDateFormat.format(parsedDate);
+
+ } else {
+ log.info("DateOfBirth has an unusal format. Can not be converted to: {}", pattern);
+
+ }
+
+ } catch (ParseException | IllegalArgumentException e) {
+ log.error("Can not parse DateOfBirth.", e);
+
+ }
+ }
+ return null;
+
}
-
+
@Override
public String getFamilyName() {
return this.familyName;
@@ -216,26 +234,16 @@ public class AuthenticationData implements IAuthData, Serializable {
*
* @param dateOfBirth The dateOfBirth to set
*/
- public void setDateOfBirth(final Date dateOfBirth) {
- this.dateOfBirth = getDateCopyOrNull(dateOfBirth);
- }
-
- /**
- * Set the date of birth.
- *
- * @param dateOfBirth date of birth String as "yyyy-MM-dd"
- */
- public void setDateOfBirth(final String dateOfBirth) {
- try {
- if (StringUtils.isNotEmpty(dateOfBirth)) {
- final DateFormat identityLinkFormat = new SimpleDateFormat(IDENTITY_LINK_DATE_FORMAT);
- this.dateOfBirth = identityLinkFormat.parse(dateOfBirth);
-
+ public void setDateOfBirth(@Nullable final String dateOfBirth) {
+ if (dateOfBirth != null) {
+ if (Pattern.matches(IDENTITY_LINK_DATE_REGEX, dateOfBirth)) {
+ this.dateOfBirth = dateOfBirth;
+
+ } else {
+ log.error("DateOfBirth: {} does NOT match to pattern: {}",
+ dateOfBirth, IDENTITY_LINK_DATE_REGEX);
+
}
-
- } catch (final ParseException e) {
- log.warn("Parse dateOfBirht from IdentityLink FAILED", e);
-
}
}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java
index 812a5171..4e04a87f 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java
@@ -1,10 +1,12 @@
package at.gv.egiz.eaaf.core.impl.idp.auth.services;
-import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration;
-import at.gv.egiz.eaaf.core.exceptions.EaafException;
+import java.util.HashSet;
+import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletRequest;
-import java.util.HashSet;
+
+import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration;
+import at.gv.egiz.eaaf.core.exceptions.EaafException;
public interface IErrorService {
/**
@@ -35,6 +37,7 @@ public interface IErrorService {
* @param internalCode internal error code
* @return external error code
*/
+ @Nonnull
String getExternalCodeFromInternal(String internalCode);
/**
@@ -45,6 +48,7 @@ public interface IErrorService {
* @return eror handle Data
* @throws EaafException In case of an internal error
*/
+ @Nonnull
IHandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException;
/**
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BirthdateAttributeBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BirthdateAttributeBuilder.java
index 19500cb3..a82a1a55 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BirthdateAttributeBuilder.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BirthdateAttributeBuilder.java
@@ -19,8 +19,7 @@
package at.gv.egiz.eaaf.core.impl.idp.builder.attributes;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import org.apache.commons.lang3.StringUtils;
import at.gv.egiz.eaaf.core.api.idp.IAttributeGenerator;
import at.gv.egiz.eaaf.core.api.idp.IAuthData;
@@ -41,11 +40,8 @@ public class BirthdateAttributeBuilder implements IPvpAttributeBuilder {
public <ATT> ATT build(final ISpConfiguration oaParam, final IAuthData authData,
final IAttributeGenerator<ATT> g) throws AttributeBuilderException {
- if (authData.getDateOfBirth() != null) {
- final DateFormat pvpDateFormat = new SimpleDateFormat(BIRTHDATE_FORMAT_PATTERN);
- final String dateString = pvpDateFormat.format(authData.getDateOfBirth());
-
- return g.buildStringAttribute(BIRTHDATE_FRIENDLY_NAME, BIRTHDATE_NAME, dateString);
+ if (StringUtils.isNotEmpty(authData.getDateOfBirth())) {
+ return g.buildStringAttribute(BIRTHDATE_FRIENDLY_NAME, BIRTHDATE_NAME, authData.getDateOfBirth());
} else {
throw new UnavailableAttributeException(BIRTHDATE_NAME);