diff options
Diffstat (limited to 'id/server/moa-id-commons/src')
8 files changed, 229 insertions, 122 deletions
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<ConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", preFix + "%"); - List<ConfigProperty> configResult = configQuery.getResultList(); + List<AbstractConfigProperty> 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<ConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", searchKey.replace("*", "%")); - List<ConfigProperty> configResult = configQuery.getResultList(); + List<AbstractConfigProperty> 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<ConfigProperty> oaSearchResult = null; - TypedQuery<ConfigProperty> 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<AbstractConfigProperty> oaSearchResult = null; + TypedQuery<AbstractConfigProperty> 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<ConfigProperty> oaSearchResult = new ArrayList<ConfigProperty>(); + List<AbstractConfigProperty> oaSearchResult = new ArrayList<AbstractConfigProperty>(); - TypedQuery<ConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery<AbstractConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaSearchQuery.setParameter("key", keyId); - List<ConfigProperty> intermResult = oaSearchQuery.getResultList(); + List<AbstractConfigProperty> 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<String, String> getKeyValueFromDatabaseDAO(Iterator<ConfigProperty> input, final String prefix, boolean removePrefix) { + private Map<String, String> getKeyValueFromDatabaseDAO(Iterator<AbstractConfigProperty> input, final String prefix, boolean removePrefix) { Map<String, String> configProp = new HashMap<String, String>(); 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<String, String> postProcessLoadOnlineApplication(EntityManager em, List<ConfigProperty> oaSearchResult) { + private Map<String, String> postProcessLoadOnlineApplication(EntityManager em, List<AbstractConfigProperty> 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<ConfigProperty> oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class); + TypedQuery<AbstractConfigProperty> oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaConfigQuery.setParameter("key", oaKey + ".%"); - List<ConfigProperty> oaConfigResult = oaConfigQuery.getResultList(); + List<AbstractConfigProperty> 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<ConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", ConfigProperty.class); - List<ConfigProperty> all = query.getResultList(); + TypedQuery<AbstractConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", AbstractConfigProperty.class); + List<AbstractConfigProperty> 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<String> keyList = new ArrayList<String>(); - Iterator<ConfigProperty> keyIt; + Iterator<AbstractConfigProperty> 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<ConfigProperty> getProperties() { -// -// if (null == em) { -// log.error("No EntityManager set!"); -// return null; -// } -// -// log.debug("Retrieving all properties from database."); -// TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); -// try { -// List<ConfigProperty> 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"> <context:annotation-config /> + <beans profile="!byteBasedConfig"> + <bean id="StringBasedConfigProperty" + class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty"/> + </beans> + + <beans profile="byteBasedConfig"> + <bean id="ByteBasedConfigProperty" + class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyByteValues" + /> + </beans> <bean id="configPropertyDao" class="at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl"/> |