From 80ea041e0240eb3d9291eb0d699bb09c90aaa2a9 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 23 Feb 2018 13:35:12 +0100 Subject: first untested unfactoring for Postgresql suppport The scheme of configuration DB changed, therefore this version is incompatible to 3.3.2 configuration --- .../config/ConfigurationProvider.java | 19 ++++- .../moa-id-configtool.properties | 1 + .../data/deploy/conf/moa-id/moa-id.properties | 3 + .../moa/id/config/ConfigurationProviderImpl.java | 5 ++ .../storage/DBAuthenticationSessionStoreage.java | 11 +-- .../id/commons/config/SpringProfileConstants.java | 1 + .../config/persistence/MOAIDConfigurationImpl.java | 39 ++++----- .../db/dao/config/AbstractConfigProperty.java | 94 ++++++++++++++++++++++ .../id/commons/db/dao/config/ConfigProperty.java | 73 ++++------------- .../db/dao/config/ConfigPropertyByteValues.java | 73 +++++++++++++++++ .../db/dao/config/DatabaseConfigPropertyImpl.java | 53 ++++-------- .../db/dao/session/AuthenticatedSessionStore.java | 8 +- .../src/main/resources/configuration.beans.xml | 10 +++ 13 files changed, 262 insertions(+), 128 deletions(-) create mode 100644 id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java create mode 100644 id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java index c5ae5065f..8aab7ef06 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java @@ -34,6 +34,7 @@ import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.Properties; import java.util.Timer; import java.util.jar.Attributes; @@ -51,7 +52,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.web.context.support.GenericWebApplicationContext; +import at.gv.egovernment.moa.id.commons.config.SpringProfileConstants; import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead; import at.gv.egovernment.moa.id.commons.ex.MOAHttpProtocolSocketFactoryException; import at.gv.egovernment.moa.id.commons.utils.MOAHttpProtocolSocketFactory; @@ -93,6 +96,8 @@ public class ConfigurationProvider { private NewConfigurationDBRead deprecatedDBRead = null; private FileBasedUserConfiguration userManagement = null; + private ArrayList activeProfiles = new ArrayList(); + public static ConfigurationProvider getInstance() throws ConfigurationException { if (instance == null) { @@ -134,12 +139,24 @@ public class ConfigurationProvider { props.load(fis); fis.close(); + //initialize generic SpringContext to set profiles + GenericWebApplicationContext rootContext = new GenericWebApplicationContext(); + if (Boolean.valueOf(props.getProperty("configuration.database.byteBasedValues", "false"))) + activeProfiles.add(SpringProfileConstants.BYTEBASEDCONFIG); + + log.info("Activate SpingProfiles: " + activeProfiles.toString()); + for (String el: activeProfiles) + rootContext.getEnvironment().addActiveProfile(el); + + //initialize SpringContext context = new ClassPathXmlApplicationContext( new String[] { "configuration.beans.xml", "moaid.webgui.beans.xml", "moaid.migration.beans.xml", "moaid.configurationtool.beans.xml" - }); + }, rootContext); + + //Autowire beans in these context AutowireCapableBeanFactory acbFactory = context.getAutowireCapableBeanFactory(); acbFactory.autowireBean(this); diff --git a/id/server/data/deploy/conf/moa-id-configuration/moa-id-configtool.properties b/id/server/data/deploy/conf/moa-id-configuration/moa-id-configtool.properties index 4520dcc14..05e68daca 100644 --- a/id/server/data/deploy/conf/moa-id-configuration/moa-id-configtool.properties +++ b/id/server/data/deploy/conf/moa-id-configuration/moa-id-configtool.properties @@ -18,6 +18,7 @@ general.moaconfig.key=ConfigurationEncryptionKey general.pvp.schemavalidation=true ##Hibnerate configuration for MOA-ID 2.0 configuration +configuration.database.byteBasedValues=false hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.connection.url=jdbc:mysql://localhost/moa-id-config?charSet=utf-8&autoReconnect=true&serverTimezone=UTC hibernate.connection.charSet=utf-8 diff --git a/id/server/data/deploy/conf/moa-id/moa-id.properties b/id/server/data/deploy/conf/moa-id/moa-id.properties index 4228b0d3a..fa6bccef0 100644 --- a/id/server/data/deploy/conf/moa-id/moa-id.properties +++ b/id/server/data/deploy/conf/moa-id/moa-id.properties @@ -62,6 +62,9 @@ protocols.oauth20.jwt.ks.key.name=oauth protocols.oauth20.jwt.ks.key.password=password ##Database configuration## +configuration.database.byteBasedValues=false + + #Hibnerate configuration for MOA-ID 3.x session store moasession.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect moasession.hibernate.connection.url=jdbc:mysql://localhost/moa-id-session?charSet=utf-8&serverTimezone=UTC diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java index 2b5459208..151eda89f 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java @@ -269,11 +269,16 @@ public abstract class ConfigurationProviderImpl implements ConfigurationProvider }else{ activeProfiles.add("advancedLogOff"); } + if (Boolean.valueOf(props.getProperty("redis.active", "false"))) { activeProfiles.add(SpringProfileConstants.REDIS_BACKEND); }else{ activeProfiles.add(SpringProfileConstants.DB_BACKEND); } + + if (Boolean.valueOf(props.getProperty("configuration.database.byteBasedValues", "false"))) + activeProfiles.add(SpringProfileConstants.BYTEBASEDCONFIG); + } public String[] getActiveProfiles(){ diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java index ad200e400..0df6379b0 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java @@ -22,6 +22,7 @@ *******************************************************************************/ package at.gv.egovernment.moa.id.storage; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -105,7 +106,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt //set additional session informations AuthenticationSessionExtensions sessionExt = new AuthenticationSessionExtensions(); sessionExt.setUniqueSessionId(target.getUniqueSessionIdentifier()); - dbsession.setAdditionalInformation(mapper.serialize(sessionExt)); + dbsession.setAdditionalInformation(mapper.serialize(sessionExt).getBytes("UTF-8")); AuthenticationSession session = new AuthenticationSession(id, now, target.getMOASession()); encryptSession(session, dbsession); @@ -120,7 +121,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt // Logger.warn("MOASession could not be created."); // throw new MOADatabaseException(e); - } catch (JsonProcessingException e) { + } catch (JsonProcessingException | UnsupportedEncodingException e) { Logger.warn("Extended session information can not be stored.", e); throw new MOADatabaseException(e); @@ -154,7 +155,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt if (MiscUtil.isNotEmpty(dbsession.getAdditionalInformation())) { try { - return (AuthenticationSessionExtensions)mapper.deserialize(dbsession.getAdditionalInformation(), + return (AuthenticationSessionExtensions)mapper.deserialize(new String(dbsession.getAdditionalInformation(), "UTF-8"), AuthenticationSessionExtensions.class); } catch (Exception e) { @@ -171,7 +172,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt AuthenticatedSessionStore dbsession = searchInDatabase(sessionID); dbsession.setAdditionalInformation( - mapper.serialize(sessionExtensions)); + mapper.serialize(sessionExtensions).getBytes("UTF-8")); entityManager.merge(dbsession); Logger.debug("MOASession with sessionID=" + sessionID + " is stored in Database"); @@ -181,7 +182,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt Logger.warn("MOASession could not be stored."); throw new MOADatabaseException(e); - } catch (JsonProcessingException e) { + } catch (JsonProcessingException | UnsupportedEncodingException e) { Logger.warn("Extended session information can not be stored.", e); throw new MOADatabaseException("Extended session information can not be stored.", e); diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java index 14824b1f8..f64e10d0d 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/SpringProfileConstants.java @@ -5,4 +5,5 @@ public final class SpringProfileConstants { public static final String ADVANCED_LOG = "advancedLogOn"; public static final String REDIS_BACKEND = "redisBackend"; public static final String DB_BACKEND = "dbBackend"; + public static final String BYTEBASEDCONFIG = "byteBasedConfig"; } 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 b9b5ad611..4fd382606 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 @@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; import at.gv.egiz.components.configuration.api.Configuration; import at.gv.egiz.components.configuration.api.ConfigurationException; import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; +import at.gv.egovernment.moa.id.commons.db.dao.config.AbstractConfigProperty; import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty; import at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl; import at.gv.egovernment.moa.id.commons.utils.KeyValueUtils; @@ -31,14 +32,6 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement // Configuration configPropertyDao; // -// /** -// * Sets the {@link ConfigPropertyDao}. -// * @param configPropertyDao the ConfigPropertyDao -// */ -// @Required -// public void setConfigPropertyDao(Configuration configPropertyDao) { -// this.configPropertyDao = configPropertyDao; -// } public void setStringValue(String id, String value) throws ConfigurationException { super.setStringValue(id, value); @@ -63,9 +56,9 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement } - TypedQuery configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", preFix + "%"); - List configResult = configQuery.getResultList(); + List configResult = configQuery.getResultList(); if (configResult == null || configResult.isEmpty()) { Logger.warn("Found no configuration keys with prefix: " + preFix + ".%"); @@ -101,9 +94,9 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement } - TypedQuery configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", searchKey.replace("*", "%")); - List configResult = configQuery.getResultList(); + List configResult = configQuery.getResultList(); if (configResult == null || configResult.isEmpty()) { Logger.warn("Found no configuration keys with searchKey: " + searchKey); @@ -134,8 +127,8 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement + ".%." + MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER; - List oaSearchResult = null; - TypedQuery oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", ConfigProperty.class); + List oaSearchResult = null; + TypedQuery oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", AbstractConfigProperty.class); oaSearchQuery.setParameter("key", keyId); oaSearchQuery.setParameter("uniqueID", publicURLPrefix); oaSearchResult = oaSearchQuery.getResultList(); @@ -164,13 +157,13 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement + ".%." + MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER; - List oaSearchResult = new ArrayList(); + List oaSearchResult = new ArrayList(); - TypedQuery oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaSearchQuery.setParameter("key", keyId); - List intermResult = oaSearchQuery.getResultList(); + List intermResult = oaSearchQuery.getResultList(); if (intermResult != null) { - for (ConfigProperty el : intermResult) { + for (AbstractConfigProperty el : intermResult) { if (publicURLPrefix.startsWith(el.getValue())) oaSearchResult.add(el); @@ -189,10 +182,10 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement * @param removePrefix: Indicates if the prefix should be removed from the result key * @return the {@link Map} of configuration properties */ - private Map getKeyValueFromDatabaseDAO(Iterator input, final String prefix, boolean removePrefix) { + private Map getKeyValueFromDatabaseDAO(Iterator input, final String prefix, boolean removePrefix) { Map configProp = new HashMap(); while (input.hasNext()) { - ConfigProperty el = input.next(); + AbstractConfigProperty el = input.next(); if (removePrefix) { if (el.getKey().startsWith(prefix)) { String propertyName = KeyValueUtils.removePrefixFromKey(el.getKey(), prefix); @@ -213,7 +206,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement * @param oaSearchResult Search result of first OA selection operation * @return Map of post-processed OA configuration key/value pairs */ - private Map postProcessLoadOnlineApplication(EntityManager em, List oaSearchResult) { + private Map postProcessLoadOnlineApplication(EntityManager em, List oaSearchResult) { if (oaSearchResult == null || oaSearchResult.size() == 0) { Logger.debug("No entries found."); return null; } @@ -231,9 +224,9 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement String oaType = KeyValueUtils.getFirstChildAfterPrefix(oaIdKey, MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES); String oaKey = KeyValueUtils.getPrefixFromKey(oaIdKey, MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER); - TypedQuery oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaConfigQuery.setParameter("key", oaKey + ".%"); - List oaConfigResult = oaConfigQuery.getResultList(); + List oaConfigResult = oaConfigQuery.getResultList(); if (oaConfigResult == null) { Logger.warn("Found no configuration keys with prefix: " + oaKey + ".%"); diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java new file mode 100644 index 000000000..d50aa9c6e --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java @@ -0,0 +1,94 @@ +package at.gv.egovernment.moa.id.commons.db.dao.config; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public abstract class AbstractConfigProperty implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @Column(name = "propertyKey", unique = true) + protected String key; + + public AbstractConfigProperty() { + super(); + } + + + /** + * Returns the property's value (which might be {@code null}). + * @return The property's value (might be {@code null}). + */ + abstract public String getValue(); + + /** + * Sets the property's value. + * @param value The value + */ + abstract public void setValue(String value); + + /** + * Returns the property's key. + * @return The key. + */ + public String getKey() { + return key; + } + + /** + * Sets the property's key. + * @param key The key + */ + public void setKey(String key) { + this.key = key; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConfigProperty other = (ConfigProperty) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + return true; + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(getImpplementationName()); + builder.append(" [key="); + builder.append(getKey()); + builder.append(", value="); + builder.append(getValue()); + builder.append("]"); + return builder.toString(); + } + + /** + * Get a name for this Entity-Implementation for logging purposes + * + * @return + */ + abstract protected String getImpplementationName(); +} \ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java index 6e2743b81..07770fdf3 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java @@ -1,95 +1,54 @@ package at.gv.egovernment.moa.id.commons.db.dao.config; -import java.io.Serializable; - import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; + /** - * Reflects a MOAID configuration entry. + * Reflects a MOAID configuration entry with String values. * */ @Table(name = "configproperty") @Entity -public class ConfigProperty implements Serializable { +public class ConfigProperty extends AbstractConfigProperty{ + + + + /** + * + */ private static final long serialVersionUID = 1L; - @Id - @Column(name = "propertyKey", unique = true) - private String key; - @Lob @Column(name = "propertyValue") private String value; - /** - * Returns the property's key. - * @return The key. - */ - public String getKey() { - return key; - } - - /** - * Sets the property's key. - * @param key The key - */ - public void setKey(String key) { - this.key = key; - } - + + /** * Returns the property's value (which might be {@code null}). * @return The property's value (might be {@code null}). */ + @Override public String getValue() { return value; + } /** * Sets the property's value. * @param value The value */ + @Override public void setValue(String value) { this.value = value; } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; + protected String getImpplementationName() { + return this.getClass().getName(); } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ConfigProperty other = (ConfigProperty) obj; - if (key == null) { - if (other.key != null) - return false; - } else if (!key.equals(other.key)) - return false; - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ConfigProperty [key="); - builder.append(key); - builder.append(", value="); - builder.append(value); - builder.append("]"); - return builder.toString(); - } } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java new file mode 100644 index 000000000..51f7e4da6 --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java @@ -0,0 +1,73 @@ +package at.gv.egovernment.moa.id.commons.db.dao.config; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Lob; +import javax.persistence.Table; + +import at.gv.egovernment.moa.logging.Logger; + + +/** + * Reflects a MOAID configuration entry with String values. + * + */ +@Table(name = "configpropertybytes") +@Entity +public class ConfigPropertyByteValues extends AbstractConfigProperty{ + + + + /** + * + */ + private static final long serialVersionUID = 1L; + + + @Lob + @Column(name = "propertyValueBytes") + private byte[] value = null; + + + /** + * Returns the property's value (which might be {@code null}). + * @return The property's value (might be {@code null}). + */ + @Override + public String getValue() { + try { + if (value != null) + return new String(value, "UTF-8"); + + } catch (UnsupportedEncodingException e) { + Logger.error("Internal DB read error! Can not read values from configuration DB.", e); + + } + + return null; + + } + + /** + * Sets the property's value. + * @param value The value + */ + @Override + public void setValue(String value) { + try { + this.value = value.getBytes("UTF-8"); + + } catch (UnsupportedEncodingException e) { + Logger.error("Internal DB write error! Can not read write to configuration DB.", e); + + } + } + + @Override + protected String getImpplementationName() { + return this.getClass().getName(); + } +} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java index aad830d65..213d1a860 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java @@ -12,6 +12,8 @@ import javax.persistence.TypedQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -32,6 +34,9 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { @PersistenceContext(unitName = "config") private EntityManager em; + @Autowired(required=true) + private ApplicationContext appContext; + /** * * @return EntityManager for database access @@ -56,7 +61,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { */ @Override protected String getValue(String key) throws ConfigurationException { - ConfigProperty property = getProperty(key); + AbstractConfigProperty property = getProperty(key); if (property == null) return null; @@ -74,7 +79,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { */ @Override protected boolean containsKey(String key) throws ConfigurationException { - ConfigProperty property = getProperty(key); + AbstractConfigProperty property = getProperty(key); if (property == null) return false; else @@ -93,7 +98,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - ConfigProperty property = new ConfigProperty(); + AbstractConfigProperty property = appContext.getBean(AbstractConfigProperty.class); property.setKey(key); property.setValue(value); log.debug("Storing '{}'.", property.toString()); @@ -104,7 +109,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { protected void deleteKey(String key) { log.debug("Deleting entry with key '{}'.", key); - ConfigProperty el = em.find(ConfigProperty.class, key); + AbstractConfigProperty el = em.find(AbstractConfigProperty.class, key); if (el != null) em.remove(el); @@ -141,8 +146,8 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - TypedQuery query = em.createQuery("select * from ConfigProperty dbconfig", ConfigProperty.class); - List all = query.getResultList(); + TypedQuery query = em.createQuery("select * from ConfigProperty dbconfig", AbstractConfigProperty.class); + List all = query.getResultList(); searchString = searchString.replace(".", "\\."); String regex = searchString.replace("*", ".*"); @@ -151,11 +156,11 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { Pattern pattern = Pattern.compile(regex); List keyList = new ArrayList(); - Iterator keyIt; + Iterator keyIt; if (all != null) { keyIt = all.iterator(); while(keyIt.hasNext()) { - ConfigProperty entry = keyIt.next(); + AbstractConfigProperty entry = keyIt.next(); String value = entry.getValue(); String key = entry.getKey(); @@ -188,9 +193,9 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { } - private ConfigProperty getProperty(String key) { + private AbstractConfigProperty getProperty(String key) { log.trace("Looking for configuration property for key '{}'.", key); - ConfigProperty result = em.find(ConfigProperty.class, key); + AbstractConfigProperty result = em.find(AbstractConfigProperty.class, key); if (result != null) { log.trace("Found configuration property {}.", result); } else { @@ -212,32 +217,4 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { } } -// @Override -// public String getPropertyValue(String key) { -// ConfigProperty property = getProperty(key); -// if (property == null) { -// return null; -// } -// return property.getValue(); -// } -// -// @Override -// public List getProperties() { -// -// if (null == em) { -// log.error("No EntityManager set!"); -// return null; -// } -// -// log.debug("Retrieving all properties from database."); -// TypedQuery query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); -// try { -// List propertiesList = query.getResultList(); -// return propertiesList; -// } catch (NoResultException e) { -// log.debug("No property found in database."); -// return null; -// } -// } - } \ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java index eeaf03544..7cb921ee7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java @@ -98,9 +98,9 @@ public class AuthenticatedSessionStore implements Serializable{ @Column(name = "pendingRequestID", nullable=true) private String pendingRequestID = ""; - @Column(name = "additionalInformation", nullable=true) + @Column(name = "additionalInformationBytes", nullable=true) @Lob - private String additionalInformation; + private byte[] additionalInformation; @Column(name = "created", updatable=false, nullable=false) @Temporal(TemporalType.TIMESTAMP) @@ -349,14 +349,14 @@ public class AuthenticatedSessionStore implements Serializable{ /** * @return the additionalInformation */ - public String getAdditionalInformation() { + public byte[] getAdditionalInformation() { return additionalInformation; } /** * @param additionalInformation the additionalInformation to set */ - public void setAdditionalInformation(String additionalInformation) { + public void setAdditionalInformation(byte[] additionalInformation) { this.additionalInformation = additionalInformation; } diff --git a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml index b97b1c88b..1251cf406 100644 --- a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml +++ b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml @@ -10,6 +10,16 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + + + + + + -- cgit v1.2.3