/******************************************************************************* * 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.protocols.pvp2x.config; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.jar.Attributes; import java.util.jar.Manifest; import org.opensaml.saml2.metadata.Company; import org.opensaml.saml2.metadata.ContactPerson; import org.opensaml.saml2.metadata.ContactPersonTypeEnumeration; import org.opensaml.saml2.metadata.EmailAddress; import org.opensaml.saml2.metadata.GivenName; import org.opensaml.saml2.metadata.LocalizedString; import org.opensaml.saml2.metadata.Organization; import org.opensaml.saml2.metadata.OrganizationDisplayName; import org.opensaml.saml2.metadata.OrganizationName; import org.opensaml.saml2.metadata.OrganizationURL; import org.opensaml.saml2.metadata.SurName; import org.opensaml.saml2.metadata.TelephoneNumber; import org.springframework.stereotype.Service; import at.gv.egiz.eaaf.modules.pvp2.api.IPVP2BasicConfiguration; import at.gv.egiz.eaaf.modules.pvp2.impl.utils.SAML2Utils; 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; @Service("MOAPVP2Configuration") public class PVPConfiguration implements IPVP2BasicConfiguration { public static final String PVP2_METADATA = "/pvp2/metadata"; public static final String PVP2_IDP_REDIRECT = "/pvp2/redirect"; public static final String PVP2_IDP_POST = "/pvp2/post"; public static final String PVP2_IDP_SOAP = "/pvp2/soap"; public static final String PVP2_IDP_ATTRIBUTEQUERY = "/pvp2/attributequery"; public static final String PVP2_SP_REDIRECT = "/pvp2/sp/redirect"; public static final String PVP2_SP_POST = "/pvp2/sp/post"; public static final String PVP_CONFIG_FILE = "pvp2config.properties"; public static final String IDP_ISSUER_NAME = "servicename"; public static final String IDP_ORG_NAME = "name.short"; public static final String IDP_ORG_DISPNAME = "name.full"; public static final String IDP_ORG_URL = "url"; public static final String IDP_CONTACT_SURNAME = "familyname"; public static final String IDP_CONTACT_GIVENNAME = "givenname"; public static final String IDP_CONTACT_MAIL = "mail"; public static final String IDP_CONTACT_TYPE = "type"; public static final String IDP_CONTACT_COMPANY = "company"; public static final String IDP_CONTACT_PHONE = "phone"; private static String moaIDVersion = null; public List getIDPPublicPath() throws ConfigurationException { List publicPath = AuthConfigurationProviderFactory.getInstance().getPublicURLPrefix(); List returnvalue = new ArrayList(); for (String el : publicPath) { if(el.endsWith("/")) { int length = el.length(); returnvalue.add(el.substring(0, length-1)); } else returnvalue.add(el); } return returnvalue; } public String getSPSSOPostService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_SP_POST; } public String getSPSSORedirectService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_SP_REDIRECT; } public String getIDPSSOPostService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_IDP_POST; } public String getIDPSSORedirectService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_IDP_REDIRECT; } public String getIDPSSOSOAPService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_IDP_SOAP; } public String getIDPSSOMetadataService(String publicURLPrefix) throws ConfigurationException { return publicURLPrefix + PVP2_METADATA; } @Override public String getIDPEntityId(String authURL) throws ConfigurationException { return getIDPSSOMetadataService(authURL); } public String getIDPIssuerName() throws ConfigurationException { if (moaIDVersion == null) { moaIDVersion = parseMOAIDVersionFromManifest(); } return AuthConfigurationProviderFactory.getInstance().getConfigurationWithKey( MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME) + moaIDVersion; } public List getIDPContacts() throws ConfigurationException { List list = new ArrayList(); Map contacts = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + "."); ContactPerson person = SAML2Utils .createSAMLObject(ContactPerson.class); String type = contacts.get(IDP_CONTACT_TYPE); if (type == null) { Logger.error("IDP Contact with SurName " + contacts.get(IDP_CONTACT_SURNAME) + " has no type defined!"); type = "unknown"; } ContactPersonTypeEnumeration enumType = null; if (type.equals(ContactPersonTypeEnumeration.ADMINISTRATIVE .toString())) { enumType = ContactPersonTypeEnumeration.ADMINISTRATIVE; } else if (type.equals(ContactPersonTypeEnumeration.BILLING .toString())) { enumType = ContactPersonTypeEnumeration.BILLING; } else if (type.equals(ContactPersonTypeEnumeration.OTHER .toString())) { enumType = ContactPersonTypeEnumeration.OTHER; } else if (type.equals(ContactPersonTypeEnumeration.SUPPORT .toString())) { enumType = ContactPersonTypeEnumeration.SUPPORT; } else if (type.equals(ContactPersonTypeEnumeration.TECHNICAL .toString())) { enumType = ContactPersonTypeEnumeration.TECHNICAL; } if (enumType == null) { Logger.error("IDP Contact with SurName " + contacts.get(IDP_CONTACT_SURNAME) + " has invalid type defined: " + type); } person.setType(enumType); String givenName = contacts.get(IDP_CONTACT_GIVENNAME); if (givenName != null) { GivenName name = SAML2Utils .createSAMLObject(GivenName.class); name.setName(givenName); person.setGivenName(name); } String company = contacts.get(IDP_CONTACT_COMPANY); if (company != null) { Company comp = SAML2Utils.createSAMLObject(Company.class); comp.setName(company); person.setCompany(comp); } String surname = contacts.get(IDP_CONTACT_SURNAME); if (surname != null) { SurName name = SAML2Utils.createSAMLObject(SurName.class); name.setName(surname); person.setSurName(name); } String phone = contacts.get(IDP_CONTACT_PHONE); if (phone != null) { TelephoneNumber telePhone = SAML2Utils .createSAMLObject(TelephoneNumber.class); telePhone.setNumber(phone); person.getTelephoneNumbers().add(telePhone); } String mail = contacts.get(IDP_CONTACT_MAIL); if (mail != null) { EmailAddress mailAddress = SAML2Utils .createSAMLObject(EmailAddress.class); mailAddress.setAddress(mail); person.getEmailAddresses().add(mailAddress); } list.add(person); return list; } public Organization getIDPOrganisation() throws ConfigurationException { Organization org = SAML2Utils.createSAMLObject(Organization.class); Map organisation = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_ORG + "."); String org_name = organisation.get(IDP_ORG_NAME); String org_dispname = organisation.get(IDP_ORG_DISPNAME); String org_url = organisation.get(IDP_ORG_URL); if (org_name == null || org_dispname == null || org_url == null) { return null; } OrganizationDisplayName dispName = SAML2Utils .createSAMLObject(OrganizationDisplayName.class); dispName.setName(new LocalizedString(org_dispname, "de")); org.getDisplayNames().add(dispName); OrganizationName name = SAML2Utils .createSAMLObject(OrganizationName.class); name.setName(new LocalizedString(org_name, "de")); org.getOrganizationNames().add(name); OrganizationURL url = SAML2Utils .createSAMLObject(OrganizationURL.class); url.setURL(new LocalizedString(org_url, "de")); org.getURLs().add(url); return org; } private String parseMOAIDVersionFromManifest() { try { @SuppressWarnings("rawtypes") Class clazz = PVPConfiguration.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (!classPath.startsWith("jar")) { Logger.info("MOA-ID Version can NOT parsed from Manifest. Set blank Version"); return new String(); } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Manifest manifest = new Manifest(new URL(manifestPath).openStream());; Attributes attributes = manifest.getMainAttributes(); String version = attributes.getValue("Implementation-Version"); if (MiscUtil.isNotEmpty(version)) return new String(" (Version: " + version + ")"); else { Logger.info("MOA-ID Version not found in Manifest. Set blank Version"); return new String(); } } catch (Throwable e) { Logger.info("MOA-ID Version can NOT parsed from Manifest. Set blank Version"); return new String(); } } }