/******************************************************************************* * 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 org.apache.log4j.Logger; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; import at.gv.egovernment.moa.id.commons.db.dao.config.AttributeProviderPlugin; import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentOA; import at.gv.egovernment.moa.id.commons.db.dao.config.CPEPS; import at.gv.egovernment.moa.id.commons.db.dao.config.OASTORK; import at.gv.egovernment.moa.id.commons.db.dao.config.OAStorkAttribute; import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.config.StorkAttribute; import at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser; import at.gv.egovernment.moa.id.configuration.validation.oa.OASTORKConfigValidation; import at.gv.egovernment.moa.id.protocols.stork2.AttributeProviderFactory; public class OASTORKConfig implements IOnlineApplicationData{ private static final Logger log = Logger.getLogger(OASTORKConfig.class); private boolean isStorkLogonEnabled = false; private int qaa; private List attributes = null; /* * VIDP settings below */ private boolean vidpEnabled = false; private List attributeProviderPlugins = new ArrayList(); private boolean requireConsent = false; private List citizenCountries; private List enabledCitizenCountries; public OASTORKConfig() { // fetch available citizen countries citizenCountries = new ArrayList(); try { for(CPEPS current : ConfigurationDBRead.getMOAIDConfiguration().getAuthComponentGeneral().getForeignIdentities().getSTORK().getCPEPS()) { citizenCountries.add(current.getCountryCode()); } }catch (NullPointerException 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 */ public List parse(OnlineApplication dbOAConfig, AuthenticatedUser authUser, HttpServletRequest request) { AuthComponentOA authdata = dbOAConfig.getAuthComponentOA(); if (authdata != null) { OASTORK config = authdata.getOASTORK(); if(config != null) { setStorkLogonEnabled(config.isStorkLogonEnabled()); try { setQaa(config.getQaa()); } catch(NullPointerException e) { // if there is no configuration available for the OA, get the default qaa level setQaa(ConfigurationDBRead.getMOAIDConfiguration().getAuthComponentGeneral().getForeignIdentities().getSTORK().getQualityAuthenticationAssuranceLevel()); } enabledCitizenCountries = new ArrayList(); for(CPEPS current : config.getCPEPS()) enabledCitizenCountries.add(current.getCountryCode()); // prepare attribute helper list attributes = new ArrayList(); try { for(StorkAttribute current : ConfigurationDBRead.getMOAIDConfiguration().getAuthComponentGeneral().getForeignIdentities().getSTORK().getAttributes()) { AttributeHelper tmp = null; for(OAStorkAttribute sepp : config.getOAAttributes()) if(sepp.getName().equals(current.getName())) tmp = new AttributeHelper(sepp); if(null == tmp) tmp = new AttributeHelper(current); attributes.add(tmp); } // 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.isEmpty()) attributeProviderPlugins.add(new AttributeProviderPlugin()); } catch (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.setQaa(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 int getQaa() { return qaa; } public void setQaa(int qaa) { this.qaa = qaa; } public List getAttributes() { List result = new ArrayList(); if(null == getHelperAttributes()) return result; for(AttributeHelper current : getHelperAttributes()) { for(StorkAttribute currentAttribute : ConfigurationDBRead.getMOAIDConfiguration().getAuthComponentGeneral().getForeignIdentities().getSTORK().getAttributes()) if(currentAttribute.getName().equals(current.getName())) { if(current.isUsed() || currentAttribute.isMandatory()) { 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 getEnabledCitizenCountries() { return enabledCitizenCountries; } public void setEnabledCitizenCountries(List update) { enabledCitizenCountries = update; } public List getEnabledCPEPS() { if (enabledCitizenCountries != null) { List result = new ArrayList(); try { for(CPEPS current : ConfigurationDBRead.getMOAIDConfiguration().getAuthComponentGeneral().getForeignIdentities().getSTORK().getCPEPS()) { if(enabledCitizenCountries.contains(current.getCountryCode())) result.add(current); } } catch (NullPointerException e){ } return result; } return null; } public List getAvailableAttributeProviderPlugins() { 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; } }