/* * 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 org.apache.log4j.Logger; 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; /** * @author tlenz * */ public class OAAuthenticationData implements IOnlineApplicationData { private static final Logger log = Logger.getLogger(OAAuthenticationData.class); 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 String misServiceSelected = null; private String elgaServiceSelected = null; private String szrgwServiceSelected = 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; /** * */ public OAAuthenticationData() { keyBoxIdentifierList = new HashMap(); MOAKeyBoxSelector[] values = MOAKeyBoxSelector.values(); for (int i=0; i parse(OnlineApplication dbOA, AuthenticatedUser authUser, HttpServletRequest request) { keyBoxIdentifier = dbOA.getKeyBoxIdentifier().value(); szrgwServiceSelected = dbOA.getSelectedSZRGWServiceURL(); AuthComponentOA oaauth = dbOA.getAuthComponentOA(); if (oaauth != null) { BKUURLS bkuurls = oaauth.getBKUURLS(); String defaulthandy = ""; String defaultlocal = ""; 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(); } Mandates mandates = oaauth.getMandates(); if (mandates != null) { mandateProfiles = null; List profileList = mandates.getProfileName(); for (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(); } TemplatesType templates = oaauth.getTemplates(); if (templates != null) { List templatetype = templates.getTemplate(); if (templatetype != null) { if (SLTemplates == null) { SLTemplates = new ArrayList(); } for (TemplateType el : templatetype) { SLTemplates.add(el.getURL()); } } } if (SLTemplates != null && SLTemplates.size() > 0) legacy = true; List transforminfos = oaauth.getTransformsInfo(); transformations = new HashMap(); for (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 (authUser.isAdmin()) { //store BKU-URLs 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())) { TemplateType el = new TemplateType(); el.setURL(getSLTemplateURL1()); template.add(el); } else template.add(new TemplateType()); if (MiscUtil.isNotEmpty(getSLTemplateURL2())) { TemplateType el = new TemplateType(); el.setURL(getSLTemplateURL2()); template.add(el); } else template.add(new TemplateType()); if (MiscUtil.isNotEmpty(getSLTemplateURL3())) { 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); } Mandates mandates = new Mandates(); if (isUseMandates()) { String[] profileList = getMandateProfiles().split(","); List dbProfiles = mandates.getProfileName(); if (dbProfiles == null) { dbProfiles = new ArrayList(); mandates.setProfileName(dbProfiles); } for (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 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 { 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 (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)) { String[] oidList = testCredentialOIDs.split(","); this.testCredentialOIDs = new ArrayList(); for (int i=0; i getMisServicesList() { return misServicesList; } /** * @return the elgaServicesList */ public List getElgaServicesList() { return elgaServicesList; } /** * @return the szrgwServicesList */ public List getSzrgwServicesList() { return szrgwServicesList; } 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; } }