/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 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: * http://www.osor.eu/eupl/ * * 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.egovernment.moa.id.configuration.data.oa; import java.util.Arrays; import java.util.List; import javax.servlet.http.HttpServletRequest; import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.AuthComponentOA; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.IdentificationNumber; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OnlineApplication; import at.gv.egovernment.moa.id.commons.validation.TargetValidator; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser; import at.gv.egovernment.moa.id.configuration.validation.oa.OATargetConfigValidation; import at.gv.egovernment.moa.util.MiscUtil; /** * @author tlenz * */ public class OATargetConfiguration implements IOnlineApplicationData { private boolean deaktivededBusinessService = false; private boolean subTargetSet = false; private String target = null; private String target_subsector = null; private String target_admin = null; private static List targetList = null; private String targetFriendlyName = null; private boolean isAdminTarget = false; private String identificationNumber = null; private String identificationType = null; private static List identificationTypeList = null; private String foreignbPKTargets = null; private String additionalbPKTargets = null; private boolean eidDemoActive = false; private boolean eidProxyActive = false; public OATargetConfiguration() { targetList = TargetValidator.getListOfTargets(); target = ""; identificationTypeList = Arrays.asList( Constants.IDENIFICATIONTYPE_FN, Constants.IDENIFICATIONTYPE_ZVR, Constants.IDENIFICATIONTYPE_ERSB, Constants.IDENIFICATIONTYPE_STORK, Constants.IDENIFICATIONTYPE_EIDAS); } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#getName() */ @Override public String getName() { return "OATargetConfig"; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#parse(at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication, at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser, javax.servlet.http.HttpServletRequest) */ @Override public List parse(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) { String target_full = dbOA.getTarget(); if (MiscUtil.isNotEmpty(target_full)) { if (TargetValidator.isValidTarget(target_full)) { target = target_full; } else { String[] target_split = target_full.split("-"); if (TargetValidator.isValidTarget(target_split[0])) { target = target_split[0]; if (target_split.length > 1) { target_subsector = target_split[1]; subTargetSet = true; } } else { target = ""; target_subsector = null; target_admin = target_full; isAdminTarget = true; } } targetFriendlyName = dbOA.getTargetFriendlyName(); } AuthComponentOA oaauth = dbOA.getAuthComponentOA(); if (oaauth != null) { IdentificationNumber idnumber = oaauth.getIdentificationNumber(); if (idnumber != null) { String number = idnumber.getValue(); if (MiscUtil.isNotEmpty(number)) { String[] split = number.split("\\+"); if (Constants.PREFIX_WPBK.startsWith(split[0]) && split.length >= 2) { identificationType = split[1]; identificationNumber = split[2]; } else if (Constants.PREFIX_EIDAS.startsWith(split[0]) && split.length >= 2) { //identificationType = split[1]; // setting at as iden category ? identificationType = Constants.IDENIFICATIONTYPE_EIDAS; identificationNumber = split[1] + "+" + split[2]; // setting sp country as ident type -> sp ident } else if (Constants.PREFIX_STORK.startsWith(split[0]) && split.length >= 2) { //identificationType = split[1]; // setting at as iden category ? identificationType = Constants.IDENIFICATIONTYPE_STORK; identificationNumber = split[2]; // setting sp country as ident type -> sp ident } } if (authUser.isOnlyBusinessService()) { deaktivededBusinessService = authUser.isOnlyBusinessService(); identificationType = authUser.getBusinessServiceType(); identificationNumber = authUser.getBusinessServiceNumber(); } } } //parse foreign bPK sector list if (dbOA.getForeignbPKTargetList() != null) { if (KeyValueUtils.isCSVValueString(dbOA.getForeignbPKTargetList())) foreignbPKTargets = KeyValueUtils.normalizeCSVValueString(dbOA.getForeignbPKTargetList()); else { if (dbOA.getForeignbPKTargetList().contains(KeyValueUtils.CSV_DELIMITER)) { //remove trailing comma if exist foreignbPKTargets = dbOA.getForeignbPKTargetList().substring(0, dbOA.getForeignbPKTargetList().indexOf(KeyValueUtils.CSV_DELIMITER)); } else foreignbPKTargets = dbOA.getForeignbPKTargetList(); } } //parse additional bPK sector list if (dbOA.getAdditionalbPKTargetList() != null) { if (KeyValueUtils.isCSVValueString(dbOA.getAdditionalbPKTargetList())) additionalbPKTargets = KeyValueUtils.normalizeCSVValueString(dbOA.getAdditionalbPKTargetList()); else { if (dbOA.getAdditionalbPKTargetList().contains(KeyValueUtils.CSV_DELIMITER)) { //remove trailing comma if exist additionalbPKTargets = dbOA.getAdditionalbPKTargetList().substring(0, dbOA.getAdditionalbPKTargetList().indexOf(KeyValueUtils.CSV_DELIMITER)); } else additionalbPKTargets = dbOA.getAdditionalbPKTargetList(); } } //parse 'Austrian eID mode' flag eidDemoActive = dbOA.getIseIDDemoModeActive(); eidProxyActive = dbOA.getIseIDProxyModeActive(); return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#store(at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication, at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser, javax.servlet.http.HttpServletRequest) */ @Override public String store(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) { AuthComponentOA authoa = dbOA.getAuthComponentOA(); if (authoa == null) { authoa = new AuthComponentOA(); dbOA.setAuthComponentOA(authoa); } if (isBusinessService(dbOA) || authUser.isOnlyBusinessService()) { dbOA.setType(Constants.MOA_CONFIG_BUSINESSSERVICE); String num = null; if (authUser.isOnlyBusinessService()) { deaktivededBusinessService = authUser.isOnlyBusinessService(); num = authUser.getBusinessServiceType() + authUser.getBusinessServiceNumber(); } else { num = getIdentificationNumber().replaceAll(" ", ""); if (num.startsWith(Constants.IDENIFICATIONTYPE_FN)) { num = num.substring(Constants.IDENIFICATIONTYPE_FN.length()); num = at.gv.egovernment.moa.util.StringUtils.deleteLeadingZeros(num); /*Fixme: * Company numbers had to be padded with '0' on left site * But this bugfix can not be activated, because this would * change all bPKs for company numbers. * * Change this in case of new bPK generation algorithms */ // num = StringUtils.leftPad(num, 7, '0'); } if (num.startsWith(Constants.IDENIFICATIONTYPE_ZVR)) num = num.substring(Constants.IDENIFICATIONTYPE_ZVR.length()); if (num.startsWith(Constants.IDENIFICATIONTYPE_ERSB)) num = num.substring(Constants.IDENIFICATIONTYPE_ERSB.length()); } IdentificationNumber idnumber = authoa.getIdentificationNumber(); if (idnumber == null) idnumber = new IdentificationNumber(); if (getIdentificationType().equals(Constants.IDENIFICATIONTYPE_EIDAS)) { idnumber.setValue(Constants.PREFIX_EIDAS + num); idnumber.setType(Constants.BUSINESSSERVICENAMES.get(getIdentificationType())); } else if (getIdentificationType().equals(Constants.IDENIFICATIONTYPE_STORK)) { idnumber.setValue(Constants.PREFIX_STORK + "AT" + "+" + num); idnumber.setType(Constants.BUSINESSSERVICENAMES.get(getIdentificationType())); } else { idnumber.setValue(Constants.PREFIX_WPBK + getIdentificationType() + "+" + num); idnumber.setType(Constants.BUSINESSSERVICENAMES.get(getIdentificationType())); } authoa.setIdentificationNumber(idnumber); } else { dbOA.setType(null); if (authUser.isAdmin()) { if (MiscUtil.isNotEmpty(getTarget_admin()) && isAdminTarget()) { dbOA.setTarget(getTarget_admin()); dbOA.setTargetFriendlyName(getTargetFriendlyName()); } else { String target = getTarget(); if (MiscUtil.isNotEmpty(getTarget_subsector()) && subTargetSet) dbOA.setTarget(target + "-" + getTarget_subsector()); else dbOA.setTarget(target); String targetname = TargetValidator.getTargetFriendlyName(target); if (MiscUtil.isNotEmpty(targetname)) dbOA.setTargetFriendlyName(targetname); } } else { if (MiscUtil.isNotEmpty(getTarget())) { String target = getTarget(); if (MiscUtil.isNotEmpty(getTarget_subsector()) && subTargetSet) dbOA.setTarget(target + "-" + getTarget_subsector()); else dbOA.setTarget(target); String targetname = TargetValidator.getTargetFriendlyName(target); if (MiscUtil.isNotEmpty(targetname)) dbOA.setTargetFriendlyName(targetname); } } } dbOA.setForeignbPKTargetList(getForeignbPKTargets()); dbOA.setAdditionalbPKTargetList(getAdditionalbPKTargets()); dbOA.setIseIDDemoModeActive(isEidDemoActive()); dbOA.setIseIDProxyModeActive(isEidProxyActive()); return null; } /** * @return */ private boolean isBusinessService(OnlineApplication dbOA) { if (dbOA.getType().equals(Constants.MOA_CONFIG_BUSINESSSERVICE)) return true; else return false; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#validate(at.gv.egovernment.moa.id.configuration.data.oa.OAGeneralConfig, at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser, javax.servlet.http.HttpServletRequest) */ @Override public List validate(OAGeneralConfig general, AuthenticatedUser authUser, HttpServletRequest request) { return new OATargetConfigValidation().validate(this, authUser.isAdmin(), general, request); } public String getTarget() { return target; } public void setTarget(String target) { this.target = target; } public String getTargetFriendlyName() { return targetFriendlyName; } public void setTargetFriendlyName(String targetFriendlyName) { this.targetFriendlyName = targetFriendlyName; } public String getIdentificationNumber() { return identificationNumber; } public void setIdentificationNumber(String identificationNumber) { this.identificationNumber = identificationNumber; } public String getIdentificationType() { return identificationType; } public void setIdentificationType(String identificationType) { this.identificationType = identificationType; } /** * @return the target_subsector */ public String getTarget_subsector() { return target_subsector; } /** * @param target_subsector the target_subsector to set */ public void setTarget_subsector(String target_subsector) { this.target_subsector = target_subsector; } /** * @return the target_admin */ public String getTarget_admin() { return target_admin; } /** * @param target_admin the target_admin to set */ public void setTarget_admin(String target_admin) { this.target_admin = target_admin; } /** * @return the targetList */ public List getTargetList() { return targetList; } /** * @return the identificationTypeList */ public List getIdentificationTypeList() { return identificationTypeList; } /** * @return the isAdminTarget */ public boolean isAdminTarget() { return isAdminTarget; } /** * @param isAdminTarget the isAdminTarget to set */ public void setAdminTarget(boolean isAdminTarget) { this.isAdminTarget = isAdminTarget; } /** * @return the deaktivededBusinessService */ public boolean isDeaktivededBusinessService() { return deaktivededBusinessService; } /** * @param deaktivededBusinessService the deaktivededBusinessService to set */ public void setDeaktivededBusinessService(boolean deaktivededBusinessService) { this.deaktivededBusinessService = deaktivededBusinessService; } /** * @return the subTargetSet */ public boolean isSubTargetSet() { return subTargetSet; } /** * @param subTargetSet the subTargetSet to set */ public void setSubTargetSet(boolean subTargetSet) { this.subTargetSet = subTargetSet; } public String getForeignbPKTargets() { return foreignbPKTargets; } public void setForeignbPKTargets(String foreignbPKTargets) { if (MiscUtil.isNotEmpty(foreignbPKTargets)) this.foreignbPKTargets = KeyValueUtils.removeAllNewlineFromString(foreignbPKTargets); else this.foreignbPKTargets = foreignbPKTargets; } public String getAdditionalbPKTargets() { return additionalbPKTargets; } public void setAdditionalbPKTargets(String additionalbPKTargets) { if (MiscUtil.isNotEmpty(additionalbPKTargets)) this.additionalbPKTargets = KeyValueUtils.removeAllNewlineFromString(additionalbPKTargets); else this.additionalbPKTargets = additionalbPKTargets; } public boolean isEidDemoActive() { return eidDemoActive; } public void setEidDemoActive(boolean eidDemoActive) { this.eidDemoActive = eidDemoActive; } public boolean isEidProxyActive() { return eidProxyActive; } public void setEidProxyActive(boolean eidProxyActive) { this.eidProxyActive = eidProxyActive; } }