/******************************************************************************* * Copyright 2017 Graz University of Technology * EAAF-Core Components has been developed in a cooperation between EGIZ, * A-SIT+, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ /******************************************************************************* *******************************************************************************/ /******************************************************************************* *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.idp; import java.io.Serializable; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import java.util.TimeZone; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.eaaf.core.api.idp.IAuthData; import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; import at.gv.egiz.eaaf.core.exceptions.EAAFStorageException; /** * @author tlenz * */ public class AuthenticationData implements IAuthData, Serializable { private static final Logger log = LoggerFactory.getLogger(AuthenticationData.class); private static final long serialVersionUID = -1042697056735596866L; public static final String IDENTITY_LINK_DATE_FORMAT = "yyyy-MM-dd"; private boolean isBaseIDTransferRestrication = true; private Map genericDataStorate = new HashedMap(); private String issuer; private Date issueInstant; private String identificationValue; private String identificationType; private IIdentityLink identityLink = null; private String familyName; private String givenName; private Date dateOfBirth; private String bPK; private String bPKType; private String ccc = null; private boolean foreigner =false; private String eIDASLoA = null; private boolean ssoSession = false; private Date ssoSessionValidTo = null; private String sessionIndex = null; private String nameID = null; private String nameIDFormat = null; public AuthenticationData() { this.issueInstant = new Date(); } @Override public String getAuthenticationIssuer() { return this.issuer; } /** * Set an unique identifier for the IDP that authenticates the user * * @param authIssuer */ public void setAuthenticationIssuer(String authIssuer) { this.issuer = authIssuer; } @Override public Date getAuthenticationIssueInstant() { return this.issueInstant; } public String getAuthenticationIssueInstantString() { SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); f.setTimeZone(TimeZone.getTimeZone("UTC")); return f.format(this.issueInstant); } /** * Set the timestamp for this user authentication process * * @param date */ public void setAuthenticationIssueInstant(Date date) { this.issueInstant = date; } @Override public String getCiticenCountryCode() { return this.ccc; } public String getBPK() { return bPK; } /** * Sets the bPK. * @param bPK The bPK to set */ public void setBPK(String bPK) { this.bPK = bPK; } public Date getDateOfBirth() { return this.dateOfBirth; } public String getFormatedDateOfBirth() { DateFormat pvpDateFormat = new SimpleDateFormat(IDENTITY_LINK_DATE_FORMAT); if (getDateOfBirth() != null) return pvpDateFormat.format(getDateOfBirth()); else return "2999-12-31"; } public String getFamilyName() { return this.familyName; } public String getGivenName() { return this.givenName; } public String getIdentificationValue() { return identificationValue; } public String getIdentificationType() { return identificationType; } @Override public IIdentityLink getIdentityLink() { return identityLink; } /** * @param identityLink the identityLink to set */ public void setIdentityLink(IIdentityLink identityLink) { this.identityLink = identityLink; } /** * Sets the dateOfBirth. * @param dateOfBirth The dateOfBirth to set */ public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } public void setDateOfBirth(String dateOfBirth) { try { if (StringUtils.isNotEmpty(dateOfBirth)) { DateFormat identityLinkFormat = new SimpleDateFormat(IDENTITY_LINK_DATE_FORMAT); this.dateOfBirth = identityLinkFormat.parse(dateOfBirth); } } catch (ParseException e) { log.warn("Parse dateOfBirht from IdentityLink FAILED", e); } } /** * Sets the familyName. * @param familyName The familyName to set */ public void setFamilyName(String familyName) { this.familyName = familyName; } /** * Sets the givenName. * @param givenName The givenName to set */ public void setGivenName(String givenName) { this.givenName = givenName; } /** * Sets the identificationValue. * @param identificationValue The identificationValue to set */ public void setIdentificationValue(String identificationValue) { this.identificationValue = identificationValue; } /** * Sets the identificationType. * @param identificationType The identificationType to set */ public void setIdentificationType(String identificationType) { this.identificationType = identificationType; } public String getBPKType() { return bPKType; } /** * Set sector identifier of user's bPK * * @param bPKType */ public void setBPKType(String bPKType) { this.bPKType = bPKType; } public String getEIDASQAALevel() { return this.eIDASLoA; } public boolean isForeigner() { return this.foreigner; } /** * Indicate the the user is a foreigner * * @param true if the user is a foreigner, otherwise false */ public void setForeigner(boolean foreigner) { this.foreigner = foreigner; } @Override public boolean isSsoSession() { return ssoSession; } /** * Indicate that the authentication was done by using an active SSO session * * @param true if a SSO was used, otherwise false */ public void setSsoSession(boolean ssoSession) { this.ssoSession = ssoSession; } /** * Country Code for the authenticated user * * @param ccc Two letter country code */ public void setCiticenCountryCode(String ccc) { this.ccc = ccc; } public String getSessionIndex() { return sessionIndex; } /** * @param sessionIndex the sessionIndex to set */ public void setSessionIndex(String sessionIndex) { this.sessionIndex = sessionIndex; } @Override public String getNameID() { return this.nameID; } /** * @param nameID the nameID to set */ public void setNameID(String nameID) { this.nameID = nameID; } /** * @return the nameIDFormat */ public String getNameIDFormat() { return nameIDFormat; } /** * @param nameIDFormat the nameIDFormat to set */ public void setNameIDFormat(String nameIDFormat) { this.nameIDFormat = nameIDFormat; } /** * @return the ssoSessionValidTo */ public Date getSsoSessionValidTo() { return ssoSessionValidTo; } /** * @param ssoSessionValidTo the ssoSessionValidTo to set */ public void setSsoSessionValidTo(Date ssoSessionValidTo) { this.ssoSessionValidTo = ssoSessionValidTo; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.data.IAuthData#isBusinessService() */ @Override public boolean isBaseIDTransferRestrication() { return isBaseIDTransferRestrication; } /** * @param isBaseIDTransmittionAllowed the isBaseIDTransmittionAllowed to set */ public void setBaseIDTransferRestrication(boolean isBaseIDTransferRestrication) { this.isBaseIDTransferRestrication = isBaseIDTransferRestrication; } /** * Returns a generic data-object with is stored with a specific identifier * * @param key The specific identifier of the data object * @param clazz The class type which is stored with this key * @return The data object or null if no data is found with this key */ public T getGenericData(String key, final Class clazz) { if (StringUtils.isNotEmpty(key)) { Object data = genericDataStorate.get(key); if (data == null) return null; try { @SuppressWarnings("unchecked") T test = (T) data; return test; } catch (Exception e) { log.warn("Generic authentication-data object can not be casted to requsted type", e); return null; } } log.info("Can not load generic session-data with key='null'"); return null; } /** * Store a generic data-object to session with a specific identifier * * @param key Identifier for this data-object * @param object Generic data-object which should be stored. This data-object had to be implement the 'java.io.Serializable' interface * @throws SessionDataStorageException Error message if the data-object can not stored to generic session-data storage */ public void setGenericData(String key, Object object) throws EAAFStorageException { if (StringUtils.isEmpty(key)) { log.info("Generic session-data can not be stored with a 'null' key"); throw new EAAFStorageException("Generic data can not be stored with a 'null' key", null); } if (object != null) { if (!Serializable.class.isInstance(object)) { log.warn("Generic data can only store objects which implements the 'Seralizable' interface"); throw new EAAFStorageException("Generic data can only store objects which implements the 'Seralizable' interface", null); } } if (genericDataStorate.containsKey(key)) log.debug("Overwrite generic data with key:" + key); else log.trace("Add generic data with key:" + key + " to session."); genericDataStorate.put(key, object); } public void seteIDASLoA(String eIDASLoA) { this.eIDASLoA = eIDASLoA; } }