/******************************************************************************* * 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.List; import javax.servlet.http.HttpServletRequest; import at.gv.egovernment.moa.id.commons.MOAIDConstants; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.AttributeProviderPlugin; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.AuthComponentOA; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.CPEPS; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.MOAIDConfiguration; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OASTORK; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OAStorkAttribute; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.StorkAttribute; 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.OASTORKConfigValidation; import at.gv.egovernment.moa.util.MiscUtil; //import at.gv.egovernment.moa.id.protocols.stork2.AttributeProviderFactory; import lombok.extern.slf4j.Slf4j; @Slf4j public class OASTORKConfig implements IOnlineApplicationData { private boolean isStorkLogonEnabled = false; private String qaa; private List attributes = null; /* * VIDP settings below */ private boolean vidpEnabled = false; private List attributeProviderPlugins = new ArrayList<>(); private boolean requireConsent = false; private final List citizenCountries; private List enabledCitizenCountries; private MOAIDConfiguration dbconfig = null; public OASTORKConfig() { // fetch available citizen countries citizenCountries = new ArrayList<>(); try { dbconfig = ConfigurationProvider.getInstance().getDbRead().getMOAIDConfiguration(); for (final CPEPS current : dbconfig.getAuthComponentGeneral().getForeignIdentities().getSTORK() .getCPEPS()) { citizenCountries.add(current.getCountryCode()); } } catch (final NullPointerException e) { } catch (final ConfigurationException e) { log.error("MOA-ID-Configuration initialization FAILED.", e); } } /* * (non-Javadoc) * * @see * at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData#getName * () */ @Override public String getName() { return "OASTORK2"; } /** * Parses the OA config for stork entities. * * @param dbOAConfig the db oa config */ @Override public List parse(OnlineApplication dbOAConfig, AuthenticatedUser authUser, HttpServletRequest request) { final AuthComponentOA authdata = dbOAConfig.getAuthComponentOA(); if (authdata != null) { final OASTORK config = authdata.getOASTORK(); if (config != null) { setStorkLogonEnabled(config.isStorkLogonEnabled()); try { setQaa(config.geteIDAS_LOA()); } catch (final NullPointerException e) { // if there is no configuration available for the OA, get the default qaa level try { setQaa(dbconfig.getAuthComponentGeneral().getForeignIdentities().getSTORK() .getGeneral_eIDAS_LOA()); } catch (final NullPointerException e1) { setQaa(MOAIDConstants.eIDAS_LOA_HIGH); } } enabledCitizenCountries = new ArrayList<>(); if (config.getCPEPS() != null) { for (final CPEPS current : config.getCPEPS()) { enabledCitizenCountries.add(current.getCountryCode()); } } // prepare attribute helper list attributes = new ArrayList<>(); try { try { for (final StorkAttribute current : dbconfig.getAuthComponentGeneral().getForeignIdentities() .getSTORK().getAttributes()) { AttributeHelper tmp = null; if (config.getOAAttributes() != null) { for (final OAStorkAttribute sepp : config.getOAAttributes()) { if (sepp.getName() != null && sepp.getName().equals(current.getName())) { tmp = new AttributeHelper(sepp); } } } if (null == tmp) { tmp = new AttributeHelper(current); } attributes.add(tmp); } } catch (final NullPointerException ex) { } // fetch vidp config if (config.isVidpEnabled() != null) { setVidpEnabled(config.isVidpEnabled()); } else { setVidpEnabled(false); } if (config.isRequireConsent() != null) { setRequireConsent(config.isRequireConsent()); } else { setRequireConsent(false); } attributeProviderPlugins = config.getAttributeProviders(); // - if no attribute providers are configured, add a dummy // TODO this is a dirty hack since we have to have one entry to // clone from in the web form. Happens when time is short. // Sorry. if (attributeProviderPlugins == null || attributeProviderPlugins.isEmpty()) { attributeProviderPlugins.add(new AttributeProviderPlugin()); } } catch (final NullPointerException ex) { log.error("Nullpointerexception encountered in Configurationinterface", ex); } } } return null; } /* * (non-Javadoc) * * @see at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData# * validate(at.gv.egovernment.moa.id.configuration.data.oa.OAGeneralConfig, * javax.servlet.http.HttpServletRequest) */ @Override public List validate(OAGeneralConfig general, AuthenticatedUser authUser, HttpServletRequest request) { return new OASTORKConfigValidation().validate(this, request); } /* * (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); } // fetch stork configuration from database model OASTORK stork = authoa.getOASTORK(); if (stork == null) { // if there is none, create a new one with default values. stork = new OASTORK(); authoa.setOASTORK(stork); stork.setStorkLogonEnabled(false); } // transfer the incoming data to the database model stork.setStorkLogonEnabled(isStorkLogonEnabled()); stork.seteIDAS_LOA(getQaa()); stork.setOAAttributes(getAttributes()); stork.setVidpEnabled(isVidpEnabled()); stork.setRequireConsent(isRequireConsent()); stork.setAttributeProviders(getAttributeProviderPlugins()); stork.setCPEPS(getEnabledCPEPS()); return null; } public boolean isStorkLogonEnabled() { return isStorkLogonEnabled; } public void setStorkLogonEnabled(boolean enabled) { this.isStorkLogonEnabled = enabled; } public String getQaa() { return qaa; } public void setQaa(String qaa) { this.qaa = qaa; } public List getAttributes() { final List result = new ArrayList<>(); if (null == getHelperAttributes()) { return result; } for (final AttributeHelper current : getHelperAttributes()) { List generalConfStorkAttr = null; try { generalConfStorkAttr = dbconfig.getAuthComponentGeneral().getForeignIdentities().getSTORK() .getAttributes(); } catch (final NullPointerException e) { log.trace("No STORK attributes in 'General Configuration'"); } if (generalConfStorkAttr != null) { for (final StorkAttribute currentAttribute : generalConfStorkAttr) { if (MiscUtil.isNotEmpty(currentAttribute.getName()) && currentAttribute.getName().equals(current.getName())) { if (current.isUsed() || currentAttribute.isMandatory()) { final OAStorkAttribute tmp = new OAStorkAttribute(); tmp.setName(current.getName()); tmp.setMandatory(current.isMandatory()); result.add(tmp); } break; } } } } return result; } public List getHelperAttributes() { return attributes; } public void setHelperAttributes(List attributes) { this.attributes = attributes; } public List getAvailableCitizenCountries() { return citizenCountries; } public List getAllowedLoALevels() { return MOAIDConstants.ALLOWED_eIDAS_LOA; } public List getEnabledCitizenCountries() { return enabledCitizenCountries; } public void setEnabledCitizenCountries(List update) { enabledCitizenCountries = update; } public List getEnabledCPEPS() { if (enabledCitizenCountries != null) { final List result = new ArrayList<>(); try { for (final CPEPS current : dbconfig.getAuthComponentGeneral().getForeignIdentities().getSTORK() .getCPEPS()) { if (enabledCitizenCountries.contains(current.getCountryCode())) { result.add(current); } } } catch (final NullPointerException e) { } return result; } return null; } public List getAvailableAttributeProviderPlugins() { // TODO: remove in final version return new ArrayList<>(); // return AttributeProviderFactory.getAvailablePlugins(); } public List getAttributeProviderPlugins() { return attributeProviderPlugins; } public void setAttributeProviderPlugins(List update) { attributeProviderPlugins = update; } public boolean isVidpEnabled() { return vidpEnabled; } public void setVidpEnabled(boolean update) { vidpEnabled = update; } public boolean isRequireConsent() { return requireConsent; } public void setRequireConsent(boolean update) { requireConsent = update; } }