/* * 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.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; 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.BKUURLS; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.MOAIDConfiguration; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.MOAKeyBoxSelector; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.Mandates; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.TemplateType; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.TemplatesType; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.TestCredentials; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.TransformsInfoType; import at.gv.egovernment.moa.id.config.webgui.exception.ConfigurationException; import at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser; import at.gv.egovernment.moa.id.configuration.config.ConfigurationProvider; import at.gv.egovernment.moa.id.configuration.validation.oa.OAAuthenticationDataValidation; import at.gv.egovernment.moa.util.MiscUtil; import lombok.extern.slf4j.Slf4j; /** * @author tlenz * */ @Slf4j public class OAAuthenticationData implements IOnlineApplicationData { private String bkuOnlineURL = null; private String bkuHandyURL = null; private String bkuLocalURL = null; private String mandateProfiles = null; private boolean useMandates = false; private List misServicesList = new ArrayList<>(); private List elgaServicesList = new ArrayList<>(); private List szrgwServicesList = new ArrayList<>(); private List eidServicesList = new ArrayList<>(); private String misServiceSelected = null; private String elgaServiceSelected = null; private String szrgwServiceSelected = null; private String eidServiceSelected = null; private boolean calculateHPI = false; private String keyBoxIdentifier = null; private static Map keyBoxIdentifierList; private boolean legacy = false; List SLTemplates = null; private Map transformations; private boolean enableTestCredentials = false; private List testCredentialOIDs = null; private boolean useTestIDLValidationTrustStore = false; private boolean useTestAuthblockValidationTrustStore = false; // SL2.0 private boolean sl20Active = false; private String sl20EndPoints = null; private boolean isMoaidMode = false; /** * @param isMoaidMode * */ public OAAuthenticationData() { try { this.isMoaidMode = ConfigurationProvider.getInstance().isMOAIDMode(); } catch (final ConfigurationException e) { e.printStackTrace(); } keyBoxIdentifierList = new HashMap<>(); final MOAKeyBoxSelector[] values = MOAKeyBoxSelector.values(); for (final MOAKeyBoxSelector value : values) { keyBoxIdentifierList.put(value.value(), value.value()); } keyBoxIdentifier = MOAKeyBoxSelector.SECURE_SIGNATURE_KEYPAIR.value(); try { final MOAIDConfiguration dbconfig = ConfigurationProvider.getInstance().getDbRead() .getMOAIDConfiguration(); if (this.isMoaidMode) { try { elgaServicesList = KeyValueUtils.getListOfCSVValues(dbconfig.getElgaMandateServiceURLs()); misServicesList = KeyValueUtils.getListOfCSVValues( dbconfig.getAuthComponentGeneral().getOnlineMandates().getConnectionParameter().getURL()); } catch (final NullPointerException e) { } try { szrgwServicesList = KeyValueUtils.getListOfCSVValues( dbconfig.getAuthComponentGeneral().getForeignIdentities().getConnectionParameter().getURL()); } catch (final NullPointerException e) { } } try { eidServicesList = KeyValueUtils.getListOfCSVValues(dbconfig.getEidSystemServiceURLs()); } catch (final NullPointerException e) { } } catch (final ConfigurationException e) { log.error("MOA-ID-Configuration initialization FAILED.", e); } // bkuLocalURL = Constants.DEFAULT_LOCALBKU_URL; // bkuHandyURL = Constants.DEFAULT_HANDYBKU_URL; // // MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); // if (moaidconfig != null) { // DefaultBKUs defaultbkus = moaidconfig.getDefaultBKUs(); // if (defaultbkus != null) { // setBkuHandyURL(defaultbkus.getHandyBKU()); // setBkuLocalURL(defaultbkus.getLocalBKU()); // setBkuOnlineURL(defaultbkus.getOnlineBKU()); // } // } } /* * (non-Javadoc) * * @see * at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#getName * () */ @Override public String getName() { return "OAAuthenticationData"; } /* * (non-Javadoc) * * @see * at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#parse( * at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication, * javax.servlet.http.HttpServletRequest) */ @Override public List parse(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) { keyBoxIdentifier = dbOA.getKeyBoxIdentifier().value(); szrgwServiceSelected = dbOA.getSelectedSZRGWServiceURL(); eidServiceSelected = dbOA.getSelectedEIDServiceURL(); final AuthComponentOA oaauth = dbOA.getAuthComponentOA(); if (oaauth != null) { final BKUURLS bkuurls = oaauth.getBKUURLS(); final String defaulthandy = ""; final String defaultlocal = ""; final String defaultonline = ""; // MOAIDConfiguration dbconfig = ConfigurationDBRead.getMOAIDConfiguration(); // if (dbconfig != null) { // DefaultBKUs defaultbkus = dbconfig.getDefaultBKUs(); // if (defaultbkus != null) { // defaulthandy = defaultbkus.getHandyBKU(); // defaultlocal = defaultbkus.getLocalBKU(); // defaultonline = defaultbkus.getOnlineBKU(); // } // } if (bkuurls != null) { if (MiscUtil.isEmpty(bkuurls.getHandyBKU())) { bkuHandyURL = defaulthandy; } else { bkuHandyURL = bkuurls.getHandyBKU(); } if (MiscUtil.isEmpty(bkuurls.getLocalBKU())) { bkuLocalURL = defaultlocal; } else { bkuLocalURL = bkuurls.getLocalBKU(); } if (MiscUtil.isEmpty(bkuurls.getOnlineBKU())) { bkuOnlineURL = defaultonline; } else { bkuOnlineURL = bkuurls.getOnlineBKU(); } } final Mandates mandates = oaauth.getMandates(); if (mandates != null) { mandateProfiles = null; final List profileList = mandates.getProfileName(); for (final String el : profileList) { if (mandateProfiles == null) { mandateProfiles = el; } else { mandateProfiles += "," + el; } } // TODO: only for RC1 if (MiscUtil.isNotEmpty(mandates.getProfiles())) { if (mandateProfiles == null) { mandateProfiles = mandates.getProfiles(); } else { mandateProfiles += "," + mandates.getProfiles(); } } if (mandateProfiles != null) { useMandates = true; } else { useMandates = false; } misServiceSelected = mandates.getSelectedMISServiceURL(); elgaServiceSelected = mandates.getSelecteELGAServiceURL(); } final TemplatesType templates = oaauth.getTemplates(); if (templates != null) { final List templatetype = templates.getTemplate(); if (templatetype != null) { if (SLTemplates == null) { SLTemplates = new ArrayList<>(); } for (final TemplateType el : templatetype) { SLTemplates.add(el.getURL()); } } } if (SLTemplates != null && SLTemplates.size() > 0) { legacy = true; } final List transforminfos = oaauth.getTransformsInfo(); transformations = new HashMap<>(); for (final TransformsInfoType el : transforminfos) { transformations.put(el.getFilename(), el.getTransformation()); } } if (oaauth.getTestCredentials() != null) { enableTestCredentials = oaauth.getTestCredentials().isEnableTestCredentials(); testCredentialOIDs = new ArrayList<>(); testCredentialOIDs.addAll(oaauth.getTestCredentials().getCredentialOID()); useTestAuthblockValidationTrustStore = oaauth.getTestCredentials().isUseTestAuthBlockTrustStore(); useTestIDLValidationTrustStore = oaauth.getTestCredentials().isUseTestIDLTrustStore(); } // parse SL2.0 information if (oaauth.isSl20Active()) { // parse SL2.0 endpoint information if (oaauth.getSl20EndPoints() != null) { if (KeyValueUtils.isCSVValueString(oaauth.getSl20EndPoints())) { sl20EndPoints = KeyValueUtils.normalizeCSVValueString(oaauth.getSl20EndPoints()); } else { if (oaauth.getSl20EndPoints().contains(KeyValueUtils.CSV_DELIMITER)) { // remove trailing comma if exist sl20EndPoints = oaauth.getSl20EndPoints().substring(0, oaauth.getSl20EndPoints().indexOf(KeyValueUtils.CSV_DELIMITER)); } else { sl20EndPoints = oaauth.getSl20EndPoints(); } } } sl20Active = oaauth.isSl20Active(); } 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); } dbOA.setCalculateHPI(isCalculateHPI()); if (MiscUtil.isNotEmpty(getSzrgwServiceSelected())) { dbOA.setSelectedSZRGWServiceURL(getSzrgwServiceSelected()); } if (MiscUtil.isNotEmpty(getEidServiceSelected())) { dbOA.setSelectedEIDServiceURL(getEidServiceSelected()); } if (authUser.isAdmin()) { // store BKU-URLs final BKUURLS bkuruls = new BKUURLS(); authoa.setBKUURLS(bkuruls); bkuruls.setHandyBKU(getBkuHandyURL()); bkuruls.setLocalBKU(getBkuLocalURL()); bkuruls.setOnlineBKU(getBkuOnlineURL()); // store SecurtiyLayerTemplates TemplatesType templates = authoa.getTemplates(); if (templates == null) { templates = new TemplatesType(); authoa.setTemplates(templates); } List template = templates.getTemplate(); if (isLegacy()) { if (template == null) { template = new ArrayList<>(); } else { template.clear(); } if (MiscUtil.isNotEmpty(getSLTemplateURL1())) { final TemplateType el = new TemplateType(); el.setURL(getSLTemplateURL1()); template.add(el); } else { template.add(new TemplateType()); } if (MiscUtil.isNotEmpty(getSLTemplateURL2())) { final TemplateType el = new TemplateType(); el.setURL(getSLTemplateURL2()); template.add(el); } else { template.add(new TemplateType()); } if (MiscUtil.isNotEmpty(getSLTemplateURL3())) { final TemplateType el = new TemplateType(); el.setURL(getSLTemplateURL3()); template.add(el); } else { template.add(new TemplateType()); } } else { if (template != null && template.size() > 0) { template.clear(); } } // store keyBox Identifier dbOA.setKeyBoxIdentifier(MOAKeyBoxSelector.fromValue(getKeyBoxIdentifier())); } else { if (dbOA.isIsNew()) { dbOA.setKeyBoxIdentifier(MOAKeyBoxSelector.SECURE_SIGNATURE_KEYPAIR); } } final Mandates mandates = new Mandates(); if (isUseMandates()) { final String[] profileList = getMandateProfiles().split(","); List dbProfiles = mandates.getProfileName(); if (dbProfiles == null) { dbProfiles = new ArrayList<>(); mandates.setProfileName(dbProfiles); } for (final String el : profileList) { dbProfiles.add(el.trim()); } mandates.setProfiles(null); if (MiscUtil.isNotEmpty(getMisServiceSelected())) { mandates.setSelectedMISServiceURL(getMisServiceSelected()); } if (MiscUtil.isNotEmpty(getElgaServiceSelected())) { mandates.setSelecteELGAServiceURL(getElgaServiceSelected()); } } else { mandates.setProfiles(null); mandates.getProfileName().clear(); } authoa.setMandates(mandates); // set default transformation if it is empty final List transformsInfo = authoa.getTransformsInfo(); if (transformsInfo == null) { // TODO: set OA specific transformation if it is required } if (enableTestCredentials) { TestCredentials testing = authoa.getTestCredentials(); // if (testing != null) // ConfigurationDBUtils.delete(testing); testing = new TestCredentials(); authoa.setTestCredentials(testing); testing.setEnableTestCredentials(enableTestCredentials); testing.setCredentialOID(testCredentialOIDs); } else { final TestCredentials testing = authoa.getTestCredentials(); if (testing != null) { testing.setEnableTestCredentials(false); } } TestCredentials testing = authoa.getTestCredentials(); if (testing == null) { testing = new TestCredentials(); authoa.setTestCredentials(testing); } testing.setUseTestAuthBlockTrustStore(useTestAuthblockValidationTrustStore); testing.setUseTestIDLTrustStore(useTestIDLValidationTrustStore); // store SL2.0 information authoa.setSl20Active(isSl20Active()); authoa.setSl20EndPoints(getSl20EndPoints()); return null; } /* * (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 OAAuthenticationDataValidation().validate(this, authUser.isAdmin(), request); } /** * @return the bkuOnlineURL */ public String getBkuOnlineURL() { return bkuOnlineURL; } /** * @param bkuOnlineURL the bkuOnlineURL to set */ public void setBkuOnlineURL(String bkuOnlineURL) { this.bkuOnlineURL = bkuOnlineURL; } /** * @return the bkuHandyURL */ public String getBkuHandyURL() { return bkuHandyURL; } /** * @param bkuHandyURL the bkuHandyURL to set */ public void setBkuHandyURL(String bkuHandyURL) { this.bkuHandyURL = bkuHandyURL; } /** * @return the bkuLocalURL */ public String getBkuLocalURL() { return bkuLocalURL; } /** * @param bkuLocalURL the bkuLocalURL to set */ public void setBkuLocalURL(String bkuLocalURL) { this.bkuLocalURL = bkuLocalURL; } /** * @return the mandateProfiles */ public String getMandateProfiles() { return mandateProfiles; } /** * @param mandateProfiles the mandateProfiles to set */ public void setMandateProfiles(String mandateProfiles) { this.mandateProfiles = mandateProfiles; } /** * @return the useMandates */ public boolean isUseMandates() { return useMandates; } /** * @param useMandates the useMandates to set */ public void setUseMandates(boolean useMandates) { this.useMandates = useMandates; } /** * @return the calculateHPI */ public boolean isCalculateHPI() { return calculateHPI; } /** * @param calculateHPI the calculateHPI to set */ public void setCalculateHPI(boolean calculateHPI) { this.calculateHPI = calculateHPI; } /** * @return the keyBoxIdentifier */ public String getKeyBoxIdentifier() { return keyBoxIdentifier; } /** * @param keyBoxIdentifier the keyBoxIdentifier to set */ public void setKeyBoxIdentifier(String keyBoxIdentifier) { this.keyBoxIdentifier = keyBoxIdentifier; } /** * @return the keyBoxIdentifierList */ public Map getKeyBoxIdentifierList() { return keyBoxIdentifierList; } /** * @return the legacy */ public boolean isLegacy() { return legacy; } /** * @param legacy the legacy to set */ public void setLegacy(boolean legacy) { this.legacy = legacy; } /** * @return the transformations */ public Map getTransformations() { return transformations; } /** * @param transformations the transformations to set */ public void setTransformations(Map transformations) { this.transformations = transformations; } /** * @return the sLTemplates */ public List getSLTemplates() { return SLTemplates; } /** * @return the sLTemplateURL1 */ public String getSLTemplateURL1() { if (SLTemplates != null && SLTemplates.size() > 0) { return SLTemplates.get(0); } else { return null; } } /** * @param sLTemplateURL1 the sLTemplateURL1 to set */ public void setSLTemplateURL1(String sLTemplateURL1) { if (SLTemplates == null) { SLTemplates = new ArrayList<>(); } SLTemplates.add(sLTemplateURL1); } /** * @return the sLTemplateURL2 */ public String getSLTemplateURL2() { if (SLTemplates != null && SLTemplates.size() > 1) { return SLTemplates.get(1); } else { return null; } } /** * @param sLTemplateURL2 the sLTemplateURL2 to set */ public void setSLTemplateURL2(String sLTemplateURL2) { if (SLTemplates == null) { SLTemplates = new ArrayList<>(); } SLTemplates.add(sLTemplateURL2); } /** * @return the sLTemplateURL3 */ public String getSLTemplateURL3() { if (SLTemplates != null && SLTemplates.size() > 2) { return SLTemplates.get(2); } else { return null; } } /** * @param sLTemplateURL3 the sLTemplateURL3 to set */ public void setSLTemplateURL3(String sLTemplateURL3) { if (SLTemplates == null) { SLTemplates = new ArrayList<>(); } SLTemplates.add(sLTemplateURL3); } /** * @return the enableTestCredentials */ public boolean isEnableTestCredentials() { return enableTestCredentials; } /** * @param enableTestCredentials the enableTestCredentials to set */ public void setEnableTestCredentials(boolean enableTestCredentials) { this.enableTestCredentials = enableTestCredentials; } /** * @return the testCredentialOIDs */ public String getTestCredentialOIDs() { String value = null; if (testCredentialOIDs != null) { for (final String el : testCredentialOIDs) { if (value == null) { value = el; } else { value += "," + el; } } } return value; } public List getTestCredialOIDList() { return this.testCredentialOIDs; } /** * @param testCredentialOIDs the testCredentialOIDs to set */ public void setTestCredentialOIDs(String testCredentialOIDs) { if (MiscUtil.isNotEmpty(testCredentialOIDs)) { final String[] oidList = testCredentialOIDs.split(","); this.testCredentialOIDs = new ArrayList<>(); for (final String element : oidList) { this.testCredentialOIDs.add(element.trim()); } } } /** * @return the useTestIDLValidationTrustStore */ public boolean isUseTestIDLValidationTrustStore() { return useTestIDLValidationTrustStore; } /** * @param useTestIDLValidationTrustStore the useTestIDLValidationTrustStore to * set */ public void setUseTestIDLValidationTrustStore( boolean useTestIDLValidationTrustStore) { this.useTestIDLValidationTrustStore = useTestIDLValidationTrustStore; } /** * @return the useTestAuthblockValidationTrustStore */ public boolean isUseTestAuthblockValidationTrustStore() { return useTestAuthblockValidationTrustStore; } /** * @param useTestAuthblockValidationTrustStore the * useTestAuthblockValidationTrustStore * to set */ public void setUseTestAuthblockValidationTrustStore( boolean useTestAuthblockValidationTrustStore) { this.useTestAuthblockValidationTrustStore = useTestAuthblockValidationTrustStore; } /** * @return the misServiceSelected */ public String getMisServiceSelected() { return misServiceSelected; } /** * @param misServiceSelected the misServiceSelected to set */ public void setMisServiceSelected(String misServiceSelected) { this.misServiceSelected = misServiceSelected; } /** * @return the elgaServiceSelected */ public String getElgaServiceSelected() { return elgaServiceSelected; } /** * @param elgaServiceSelected the elgaServiceSelected to set */ public void setElgaServiceSelected(String elgaServiceSelected) { this.elgaServiceSelected = elgaServiceSelected; } /** * @return the szrgwServiceSelected */ public String getSzrgwServiceSelected() { return szrgwServiceSelected; } /** * @param szrgwServiceSelected the szrgwServiceSelected to set */ public void setSzrgwServiceSelected(String szrgwServiceSelected) { this.szrgwServiceSelected = szrgwServiceSelected; } /** * @return the misServicesList */ public List getMisServicesList() { return misServicesList; } /** * @return the elgaServicesList */ public List getElgaServicesList() { return elgaServicesList; } /** * @return the szrgwServicesList */ public List getSzrgwServicesList() { return szrgwServicesList; } public List getEidServicesList() { return eidServicesList; } public String getEidServiceSelected() { return eidServiceSelected; } public void setEidServiceSelected(String eidServiceSelected) { this.eidServiceSelected = eidServiceSelected; } public boolean isSl20Active() { return sl20Active; } public void setSl20Active(boolean sl20Active) { this.sl20Active = sl20Active; } public String getSl20EndPoints() { return sl20EndPoints; } public void setSl20EndPoints(String sl20EndPoints) { if (MiscUtil.isNotEmpty(sl20EndPoints)) { this.sl20EndPoints = KeyValueUtils.removeAllNewlineFromString(sl20EndPoints); } else { this.sl20EndPoints = sl20EndPoints; } } public boolean isMoaidMode() { return isMoaidMode; } }