/******************************************************************************* * 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.config.stork; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import at.gv.egovernment.moa.id.commons.api.IStorkConfig; import at.gv.egovernment.moa.id.commons.api.data.CPEPS; import at.gv.egovernment.moa.id.commons.api.data.SignatureCreationParameter; import at.gv.egovernment.moa.id.commons.api.data.SignatureVerificationParameter; import at.gv.egovernment.moa.id.commons.api.data.StorkAttribute; import at.gv.egovernment.moa.id.commons.api.exceptions.ConfigurationException; import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; import at.gv.egovernment.moa.util.StringUtils; /** * Encapsulates several STORK configuration parameters according MOA configuration * * @author bzwattendorfer * */ public class STORKConfig implements IStorkConfig { /** STORK SAML signature creation parameters */ private Properties props = null; private Map cpepsMap = new HashMap(); private String basedirectory = null; private SignatureVerificationParameter sigverifyparam = null; private List attr = null; public STORKConfig(Properties props, String basedirectory) throws ConfigurationException { this.basedirectory = basedirectory; this.props = props; //create CPEPS map List cpeps = new ArrayList(); Map storkCPEPSProps = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST + "."); if (storkCPEPSProps != null) { Set keyValues = storkCPEPSProps.keySet(); for (Object elObj : keyValues) { if (elObj instanceof String) { String el = (String) elObj; if (el.endsWith(MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_COUNTRY)) { int index = el.indexOf("."); String listCounter = el.substring(0, index); if (MiscUtil.isNotEmpty(storkCPEPSProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_COUNTRY))) { try { //Assertion encryption is enabled by default boolean enableAssertionEncryption = true; String enableAssertionEncryptionString = storkCPEPSProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_SUPPORT_XMLDSIG); if (MiscUtil.isNotEmpty(enableAssertionEncryptionString)) { enableAssertionEncryption = Boolean.parseBoolean(enableAssertionEncryptionString); } CPEPS moacpep = new CPEPS(storkCPEPSProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_COUNTRY), new URL(storkCPEPSProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_URL)), enableAssertionEncryption); cpepsMap.put(moacpep.getCountryCode(), moacpep); } catch (MalformedURLException e) { Logger.warn("CPEPS URL " + storkCPEPSProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_CPEPS_LIST_URL) + " are not parseable.", e); } } } } } } attr = new ArrayList(); Map storkAttributeProps = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( MOAIDConfigurationConstants.GENERAL_AUTH_STORK_ATTRIBUTES_LIST); if (storkAttributeProps != null) { Set keyValues = storkAttributeProps.keySet(); for (Object elObj : keyValues) { if (elObj instanceof String) { String el = (String) elObj; if (el.endsWith(MOAIDConfigurationConstants.GENERAL_AUTH_STORK_ATTRIBUTES_LIST_NAME)) { int index = el.indexOf("."); String listCounter = el.substring(0, index); StorkAttribute moaStorkAttr = new StorkAttribute(storkAttributeProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_ATTRIBUTES_LIST_NAME), Boolean.valueOf(storkAttributeProps.get(listCounter + "." + MOAIDConfigurationConstants.GENERAL_AUTH_STORK_ATTRIBUTES_LIST_MANDATORY))); attr.add(moaStorkAttr); } } } } } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#getSignatureCreationParameter() */ @Override public SignatureCreationParameter getSignatureCreationParameter() { return new SignatureCreationParameter(props, basedirectory); } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#getSignatureVerificationParameter() */ @Override public SignatureVerificationParameter getSignatureVerificationParameter() { return sigverifyparam; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#getCpepsMap() */ @Override public Map getCpepsMap() { return cpepsMap; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#isSTORKAuthentication(java.lang.String) */ @Override public boolean isSTORKAuthentication(String ccc) { if (StringUtils.isEmpty(ccc) || this.cpepsMap.isEmpty()) return false; if (this.cpepsMap.containsKey(ccc.toUpperCase())) return true; else return false; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#getCPEPS(java.lang.String) */ @Override public CPEPS getCPEPS(String ccc) { if (isSTORKAuthentication(ccc)) return this.cpepsMap.get(ccc); else return null; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.config.stork.IStorkConfig#getStorkAttributes() */ @Override public List getStorkAttributes() { return attr; } }