From e0c190004d654a2fa4f91f33133f6d55444e3798 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 19 Jun 2015 13:34:42 +0200 Subject: refactoring for properties based configuration --- .../id/auth/builder/AuthenticationDataBuilder.java | 2 +- .../moa/id/config/auth/AuthConfiguration.java | 12 +- .../id/config/auth/AuthConfigurationProvider.java | 18 ++ .../PropertyBasedAuthConfigurationProvider.java | 203 +++++++++-------- .../gv/egovernment/moa/id/moduls/SSOManager.java | 30 +-- .../protocols/pvp2x/config/PVPConfiguration.java | 245 +++++++++------------ .../config/MOAIDConfigurationConstants.java | 31 +-- .../config/persistence/MOAIDConfiguration.java | 66 +++--- .../config/persistence/MOAIDConfigurationImpl.java | 137 +++++++----- .../moa/id/commons/db/ConfigurationDBRead.java | 7 + 10 files changed, 396 insertions(+), 355 deletions(-) diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/AuthenticationDataBuilder.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/AuthenticationDataBuilder.java index f646f200d..ffadc2631 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/AuthenticationDataBuilder.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/builder/AuthenticationDataBuilder.java @@ -930,7 +930,7 @@ public class AuthenticationDataBuilder implements MOAIDAuthConstants { //set max. SSO session time if (authData.isSsoSession()) { - long maxSSOSessionTime = AuthConfigurationProviderFactory.getInstance().getTimeOuts().getMOASessionCreated().longValue() * 1000; + long maxSSOSessionTime = AuthConfigurationProviderFactory.getInstance().getSSOCreatedTimeOut() * 1000; Date ssoSessionValidTo = new Date(session.getSessionCreated().getTime() + maxSSOSessionTime); authData.setSsoSessionValidTo(ssoSessionValidTo); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java index 7228e6129..b93312f78 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java @@ -19,11 +19,21 @@ public interface AuthConfiguration extends ConfigurationProvider{ public Properties getGeneralOAuth20ProperiesConfig(); public ProtocolAllowed getAllowedProtocols(); - + + @Deprecated public PVP2 getGeneralPVP2DBConfig(); + public Properties getConfigurationWithPrefix(final String Prefix); + + public String getConfigurationWithKey(final String key); + + @Deprecated public TimeOuts getTimeOuts() throws ConfigurationException; + public int getTransactionTimeOut(); + public int getSSOCreatedTimeOut(); + public int getSSOUpdatedTimeOut(); + public String getAlternativeSourceID() throws ConfigurationException; public List getLegacyAllowedProtocols(); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java index dfb2a4dfd..7ebde05df 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java @@ -1199,5 +1199,23 @@ private void setCertStoreDirectory() throws ConfigurationException { } return moasp; } + +/* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getConfigurationWithPrefix(java.lang.String) + */ +@Override +public Properties getConfigurationWithPrefix(String Prefix) { + // TODO Auto-generated method stub + return null; +} + +/* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getConfigurationWithKey(java.lang.String) + */ +@Override +public String getConfigurationWithKey(String key) { + // TODO Auto-generated method stub + return null; +} } diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java index 94fbe46c4..378dafa23 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java @@ -140,6 +140,27 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide } } + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getPropertiesWithPrefix(java.lang.String) + */ + @Override + public Properties getConfigurationWithPrefix(String Prefix) { + return configuration.getPropertySubset(Prefix); + } + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getPropertyWithKey(java.lang.String) + */ + @Override + public String getConfigurationWithKey(String key) { + try { + return configuration.getStringValue(key); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + return null; + } + } + /** * Returns the general pvp2 properties config. NOTE: may be empty but never {@code null}. * @return the general pvp2 properties config. @@ -162,91 +183,92 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide * @return the allowed protocols or {@code null}. */ public ProtocolAllowed getAllowedProtocols() { - - AuthComponentGeneral authComponentGeneral; try { - authComponentGeneral = getAuthComponentGeneral(); - } catch (ConfigurationException e) { - return null; - } - Protocols protocols = authComponentGeneral.getProtocols(); - if (protocols != null) { ProtocolAllowed allowedProtcols = new ProtocolAllowed(); - if (protocols.getSAML1() != null) { - allowedProtcols.setSAML1Active(protocols.getSAML1().isIsActive()); - } - - if (protocols.getOAuth() != null) { - allowedProtcols.setOAUTHActive(protocols.getOAuth().isIsActive()); - } - - if (protocols.getPVP2() != null) { - allowedProtcols.setPVP21Active(protocols.getPVP2().isIsActive()); - } + + allowedProtcols.setOAUTHActive( + configuration.getBooleanValue(MOAIDConfigurationConstants.GENERAL_PROTOCOLS_OPENID_ENABLED, true)); + allowedProtcols.setSAML1Active( + configuration.getBooleanValue(MOAIDConfigurationConstants.GENERAL_PROTOCOLS_SAML1_ENABLED, false)); + allowedProtcols.setPVP21Active( + configuration.getBooleanValue(MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_ENABLED, true)); + return allowedProtcols; - } else { - Logger.warn("Error in MOA-ID Configuration. No general Protcol configuration found."); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + Logger.error("Can not load protocol enabled information from configuration.", e); return null; } + + } + /** * Returns the general PVP2 configuration. NOTE: may return {@code null}. * * @return the general PVP2 configuration or {@code null}. + * + * @deprecated */ public PVP2 getGeneralPVP2DBConfig() { + return null; + } - AuthComponentGeneral authComponentGeneral; + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getTransactionTimeOut() + */ + @Override + public int getTransactionTimeOut() { try { - authComponentGeneral = getAuthComponentGeneral(); - } catch (ConfigurationException e) { - return null; + return configuration.getIntegerValue( + MOAIDConfigurationConstants.GENERAL_AUTH_TIMEOUTS_TRANSACTION, 300); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + Logger.warn("No transaction timeout defined. Use default values", e); + return 300; } - Protocols protocols = authComponentGeneral.getProtocols(); - PVP2 result = null; - if (protocols != null) { - PVP2 pvp2 = protocols.getPVP2(); - if (pvp2 != null) { - result = new PVP2(); - result.setIssuerName(pvp2.getIssuerName()); - result.setPublicURLPrefix(pvp2.getPublicURLPrefix()); - - if (pvp2.getOrganization() != null) { - Organization org = new Organization(); - result.setOrganization(org); - org.setDisplayName(pvp2.getOrganization().getDisplayName()); - org.setName(pvp2.getOrganization().getName()); - org.setURL(pvp2.getOrganization().getURL()); - } - - if (pvp2.getContact() != null) { - List cont = new ArrayList(); - result.setContact(cont); - for (Contact e : pvp2.getContact()) { - Contact c = new Contact(); - c.setCompany(e.getCompany()); - c.setGivenName(e.getGivenName()); - c.getMail().addAll(e.getMail()); - c.getPhone().addAll(e.getPhone()); - c.setSurName(e.getSurName()); - c.setType(e.getType()); - cont.add(c); - } - } - } + } - } else { - Logger.warn("Error in MOA-ID Configuration. No general Protcol configuration found."); + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getSSOCreatedTimeOut() + */ + @Override + public int getSSOCreatedTimeOut() { + try { + return configuration.getIntegerValue( + MOAIDConfigurationConstants.GENERAL_AUTH_TIMEOUS_SSO_CREATE, 2700); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + Logger.warn("No SSO created timeout defined. Use default values", e); + return 2700; } - return result; } + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.auth.AuthConfiguration#getSSOUpdatedTimeOut() + */ + @Override + public int getSSOUpdatedTimeOut() { + try { + return configuration.getIntegerValue( + MOAIDConfigurationConstants.GENERAL_AUTH_TIMEOUS_SSO_UPDATE, 1200); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + Logger.warn("No SSO updated timeout defined. Use default values", e); + return 1200; + } + } + + /** * Returns the configured timeouts, or a default timeout. * * @return the configured timeout, or the default (never {@code null}). * @throws ConfigurationException is thrown in case of missing {@link AuthComponentGeneral}. + * + * @deprecated */ public TimeOuts getTimeOuts() throws ConfigurationException { @@ -257,27 +279,27 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide timeouts.setMOASessionCreated(new BigInteger("2700")); timeouts.setMOASessionUpdated(new BigInteger("1200")); - AuthComponentGeneral authComponentGeneral = getAuthComponentGeneral(); - // search timeouts in config - GeneralConfiguration generalConfiguration = authComponentGeneral.getGeneralConfiguration(); - if (generalConfiguration != null) { - if (generalConfiguration.getTimeOuts() != null) { - if (generalConfiguration.getTimeOuts().getAssertion() != null) { - timeouts.setAssertion(generalConfiguration.getTimeOuts().getAssertion()); - } - - if (generalConfiguration.getTimeOuts().getMOASessionCreated() != null) { - timeouts.setMOASessionCreated(generalConfiguration.getTimeOuts().getMOASessionCreated()); - } - - if (generalConfiguration.getTimeOuts().getMOASessionUpdated() != null) { - timeouts.setMOASessionUpdated(generalConfiguration.getTimeOuts().getMOASessionUpdated()); - } - - } else { - Logger.info("No TimeOuts defined. Use default values"); - } - } +// AuthComponentGeneral authComponentGeneral = getAuthComponentGeneral(); +// // search timeouts in config +// GeneralConfiguration generalConfiguration = authComponentGeneral.getGeneralConfiguration(); +// if (generalConfiguration != null) { +// if (generalConfiguration.getTimeOuts() != null) { +// if (generalConfiguration.getTimeOuts().getAssertion() != null) { +// timeouts.setAssertion(generalConfiguration.getTimeOuts().getAssertion()); +// } +// +// if (generalConfiguration.getTimeOuts().getMOASessionCreated() != null) { +// timeouts.setMOASessionCreated(generalConfiguration.getTimeOuts().getMOASessionCreated()); +// } +// +// if (generalConfiguration.getTimeOuts().getMOASessionUpdated() != null) { +// timeouts.setMOASessionUpdated(generalConfiguration.getTimeOuts().getMOASessionUpdated()); +// } +// +// } else { +// Logger.info("No TimeOuts defined. Use default values"); +// } +// } return timeouts; } @@ -288,20 +310,13 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide * @throws ConfigurationException is thrown in case of missing {@link AuthComponentGeneral} */ public String getAlternativeSourceID() throws ConfigurationException { - AuthComponentGeneral authComponentGeneral = getAuthComponentGeneral(); - String alternativeSourceId = null; - Protocols protocols = authComponentGeneral.getProtocols(); - if (protocols != null) { - SAML1 saml1 = protocols.getSAML1(); - if (saml1 != null && MiscUtil.isNotEmpty(saml1.getSourceID())) { - alternativeSourceId = saml1.getSourceID(); - } - } - GeneralConfiguration generalConfiguration = authComponentGeneral.getGeneralConfiguration(); - if (generalConfiguration != null && MiscUtil.isEmpty(alternativeSourceId)) { - alternativeSourceId = generalConfiguration.getAlternativeSourceID(); + try { + return configuration.getStringValue(MOAIDConfigurationConstants.GENERAL_PROTOCOLS_SAML1_SOURCEID); + + } catch (at.gv.egiz.components.configuration.api.ConfigurationException e) { + Logger.warn("SAML1 SourceID can not be read from configuration.", e); + return null; } - return alternativeSourceId; } /** diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java index 621426ff1..5fc1f3c4d 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java @@ -25,10 +25,8 @@ package at.gv.egovernment.moa.id.moduls; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.Reader; import java.io.StringWriter; import java.net.URI; import java.util.Date; @@ -38,15 +36,12 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import org.apache.velocity.app.VelocityEngine; import org.hibernate.Query; import org.hibernate.Session; import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants; -import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.auth.exception.MOAIDException; import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; import at.gv.egovernment.moa.id.commons.db.dao.session.AuthenticatedSessionStore; @@ -54,7 +49,6 @@ import at.gv.egovernment.moa.id.commons.db.dao.session.InterfederationSessionSto import at.gv.egovernment.moa.id.commons.db.dao.session.OldSSOSessionIDStore; import at.gv.egovernment.moa.id.config.ConfigurationException; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory; -import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage; import at.gv.egovernment.moa.id.util.Random; import at.gv.egovernment.moa.id.util.VelocityProvider; @@ -74,21 +68,11 @@ public class SSOManager { private static final int INTERFEDERATIONCOOKIEMAXAGE = 5 * 60;// sec private static SSOManager instance = null; - private static int sso_timeout; public static SSOManager getInstance() { if (instance == null) { instance = new SSOManager(); - - try { - sso_timeout = (int) AuthConfigurationProviderFactory.getInstance().getTimeOuts().getMOASessionUpdated().longValue(); - - } - catch (ConfigurationException e) { - Logger.info("SSO Timeout can not be loaded from MOA-ID configuration. Use default Timeout with " + DEFAULTSSOTIMEOUT); - sso_timeout = DEFAULTSSOTIMEOUT; - } - + } return instance; @@ -151,7 +135,7 @@ public class SSOManager { //check if session is out of lifetime Date now = new Date(); - long maxSSOSessionTime = AuthConfigurationProviderFactory.getInstance().getTimeOuts().getMOASessionCreated().longValue() * 1000; + long maxSSOSessionTime = AuthConfigurationProviderFactory.getInstance().getSSOCreatedTimeOut() * 1000; Date ssoSessionValidTo = new Date(storedSession.getCreated().getTime() + maxSSOSessionTime); if (now.after(ssoSessionValidTo)) { Logger.info("Found outdated SSO session information. Start reauthentication process ... "); @@ -249,7 +233,15 @@ public class SSOManager { } public void setSSOSessionID(HttpServletRequest httpReq, HttpServletResponse httpResp, String ssoId) { - setCookie(httpReq, httpResp, SSOCOOKIE, ssoId, sso_timeout); + int ssoTimeOut; + try { + ssoTimeOut = (int) AuthConfigurationProviderFactory.getInstance().getSSOCreatedTimeOut(); + + } catch (ConfigurationException e) { + Logger.info("SSO Timeout can not be loaded from MOA-ID configuration. Use default Timeout with " + DEFAULTSSOTIMEOUT); + ssoTimeOut = DEFAULTSSOTIMEOUT; + } + setCookie(httpReq, httpResp, SSOCOOKIE, ssoId, ssoTimeOut); } diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/config/PVPConfiguration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/config/PVPConfiguration.java index d6f6308fd..5c473f32d 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/config/PVPConfiguration.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/config/PVPConfiguration.java @@ -24,7 +24,6 @@ package at.gv.egovernment.moa.id.protocols.pvp2x.config; import iaik.x509.X509Certificate; -import java.io.File; import java.net.URL; import java.security.cert.CertificateException; import java.util.ArrayList; @@ -46,7 +45,7 @@ import org.opensaml.saml2.metadata.OrganizationURL; import org.opensaml.saml2.metadata.SurName; import org.opensaml.saml2.metadata.TelephoneNumber; -import at.gv.egovernment.moa.id.commons.db.dao.config.Contact; +import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; import at.gv.egovernment.moa.id.commons.db.dao.config.OAPVP2; import at.gv.egovernment.moa.id.config.ConfigurationException; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory; @@ -92,31 +91,19 @@ public class PVPConfiguration { public static final String IDP_KEYALIASENCRYTPION = "sp.ks.assertion.encryption.alias"; public static final String IDP_KEY_PASSENCRYTPION = "sp.ks.assertion.encryption.keypassword"; - public static final String IDP_ISSUER_NAME = "idp.issuer.name"; - - public static final String METADATA_FILE = "md.dir"; - public static final String METADATA_EXTENSION = "md.ext"; - - public static final String IDP_ENTITY = "idp.entityid"; - public static final String IDP_ORG_NAME = "idp.org.name"; - public static final String IDP_ORG_DISPNAME = "idp.org.dispname"; - public static final String IDP_ORG_URL = "idp.org.url"; - - public static final String IDP_PUBLIC_URL = "idp.public.url"; - - public static final String IDP_TRUST_STORE = "idp.truststore"; - public static final String SP_TARGET_PREFIX = "sp.target."; - - public static final String IDP_CONTACT_PREFIX = "idp.contact"; - public static final String IDP_CONTACT_LIST = "idp.contact_list"; - - public static final String IDP_CONTACT_SURNAME = "surname"; - 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"; - + public static final String IDP_ISSUER_NAME = "servicename"; + + public static final String IDP_ORG_NAME = "org.name.short"; + public static final String IDP_ORG_DISPNAME = "org.name.full"; + public static final String IDP_ORG_URL = "org.url"; + + public static final String IDP_CONTACT_SURNAME = "contact.familyname"; + public static final String IDP_CONTACT_GIVENNAME = "contact.givenname"; + public static final String IDP_CONTACT_MAIL = "contact.mail"; + public static final String IDP_CONTACT_TYPE = "contact.type"; + public static final String IDP_CONTACT_COMPANY = "contact.company"; + public static final String IDP_CONTACT_PHONE = "contact.phone"; + private static String moaIDVersion = null; //PVP2 generalpvpconfigdb; @@ -211,28 +198,8 @@ public class PVPConfiguration { moaIDVersion = parseMOAIDVersionFromManifest(); } - return AuthConfigurationProviderFactory.getInstance().getGeneralPVP2DBConfig().getIssuerName() + moaIDVersion; - } - - public List getMetadataFiles() { - String filter = props.getProperty(METADATA_EXTENSION); - - if (filter == null) { - filter = ".mdxml"; - } - - List files = new ArrayList(); - - File[] faFiles = new File(props.getProperty(METADATA_FILE)).listFiles(); - for (File file : faFiles) { - if (!file.isDirectory()) { - if (file.getName().endsWith(filter)) { - files.add(file.getAbsolutePath()); - } - } - } - - return files; + return AuthConfigurationProviderFactory.getInstance().getConfigurationWithKey( + MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME) + moaIDVersion; } //TODO: @@ -287,112 +254,100 @@ public class PVPConfiguration { public List getIDPContacts() throws ConfigurationException { List list = new ArrayList(); - List contacts = AuthConfigurationProviderFactory.getInstance().getGeneralPVP2DBConfig().getContact(); + Properties contacts = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( + MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + "."); - if (contacts != null) { + ContactPerson person = SAML2Utils + .createSAMLObject(ContactPerson.class); + + String type = contacts.getProperty(IDP_CONTACT_TYPE); + + if (type == null) { + Logger.error("IDP Contact with SurName " + contacts.getProperty(IDP_CONTACT_SURNAME) + + " has no type defined!"); + } + + 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.getProperty(IDP_CONTACT_SURNAME) + + " has invalid type defined: " + type); + } + + person.setType(enumType); + + String givenName = contacts.getProperty(IDP_CONTACT_GIVENNAME); + + if (givenName != null) { + GivenName name = SAML2Utils + .createSAMLObject(GivenName.class); + name.setName(givenName); + person.setGivenName(name); + } + + String company = contacts.getProperty(IDP_CONTACT_COMPANY); + + if (company != null) { + Company comp = SAML2Utils.createSAMLObject(Company.class); + comp.setName(company); + person.setCompany(comp); + } + + String surname = contacts.getProperty(IDP_CONTACT_SURNAME); + + if (surname != null) { + SurName name = SAML2Utils.createSAMLObject(SurName.class); + name.setName(surname); + person.setSurName(name); + } + + String phone = contacts.getProperty(IDP_CONTACT_PHONE); + if (phone != null) { + TelephoneNumber telePhone = SAML2Utils + .createSAMLObject(TelephoneNumber.class); + telePhone.setNumber(phone); + person.getTelephoneNumbers().add(telePhone); + } - for (Contact contact : contacts) { - - ContactPerson person = SAML2Utils - .createSAMLObject(ContactPerson.class); - - String type = contact.getType(); - - if (type == null) { - Logger.error("IDP Contact with SurName " + contact.getSurName() - + " has no type defined!"); - break; - } - - 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 " + contact.getSurName() - + " has invalid type defined: " + type); - break; - } - - person.setType(enumType); - - String givenName = contact.getGivenName(); - - if (givenName != null) { - GivenName name = SAML2Utils - .createSAMLObject(GivenName.class); - name.setName(givenName); - person.setGivenName(name); - } - - String company = contact.getCompany(); - - if (company != null) { - Company comp = SAML2Utils.createSAMLObject(Company.class); - comp.setName(company); - person.setCompany(comp); - } - - String surname = contact.getSurName(); - - if (surname != null) { - SurName name = SAML2Utils.createSAMLObject(SurName.class); - name.setName(surname); - person.setSurName(name); - } - - List phones = contact.getPhone(); - for (String phone : phones) { - TelephoneNumber telePhone = SAML2Utils - .createSAMLObject(TelephoneNumber.class); - telePhone.setNumber(phone); - person.getTelephoneNumbers().add(telePhone); - } - - List mails = contact.getMail(); - for (String mail : mails) { - EmailAddress mailAddress = SAML2Utils - .createSAMLObject(EmailAddress.class); - mailAddress.setAddress(mail); - person.getEmailAddresses().add(mailAddress); - } - - list.add(person); - } + String mail = contacts.getProperty(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); - at.gv.egovernment.moa.id.commons.db.dao.config.Organization organisation = AuthConfigurationProviderFactory.getInstance().getGeneralPVP2DBConfig().getOrganization(); - - String org_name = null; - String org_dispname = null; - String org_url = null; - - if (organisation != null) { - org_name = organisation.getName(); - org_dispname = organisation.getDisplayName(); - org_url = organisation.getURL(); - } + Properties organisation = AuthConfigurationProviderFactory.getInstance().getConfigurationWithPrefix( + MOAIDConfigurationConstants.GENERAL_PROTOCOLS_PVP2X_METADATA_ORG + "."); + String org_name = organisation.getProperty(IDP_ORG_NAME); + String org_dispname = organisation.getProperty(IDP_ORG_DISPNAME); + String org_url = organisation.getProperty(IDP_ORG_URL); + if (org_name == null || org_dispname == null || org_url == null) { return null; } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java index 6217c6c68..71c95c1e6 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java @@ -175,10 +175,10 @@ public final class MOAIDConfigurationConstants { public static final String GENERAL_AUTH_SSO_TARGET = GENERAL_AUTH + "." + SSO + ".target"; public static final String GENERAL_AUTH_SSO_AUTHBLOCK_TEXT = GENERAL_AUTH + "." + SSO + ".authblock.text"; - private static final String GENERAL_PROTOCOLS = PROTOCOLS; - private static final String GENERAL_PROTOCOLS_SAML1 = GENERAL_PROTOCOLS + "." + SAML1; - private static final String GENERAL_PROTOCOLS_PVP2X = GENERAL_PROTOCOLS + "." + PVP2X; - private static final String GENERAL_PROTOCOLS_OPENID = GENERAL_PROTOCOLS + "." + OPENID; + public static final String GENERAL_PROTOCOLS = PROTOCOLS; + public static final String GENERAL_PROTOCOLS_SAML1 = GENERAL_PROTOCOLS + "." + SAML1; + public static final String GENERAL_PROTOCOLS_PVP2X = GENERAL_PROTOCOLS + "." + PVP2X; + public static final String GENERAL_PROTOCOLS_OPENID = GENERAL_PROTOCOLS + "." + OPENID; public static final String GENERAL_PROTOCOLS_SAML1_ENABLED = GENERAL_PROTOCOLS_SAML1 + ".enabled"; public static final String GENERAL_PROTOCOLS_SAML1_LEGACY = GENERAL_PROTOCOLS_SAML1 + ".legacy"; public static final String GENERAL_PROTOCOLS_SAML1_SOURCEID = GENERAL_PROTOCOLS_SAML1 + ".sourceID"; @@ -187,17 +187,20 @@ public final class MOAIDConfigurationConstants { public static final String GENERAL_PROTOCOLS_PVP2X_ENABLED = GENERAL_PROTOCOLS_PVP2X + ".enabled"; public static final String GENERAL_PROTOCOLS_PVP2X_LEGACY = GENERAL_PROTOCOLS_PVP2X + ".legacy"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME = GENERAL_PROTOCOLS_PVP2X + ".metadata.servicename"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_SHORTNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.name.short"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_FULLNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.name.full"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_URL = GENERAL_PROTOCOLS_PVP2X + ".metadata.org.url"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA = GENERAL_PROTOCOLS_PVP2X + ".metadata"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_SERVICENAMME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".servicename"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG = GENERAL_PROTOCOLS_PVP2X_METADATA + ".org"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_SHORTNAME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".name.short"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_FULLNAME = GENERAL_PROTOCOLS_PVP2X_METADATA + ".name.full"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_ORG_URL = GENERAL_PROTOCOLS_PVP2X_METADATA + ".url"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_FAMLIYNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.familyname"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_GIVENNAME = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.givenname"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_MAIL = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.mail"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_PHONE = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.phone"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_COMPANY = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.company"; - public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_TYPE = GENERAL_PROTOCOLS_PVP2X + ".metadata.contact.type"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT = GENERAL_PROTOCOLS_PVP2X_METADATA + ".contact"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_FAMLIYNAME = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".familyname"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_GIVENNAME = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".givenname"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_MAIL = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".mail"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_PHONE = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".phone"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_COMPANY = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".company"; + public static final String GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT_TYPE = GENERAL_PROTOCOLS_PVP2X_METADATA_CONTACT + ".type"; public static final String GENERAL_AUTH_AUTHBLOCK_TRANSFORMATION_NAME = GENERAL_AUTH + ".authblock.transformation.name"; public static final String GENERAL_AUTH_AUTHBLOCK_TRANSFORMATION_BASE64 = GENERAL_AUTH + ".authblock.transformation.base64"; diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java index 45f37ef97..026a907d7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java @@ -1,44 +1,54 @@ package at.gv.egovernment.moa.id.commons.config.persistence; -import java.util.List; +import java.util.Properties; import at.gv.egiz.components.configuration.api.Configuration; /** * An interface for a key-value configuration. */ -public interface MOAIDConfiguration { +public interface MOAIDConfiguration extends Configuration { /** - * Gets all keys in the database. NOTE: may return an empty list or {@code null}. - * @return a List containing all keys in the database or {@code null}. - */ - List getAllKeys(); - - /** - * Get the value associated with the given key as {@link Object}. - * @param key the key - * @return the String associated with the given key or {@code null} if the key does not exist or does not have a value. - */ - String get(String key); - - /** - * Get the object of type {@code T} associated with the given key. + * Get all key/value pairs with a prefix * - * @param key the key - * @param clazz the type of the requested object - * @return the object associated with the given key or {@code null} if the key does not exist or does not have a value. - */ - T get(String key, Class clazz); - - /** - * Store an object associated with a key. If the given object is set to {@code null} then the entry associated with the key is deleted. + * @param preFix A key prefix + * @return All key/value pairs with this prefix. The prefix is removed from the key. * - * @param key the key under which the value is stored, respectively key determining the entry to be deleted. - * @param value the String to store. if value is set to {@code null} then the entry associated with key {@code key} is deleted. - * @return {@code true} if the operation was carried out successfully, {@code false} otherwise. */ - boolean set(String key, String value); + Properties getPropertySubset(final String preFix); + + +// /** +// * Gets all keys in the database. NOTE: may return an empty list or {@code null}. +// * @return a List containing all keys in the database or {@code null}. +// */ +// List getAllKeys(); +// +// /** +// * Get the value associated with the given key as {@link Object}. +// * @param key the key +// * @return the String associated with the given key or {@code null} if the key does not exist or does not have a value. +// */ +// String get(String key); +// +// /** +// * Get the object of type {@code T} associated with the given key. +// * +// * @param key the key +// * @param clazz the type of the requested object +// * @return the object associated with the given key or {@code null} if the key does not exist or does not have a value. +// */ +// T get(String key, Class clazz); +// +// /** +// * Store an object associated with a key. If the given object is set to {@code null} then the entry associated with the key is deleted. +// * +// * @param key the key under which the value is stored, respectively key determining the entry to be deleted. +// * @param value the String to store. if value is set to {@code null} then the entry associated with key {@code key} is deleted. +// * @return {@code true} if the operation was carried out successfully, {@code false} otherwise. +// */ +// boolean set(String key, String value); // // /** // * Get the object of type {@code T} associated with the given key from the database. If the key does not exist or does not have a value, the given default diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java index 10ed19f83..442ff6247 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java @@ -2,6 +2,7 @@ package at.gv.egovernment.moa.id.commons.config.persistence; import java.util.Arrays; import java.util.List; +import java.util.Properties; import javax.persistence.EntityExistsException; @@ -11,13 +12,14 @@ import org.springframework.beans.factory.annotation.Required; import org.springframework.stereotype.Component; import at.gv.egiz.components.configuration.api.Configuration; +import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyDaoImpl; /** * The implementation of a key-value configuration implementing the {@link Configuration} interface. * It employs the {@link ConfigPropertyDao} to persist configuration data. */ @Component -public class MOAIDConfigurationImpl implements MOAIDConfiguration { +public class MOAIDConfigurationImpl extends ConfigPropertyDaoImpl implements MOAIDConfiguration { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -33,64 +35,93 @@ public class MOAIDConfigurationImpl implements MOAIDConfiguration { this.configPropertyDao = configPropertyDao; } + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#getPropertySubset(java.lang.String) + */ @Override - public List getAllKeys(){ - try { - return Arrays.asList(this.configPropertyDao.getConfigurationIds()); - } catch (Exception e) { - log.debug("Error while retrieving a list of all keys in the database."); - return null; - } + public Properties getPropertySubset(String preFix) { + // TODO Auto-generated method stub + return null; } + + + /** + * Small helper method. NOTE: may return empty properties, but never {@code null}. + * @param propPrefix the prefix of the desired property. + * @return the {@link Properties} + */ + private Properties getGeneralProperiesConfig(Properties input, final String propPrefix) { - @Override - public String get(String key) { - // return null if key does not exist - try { - return configPropertyDao.getStringValue(key); - - } catch (Exception e) { - log.debug("Error while searching value of key '{}' to object.", key); - return null; - } - } - - @Override - public T get(String key, Class clazz) { - // return null if key does not exist - try { - T property = configPropertyDao.getObjectValue(key, clazz); - return property; - - } catch (IllegalArgumentException e) { - log.debug("Error while searching for key '{}' in the database.", key); - return null; - } catch (Exception e) { - log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass()); - return null; - } - } - - @Override - public boolean set(String key, String value) { - - try { - //TODO: add delete - if (value == null) { - //configPropertyDao.delete(key); - return true; - } else { - configPropertyDao.setStringValue(key, value); - return true; + Properties configProp = new Properties(); + for (Object key : input.keySet()) { + if (key.toString().startsWith(propPrefix)) { + String propertyName = key.toString().substring(propPrefix.length()); + configProp.put(propertyName, input.get(key.toString())); } - } catch (EntityExistsException e) { - log.debug("Property '{}' already exists!", key); - return false; - } catch (Exception e) { - log.debug("Error while setting value for key '{}' in the database.", key); - return false; } + return configProp; } + + +// @Override +// public List getAllKeys(){ +// try { +// return Arrays.asList(this.configPropertyDao.getConfigurationIds()); +// } catch (Exception e) { +// log.debug("Error while retrieving a list of all keys in the database."); +// return null; +// } +// } +// +// @Override +// public String get(String key) { +// // return null if key does not exist +// try { +// return configPropertyDao.getStringValue(key); +// +// } catch (Exception e) { +// log.debug("Error while searching value of key '{}' to object.", key); +// return null; +// } +// } +// +// @Override +// public T get(String key, Class clazz) { +// // return null if key does not exist +// try { +// T property = configPropertyDao.getObjectValue(key, clazz); +// return property; +// +// } catch (IllegalArgumentException e) { +// log.debug("Error while searching for key '{}' in the database.", key); +// return null; +// } catch (Exception e) { +// log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass()); +// return null; +// } +// } +// +// @Override +// public boolean set(String key, String value) { +// +// try { +// //TODO: add delete +// if (value == null) { +// //configPropertyDao.delete(key); +// return true; +// } else { +// configPropertyDao.setStringValue(key, value); +// return true; +// } +// } catch (EntityExistsException e) { +// log.debug("Property '{}' already exists!", key); +// return false; +// } catch (Exception e) { +// log.debug("Error while setting value for key '{}' in the database.", key); +// return false; +// } +// } // @Override // public T get(String key, Class clazz, Object defaultValue) { diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java index f5421a47d..22a7bf76b 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBRead.java @@ -40,6 +40,13 @@ import at.gv.egovernment.moa.util.MiscUtil; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * + * @author tlenz + * + * @deprecated + */ + @SuppressWarnings("rawtypes") public class ConfigurationDBRead { -- cgit v1.2.3