From: <fg...@us...> - 2008-01-31 22:34:48
|
Revision: 588 http://openutils.svn.sourceforge.net/openutils/?rev=588&view=rev Author: fgiust Date: 2008-01-31 14:34:54 -0800 (Thu, 31 Jan 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-junit-2.0.2 Added Paths: ----------- tags/openutils-testing-junit-2.0.2/ tags/openutils-testing-junit-2.0.2/pom.xml Removed Paths: ------------- tags/openutils-testing-junit-2.0.2/pom.xml Copied: tags/openutils-testing-junit-2.0.2 (from rev 582, trunk/openutils-testing-junit) Deleted: tags/openutils-testing-junit-2.0.2/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2008-01-31 22:20:03 UTC (rev 582) +++ tags/openutils-testing-junit-2.0.2/pom.xml 2008-01-31 22:34:54 UTC (rev 588) @@ -1,159 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-junit</artifactId> - <name>openutils test utils (junit)</name> - <version>2.0.2-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.2.2.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - <exclusion> - <artifactId>commons-logging</artifactId> - <groupId>commons-logging</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-testing-junit-2.0.2/pom.xml (from rev 587, trunk/openutils-testing-junit/pom.xml) =================================================================== --- tags/openutils-testing-junit-2.0.2/pom.xml (rev 0) +++ tags/openutils-testing-junit-2.0.2/pom.xml 2008-01-31 22:34:54 UTC (rev 588) @@ -0,0 +1,165 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-junit</artifactId> + <name>openutils test utils (junit)</name> + <version>2.0.2</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.2</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + <exclusion> + <artifactId>commons-logging</artifactId> + <groupId>commons-logging</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-2.0.2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-2.0.2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-2.0.2</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2008-02-01 10:59:44
|
Revision: 592 http://openutils.svn.sourceforge.net/openutils/?rev=592&view=rev Author: molaschi Date: 2008-02-01 02:59:48 -0800 (Fri, 01 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-bshd5-2.0.1 Added Paths: ----------- tags/openutils-bshd5-2.0.1/ tags/openutils-bshd5-2.0.1/pom.xml tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Removed Paths: ------------- tags/openutils-bshd5-2.0.1/pom.xml tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java Copied: tags/openutils-bshd5-2.0.1 (from rev 589, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-2.0.1/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2008-01-31 22:35:00 UTC (rev 589) +++ tags/openutils-bshd5-2.0.1/pom.xml 2008-02-01 10:59:48 UTC (rev 592) @@ -1,108 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>2.0.1-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-2.0.1/pom.xml (from rev 591, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-2.0.1/pom.xml (rev 0) +++ tags/openutils-bshd5-2.0.1/pom.xml 2008-02-01 10:59:48 UTC (rev 592) @@ -0,0 +1,114 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>2.0.1</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-2.0.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-01-31 22:35:00 UTC (rev 589) +++ tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-02-01 10:59:48 UTC (rev 592) @@ -1,305 +0,0 @@ -package it.openutils.hibernate.example; - -import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataRetrievalFailureException; - - -/** - * @author Fabrizio Giustina - * @version $Id: $ - */ -public final class EnhancedExample -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); - - private Map<String, FilterMetadata> metadata; - - private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - { - this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; - fillCriteria(null, crit, filter); - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @param metadata Map of property names - filter metadata - * @throws HibernateException exception while building the criteria - */ - public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) - throws HibernateException - { - new EnhancedExample(crit, filter, metadata); - } - - /** - * Adds contitions to an existing criteria or create sub-criteria for associations. - * @param crit Criteria - * @param propertyName property name in parent bean - * @param value property value - * @throws HibernateException exception while building the criteria - */ - private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) - throws HibernateException - { - - String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( - propertyName, - ".") : propertyName; - - if (isSimpleType(value) || value.getClass().isEnum()) - { - - // don't filter on empty strings! - if (value instanceof String && StringUtils.isBlank((String) value)) - { - return; - } - - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd == null) - { - fmd = FilterMetadata.EQUAL; - } - - fmd.createFilter(crit, simplePropertyName, value); - - } - else - { - if (containsSomething(value)) - { - // @todo handle multiple associations in lists? - // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 - if ((value instanceof Set || value instanceof List) && !((Collection< ? >) value).isEmpty()) - { - // collection: the new criteria has already been created, now we only nee to analize content - - for (Object element : ((Collection< ? >) value)) - { - - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, element); - } - } - else if ((value instanceof Map) && !((Map< ? , ? >) value).isEmpty()) - { - FilterMetadata fmd = metadata.get(propertyName); - - if (fmd != null) - { - fmd.createFilter(crit, simplePropertyName, value); - } - else - { - log.warn( - "Maps are not handled without a FilterMetadata. Property is {} and value is {}.", - propertyName, - value); - } - } - else - { - log.debug("crit.createCriteria({})", simplePropertyName); - Criteria childrenCriteria = crit.createCriteria(simplePropertyName); - fillCriteria(propertyName, childrenCriteria, value); - } - } - } - } - - /** - * Check if the bean contains at least a valid property. - * @param bean javabean - * @return <code>true</code> if the bean contains at least a valid property - */ - @SuppressWarnings("unchecked") - private boolean containsSomething(Object bean) - { - - if (bean == null) - { - return false; - } - if (isSimpleType(bean)) - { - return true; - } - - if (bean instanceof Collection) - { - - Collection< ? > coll = ((Collection< ? >) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.iterator().next())) - { - return true; - } - } - else if (bean instanceof Map) - { - Map< ? , ? > coll = ((Map< ? , ? >) bean); - if (coll.isEmpty()) - { - return false; - } - - if (containsSomething(coll.values().iterator().next())) - { - return true; - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(bean); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(bean, "NULL"), e); - return false; - } - - for (Map.Entry<String, Object> property : properties.entrySet()) - { - - if (!PropertyUtils.isWriteable(bean, property.getKey())) - { - // skip readonly properties - continue; - } - - Object propertyValue = property.getValue(); - if (propertyValue == null) - { - continue; - } - - if (isSimpleType(propertyValue) || containsSomething(propertyValue)) - { - return true; - } - } - - return false; - } - - /** - * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. - * @param crit Criteria - * @param filter javabean which will be analyzed for non-null properties - * @throws HibernateException exception while building the criteria - */ - @SuppressWarnings("unchecked") - private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException - { - if ((filter instanceof Set || filter instanceof List) && !((Collection< ? >) filter).isEmpty()) - { - // collection: the new criteria has already been created, now we only need to analize content - for (Object element : ((Collection< ? >) filter)) - { - fillCriteria(parentPropertyName, crit, element); - } - } - - Map<String, Object> properties; - try - { - properties = PropertyUtils.describe(filter); - } - catch (Throwable e) - { - if (e instanceof InvocationTargetException) - { - e = ((InvocationTargetException) e).getTargetException(); - } - - throw new DataRetrievalFailureException( - "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " - + ClassUtils.getShortClassName(filter, "NULL") - + ":" - + e.getClass(), - e); - } - - Iterator<String> iterator = properties.keySet().iterator(); - while (iterator.hasNext()) - { - String propertyName = iterator.next(); - - Object value = properties.get(propertyName); - - // add only non-null values, ignore read-only properties - if (value != null && PropertyUtils.isWriteable(filter, propertyName)) - { - String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName - + "." - + propertyName; - addCondition(crit, composedPropertyName, value, filter); - } - } - } - - /** - * Check if the given object is a simple java type - * @param object object to check - * @return <code>true</code>if the given object is a simple type - */ - private boolean isSimpleType(Object object) - { - - Class< ? extends Object> objClass = object.getClass(); - - return objClass.isPrimitive() - || objClass.equals(Integer.class) - || objClass.equals(Long.class) - || objClass.equals(Short.class) - || objClass.equals(Boolean.class) - || objClass.equals(String.class) - || objClass.equals(Double.class) - || objClass.equals(Float.class) - || objClass.equals(Date.class) - || objClass.equals(Byte.class) - || objClass.equals(BigDecimal.class) - || objClass.equals(Timestamp.class) - || objClass.equals(Character.class) - || Calendar.class.isAssignableFrom(objClass); - } - -} Copied: tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (from rev 590, trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/EnhancedExample.java) =================================================================== --- tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java (rev 0) +++ tags/openutils-bshd5-2.0.1/src/main/java/it/openutils/hibernate/example/EnhancedExample.java 2008-02-01 10:59:48 UTC (rev 592) @@ -0,0 +1,306 @@ +package it.openutils.hibernate.example; + +import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.mapping.Value; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataRetrievalFailureException; + + +/** + * @author Fabrizio Giustina + * @version $Id: $ + */ +public final class EnhancedExample +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnhancedExample.class); + + private Map<String, FilterMetadata> metadata; + + private EnhancedExample(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + { + this.metadata = metadata == null ? new HashMap<String, FilterMetadata>(0) : metadata; + fillCriteria(null, crit, filter); + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @param metadata Map of property names - filter metadata + * @throws HibernateException exception while building the criteria + */ + public static void create(Criteria crit, Object filter, Map<String, FilterMetadata> metadata) + throws HibernateException + { + new EnhancedExample(crit, filter, metadata); + } + + /** + * Adds contitions to an existing criteria or create sub-criteria for associations. + * @param crit Criteria + * @param propertyName property name in parent bean + * @param value property value + * @throws HibernateException exception while building the criteria + */ + private void addCondition(Criteria crit, String propertyName, Object value, Object parentObject) + throws HibernateException + { + + String simplePropertyName = StringUtils.contains(propertyName, ".") ? StringUtils.substringAfterLast( + propertyName, + ".") : propertyName; + + if (isSimpleType(value) || value.getClass().isEnum()) + { + + // don't filter on empty strings! + if (value instanceof String && StringUtils.isBlank((String) value)) + { + return; + } + + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd == null) + { + fmd = FilterMetadata.EQUAL; + } + + fmd.createFilter(crit, simplePropertyName, value); + + } + else + { + if (containsSomething(value)) + { + // @todo handle multiple associations in lists? + // see http://opensource2.atlassian.com/projects/hibernate/browse/HHH-879 + if ((value instanceof Set || value instanceof List) && !((Collection< ? >) value).isEmpty()) + { + // collection: the new criteria has already been created, now we only nee to analize content + + for (Object element : ((Collection< ? >) value)) + { + + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, element); + } + } + else if ((value instanceof Map) && !((Map< ? , ? >) value).isEmpty()) + { + FilterMetadata fmd = metadata.get(propertyName); + + if (fmd != null) + { + fmd.createFilter(crit, simplePropertyName, value); + } + else + { + log.warn( + "Maps are not handled without a FilterMetadata. Property is {} and value is {}.", + propertyName, + value); + } + } + else + { + log.debug("crit.createCriteria({})", simplePropertyName); + Criteria childrenCriteria = crit.createCriteria(simplePropertyName); + fillCriteria(propertyName, childrenCriteria, value); + } + } + } + } + + /** + * Check if the bean contains at least a valid property. + * @param bean javabean + * @return <code>true</code> if the bean contains at least a valid property + */ + @SuppressWarnings("unchecked") + private boolean containsSomething(Object bean) + { + + if (bean == null) + { + return false; + } + if (isSimpleType(bean) || bean.getClass().isEnum()) + { + return true; + } + + if (bean instanceof Collection) + { + + Collection< ? > coll = ((Collection< ? >) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.iterator().next())) + { + return true; + } + } + else if (bean instanceof Map) + { + Map< ? , ? > coll = ((Map< ? , ? >) bean); + if (coll.isEmpty()) + { + return false; + } + + if (containsSomething(coll.values().iterator().next())) + { + return true; + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(bean); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + log.error("Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(bean, "NULL"), e); + return false; + } + + for (Map.Entry<String, Object> property : properties.entrySet()) + { + + if (!PropertyUtils.isWriteable(bean, property.getKey())) + { + // skip readonly properties + continue; + } + + Object propertyValue = property.getValue(); + if (propertyValue == null) + { + continue; + } + + if (isSimpleType(propertyValue) || containsSomething(propertyValue)) + { + return true; + } + } + + return false; + } + + /** + * Fills a criteria object calling addCondition() for any non-null property or for any component in collections. + * @param crit Criteria + * @param filter javabean which will be analyzed for non-null properties + * @throws HibernateException exception while building the criteria + */ + @SuppressWarnings("unchecked") + private void fillCriteria(String parentPropertyName, Criteria crit, Object filter) throws HibernateException + { + if ((filter instanceof Set || filter instanceof List) && !((Collection< ? >) filter).isEmpty()) + { + // collection: the new criteria has already been created, now we only need to analize content + for (Object element : ((Collection< ? >) filter)) + { + fillCriteria(parentPropertyName, crit, element); + } + } + + Map<String, Object> properties; + try + { + properties = PropertyUtils.describe(filter); + } + catch (Throwable e) + { + if (e instanceof InvocationTargetException) + { + e = ((InvocationTargetException) e).getTargetException(); + } + + throw new DataRetrievalFailureException( + "Unable to build filter, PropertyUtils.describe throws an exception while analizing class " + + ClassUtils.getShortClassName(filter, "NULL") + + ":" + + e.getClass(), + e); + } + + Iterator<String> iterator = properties.keySet().iterator(); + while (iterator.hasNext()) + { + String propertyName = iterator.next(); + + Object value = properties.get(propertyName); + + // add only non-null values, ignore read-only properties + if (value != null && PropertyUtils.isWriteable(filter, propertyName)) + { + String composedPropertyName = (parentPropertyName == null) ? propertyName : parentPropertyName + + "." + + propertyName; + addCondition(crit, composedPropertyName, value, filter); + } + } + } + + /** + * Check if the given object is a simple java type + * @param object object to check + * @return <code>true</code>if the given object is a simple type + */ + private boolean isSimpleType(Object object) + { + + Class< ? extends Object> objClass = object.getClass(); + + return objClass.isPrimitive() + || objClass.equals(Integer.class) + || objClass.equals(Long.class) + || objClass.equals(Short.class) + || objClass.equals(Boolean.class) + || objClass.equals(String.class) + || objClass.equals(Double.class) + || objClass.equals(Float.class) + || objClass.equals(Date.class) + || objClass.equals(Byte.class) + || objClass.equals(BigDecimal.class) + || objClass.equals(Timestamp.class) + || objClass.equals(Character.class) + || Calendar.class.isAssignableFrom(objClass); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-03 21:07:46
|
Revision: 596 http://openutils.svn.sourceforge.net/openutils/?rev=596&view=rev Author: fgiust Date: 2008-02-03 13:07:50 -0800 (Sun, 03 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-2.0 Added Paths: ----------- tags/openutils-dbmigration-2.0/ tags/openutils-dbmigration-2.0/pom.xml Removed Paths: ------------- tags/openutils-dbmigration-2.0/pom.xml Copied: tags/openutils-dbmigration-2.0 (from rev 594, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-2.0/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-dbmigration-2.0/pom.xml 2008-02-03 21:07:50 UTC (rev 596) @@ -1,97 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration</name> - <version>2.0-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi</artifactId> - <version>3.0-FINAL</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-2.0/pom.xml (from rev 595, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-2.0/pom.xml (rev 0) +++ tags/openutils-dbmigration-2.0/pom.xml 2008-02-03 21:07:50 UTC (rev 596) @@ -0,0 +1,102 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration</name> + <version>2.0</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>3.0-FINAL</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-2.0</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-03 21:20:03
|
Revision: 600 http://openutils.svn.sourceforge.net/openutils/?rev=600&view=rev Author: fgiust Date: 2008-02-03 13:20:09 -0800 (Sun, 03 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-deployment-2.0 Added Paths: ----------- tags/openutils-deployment-2.0/ tags/openutils-deployment-2.0/pom.xml tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java tags/openutils-deployment-2.0/src/site/apt/index.apt Removed Paths: ------------- tags/openutils-deployment-2.0/pom.xml tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java tags/openutils-deployment-2.0/src/site/apt/index.apt Copied: tags/openutils-deployment-2.0 (from rev 594, trunk/openutils-deployment) Deleted: tags/openutils-deployment-2.0/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/pom.xml 2008-02-03 21:20:09 UTC (rev 600) @@ -1,71 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>2.0-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-deployment-2.0/pom.xml (from rev 599, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-2.0/pom.xml (rev 0) +++ tags/openutils-deployment-2.0/pom.xml 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>2.0</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-2.0</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2008-02-03 21:20:09 UTC (rev 600) @@ -1,80 +0,0 @@ -package it.openutils.deployment.log4j; - -import java.io.File; -import java.io.FileNotFoundException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.MessageFormat; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DeploymentResolver -{ - - public static File resolveServerRelativeLocation(ServletContext context, String commaSeparatedListOfPaths) - throws FileNotFoundException - { - String[] propertiesLocation = StringUtils.split(commaSeparatedListOfPaths, ','); - - String servername = resolveServerName(); - - String rootPath = StringUtils.replace(context.getRealPath("/"), "\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ - String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$ - - for (int j = 0; j < propertiesLocation.length; j++) - { - String location = StringUtils.trim(propertiesLocation[j]); - location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$ - location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$ - - File initFile = new File(rootPath, location); - - if (!initFile.exists() || initFile.isDirectory()) - { - continue; - } - - return initFile; - - } - - throw new FileNotFoundException( - MessageFormat - .format( - "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$ - new Object[]{ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath })); - - } - - /** - * Resolve the current server name. - * @return server name, all lowercase, without domain - */ - public static String resolveServerName() - { - String servername = null; - - try - { - servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - if (StringUtils.contains(servername, ".")) - { - servername = StringUtils.substringBefore(servername, "."); - } - - } - catch (UnknownHostException e) - { - System.err.println(e.getMessage()); - } - return servername; - } -} Copied: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java (from rev 598, trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java) =================================================================== --- tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java (rev 0) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,95 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.deployment.log4j; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.MessageFormat; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DeploymentResolver +{ + + public static File resolveServerRelativeLocation(ServletContext context, String commaSeparatedListOfPaths) + throws FileNotFoundException + { + String[] propertiesLocation = StringUtils.split(commaSeparatedListOfPaths, ','); + + String servername = resolveServerName(); + + String rootPath = StringUtils.replace(context.getRealPath("/"), "\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ + String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$ + + for (int j = 0; j < propertiesLocation.length; j++) + { + String location = StringUtils.trim(propertiesLocation[j]); + location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$ + location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$ + + File initFile = new File(rootPath, location); + + if (!initFile.exists() || initFile.isDirectory()) + { + continue; + } + + return initFile; + + } + + throw new FileNotFoundException( + MessageFormat + .format( + "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$ + new Object[]{ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath})); + + } + + /** + * Resolve the current server name. + * @return server name, all lowercase, without domain + */ + public static String resolveServerName() + { + String servername = null; + + try + { + servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + if (StringUtils.contains(servername, ".")) + { + servername = StringUtils.substringBefore(servername, "."); + } + + } + catch (UnknownHostException e) + { + System.err.println(e.getMessage()); + } + return servername; + } +} Deleted: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2008-02-03 21:20:09 UTC (rev 600) @@ -1,108 +0,0 @@ -package it.openutils.deployment.log4j; - -import java.io.FileNotFoundException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.springframework.util.Log4jConfigurer; -import org.springframework.web.util.Log4jConfigListener; -import org.springframework.web.util.WebUtils; - - -/** - * @author Fabrizio Giustina - * @version $Id$ - */ -public class EnvironmentLog4jConfigListener extends Log4jConfigListener -{ - - /** - * Default value for the DEFAULT_INITIALIZATION_PARAMETER parameter. - */ - public static final String DEFAULT_INITIALIZATION_PARAMETER = // - "WEB-INF/config/${servername}/${webapp}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/${servername}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/${webapp}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/default/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/log4j.xml"; //$NON-NLS-1$ - - /** - * {@inheritDoc} - */ - @Override - public void contextInitialized(ServletContextEvent event) - { - initLogging(event.getServletContext()); - } - - public static void initLogging(ServletContext servletContext) - { - if (exposeWebAppRoot(servletContext)) - { - WebUtils.setWebAppRootSystemProperty(servletContext); - - String servername = DeploymentResolver.resolveServerName(); - if (servername != null) - { - System.setProperty("server.name", servername); - System.setProperty("server", servername); - } - } - - String locationList = servletContext.getInitParameter("log4jConfigLocation"); - - if (locationList == null) - { - locationList = DEFAULT_INITIALIZATION_PARAMETER; - } - - String location; - - try - { - location = DeploymentResolver.resolveServerRelativeLocation(servletContext, locationList).getAbsolutePath(); - } - catch (FileNotFoundException ex) - { - throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); - } - if (location != null) - { - servletContext.log("Initializing Log4J from [" + location + "]"); - try - { - - String intervalString = servletContext.getInitParameter("log4jRefreshInterval"); - if (intervalString != null) - { - try - { - long refreshInterval = Long.parseLong(intervalString); - Log4jConfigurer.initLogging(location, refreshInterval); - } - catch (NumberFormatException ex) - { - throw new IllegalArgumentException("Invalid 'log4jRefreshInterval' parameter: " - + ex.getMessage()); - } - } - else - { - Log4jConfigurer.initLogging(location); - } - } - catch (FileNotFoundException ex) - { - throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); - } - } - } - - private static boolean exposeWebAppRoot(ServletContext servletContext) - { - String exposeWebAppRootParam = servletContext.getInitParameter("log4jExposeWebAppRoot"); - return exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam).booleanValue(); - } - -} Copied: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java (from rev 598, trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java) =================================================================== --- tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java (rev 0) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,123 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.deployment.log4j; + +import java.io.FileNotFoundException; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.springframework.util.Log4jConfigurer; +import org.springframework.web.util.Log4jConfigListener; +import org.springframework.web.util.WebUtils; + + +/** + * @author Fabrizio Giustina + * @version $Id$ + */ +public class EnvironmentLog4jConfigListener extends Log4jConfigListener +{ + + /** + * Default value for the DEFAULT_INITIALIZATION_PARAMETER parameter. + */ + public static final String DEFAULT_INITIALIZATION_PARAMETER = // + "WEB-INF/config/${servername}/${webapp}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/${servername}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/${webapp}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/default/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/log4j.xml"; //$NON-NLS-1$ + + /** + * {@inheritDoc} + */ + @Override + public void contextInitialized(ServletContextEvent event) + { + initLogging(event.getServletContext()); + } + + public static void initLogging(ServletContext servletContext) + { + if (exposeWebAppRoot(servletContext)) + { + WebUtils.setWebAppRootSystemProperty(servletContext); + + String servername = DeploymentResolver.resolveServerName(); + if (servername != null) + { + System.setProperty("server.name", servername); + System.setProperty("server", servername); + } + } + + String locationList = servletContext.getInitParameter("log4jConfigLocation"); + + if (locationList == null) + { + locationList = DEFAULT_INITIALIZATION_PARAMETER; + } + + String location; + + try + { + location = DeploymentResolver.resolveServerRelativeLocation(servletContext, locationList).getAbsolutePath(); + } + catch (FileNotFoundException ex) + { + throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); + } + if (location != null) + { + servletContext.log("Initializing Log4J from [" + location + "]"); + try + { + + String intervalString = servletContext.getInitParameter("log4jRefreshInterval"); + if (intervalString != null) + { + try + { + long refreshInterval = Long.parseLong(intervalString); + Log4jConfigurer.initLogging(location, refreshInterval); + } + catch (NumberFormatException ex) + { + throw new IllegalArgumentException("Invalid 'log4jRefreshInterval' parameter: " + + ex.getMessage()); + } + } + else + { + Log4jConfigurer.initLogging(location); + } + } + catch (FileNotFoundException ex) + { + throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); + } + } + } + + private static boolean exposeWebAppRoot(ServletContext servletContext) + { + String exposeWebAppRootParam = servletContext.getInitParameter("log4jExposeWebAppRoot"); + return exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam).booleanValue(); + } + +} Deleted: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2008-02-03 21:20:09 UTC (rev 600) @@ -1,175 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.IOException; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Properties; - -import javax.sql.DataSource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DatabaseEnvironmentPropertyConfigurer extends EnvironmentPropertyConfigurer - implements - ApplicationContextAware, - ApplicationListener -{ - - private static Logger log = LoggerFactory.getLogger(DatabaseEnvironmentPropertyConfigurer.class); - - private String sqlQuery; - - private String dataSourceName; - - private DataSource dataSource; - - private ApplicationContext applicationContext; - - public void setSqlQuery(String sqlQuery) - { - this.sqlQuery = sqlQuery; - } - - public void setDataSourceName(String dataSourceName) - { - this.dataSourceName = dataSourceName; - } - - /** - * {@inheritDoc} - */ - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - this.applicationContext = applicationContext; - } - - /** - * Get Spring Context proprieties. - * @return A properties object containing all spring properties. - */ - @Override - public Properties getProperties() - { - // loadAndRefresh(); @todo is this needed anymore? - return properties; - } - - /** - * @throws IOException - */ - private void loadAndRefresh() throws IOException - { - properties = mergeProperties(); - refresh(); - } - - /** - * used to reload configuration code from db - */ - public void refresh() - { - manuallyLoadDatasource(); - - /** - * inner utility class to create properties from rows extracted by the query - * @author diego - * @version $Id$ - */ - class RowHandler implements RowCallbackHandler - { - - /** - * {@inheritDoc} - */ - public void processRow(final ResultSet rs) throws SQLException - { - String parmName = rs.getString(1); - String parmValue = rs.getString(2); - - log.debug("Configuring property {}={}", parmName, parmValue); - properties.put(parmName, parmValue); - - } - } - - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - try - { - jdbcTemplate.query(sqlQuery, new RowHandler()); - } - catch (DataAccessException e) - { - log.error(e.getMessage()); - } - } - - /** - * {@inheritDoc} - */ - public void onApplicationEvent(ApplicationEvent event) - { - manuallyLoadDatasource(); - } - - /** - * - */ - private void manuallyLoadDatasource() - { - if (dataSource == null) - { - dataSource = (DataSource) applicationContext.getBean(dataSourceName); - try - { - properties = mergeProperties(); - } - catch (IOException e) - { - log.debug("Exception while loading environment properties from file."); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - - super.postProcessBeanFactory(beanFactory); - - try - { - loadAndRefresh(); - Properties mergedProps = properties; - - // Convert the merged properties, if necessary. - convertProperties(mergedProps); - - // Let the subclass process the properties. - processProperties(beanFactory, mergedProps); - } - catch (IOException ex) - { - throw new BeanInitializationException("Could not load properties", ex); - } - - } -} Copied: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java (from rev 598, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,190 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.deployment.spring; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import javax.sql.DataSource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanInitializationException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DatabaseEnvironmentPropertyConfigurer extends EnvironmentPropertyConfigurer + implements + ApplicationContextAware, + ApplicationListener +{ + + private static Logger log = LoggerFactory.getLogger(DatabaseEnvironmentPropertyConfigurer.class); + + private String sqlQuery; + + private String dataSourceName; + + private DataSource dataSource; + + private ApplicationContext applicationContext; + + public void setSqlQuery(String sqlQuery) + { + this.sqlQuery = sqlQuery; + } + + public void setDataSourceName(String dataSourceName) + { + this.dataSourceName = dataSourceName; + } + + /** + * {@inheritDoc} + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } + + /** + * Get Spring Context proprieties. + * @return A properties object containing all spring properties. + */ + @Override + public Properties getProperties() + { + // loadAndRefresh(); @todo is this needed anymore? + return properties; + } + + /** + * @throws IOException + */ + private void loadAndRefresh() throws IOException + { + properties = mergeProperties(); + refresh(); + } + + /** + * used to reload configuration code from db + */ + public void refresh() + { + manuallyLoadDatasource(); + + /** + * inner utility class to create properties from rows extracted by the query + * @author diego + * @version $Id$ + */ + class RowHandler implements RowCallbackHandler + { + + /** + * {@inheritDoc} + */ + public void processRow(final ResultSet rs) throws SQLException + { + String parmName = rs.getString(1); + String parmValue = rs.getString(2); + + log.debug("Configuring property {}={}", parmName, parmValue); + properties.put(parmName, parmValue); + + } + } + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + try + { + jdbcTemplate.query(sqlQuery, new RowHandler()); + } + catch (DataAccessException e) + { + log.error(e.getMessage()); + } + } + + /** + * {@inheritDoc} + */ + public void onApplicationEvent(ApplicationEvent event) + { + manuallyLoadDatasource(); + } + + /** + * + */ + private void manuallyLoadDatasource() + { + if (dataSource == null) + { + dataSource = (DataSource) applicationContext.getBean(dataSourceName); + try + { + properties = mergeProperties(); + } + catch (IOException e) + { + log.debug("Exception while loading environment properties from file."); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + + super.postProcessBeanFactory(beanFactory); + + try + { + loadAndRefresh(); + Properties mergedProps = properties; + + // Convert the merged properties, if necessary. + convertProperties(mergedProps); + + // Let the subclass process the properties. + processProperties(beanFactory, mergedProps); + } + catch (IOException ex) + { + throw new BeanInitializationException("Could not load properties", ex); + } + + } +} Deleted: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-03 21:20:09 UTC (rev 600) @@ -1,323 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.util.ResourceUtils; -import org.springframework.web.context.WebApplicationContext; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ApplicationContextAware -{ - - /** - * Application name (webapp name) variable. - */ - private static final String PROPERTY_APPL = "${appl}"; - - /** - * Environment (server name) variable. - */ - private static final String PROPERTY_ENV = "${env}"; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * @deprecated use defaultLocation - */ - @Deprecated - private String defaultEnvironment; - - private ServletContext servletContext; - - private String fileLocation; - - /** - * Cached properties (super field is private). - */ - protected Properties properties; - - /** - * Are properties inherited from default configuration? default is true, - */ - private boolean inherit = true; - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Sets the inherit. - * @param inherit the inherit to set - */ - public void setInherit(boolean inherit) - { - this.inherit = inherit; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - * @deprecated use defaultLocation - */ - @Deprecated - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - try - { - hostname = StringUtils.substringBefore( - StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()), - "."); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); // should not happen - } - - if (hostname != null) - { - System.setProperty("env", hostname); - } - - String applName = getApplicationName(); - if (applName != null) - { - System.setProperty("appl", applName); - } - - URL propertyUrl = null; - - String fileLocationFull = fileLocation; - - if (defaultEnvironment != null) - { - log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " - + "as the last comma separated value in \"fileLocation\""); - fileLocationFull = fileLocationFull - + "," - + StringUtils.replace(fileLocationFull, PROPERTY_ENV, this.defaultEnvironment); - } - - String replacedLocations = StringUtils.replace(fileLocationFull, PROPERTY_ENV, hostname); - replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); - - String[] locations = StringUtils.split(replacedLocations, ","); - - if (inherit) - { - ArrayUtils.reverse(locations); - } - - Properties props = new Properties(); - boolean found = false; - - for (String loc : locations) - { - propertyUrl = getResource(StringUtils.strip(loc)); - if (propertyUrl != null) - { - found = true; - log.debug("Loading property file at {}", loc); - - Resource resource = new UrlResource(propertyUrl); - InputStream is = null; - - try - { - is = resource.getInputStream(); - props.load(is); - } - catch (IOException e) - { - log.error("Error loading " + propertyUrl.toString(), e); - } - finally - { - if (is != null) - { - try - { - is.close(); - } - catch (IOException e) - { - // ignore - } - } - } - - if (!inherit) - { - break; - } - } - log.debug("Property file not found at {}", loc); - - } - - if (!found) - { - log.error("No properties found at {}", replacedLocations); - } - - this.properties = props; - super.setProperties(props); - - } - - super.postProcessBeanFactory(beanFactory); - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null) - { - try - { - if (resource != null && !resource.startsWith("/")) - { - url = servletContext.getResource("/" + resource); - } - else - { - url = servletContext.getResource(resource); - } - - if (url != null) - { - // check needed for servletUnit - // we need to check for a connection because getResource always returns a URL, also if the resource - // doesn't exists - url.openConnection().connect(); - } - - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - catch (IOException e) - { - // ignore, URL is not a valid resource - url = null; - } - } - else - { - try - { - url = ResourceUtils.getURL(resource); - url.openStream().close(); // test if the resource actually exists - } - catch (IOException e) - { - // ignore, can be normal - url = null; - } - } - return url; - } - - private String getApplicationName() - { - if (servletContext != null) - { - String url = servletContext.getRealPath("/"); - url = StringUtils.replace(url, "\\", "/"); - if (url.endsWith("/")) - { - url = StringUtils.substringBeforeLast(url, "/"); - } - - return StringUtils.substringAfterLast(url, "/"); - } - return StringUtils.EMPTY; - } - - /** - * Returns the Properties loaded by this configurer. - * @return Properties - */ - public Properties getProperties() - { - return properties; - } - - /** - * Returns a single property. - * @param key Property key - * @return property value or <code>null</code> if not found. - */ - public String getProperty(String key) - { - // better be safe, it doesn't hurt - if (properties == null) - { - return null; - } - return properties.getProperty(key); - } - - /** - * {@inheritDoc} - */ - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - try - { - if (applicationContext instanceof WebApplicationContext) - { - this.servletContext = ((WebApplicationContext) applicationContext).getServletContext(); - } - } - catch (NoClassDefFoundError e) - { - // ignore, we are not in a web project or spring web is not available - } - } -} Copied: tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 598, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-2.0/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,338 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.deployment.spring; + +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.Properties; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.util.ResourceUtils; +import org.springframework.web.context.WebApplicationContext; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ApplicationContextAware +{ + + /** + * Application name (webapp name) variable. + */ + private static final String PROPERTY_APPL = "${appl}"; + + /** + * Environment (server name) variable. + */ + private static final String PROPERTY_ENV = "${env}"; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * @deprecated use defaultLocation + */ + @Deprecated + private String defaultEnvironment; + + private ServletContext servletContext; + + private String fileLocation; + + /** + * Cached properties (super field is private). + */ + protected Properties properties; + + /** + * Are properties inherited from default configuration? default is true, + */ + private boolean inherit = true; + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Sets the inherit. + * @param inherit the inherit to set + */ + public void setInherit(boolean inherit) + { + this.inherit = inherit; + } + + /** + * Setter for <code>defaultEnvironment</code>. + * @param defaultEnvironment The defaultEnvironment to set. + * @deprecated use defaultLocation + */ + @Deprecated + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + if (fileLocation != null) + { + + String hostname = null; + try + { + hostname = StringUtils.substringBefore( + StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()), + "."); + } + catch (UnknownHostException e) + { + log.error(e.getMessage()); // should not happen + } + + if (hostname != null) + { + System.setProperty("env", hostname); + } + + String applName = getApplicationName(); + if (applName != null) + { + System.setProperty("appl", applName); + } + + URL propertyUrl = null; + + String fileLocationFull = fileLocation; + + if (defaultEnvironment != null) + { + log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " + + "as the last comma separated value in \"fileLocation\""); + fileLocationFull = fileLocationFull + + "," + + StringUtils.replace(fileLocationFull, PROPERTY_ENV, this.defaultEnvironment); + } + + String replacedLocations = StringUtils.replace(fileLocationFull, PROPERTY_ENV, hostname); + replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); + + String[] locations = StringUtils.split(replacedLocations, ","); + + if (inherit) + { + ArrayUtils.reverse(locations); + } + + Properties props = new Properties(); + boolean found = false; + + for (String loc : locations) + { + propertyUrl = getResource(StringUtils.strip(loc)); + if (propertyUrl != null) + { + found = true; + log.debug("Loading property file at {}", loc); + + Resource resource = new UrlResource(propertyUrl); + InputStream is = null; + + try + { + is = resource.getInputStream(); + props.load(is); + } + catch (IOException e) + { + log.error("Error loading " + propertyUrl.toString(), e); + } + finally + { + if (is != null) + { + try + { + is.close(); + } + catch (IOException e) + { + // ignore + } + } + } + + if (!inherit) + { + break; + } + } + log.debug("Property file not found at {}", loc); + + } + + if (!found) + { + log.error("No properties found at {}", replacedLocations); + } + + this.properties = props; + super.setProperties(props); + + } + + super.postProcessBeanFactory(beanFactory); + } + + private URL getResource(String resource) + { + URL url = null; + + if (servletContext != null) + { + try + { + if (resource != null && !resource.startsWith("/")) + { + url = servletContext.getResource("/" + resource); + } + else + { + url = servletContext.getResource(resource); + } + + if (url != null) + { + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } + + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } + } + else + { + try + { + url = ResourceUtils.getURL(resource); + url.openStream().close(); // test if the resource actually exists + } + catch (IOException e) + { + // ignore, can be normal + url = null; + } + } + return url; + } + + private String getApplicationName() + { + if (servletContext != null) + { + String url = servletContext.getRealPath("/"); + url = StringUtils.replace(url, "\\", "/"); + if (url.endsWith("/")) + { + url = StringUtils.substringBeforeLast(url, "/"); + } + + return StringUtils.substringAfterLast(url, "/"); + } + return StringUtils.EMPTY; + } + + /** + * Returns the Properties loaded by this configurer. + * @return Properties + */ + public Properties getProperties() + { + return properties; + } + + /** + * Returns a single property. + * @param key Property key + * @return property value or <code>null</code> if not found. + */ + public String getProperty(String key) + { + // better be safe, it doesn't hurt + if (properties == null) + { + return null; + } + return properties.getProperty(key); + } + + /** + * {@inheritDoc} + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + try + { + if (applicationContext instanceof WebApplicationContext) + { + this.servletContext = ((WebApplicationContext) applicationContext).getServletContext(); + } + } + catch (NoClassDefFoundError e) + { + // ignore, we are not in a web project or spring web is not available + } + } +} Deleted: tags/openutils-deployment-2.0/src/site/apt/index.apt =================================================================== --- trunk/openutils-deployment/src/site/apt/index.apt 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-deployment-2.0/src/site/apt/index.apt 2008-02-03 21:20:09 UTC (rev 600) @@ -1,15 +0,0 @@ - -------------------------- - O p e n u t i l s - -------------------------- - Fabrizio Giustina - -------------------------- - -openutils-deployment - - - - -Released versions - - Check it at {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-deployment}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-deployment}} - Copied: tags/openutils-deployment-2.0/src/site/apt/index.apt (from rev 598, trunk/openutils-deployment/src/site/apt/index.apt) =================================================================== --- tags/openutils-deployment-2.0/src/site/apt/index.apt (rev 0) +++ tags/openutils-deployment-2.0/src/site/apt/index.apt 2008-02-03 21:20:09 UTC (rev 600) @@ -0,0 +1,42 @@ + -------------------------- + O p e n u t i l s + -------------------------- + Fabrizio Giustina + -------------------------- + +openutils-deployment + + Openutils-deployment contains a few utility classes that allow switching between different configurations in an application. + + Openutils-deployment works by embedding configurations for different environments in the final application, and by + choosing the correct configuration at runtime dependending on: + + * the server name + + * the webapp name (for web projects) + + [] + + You can find a spring propertyconfigurer and a log4j servlet listener that follow this pattern. + + The following example is a configuration snippet for <<<it.openutils.deployment.spring.EnvironmentPropertyConfigurer>>>: + The ${env} variable will be replaced at runtime with the name of the current server and any existing configuration file + wil be loaded. + + ++--------------------------------------------+ + <bean id="environmentProperties" class="it.openutils.deployment.spring.EnvironmentPropertyConfigurer"> + <property name="fileLocation" + value="WEB-INF/config/${env}/environment.properties, + WEB-INF/config/default/environment.properties, + classpath:environment-${env}.properties, + classpath:environment.properties" /> + </bean> ++--------------------------------------------+ + + + +Released versions + + Check it at {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-deployment}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-deployment}} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-03 22:49:56
|
Revision: 604 http://openutils.svn.sourceforge.net/openutils/?rev=604&view=rev Author: fgiust Date: 2008-02-03 14:49:59 -0800 (Sun, 03 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-2.0.1 Added Paths: ----------- tags/openutils-dbmigration-2.0.1/ tags/openutils-dbmigration-2.0.1/pom.xml tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java Removed Paths: ------------- tags/openutils-dbmigration-2.0.1/pom.xml tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java Copied: tags/openutils-dbmigration-2.0.1 (from rev 594, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-2.0.1/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-dbmigration-2.0.1/pom.xml 2008-02-03 22:49:59 UTC (rev 604) @@ -1,97 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration</name> - <version>2.0-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi</artifactId> - <version>3.0-FINAL</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.1/pom.xml (from rev 603, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-2.0.1/pom.xml (rev 0) +++ tags/openutils-dbmigration-2.0.1/pom.xml 2008-02-03 22:49:59 UTC (rev 604) @@ -0,0 +1,102 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration</name> + <version>2.0.1</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>3.0-FINAL</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-2.0.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-03 22:49:59 UTC (rev 604) @@ -1,63 +0,0 @@ -package it.openutils.migration.generic; - -import it.openutils.migration.task.setup.BaseConditionalTask; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.lang.StringUtils; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask -{ - - private String column; - - /** - * Sets the column. - * @param column the column to set - */ - public void setColumn(String column) - { - this.column = column; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean check(SimpleJdbcTemplate jdbcTemplate) - { - final String catalog = null; - final String schema = null; - - String columnTrim = StringUtils.trim(column); - - final String tableName = StringUtils.substringBefore(columnTrim, "."); - final String columnName = StringUtils.substringAfter(columnTrim, "."); - return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - - DatabaseMetaData dbMetadata = con.getMetaData(); - ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName); - boolean tableExists = rs.first(); - rs.close(); - - return !tableExists; - } - }); - } - -} Copied: tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (from rev 602, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-03 22:49:59 UTC (rev 604) @@ -0,0 +1,63 @@ +package it.openutils.migration.generic; + +import it.openutils.migration.task.setup.BaseConditionalTask; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.apache.commons.lang.StringUtils; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask +{ + + private String column; + + /** + * Sets the column. + * @param column the column to set + */ + public void setColumn(String column) + { + this.column = column; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean check(SimpleJdbcTemplate jdbcTemplate) + { + final String catalog = null; + final String schema = null; + + String columnTrim = StringUtils.trim(column); + + final String tableName = StringUtils.substringBefore(columnTrim, "."); + final String columnName = StringUtils.substringAfter(columnTrim, "."); + return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + + DatabaseMetaData dbMetadata = con.getMetaData(); + ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName); + boolean tableExists = rs.next(); + rs.close(); + + return !tableExists; + } + }); + } + +} Deleted: tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-03 22:49:59 UTC (rev 604) @@ -1,137 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.migration.generic; - -import it.openutils.migration.task.setup.GenericConditionalTask; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * @author fgiust - * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $ - */ -public abstract class JdbcObjectCreationTask extends GenericConditionalTask -{ - - protected String catalog; - - abstract String getObjectType(); - - /** - * {@inheritDoc} - */ - @Override - public void execute(DataSource dataSource) - { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); - - for (Resource script : scripts) - { - - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - String fqTableName = this.objectNameFromFileName(script); - String tmptableName = null; - String tmpschema = null; - - if (StringUtils.contains(fqTableName, ".")) - { - String[] tokens = StringUtils.split(fqTableName, "."); - tmptableName = tokens[1]; - tmpschema = tokens[0]; - } - else - { - tmptableName = fqTableName; - } - - final String tableName = tmptableName; - final String schema = tmpschema; - - boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - - DatabaseMetaData dbMetadata = con.getMetaData(); - ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType() }); - boolean tableExists = rs.first(); - rs.close(); - - return tableExists; - } - }); - - if (!result) - { - String scriptContent; - InputStream is = null; - - try - { - is = script.getInputStream(); - scriptContent = IOUtils.toString(is, "UTF8"); - } - catch (IOException e) - { - log.error( - "Unable to execute db task \"{}\", script \"{}\" can't be read.", - getDescription(), - script); - return; - } - finally - { - IOUtils.closeQuietly(is); - } - - String[] ddls = StringUtils.split(scriptContent, ";"); - - log.info("Creating new {} {}", getObjectType(), tableName); - - for (String ddl : ddls) - { - if (StringUtils.isNotBlank(ddl)) - { - log.debug("Executing:\n{}", ddl); - jdbcTemplate.update(ddl); - } - } - } - } - } -} \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java (from rev 602, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.1/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-03 22:49:59 UTC (rev 604) @@ -0,0 +1,137 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.migration.generic; + +import it.openutils.migration.task.setup.GenericConditionalTask; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * @author fgiust + * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $ + */ +public abstract class JdbcObjectCreationTask extends GenericConditionalTask +{ + + protected String catalog; + + abstract String getObjectType(); + + /** + * {@inheritDoc} + */ + @Override + public void execute(DataSource dataSource) + { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + + for (Resource script : scripts) + { + + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + String fqTableName = this.objectNameFromFileName(script); + String tmptableName = null; + String tmpschema = null; + + if (StringUtils.contains(fqTableName, ".")) + { + String[] tokens = StringUtils.split(fqTableName, "."); + tmptableName = tokens[1]; + tmpschema = tokens[0]; + } + else + { + tmptableName = fqTableName; + } + + final String tableName = tmptableName; + final String schema = tmpschema; + + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + + DatabaseMetaData dbMetadata = con.getMetaData(); + ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType() }); + boolean tableExists = rs.next(); + rs.close(); + + return tableExists; + } + }); + + if (!result) + { + String scriptContent; + InputStream is = null; + + try + { + is = script.getInputStream(); + scriptContent = IOUtils.toString(is, "UTF8"); + } + catch (IOException e) + { + log.error( + "Unable to execute db task \"{}\", script \"{}\" can't be read.", + getDescription(), + script); + return; + } + finally + { + IOUtils.closeQuietly(is); + } + + String[] ddls = StringUtils.split(scriptContent, ";"); + + log.info("Creating new {} {}", getObjectType(), tableName); + + for (String ddl : ddls) + { + if (StringUtils.isNotBlank(ddl)) + { + log.debug("Executing:\n{}", ddl); + jdbcTemplate.update(ddl); + } + } + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-11 20:53:12
|
Revision: 613 http://openutils.svn.sourceforge.net/openutils/?rev=613&view=rev Author: fgiust Date: 2008-02-11 12:50:50 -0800 (Mon, 11 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-2.0.2 Added Paths: ----------- tags/openutils-dbmigration-2.0.2/ tags/openutils-dbmigration-2.0.2/pom.xml tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/oracle/ tags/openutils-dbmigration-2.0.2/src/site/changes/ Removed Paths: ------------- tags/openutils-dbmigration-2.0.2/pom.xml tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java Copied: tags/openutils-dbmigration-2.0.2 (from rev 605, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-2.0.2/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2008-02-03 22:50:06 UTC (rev 605) +++ tags/openutils-dbmigration-2.0.2/pom.xml 2008-02-11 20:50:50 UTC (rev 613) @@ -1,96 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration</name> - <version>2.0.2-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi</artifactId> - <version>3.0-FINAL</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.2/pom.xml (from rev 612, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-2.0.2/pom.xml (rev 0) +++ tags/openutils-dbmigration-2.0.2/pom.xml 2008-02-11 20:50:50 UTC (rev 613) @@ -0,0 +1,102 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration</name> + <version>2.0.2</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>3.0-FINAL</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-2.0.2</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-03 22:50:06 UTC (rev 605) +++ tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-11 20:50:50 UTC (rev 613) @@ -1,63 +0,0 @@ -package it.openutils.migration.generic; - -import it.openutils.migration.task.setup.BaseConditionalTask; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.commons.lang.StringUtils; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask -{ - - private String column; - - /** - * Sets the column. - * @param column the column to set - */ - public void setColumn(String column) - { - this.column = column; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean check(SimpleJdbcTemplate jdbcTemplate) - { - final String catalog = null; - final String schema = null; - - String columnTrim = StringUtils.trim(column); - - final String tableName = StringUtils.substringBefore(columnTrim, "."); - final String columnName = StringUtils.substringAfter(columnTrim, "."); - return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - - DatabaseMetaData dbMetadata = con.getMetaData(); - ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName); - boolean tableExists = rs.next(); - rs.close(); - - return !tableExists; - } - }); - } - -} Copied: tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (from rev 611, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-11 20:50:50 UTC (rev 613) @@ -0,0 +1,83 @@ +package it.openutils.migration.generic; + +import it.openutils.migration.task.setup.BaseConditionalTask; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.apache.commons.lang.StringUtils; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask +{ + + private String column; + + protected String catalog; + + protected String schema; + + /** + * Sets the catalog. + * @param catalog the catalog to set + */ + public void setCatalog(String catalog) + { + this.catalog = catalog; + } + + /** + * Sets the schema. + * @param schema the schema to set + */ + public void setSchema(String schema) + { + this.schema = schema; + } + + /** + * Sets the column. + * @param column the column to set + */ + public void setColumn(String column) + { + this.column = column; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean check(SimpleJdbcTemplate jdbcTemplate) + { + + String columnTrim = StringUtils.trim(column); + + final String tableName = StringUtils.substringBefore(columnTrim, "."); + final String columnName = StringUtils.substringAfter(columnTrim, "."); + return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + + DatabaseMetaData dbMetadata = con.getMetaData(); + ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName); + boolean tableExists = rs.next(); + rs.close(); + + return !tableExists; + } + }); + } + +} Deleted: tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-03 22:50:06 UTC (rev 605) +++ tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-11 20:50:50 UTC (rev 613) @@ -1,137 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.migration.generic; - -import it.openutils.migration.task.setup.GenericConditionalTask; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * @author fgiust - * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $ - */ -public abstract class JdbcObjectCreationTask extends GenericConditionalTask -{ - - protected String catalog; - - abstract String getObjectType(); - - /** - * {@inheritDoc} - */ - @Override - public void execute(DataSource dataSource) - { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); - - for (Resource script : scripts) - { - - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - String fqTableName = this.objectNameFromFileName(script); - String tmptableName = null; - String tmpschema = null; - - if (StringUtils.contains(fqTableName, ".")) - { - String[] tokens = StringUtils.split(fqTableName, "."); - tmptableName = tokens[1]; - tmpschema = tokens[0]; - } - else - { - tmptableName = fqTableName; - } - - final String tableName = tmptableName; - final String schema = tmpschema; - - boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - - DatabaseMetaData dbMetadata = con.getMetaData(); - ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType() }); - boolean tableExists = rs.next(); - rs.close(); - - return tableExists; - } - }); - - if (!result) - { - String scriptContent; - InputStream is = null; - - try - { - is = script.getInputStream(); - scriptContent = IOUtils.toString(is, "UTF8"); - } - catch (IOException e) - { - log.error( - "Unable to execute db task \"{}\", script \"{}\" can't be read.", - getDescription(), - script); - return; - } - finally - { - IOUtils.closeQuietly(is); - } - - String[] ddls = StringUtils.split(scriptContent, ";"); - - log.info("Creating new {} {}", getObjectType(), tableName); - - for (String ddl : ddls) - { - if (StringUtils.isNotBlank(ddl)) - { - log.debug("Executing:\n{}", ddl); - jdbcTemplate.update(ddl); - } - } - } - } - } -} \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java (from rev 611, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-11 20:50:50 UTC (rev 613) @@ -0,0 +1,162 @@ +// temporary patch until a new openutils-dbmigration release is outF +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.migration.generic; + +import it.openutils.migration.task.setup.GenericConditionalTask; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * @author fgiust + * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $ + */ +public abstract class JdbcObjectCreationTask extends GenericConditionalTask +{ + + protected String catalog; + + protected String schema; + + abstract String getObjectType(); + + /** + * Sets the catalog. + * @param catalog the catalog to set + */ + public void setCatalog(String catalog) + { + this.catalog = catalog; + } + + /** + * Sets the schema. + * @param schema the schema to set + */ + public void setSchema(String schema) + { + this.schema = schema; + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(DataSource dataSource) + { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + + for (Resource script : scripts) + { + + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + String fqTableName = this.objectNameFromFileName(script); + String tmptableName = null; + String tmpschema = schema; + + if (StringUtils.contains(fqTableName, ".")) + { + String[] tokens = StringUtils.split(fqTableName, "."); + tmptableName = tokens[1]; + tmpschema = tokens[0]; + } + else + { + tmptableName = fqTableName; + } + + final String tableName = tmptableName; + final String schema = tmpschema; + + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + + DatabaseMetaData dbMetadata = con.getMetaData(); + ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType()}); + boolean tableExists = rs.next(); + rs.close(); + + return tableExists; + } + }); + + if (!result) + { + String scriptContent; + InputStream is = null; + + try + { + is = script.getInputStream(); + scriptContent = IOUtils.toString(is, "UTF8"); + } + catch (IOException e) + { + log.error( + "Unable to execute db task \"{}\", script \"{}\" can't be read.", + getDescription(), + script); + return; + } + finally + { + IOUtils.closeQuietly(is); + } + + String[] ddls = StringUtils.split(scriptContent, ";"); + + log.info("Creating new {} {}", getObjectType(), tableName); + + for (String ddl : ddls) + { + if (StringUtils.isNotBlank(ddl)) + { + log.debug("Executing:\n{}", ddl); + jdbcTemplate.update(ddl); + } + } + } + else + { + log.debug("{} {} already existing", getObjectType(), tableName); + } + } + } +} \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.2/src/main/java/it/openutils/migration/oracle (from rev 611, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle) Copied: tags/openutils-dbmigration-2.0.2/src/site/changes (from rev 611, trunk/openutils-dbmigration/src/site/changes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-02-19 10:27:51
|
Revision: 624 http://openutils.svn.sourceforge.net/openutils/?rev=624&view=rev Author: fcarone Date: 2008-02-19 02:27:54 -0800 (Tue, 19 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-spring-2.0 Added Paths: ----------- tags/openutils-spring-2.0/ tags/openutils-spring-2.0/pom.xml Removed Paths: ------------- tags/openutils-spring-2.0/pom.xml Copied: tags/openutils-spring-2.0 (from rev 614, trunk/openutils-spring) Deleted: tags/openutils-spring-2.0/pom.xml =================================================================== --- trunk/openutils-spring/pom.xml 2008-02-11 20:51:03 UTC (rev 614) +++ tags/openutils-spring-2.0/pom.xml 2008-02-19 10:27:54 UTC (rev 624) @@ -1,150 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-spring</artifactId> - <name>openutils spring tools</name> - <version>2.0-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>jstl:jar</artifactId> - </exclusion> - <exclusion> - <groupId>taglibs</groupId> - <artifactId>standard</artifactId> - </exclusion> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>struts</groupId> - <artifactId>struts</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>net.sf.json-lib</groupId> - <artifactId>json-lib</artifactId> - <version>1.1</version> - <classifier>jdk15</classifier> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3.1</version> - </dependency> - <dependency> - <groupId>javax.mail</groupId> - <artifactId>mail</artifactId> - <version>1.4</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.freemarker</groupId> - <artifactId>freemarker</artifactId> - <version>2.3.11</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-spring-2.0/pom.xml (from rev 623, trunk/openutils-spring/pom.xml) =================================================================== --- tags/openutils-spring-2.0/pom.xml (rev 0) +++ tags/openutils-spring-2.0/pom.xml 2008-02-19 10:27:54 UTC (rev 624) @@ -0,0 +1,155 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-spring</artifactId> + <name>openutils spring tools</name> + <version>2.0</version> + <description /> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>jstl:jar</artifactId> + </exclusion> + <exclusion> + <groupId>taglibs</groupId> + <artifactId>standard</artifactId> + </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>struts</groupId> + <artifactId>struts</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <version>1.1</version> + <classifier>jdk15</classifier> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.1</version> + </dependency> + <dependency> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + <version>1.4</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.freemarker</groupId> + <artifactId>freemarker</artifactId> + <version>2.3.11</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-2.0</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-02-19 10:40:14
|
Revision: 628 http://openutils.svn.sourceforge.net/openutils/?rev=628&view=rev Author: fcarone Date: 2008-02-19 02:35:55 -0800 (Tue, 19 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-usermanagement-2.0 Added Paths: ----------- tags/openutils-usermanagement-2.0/ tags/openutils-usermanagement-2.0/pom.xml tags/openutils-usermanagement-2.0/src/ tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml Removed Paths: ------------- tags/openutils-usermanagement-2.0/pom.xml tags/openutils-usermanagement-2.0/src/ tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml Copied: tags/openutils-usermanagement-2.0 (from rev 620, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-2.0/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2008-02-19 10:22:39 UTC (rev 620) +++ tags/openutils-usermanagement-2.0/pom.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,140 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>2.0-SNAPSHOT</version> - <description>Usermanagement classes</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring</artifactId> - <version>2.0-SNAPSHOT</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.2-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.3-SNAPSHOT</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.3</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.2.2.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/pom.xml (from rev 627, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-2.0/pom.xml (rev 0) +++ tags/openutils-usermanagement-2.0/pom.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,179 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>2.0</version> + <description>Usermanagement classes</description> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-2.0</url> + </scm> +</project> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/src (from rev 619, trunk/openutils-usermanagement/src) Deleted: tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java =================================================================== --- trunk/openutils-usermanagement/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java 2008-02-19 10:35:55 UTC (rev 628) @@ -1,32 +0,0 @@ -package it.openutils.usermanagement.manager; - -import it.openutils.testing.junit.GenericsDbUnitTestCase; - - -/** - * @author fgiust - * @version $Id$ - */ -public class UserManagerTest extends GenericsDbUnitTestCase<UserManager> -{ - - /** - * test for changePassword() - */ - public void testChangePassword() - { - String newPwd = "2345"; - - Boolean result = instance.changePassword("UserUno", "password", newPwd); - assertTrue(result); - - } - - public void testResetPassword() - { - - String newPwd = instance.resetPassword("UserUno"); - assertNotNull("nothing returned by resetPassword ", newPwd); - } - -} Copied: tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java (from rev 620, trunk/openutils-usermanagement/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/java/it/openutils/usermanagement/manager/UserManagerTest.java 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,62 @@ +package it.openutils.usermanagement.manager; + +import it.openutils.testing.DbUnitExecution; +import it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests; + +import org.dbunit.operation.InsertOperation; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.transaction.TransactionConfiguration; +import org.springframework.test.context.transaction.TransactionalTestExecutionListener; +import org.springframework.transaction.annotation.Transactional; + + +/** + * @author fgiust + * @version $Id$ + */ +@ContextConfiguration(locations = {"/spring-tests.xml" }) +@DbUnitExecution(datasets = {"/UserManagerTest-load.xml" }, dataSource = "dataSource", // + insertOperation = InsertOperation.class) +@TestExecutionListeners({TransactionalTestExecutionListener.class }) +@Transactional +@TransactionConfiguration(transactionManager = "transactionManager") +public class UserManagerTest extends AbstractDbUnitJunitSpringContextTests +{ + + @Autowired + private UserManager instance; + + /** + * test for changePassword() + */ + @Test + public void testChangePassword() + { + String newPwd = "2345"; + + Boolean result = instance.changePassword("UserUno", "password", newPwd); + Assert.assertTrue(result); + } + + @Test + public void testResetPassword() + { + String newPwd = instance.resetPassword("UserUno"); + Assert.assertNotNull("nothing returned by resetPassword ", newPwd); + } + + + /** + * Sets the instance. + * @param instance the instance to set + */ + public void setInstance(UserManager instance) + { + this.instance = instance; + } + +} Deleted: tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml =================================================================== --- trunk/openutils-usermanagement/src/test/resources/spring-dao.xml 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" -"http://www.springframework.org/dtd/spring-beans.dtd"> -<beans> - - <bean id="userDAO" parent="txProxyTemplate"> - <property name="target"> - <bean class="it.openutils.usermanagement.dao.UserDAOImpl"> - <property name="sessionFactory" ref="sessionFactory" /> - </bean> - </property> - </bean> - <bean id="groupDAO" parent="txProxyTemplate"> - <property name="target"> - <bean class="it.openutils.usermanagement.dao.GroupDAOImpl"> - <property name="sessionFactory" ref="sessionFactory" /> - </bean> - </property> - </bean> - <bean id="roleDAO" parent="txProxyTemplate"> - <property name="target"> - <bean class="it.openutils.usermanagement.dao.RoleDAOImpl"> - <property name="sessionFactory" ref="sessionFactory" /> - </bean> - </property> - </bean> - -</beans> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml (from rev 620, trunk/openutils-usermanagement/src/test/resources/spring-dao.xml) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-dao.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,26 @@ +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> + <bean id="userDAO" parent="txProxyTemplate"> + <property name="target"> + <bean class="it.openutils.usermanagement.dao.UserDAOImpl"> + <property name="sessionFactory" ref="sessionFactory" /> + </bean> + </property> + </bean> + <bean id="groupDAO" parent="txProxyTemplate"> + <property name="target"> + <bean class="it.openutils.usermanagement.dao.GroupDAOImpl"> + <property name="sessionFactory" ref="sessionFactory" /> + </bean> + </property> + </bean> + <bean id="roleDAO" parent="txProxyTemplate"> + <property name="target"> + <bean class="it.openutils.usermanagement.dao.RoleDAOImpl"> + <property name="sessionFactory" ref="sessionFactory" /> + </bean> + </property> + </bean> +</beans> \ No newline at end of file Deleted: tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml =================================================================== --- trunk/openutils-usermanagement/src/test/resources/spring-database.xml 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> -<!-- - # ATTENZIONE: queste proprietà sono utilizzate solo per gli unit tests - # i file per la configurazione del db utilizzati dall'applicazione web sono in - # src/main/web-app/WEB-INF ---> -<beans> - <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> - <property name="location"> - <value>classpath:database.properties</value> - </property> - </bean> - <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> - <property name="driverClassName"> - <value>${hibernate.connection.driver}</value> - </property> - <property name="url"> - <value>${hibernate.connection.url}</value> - </property> - <property name="username"> - <value>${hibernate.connection.username}</value> - </property> - <property name="password"> - <value>${hibernate.connection.password}</value> - </property> - </bean> -</beans> Copied: tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml (from rev 620, trunk/openutils-usermanagement/src/test/resources/spring-database.xml) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-database.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,29 @@ +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> + <!-- + # ATTENZIONE: queste proprietà sono utilizzate solo per gli unit tests + # i file per la configurazione del db utilizzati dall'applicazione web sono in + # src/main/web-app/WEB-INF + --> + <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <property name="location"> + <value>classpath:database.properties</value> + </property> + </bean> + <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> + <property name="driverClassName"> + <value>${hibernate.connection.driver}</value> + </property> + <property name="url"> + <value>${hibernate.connection.url}</value> + </property> + <property name="username"> + <value>${hibernate.connection.username}</value> + </property> + <property name="password"> + <value>${hibernate.connection.password}</value> + </property> + </bean> +</beans> Deleted: tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml =================================================================== --- trunk/openutils-usermanagement/src/test/resources/spring-hibernate.xml 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" -"http://www.springframework.org/dtd/spring-beans.dtd"> -<beans> - - <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> - <property name="dataSource"> - <ref bean="dataSource" /> - </property> - <property name="configLocation"> - <value>classpath:hibernate.cfg.xml</value> - </property> - <property name="configurationClass"> - <value>org.hibernate.cfg.AnnotationConfiguration</value> - </property> - <property name="hibernateProperties"> - <props> - <prop key="hibernate.dialect">${hibernate.dialect}</prop> - <prop key="hibernate.generate_statistics">false</prop> - <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop> - <prop key="hibernate.show_sql">false</prop> - <prop key="hibernate.use_sql_comments">false</prop> - <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> - </props> - </property> - </bean> - <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> - <property name="sessionFactory"> - <ref local="sessionFactory" /> - </property> - </bean> - <bean id="txProxyTemplate" abstract="true" - class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> - <property name="transactionManager"> - <ref bean="transactionManager" /> - </property> - <property name="transactionAttributes"> - <props> - <prop key="save*">PROPAGATION_REQUIRED</prop> - <prop key="delete*">PROPAGATION_REQUIRED</prop> - <prop key="update*">PROPAGATION_REQUIRED</prop> - <prop key="clean*">PROPAGATION_REQUIRED</prop> - <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> - </props> - </property> - </bean> -</beans> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml (from rev 620, trunk/openutils-usermanagement/src/test/resources/spring-hibernate.xml) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-hibernate.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,46 @@ +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> + <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> + <property name="dataSource"> + <ref bean="dataSource" /> + </property> + <property name="configLocation"> + <value>classpath:hibernate.cfg.xml</value> + </property> + <property name="configurationClass"> + <value>org.hibernate.cfg.AnnotationConfiguration</value> + </property> + <property name="hibernateProperties"> + <props> + <prop key="hibernate.dialect">${hibernate.dialect}</prop> + <prop key="hibernate.generate_statistics">false</prop> + <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop> + <prop key="hibernate.show_sql">false</prop> + <prop key="hibernate.use_sql_comments">false</prop> + <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> + </props> + </property> + </bean> + <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> + <property name="sessionFactory"> + <ref local="sessionFactory" /> + </property> + </bean> + <bean id="txProxyTemplate" abstract="true" + class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> + <property name="transactionManager"> + <ref bean="transactionManager" /> + </property> + <property name="transactionAttributes"> + <props> + <prop key="save*">PROPAGATION_REQUIRED</prop> + <prop key="delete*">PROPAGATION_REQUIRED</prop> + <prop key="update*">PROPAGATION_REQUIRED</prop> + <prop key="clean*">PROPAGATION_REQUIRED</prop> + <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> + </props> + </property> + </bean> +</beans> \ No newline at end of file Deleted: tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml =================================================================== --- trunk/openutils-usermanagement/src/test/resources/spring-managers.xml 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,21 +0,0 @@ -<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> -<beans> - <bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" - autowire="byType"> - <property name="transactionManager"> - <ref bean="transactionManager" /> - </property> - <property name="transactionAttributes"> - <props> - <prop key="*">PROPAGATION_REQUIRED</prop> - </props> - </property> - <property name="target"> - <bean class="it.openutils.usermanagement.manager.UserManagerImpl" autowire="byType"></bean> - </property> - </bean> - <bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.ShaPasswordEncoder" /> - <bean id="userDetailsService" class="it.openutils.usermanagement.acegi.HibernateUserDetailsServiceImpl" - autowire="byType"> - </bean> -</beans> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml (from rev 620, trunk/openutils-usermanagement/src/test/resources/spring-managers.xml) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-managers.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,27 @@ +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> + <bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> + <property name="transactionManager"> + <ref bean="transactionManager" /> + </property> + <property name="transactionAttributes"> + <props> + <prop key="*">PROPAGATION_REQUIRED</prop> + </props> + </property> + <property name="target"> + <bean class="it.openutils.usermanagement.manager.UserManagerImpl"> + <property name="passwordEncoder" ref="passwordEncoder" /> + <property name="userDAO" ref="userDAO" /> + </bean> + </property> + </bean> + <bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.ShaPasswordEncoder" /> + <bean id="userDetailsService" class="it.openutils.usermanagement.acegi.HibernateUserDetailsServiceImpl" + autowire="byType"> + <property name="userDao" ref="userDAO" /> + <property name="groupDAO" ref="groupDAO" /> + </bean> +</beans> \ No newline at end of file Deleted: tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml =================================================================== --- trunk/openutils-usermanagement/src/test/resources/spring-tests.xml 2008-02-17 09:11:48 UTC (rev 619) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> -<beans> - <import resource="classpath:spring-database.xml" /> - <import resource="classpath:spring-hibernate.xml" /> - <import resource="classpath:spring-dao.xml" /> - <import resource="classpath:spring-managers.xml" /> -</beans> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml (from rev 620, trunk/openutils-usermanagement/src/test/resources/spring-tests.xml) =================================================================== --- tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml (rev 0) +++ tags/openutils-usermanagement-2.0/src/test/resources/spring-tests.xml 2008-02-19 10:35:55 UTC (rev 628) @@ -0,0 +1,9 @@ +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> + <import resource="classpath:spring-database.xml" /> + <import resource="classpath:spring-hibernate.xml" /> + <import resource="classpath:spring-dao.xml" /> + <import resource="classpath:spring-managers.xml" /> +</beans> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-02-19 15:23:41
|
Revision: 634 http://openutils.svn.sourceforge.net/openutils/?rev=634&view=rev Author: fcarone Date: 2008-02-19 07:22:42 -0800 (Tue, 19 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-2.0.3 Added Paths: ----------- tags/openutils-testing-2.0.3/ tags/openutils-testing-2.0.3/pom.xml tags/openutils-testing-2.0.3/src/site/changes/changes.xml Removed Paths: ------------- tags/openutils-testing-2.0.3/pom.xml tags/openutils-testing-2.0.3/src/site/changes/changes.xml Copied: tags/openutils-testing-2.0.3 (from rev 630, trunk/openutils-testing) Deleted: tags/openutils-testing-2.0.3/pom.xml =================================================================== --- trunk/openutils-testing/pom.xml 2008-02-19 13:41:04 UTC (rev 630) +++ tags/openutils-testing-2.0.3/pom.xml 2008-02-19 15:22:42 UTC (rev 634) @@ -1,64 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing</artifactId> - <name>openutils test utils</name> - <version>2.0.3-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>junit-addons</groupId> - <artifactId>junit-addons</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> Copied: tags/openutils-testing-2.0.3/pom.xml (from rev 633, trunk/openutils-testing/pom.xml) =================================================================== --- tags/openutils-testing-2.0.3/pom.xml (rev 0) +++ tags/openutils-testing-2.0.3/pom.xml 2008-02-19 15:22:42 UTC (rev 634) @@ -0,0 +1,70 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing</artifactId> + <name>openutils test utils</name> + <version>2.0.3</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-2.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-testing-2.0.3/src/site/changes/changes.xml =================================================================== --- trunk/openutils-testing/src/site/changes/changes.xml 2008-02-19 13:41:04 UTC (rev 630) +++ tags/openutils-testing-2.0.3/src/site/changes/changes.xml 2008-02-19 15:22:42 UTC (rev 634) @@ -1,37 +0,0 @@ -<?xml version="1.0"?> -<!-- - "type" attribute can be: add, remove, update or fix. ---> -<document> - <properties> - <title>Changes</title> - <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> - </properties> - <body> - <release version="2.0.3" date="in svn" description="2.0.2"> - <action type="update" dev="fgiust"> - it.openutils.testing.DateAssert is now thread safe. Failure messages have been improved. - </action> - </release> - <release version="2.0.2" date="2008-01-31" description="2.0.2"> - <action type="add" dev="fgiust"> - New dbunit operation classes for mssql and mysql (extension of standard dbunit operation, but refactored so that - they can be used in annotations). See the javadocs in the it.openutils.testing.dbunit package - </action> - <action type="update" dev="fgiust"> - truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of DbUnitOperation.TRUNCATE. - </action> - <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the provided connection</action> - <action type="add" dev="fgiust">new DbUnitUtils.exportTablesToDir() utility method</action> - </release> - <release version="2.0.1" date="2008-01-30" description="2.0.1"> - <action type="fix" dev="fgiust"> - (junit version only). it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests was totally broken due to - the setup method being protected. Fixed + added tests - </action> - </release> - <release version="2.0" date="2008-01-20" description="2.0 release"> - <action type="update" dev="fgiust">Totally reworked dbunit test framework.</action> - </release> - </body> -</document> \ No newline at end of file Copied: tags/openutils-testing-2.0.3/src/site/changes/changes.xml (from rev 632, trunk/openutils-testing/src/site/changes/changes.xml) =================================================================== --- tags/openutils-testing-2.0.3/src/site/changes/changes.xml (rev 0) +++ tags/openutils-testing-2.0.3/src/site/changes/changes.xml 2008-02-19 15:22:42 UTC (rev 634) @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<!-- + "type" attribute can be: add, remove, update or fix. +--> +<document> + <properties> + <title>Changes</title> + <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + </properties> + <body> + <release version="2.0.3" date="2008-02-19" description="2.0.3"> + <action type="update" dev="fgiust"> + it.openutils.testing.DateAssert is now thread safe. Failure messages have been improved. + </action> + <action type="add" dev="fcarone"> + New option for DbUnitExection to specify the DatabaseConfig.PROPERTY_DATATYPE_FACTORY added. + </action> + </release> + <release version="2.0.2" date="2008-01-31" description="2.0.2"> + <action type="add" dev="fgiust"> + New dbunit operation classes for mssql and mysql (extension of standard dbunit operation, but refactored so that + they can be used in annotations). See the javadocs in the it.openutils.testing.dbunit package + </action> + <action type="update" dev="fgiust"> + truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of DbUnitOperation.TRUNCATE. + </action> + <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the provided connection</action> + <action type="add" dev="fgiust">new DbUnitUtils.exportTablesToDir() utility method</action> + </release> + <release version="2.0.1" date="2008-01-30" description="2.0.1"> + <action type="fix" dev="fgiust"> + (junit version only). it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests was totally broken due to + the setup method being protected. Fixed + added tests + </action> + </release> + <release version="2.0" date="2008-01-20" description="2.0 release"> + <action type="update" dev="fgiust">Totally reworked dbunit test framework.</action> + </release> + </body> +</document> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-02-20 10:07:14
|
Revision: 650 http://openutils.svn.sourceforge.net/openutils/?rev=650&view=rev Author: fgiust Date: 2008-02-20 02:02:19 -0800 (Wed, 20 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-log4j-2.0 Added Paths: ----------- tags/openutils-log4j-2.0/ tags/openutils-log4j-2.0/pom.xml tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java tags/openutils-log4j-2.0/src/site/changes/ Removed Paths: ------------- tags/openutils-log4j-2.0/pom.xml tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java Copied: tags/openutils-log4j-2.0 (from rev 594, trunk/openutils-log4j) Deleted: tags/openutils-log4j-2.0/pom.xml =================================================================== --- trunk/openutils-log4j/pom.xml 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-log4j-2.0/pom.xml 2008-02-20 10:02:19 UTC (rev 650) @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-log4j</artifactId> - <packaging>jar</packaging> - <version>2.0-SNAPSHOT</version> - <name>openutils for Log4j</name> - <description>openutils log4j extensions</description> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.14</version> - </dependency> - <dependency> - <groupId>javax.mail</groupId> - <artifactId>mail</artifactId> - <version>1.4</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> Copied: tags/openutils-log4j-2.0/pom.xml (from rev 649, trunk/openutils-log4j/pom.xml) =================================================================== --- tags/openutils-log4j-2.0/pom.xml (rev 0) +++ tags/openutils-log4j-2.0/pom.xml 2008-02-20 10:02:19 UTC (rev 650) @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-log4j</artifactId> + <packaging>jar</packaging> + <version>2.0</version> + <name>openutils for Log4j</name> + <description>openutils log4j extensions</description> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.14</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + <version>1.4</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-log4j-2.0</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-log4j-2.0</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-log4j-2.0</url> + </scm> +</project> Deleted: tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java =================================================================== --- trunk/openutils-log4j/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-02-20 10:02:19 UTC (rev 650) @@ -1,663 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.log4j; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Timer; -import java.util.TimerTask; - -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Multipart; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; - -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Layout; -import org.apache.log4j.Level; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.helpers.LogLog; -import org.apache.log4j.helpers.OptionConverter; -import org.apache.log4j.spi.ErrorCode; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.spi.TriggeringEventEvaluator; - - -/** - * An alternative of <code>org.apache.log4j.net.SMTPAppender</code> with few differences: - * <ul> - * <li>allow customizing the mail subject using a pattern</li> - * <li>can be configured with a timeout (in seconds), it will only send messages after this timeout</li> - * <li>it will send a mail for every single message (bufferSize is not supported), but it will aggregate any identical - * log event received during the timeout. Identical events are log with same message and same stack trace</li> - * </ul> - * - * <pre> - * <appender name="mail" class="it.openutils.log4j.AlternateSMTPAppender"> - * <param name="Threshold" value="ERROR" /> - * <param name="To" value="lo...@ex..." /> - * <param name="From" value="in...@ex..." /> - * <param name="SMTPHost" value="localhost" /> - * <param name="Timeout" value="180" /> - * <param name="Subject" value="[EXAMPLE] %m" /> - * <layout class="org.apache.log4j.PatternLayout"> - * <param name="ConversionPattern" value="%-5p %c %d{dd.MM.yyyy HH:mm:ss} -- %m%n" /> - * </layout> - * <param name="Header" - * value=" - * =================================== - * Myapp (production environment) - * Date: %d{dd.MM.yyyy HH:mm:ss} - * =================================== - * " /> - * </appender> - * </pre> - * - * @author Fabrizio Giustina - * @version $Id$ - */ -public class AlternateSMTPAppender extends AppenderSkeleton -{ - - private String to; - - private String from; - - private Layout subjectLayout; - - private String smtpHost; - - private boolean locationInfo; - - private Timer timer = new Timer(); - - private TimerTask timerTask; - - private int timeout; - - protected Map<LoggingEventAggregator, LoggingEventAggregator> events = new LinkedHashMap<LoggingEventAggregator, LoggingEventAggregator>() - { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * {@inheritDoc} - */ - @Override - public LoggingEventAggregator put(LoggingEventAggregator key, LoggingEventAggregator value) - { - LoggingEventAggregator lea = this.get(key); - if (lea != null) - { - lea.incrementCount(); - return lea; - } - - return super.put(key, value); - } - - }; - - protected Message msg; - - protected TriggeringEventEvaluator evaluator; - - /** - * The default constructor will instantiate the appender with a {@link TriggeringEventEvaluator} that will trigger - * on events with level ERROR or higher. - */ - public AlternateSMTPAppender() - { - this(new DefaultEvaluator()); - } - - /** - * Use <code>evaluator</code> passed as parameter as the {@link TriggeringEventEvaluator} for this SMTPAppender. - */ - public AlternateSMTPAppender(TriggeringEventEvaluator evaluator) - { - this.evaluator = evaluator; - } - - /** - * Activate the specified options, such as the smtp host, the recipient, from, etc. - */ - @Override - public void activateOptions() - { - Properties props = new Properties(System.getProperties()); - if (smtpHost != null) - { - props.put("mail.smtp.host", smtpHost); - } - - Session session = Session.getInstance(props, null); - // session.setDebug(true); - msg = new MimeMessage(session); - - try - { - if (from != null) - { - msg.setFrom(getAddress(from)); - } - else - { - msg.setFrom(); - } - - msg.setRecipients(Message.RecipientType.TO, parseAddress(to)); - } - catch (MessagingException e) - { - LogLog.error("Could not activate SMTPAppender options.", e); - } - } - - /** - * Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the - * event triggers an e-mail to be sent. - */ - @Override - public void append(LoggingEvent event) - { - - if (!checkEntryConditions()) - { - return; - } - - event.getThreadName(); - event.getNDC(); - if (locationInfo) - { - event.getLocationInformation(); - } - - LoggingEventAggregator leg = new LoggingEventAggregator(event); - - events.put(leg, leg); - - if (evaluator.isTriggeringEvent(event)) - { - if (timeout == 0) - { - // send immediately - sendBuffer(events.values()); - return; - } - if (timerTask == null) - { - - timerTask = new TimerTask() - { - - @Override - public void run() - { - Collection<LoggingEventAggregator> le; - synchronized (events) - { - le = new ArrayList<LoggingEventAggregator>(events.values()); - events.clear(); - timerTask = null; - } - - sendBuffer(le); - } - }; - - this.timer.schedule(this.timerTask, this.timeout * 1000L); - - } - } - } - - /** - * This method determines if there is a sense in attempting to append. - * <p> - * It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the - * boolean value <code>false</code> is returned. - */ - protected boolean checkEntryConditions() - { - if (this.msg == null) - { - errorHandler.error("Message object not configured."); - return false; - } - - if (this.evaluator == null) - { - errorHandler.error("No TriggeringEventEvaluator is set for appender [" + name + "]."); - return false; - } - - if (this.layout == null) - { - errorHandler.error("No layout set for appender named [" + name + "]."); - return false; - } - return true; - } - - @Override - public synchronized void close() - { - this.closed = true; - } - - InternetAddress getAddress(String addressStr) - { - try - { - return new InternetAddress(addressStr); - } - catch (AddressException e) - { - errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); - return null; - } - } - - InternetAddress[] parseAddress(String addressStr) - { - try - { - return InternetAddress.parse(addressStr, true); - } - catch (AddressException e) - { - errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); - return null; - } - } - - /** - * Returns value of the <b>To</b> option. - */ - public String getTo() - { - return to; - } - - /** - * The <code>SMTPAppender</code> requires a {@link org.apache.log4j.Layout layout}. - */ - @Override - public boolean requiresLayout() - { - return true; - } - - /** - * Send the contents of the cyclic buffer as an e-mail message. - */ - protected void sendBuffer(Collection<LoggingEventAggregator> eventsCollection) - { - - // Note: this code already owns the monitor for this - // appender. This frees us from needing to synchronize on 'cb'. - try - { - - for (LoggingEventAggregator lea : eventsCollection) - { - MimeBodyPart part = new MimeBodyPart(); - - StringBuffer sbuf = new StringBuffer(); - String t = layout.getHeader(); - if (t != null) - { - sbuf.append(t); - } - - sbuf.append("\nNumber of occurences: "); - sbuf.append(lea.getCount()); - sbuf.append("\n\n"); - - LoggingEvent event = lea.getLoggingEvent(); - - if (this.subjectLayout != null) - { - String subject = this.subjectLayout.format(event); - - if (subject != null) - { - subject = subject.trim(); - if (subject.indexOf("\n") > 0) - { - subject = subject.substring(0, subject.indexOf("\n")); - } - } - - this.msg.setSubject(subject); - } - - sbuf.append(layout.format(event)); - if (layout.ignoresThrowable()) - { - String[] s = event.getThrowableStrRep(); - if (s != null) - { - for (String element : s) - { - sbuf.append(element); - } - } - } - t = layout.getFooter(); - if (t != null) - { - sbuf.append(t); - } - part.setContent(sbuf.toString(), layout.getContentType()); - - Multipart mp = new MimeMultipart(); - mp.addBodyPart(part); - msg.setContent(mp); - - msg.setSentDate(new Date()); - Transport.send(msg); - } - - } - catch (Exception e) - { - LogLog.error("Error occured while sending e-mail notification.", e); - } - - } - - /** - * Returns value of the <b>EvaluatorClass</b> option. - */ - public String getEvaluatorClass() - { - return evaluator == null ? null : evaluator.getClass().getName(); - } - - /** - * Returns value of the <b>From</b> option. - */ - public String getFrom() - { - return from; - } - - /** - * Returns value of the <b>Subject</b> option. - */ - public String getSubject() - { - return subjectLayout.toString(); - } - - /** - * The <b>From</b> option takes a string value which should be a e-mail address of the sender. - */ - public void setFrom(String from) - { - this.from = from; - } - - /** - * The <b>Subject</b> option takes a string value which should be a the subject of the e-mail message. - */ - public void setSubject(String subjectPattern) - { - this.subjectLayout = new PatternLayout(subjectPattern); - } - - /** - * This option is ignored! - */ - @Deprecated - public void setBufferSize(int bufferSize) - { - // kept as deprecated - LogLog.warn("BufferSize property is deprecated for " + getClass().getName()); - } - - /** - * The <b>SMTPHost</b> option takes a string value which should be a the host name of the SMTP server that will - * send the e-mail message. - */ - public void setSMTPHost(String smtpHost) - { - this.smtpHost = smtpHost; - } - - /** - * Returns value of the <b>SMTPHost</b> option. - */ - public String getSMTPHost() - { - return smtpHost; - } - - /** - * The <b>To</b> option takes a string value which should be a comma separated list of e-mail address of the - * recipients. - */ - public void setTo(String to) - { - this.to = to; - } - - /** - * Returns value of the <b>BufferSize</b> option. - */ - public int getBufferSize() - { - return 0; - } - - /** - * The <b>EvaluatorClass</b> option takes a string value representing the name of the class implementing the {@link - * TriggeringEventEvaluator} interface. A corresponding object will be instantiated and assigned as the triggering - * event evaluator for the SMTPAppender. - */ - public void setEvaluatorClass(String value) - { - evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName( - value, - TriggeringEventEvaluator.class, - evaluator); - } - - /** - * @param value - */ - public void setEvaluator(TriggeringEventEvaluator value) - { - evaluator = value; - } - - /** - * The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be - * no effort to extract the location information related to the event. As a result, the layout that formats the - * events as they are sent out in an e-mail is likely to place the wrong location information (if present in the - * format). - * <p> - * Location information extraction is comparatively very slow and should be avoided unless performance is not a - * concern. - */ - public void setLocationInfo(boolean locationInfo) - { - this.locationInfo = locationInfo; - } - - /** - * Returns value of the <b>LocationInfo</b> option. - */ - public boolean getLocationInfo() - { - return locationInfo; - } - - /** - * Returns the timeout. - * @return the timeout - */ - public int getTimeout() - { - return timeout; - } - - /** - * Sets the timeout. - * @param timeout the timeout to set - */ - public void setTimeout(int timeout) - { - this.timeout = timeout; - } -} - - -class LoggingEventAggregator -{ - - private LoggingEvent loggingEvent; - - private int count; - - public LoggingEventAggregator(LoggingEvent loggingEvent) - { - this.loggingEvent = loggingEvent; - this.count = 1; - } - - /** - * Returns the loggingEvent. - * @return the loggingEvent - */ - public LoggingEvent getLoggingEvent() - { - return loggingEvent; - } - - /** - * Returns the count. - * @return the count - */ - public int getCount() - { - return count; - } - - /** - * Sets the count. - * @param count the count to set - */ - public void setCount(int count) - { - this.count = count; - } - - public void incrementCount() - { - count++; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - - Object lem = loggingEvent.getMessage(); - String[] thstr = loggingEvent.getThrowableStrRep(); - result = prime * result + ((lem == null) ? 0 : lem.hashCode()); - result = prime * result + Arrays.hashCode(thstr); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final LoggingEventAggregator other = (LoggingEventAggregator) obj; - - Object lem = loggingEvent.getMessage(); - String[] thstr = loggingEvent.getThrowableStrRep(); - - Object otherLem = other.loggingEvent.getMessage(); - String[] otherThstr = other.loggingEvent.getThrowableStrRep(); - - if (lem == null) - { - if (otherLem != null) - { - return false; - } - } - - else if (!lem.equals(otherLem)) - { - return false; - } - if (!Arrays.equals(thstr, otherThstr)) - { - return false; - } - return true; - } - -} - - -class DefaultEvaluator implements TriggeringEventEvaluator -{ - - public boolean isTriggeringEvent(LoggingEvent event) - { - return event.getLevel().isGreaterOrEqual(Level.ERROR); - } -} Copied: tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java (from rev 648, trunk/openutils-log4j/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java) =================================================================== --- tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java (rev 0) +++ tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-02-20 10:02:19 UTC (rev 650) @@ -0,0 +1,676 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.log4j; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Timer; +import java.util.TimerTask; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimeUtility; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.helpers.LogLog; +import org.apache.log4j.helpers.OptionConverter; +import org.apache.log4j.spi.ErrorCode; +import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.TriggeringEventEvaluator; + + +/** + * An alternative of <code>org.apache.log4j.net.SMTPAppender</code> with few differences: + * <ul> + * <li>allow customizing the mail subject using a pattern</li> + * <li>can be configured with a timeout (in seconds), it will only send messages after this timeout</li> + * <li>it will send a mail for every single message (bufferSize is not supported), but it will aggregate any identical + * log event received during the timeout. Identical events are log with same message and same stack trace</li> + * </ul> + * + * <pre> + * <appender name="mail" class="it.openutils.log4j.AlternateSMTPAppender"> + * <param name="Threshold" value="ERROR" /> + * <param name="To" value="lo...@ex..." /> + * <param name="From" value="in...@ex..." /> + * <param name="SMTPHost" value="localhost" /> + * <param name="Timeout" value="180" /> + * <param name="Subject" value="[EXAMPLE] %m" /> + * <layout class="it.openutils.log4j.FilteredPatternLayout"> + * <param name="ConversionPattern" value="%-5p %c %d{dd.MM.yyyy HH:mm:ss} -- %m%n" /> + * <param name="Header" + * value=" + * =================================== + * Myapp (production environment) + * Date: %d{dd.MM.yyyy HH:mm:ss} + * =================================== + * " /> + * </layout> + * </appender> + * </pre> + * + * @author Fabrizio Giustina + * @version $Id: $ + */ +public class AlternateSMTPAppender extends AppenderSkeleton +{ + + private String to; + + private String from; + + private Layout subjectLayout; + + private String smtpHost; + + private boolean locationInfo; + + private Timer timer = new Timer("log4j mail appender", true); + + private TimerTask timerTask; + + private int timeout; + + protected Map<LoggingEventAggregator, LoggingEventAggregator> events = new LinkedHashMap<LoggingEventAggregator, LoggingEventAggregator>() + { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * {@inheritDoc} + */ + @Override + public LoggingEventAggregator put(LoggingEventAggregator key, LoggingEventAggregator value) + { + LoggingEventAggregator lea = this.get(key); + if (lea != null) + { + lea.incrementCount(); + return lea; + } + + return super.put(key, value); + } + + }; + + protected Message msg; + + protected TriggeringEventEvaluator evaluator; + + /** + * The default constructor will instantiate the appender with a {@link TriggeringEventEvaluator} that will trigger + * on events with level ERROR or higher. + */ + public AlternateSMTPAppender() + { + this(new DefaultEvaluator()); + + // force loading this class + MimeBodyPart.class.getName(); + MimeUtility.class.getName(); + } + + /** + * Use <code>evaluator</code> passed as parameter as the {@link TriggeringEventEvaluator} for this SMTPAppender. + */ + public AlternateSMTPAppender(TriggeringEventEvaluator evaluator) + { + this.evaluator = evaluator; + } + + /** + * Activate the specified options, such as the smtp host, the recipient, from, etc. + */ + @Override + public void activateOptions() + { + Properties props = new Properties(System.getProperties()); + if (smtpHost != null) + { + props.put("mail.smtp.host", smtpHost); + } + + Session session = Session.getInstance(props, null); + // session.setDebug(true); + msg = new MimeMessage(session); + + try + { + if (from != null) + { + msg.setFrom(getAddress(from)); + } + else + { + msg.setFrom(); + } + + msg.setRecipients(Message.RecipientType.TO, parseAddress(to)); + } + catch (MessagingException e) + { + LogLog.error("Could not activate SMTPAppender options.", e); + } + } + + /** + * Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the + * event triggers an e-mail to be sent. + */ + @Override + public void append(LoggingEvent event) + { + + if (!checkEntryConditions()) + { + return; + } + + event.getThreadName(); + event.getNDC(); + if (locationInfo) + { + event.getLocationInformation(); + } + + LoggingEventAggregator leg = new LoggingEventAggregator(event); + + events.put(leg, leg); + + if (evaluator.isTriggeringEvent(event)) + { + if (timeout == 0) + { + // send immediately + sendBuffer(events.values()); + return; + } + if (timerTask == null) + { + + timerTask = new TimerTask() + { + + @Override + public void run() + { + Collection<LoggingEventAggregator> le; + synchronized (events) + { + le = new ArrayList<LoggingEventAggregator>(events.values()); + events.clear(); + timerTask = null; + } + + sendBuffer(le); + } + }; + + this.timer.schedule(this.timerTask, this.timeout * 1000L); + + } + } + } + + /** + * This method determines if there is a sense in attempting to append. + * <p> + * It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the + * boolean value <code>false</code> is returned. + */ + protected boolean checkEntryConditions() + { + if (this.msg == null) + { + errorHandler.error("Message object not configured."); + return false; + } + + if (this.evaluator == null) + { + errorHandler.error("No TriggeringEventEvaluator is set for appender [" + name + "]."); + return false; + } + + if (this.layout == null) + { + errorHandler.error("No layout set for appender named [" + name + "]."); + return false; + } + return true; + } + + @Override + public synchronized void close() + { + this.closed = true; + } + + InternetAddress getAddress(String addressStr) + { + try + { + return new InternetAddress(addressStr); + } + catch (AddressException e) + { + errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); + return null; + } + } + + InternetAddress[] parseAddress(String addressStr) + { + try + { + return InternetAddress.parse(addressStr, true); + } + catch (AddressException e) + { + errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); + return null; + } + } + + /** + * Returns value of the <b>To</b> option. + */ + public String getTo() + { + return to; + } + + /** + * The <code>SMTPAppender</code> requires a {@link org.apache.log4j.Layout layout}. + */ + @Override + public boolean requiresLayout() + { + return true; + } + + /** + * Send the contents of the cyclic buffer as an e-mail message. + */ + protected void sendBuffer(Collection<LoggingEventAggregator> eventsCollection) + { + + // Note: this code already owns the monitor for this + // appender. This frees us from needing to synchronize on 'cb'. + try + { + + for (LoggingEventAggregator lea : eventsCollection) + { + MimeBodyPart part = new MimeBodyPart(); + + StringBuffer sbuf = new StringBuffer(); + String t = layout.getHeader(); + if (t != null) + { + t = StringUtils.replace(t, "%o", Integer.toString(lea.getCount())); + t = StringUtils.replace(t, "%n", Layout.LINE_SEP); + sbuf.append(t); + sbuf.append("\n"); + } + + LoggingEvent event = lea.getLoggingEvent(); + + if (this.subjectLayout != null) + { + String subject = this.subjectLayout.format(event); + + if (subject != null) + { + subject = subject.trim(); + if (subject.indexOf("\n") > 0) + { + subject = subject.substring(0, subject.indexOf("\n")); + } + } + + this.msg.setSubject(subject); + } + + sbuf.append(layout.format(event)); + if (layout.ignoresThrowable()) + { + String[] s = event.getThrowableStrRep(); + if (s != null) + { + for (String element : s) + { + sbuf.append(element); + } + } + } + t = layout.getFooter(); + if (t != null) + { + t = StringUtils.replace(t, "%n", Layout.LINE_SEP); + sbuf.append(t); + } + part.setContent(sbuf.toString(), layout.getContentType()); + + Multipart mp = new MimeMultipart(); + mp.addBodyPart(part); + msg.setContent(mp); + + msg.setSentDate(new Date()); + Transport.send(msg); + } + + } + catch (Exception e) + { + LogLog.error("Error occured while sending e-mail notification.", e); + } + + } + + /** + * Returns value of the <b>EvaluatorClass</b> option. + */ + public String getEvaluatorClass() + { + return evaluator == null ? null : evaluator.getClass().getName(); + } + + /** + * Returns value of the <b>From</b> option. + */ + public String getFrom() + { + return from; + } + + /** + * Returns value of the <b>Subject</b> option. + */ + public String getSubject() + { + return subjectLayout.toString(); + } + + /** + * The <b>From</b> option takes a string value which should be a e-mail address of the sender. + */ + public void setFrom(String from) + { + this.from = from; + } + + /** + * The <b>Subject</b> option takes a string value which should be a the subject of the e-mail message. + */ + public void setSubject(String subjectPattern) + { + this.subjectLayout = new PatternLayout(subjectPattern); + } + + /** + * This option is ignored! + */ + @Deprecated + public void setBufferSize(int bufferSize) + { + // kept as deprecated + LogLog.warn("BufferSize property is deprecated for " + getClass().getName()); + } + + /** + * The <b>SMTPHost</b> option takes a string value which should be a the host name of the SMTP server that will + * send the e-mail message. + */ + public void setSMTPHost(String smtpHost) + { + this.smtpHost = smtpHost; + } + + /** + * Returns value of the <b>SMTPHost</b> option. + */ + public String getSMTPHost() + { + return smtpHost; + } + + /** + * The <b>To</b> option takes a string value which should be a comma separated list of e-mail address of the + * recipients. + */ + public void setTo(String to) + { + this.to = to; + } + + /** + * Returns value of the <b>BufferSize</b> option. + */ + public int getBufferSize() + { + return 0; + } + + /** + * The <b>EvaluatorClass</b> option takes a string value representing the name of the class implementing the {@link + * TriggeringEventEvaluator} interface. A corresponding object will be instantiated and assigned as the triggering + * event evaluator for the SMTPAppender. + */ + public void setEvaluatorClass(String value) + { + evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName( + value, + TriggeringEventEvaluator.class, + evaluator); + } + + /** + * @param value + */ + public void setEvaluator(TriggeringEventEvaluator value) + { + evaluator = value; + } + + /** + * The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be + * no effort to extract the location information related to the event. As a result, the layout that formats the + * events as they are sent out in an e-mail is likely to place the wrong location information (if present in the + * format). + * <p> + * Location information extraction is comparatively very slow and should be avoided unless performance is not a + * concern. + */ + public void setLocationInfo(boolean locationInfo) + { + this.locationInfo = locationInfo; + } + + /** + * Returns value of the <b>LocationInfo</b> option. + */ + public boolean getLocationInfo() + { + return locationInfo; + } + + /** + * Returns the timeout. + * @return the timeout + */ + public int getTimeout() + { + return timeout; + } + + /** + * Sets the timeout. + * @param timeout the timeout to set + */ + public void setTimeout(int timeout) + { + this.timeout = timeout; + } +} + + +class LoggingEventAggregator +{ + + private LoggingEvent loggingEvent; + + private int count; + + public LoggingEventAggregator(LoggingEvent loggingEvent) + { + this.loggingEvent = loggingEvent; + this.count = 1; + } + + /** + * Returns the loggingEvent. + * @return the loggingEvent + */ + public LoggingEvent getLoggingEvent() + { + return loggingEvent; + } + + /** + * Returns the count. + * @return the count + */ + public int getCount() + { + return count; + } + + /** + * Sets the count. + * @param count the count to set + */ + public void setCount(int count) + { + this.count = count; + } + + public void incrementCount() + { + count++; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + + Object lem = loggingEvent.getMessage(); + String[] thstr = loggingEvent.getThrowableStrRep(); + result = prime * result + ((lem == null) ? 0 : lem.hashCode()); + result = prime * result + Arrays.hashCode(thstr); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final LoggingEventAggregator other = (LoggingEventAggregator) obj; + + Object lem = loggingEvent.getMessage(); + String[] thstr = loggingEvent.getThrowableStrRep(); + + Object otherLem = other.loggingEvent.getMessage(); + String[] otherThstr = other.loggingEvent.getThrowableStrRep(); + + int length = Math.min(otherThstr.length, thstr.length); + length = Math.min(10, length); + + otherThstr = (String[]) ArrayUtils.subarray(otherThstr, 0, length); + String[] thisThstr = (String[]) ArrayUtils.subarray(thstr, 0, length); + + if (lem == null) + { + if (otherLem != null) + { + return false; + } + } + + else if (!lem.equals(otherLem)) + { + return false; + } + if (!Arrays.equals(thisThstr, otherThstr)) + { + return false; + } + return true; + } + +} + + +class DefaultEvaluator implements TriggeringEventEvaluator +{ + + public boolean isTriggeringEvent(LoggingEvent event) + { + return event.getLevel().isGreaterOrEqual(Level.ERROR); + } +} \ No newline at end of file Deleted: tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java =================================================================== --- trunk/openutils-log4j/src/main/java/it/openutils/log4j/FilteredPatternLayout.java 2008-02-03 21:02:50 UTC (rev 594) +++ tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java 2008-02-20 10:02:19 UTC (rev 650) @@ -1,145 +0,0 @@ -/* - * Copyright 2005 Fabrizio Giustina. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.log4j; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.apache.log4j.PatternLayout; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.spi.ThrowableInformation; - - -/** - * An extension of <code>org.apache.log4j.PatternLayout</code> which strips out from stack traces a list of configured - * entries. Sample configuration: - * - * <pre> - * <appender name="console" class="org.apache.log4j.ConsoleAppender"> - * <layout class="it.openutils.log4j.FilteredPatternLayout"> - * <param name="ConversionPattern" value="%-5p %c %F(%M:%L) %d{dd.MM.yyyy HH:mm:ss} %m%n" /> - * <param name="Filter" value="org.apache.catalina" /> - * <param name="Filter" value="sun.reflect" /> - * <param name="Filter" value="javax.servlet.http" /> - * </layout> - * </appender> - * </pre> - * - * @author Fabrizio Giustina - * @version $Id$ - */ -public class FilteredPatternLayout extends PatternLayout -{ - - /** - * Line separator for stacktrace frames. - */ - private static String lineSeparator = "\n"; - - /** - * Holds the list of filtered frames. - */ - private Set<String> filteredFrames = new HashSet<String>(); - - static - { - try - { - lineSeparator = System.getProperty("line.separator"); - } - catch (SecurityException ex) - { - // ignore - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean ignoresThrowable() - { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public String format(LoggingEvent event) - { - - ThrowableInformation throwableInformation = event.getThrowableInformation(); - - if (throwableInformation == null) - { - return super.format(event); - } - - return super.format(event) + getFilteredStacktrace(throwableInformation); - } - - /** - * Adds a new filtered frame. Any stack frame starting with <code>"at "</code> + <code>filter</code> will not be - * written to the log. - * @param filter a class name or package name to be filtered - */ - public void setFilter(String filter) - { - filteredFrames.add("at " + filter); - } - - private String getFilteredStacktrace(ThrowableInformation throwableInformation) - { - StringBuffer buffer = new StringBuffer(); - - String[] s = throwableInformation.getThrowableStrRep(); - - for (int j = 0; j < s.length; j++) - { - String string = s[j]; - - if (startsWithAFilteredPAttern(string)) - { - continue; - } - buffer.append(string); - buffer.append(lineSeparator); - } - - return buffer.toString(); - } - - /** - * Check if the given string starts with any of the filtered patterns. - * @param string checked String - * @return <code>true</code> if the begininning of the string matches a filtered pattern, <code>false</code> - * otherwise - */ - private boolean startsWithAFilteredPAttern(String string) - { - Iterator<String> iterator = filteredFrames.iterator(); - while (iterator.hasNext()) - { - if (string.trim().startsWith(iterator.next())) - { - return true; - } - } - return false; - } -} Copied: tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java (from rev 648, trunk/openutils-log4j/src/main/java/it/openutils/log4j/FilteredPatternLayout.java) =================================================================== --- tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java (rev 0) +++ tags/openutils-log4j-2.0/src/main/java/it/openutils/log4j/FilteredPatternLayout.java 2008-02-20 10:02:19 UTC (rev 650) @@ -0,0 +1,188 @@ +/* + * Copyright 2005 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.log4j; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.log4j.PatternLayout; +import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.ThrowableInformation; + + +/** + * An extension of <code>org.apache.log4j.PatternLayout</code> which strips out from stack traces a list of configured + * entries. Sample configuration: + * + * <pre> + * <appender name="console" class="org.apache.log4j.ConsoleAppender"> + * <layout class="it.openutils.log4j.FilteredPatternLayout"> + * <param name="ConversionPattern" value="%-5p %c %F(%M:%L) %d{dd.MM.yyyy HH:mm:ss} %m%n" /> + * <param name="Filter" value="org.apache.catalina" /> + * <param name="Filter" value="sun.reflect" /> + * <param name="Filter" value="javax.servlet.http" /> + * </layout> + * </appender> + * </pre> + * + * @author Fabrizio Giustina + * @version $Id: FilteredPatternLayout.java 8589 2008-02-10 18:01:57Z fgiust $ + */ +public class FilteredPatternLayout extends PatternLayout +{ + + /** + * Holds the list of filtered frames. + */ + private Set<String> filteredFrames = new HashSet<String>(); + + private String header; + + private String footer; + + /** + * Line separator for stacktrace frames. + */ + private static String lineSeparator = "\n"; + + static + { + try + { + lineSeparator = System.getProperty("line.separator"); + } + catch (SecurityException ex) + { + // ignore + } + } + + /** + * Returns the header. + * @return the header + */ + @Override + public String getHeader() + { + return header; + } + + /** + * Sets the header. + * @param header the header to set + */ + public void setHeader(String header) + { + this.header = header; + } + + /** + * Returns the footer. + * @return the footer + */ + @Override + public String getFooter() + { + return footer; + } + + /** + * Sets the footer. + * @param footer the footer to set + */ + public void setFooter(String footer) + { + this.footer = footer; + } + + /** + * @see org.apache.log4j.Layout#ignoresThrowable() + */ + @Override + public boolean ignoresThrowable() + { + return false; + } + + /** + * @see org.apache.log4j.PatternLayout#format(org.apache.log4j.spi.LoggingEvent) + */ + @Override + public String format(LoggingEvent event) + { + + ThrowableInformation throwableInformation = event.getThrowableInformation(); + + if (throwableInformation == null) + { + return super.format(event); + } + + return super.format(event) + getFilteredStacktrace(throwableInformation); + } + + /** + * Adds a new filtered frame. Any stack frame starting with <code>"at "</code> + <code>filter</code> will not be + * written to the log. + * @param filter a class name or package name to be filtered + */ + public void setFilter(String filter) + { + filteredFrames.add("at " + filter); + } + + private String getFilteredStacktrace(ThrowableInformation throwableInformation) + { + StringBuffer buffer = new StringBuffer(); + + String[] s = throwableInformation.getThrowableStrRep(); + + for (int j = 0; j < s.length; j++) + { + String string = s[j]; + + if (startsWithAFilteredPAttern(string)) + { + continue; + } + buffer.append(string); + buffer.append(lineSeparator); + } + + return buffer.toString(); + } + + /** + * Check if the given string starts with any of the filtered patterns. + * @param string checked String + * @return <code>true</code> if the begininning of the string matches a filtered pattern, <code>false</code> + * otherwise + */ + private boolean startsWithAFilteredPAttern(String string) + { + Iterator<String> iterator = filteredFrames.iterator(); + while (iterator.hasNext()) + { + if (string.trim().startsWith(iterator.next())) + { + return true; + } + } + return false; + } + +} Copied: tags/openutils-log4j-2.0/src/site/changes (from rev 648, trunk/openutils-log4j/src/site/changes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-02-20 16:56:27
|
Revision: 670 http://openutils.svn.sourceforge.net/openutils/?rev=670&view=rev Author: fcarone Date: 2008-02-20 08:56:29 -0800 (Wed, 20 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-hibernate-security-0.0.3 Added Paths: ----------- tags/openutils-hibernate-security-0.0.3/ tags/openutils-hibernate-security-0.0.3/pom.xml tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/utils/ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.3/src/test/java/it/openutils/hibernate/security/ tags/openutils-hibernate-security-0.0.3/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-dao.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-managers.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-security.xml Removed Paths: ------------- tags/openutils-hibernate-security-0.0.3/pom.xml tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.3/src/test/java/it/openutils/hibernate/security/ tags/openutils-hibernate-security-0.0.3/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-dao.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-managers.xml tags/openutils-hibernate-security-0.0.3/src/test/resources/spring-security.xml Copied: tags/openutils-hibernate-security-0.0.3 (from rev 645, trunk/openutils-hibernate-security) Deleted: tags/openutils-hibernate-security-0.0.3/pom.xml =================================================================== --- trunk/openutils-hibernate-security/pom.xml 2008-02-19 18:28:34 UTC (rev 645) +++ tags/openutils-hibernate-security-0.0.3/pom.xml 2008-02-20 16:56:29 UTC (rev 670) @@ -1,225 +0,0 @@ -<?xml version="1.0"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>openutils</artifactId> - <groupId>net.sourceforge.openutils</groupId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-hibernate-security</artifactId> - <name>openutils hibernate security</name> - <version>0.0.3-SNAPSHOT</version> - <description>Hibernate Security classes</description> - <properties> - <spring.version>2.5.1</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <!-- already imported cglib-nodep by spring --> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.5.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <artifactId>spring-remoting</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-jdbc</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-support</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>1.8.0.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> Copied: tags/openutils-hibernate-security-0.0.3/pom.xml (from rev 669, trunk/openutils-hibernate-security/pom.xml) =================================================================== --- tags/openutils-hibernate-security-0.0.3/pom.xml (rev 0) +++ tags/openutils-hibernate-security-0.0.3/pom.xml 2008-02-20 16:56:29 UTC (rev 670) @@ -0,0 +1,229 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-hibernate-security</artifactId> + <name>openutils hibernate security</name> + <version>0.0.3</version> + <description>Hibernate Security classes</description> + <properties> + <spring.version>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <!-- already imported cglib-nodep by spring --> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.5.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <artifactId>spring-remoting</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-support</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.8.0.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-hibernate-security-0.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-19 18:28:34 UTC (rev 645) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-20 16:56:29 UTC (rev 670) @@ -1,155 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.aop; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.ArrayList; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.context.SecurityContextHolder; -import org.apache.commons.lang.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Filter; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id: $ - */ -@Aspect -public class AOPSecurity -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AOPSecurity.class); - - private SecurityRuleManager securityRuleManager; - - private List<String> securedDAOs; - - private boolean enabled; - - /** - * @param pjp The proceeding joinpoint - * @param filter The entity we are going to filter - * @param additionalCriteria The additional criteria list, cannot be null - * @return The execution invocation result - * @throws Throwable Any exception occurring in the invoked method - */ - @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " - + // - " args(filter, .., additionalCriteria)") - public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) - throws Throwable - { - if (!enabled) - { - log.debug("DAO security disabled, proceeding."); - return pjp.proceed(); - } - - if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) - { - log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); - return pjp.proceed(); - } - - log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) - { - throw new SecurityException("Authentication is not valid"); - } - GrantedAuthority[] authorities = authentication.getAuthorities(); - List<String> roles = new ArrayList<String>(); - for (int i = 0; i < authorities.length; i++) - { - roles.add(authorities[i].getAuthority()); - } - - String entity = filter.getClass().getCanonicalName(); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); - - if (rules.isEmpty()) - { - if (log.isWarnEnabled()) - { - String grantedRoles = StringUtils.EMPTY; - for (int i = 0; i < authorities.length; i++) - { - grantedRoles += authorities[i].getAuthority() + " "; - } - log.warn("Access is denied on " + entity + ", for user {} with roles {}", SecurityContextHolder - .getContext() - .getAuthentication() - .getPrincipal() - .toString(), grantedRoles); - } - throw new SecurityException("Access denied"); - } - - Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); - - Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter - .getFilterDefinition() - .getDefaultFilterCondition()); - - log.debug("Adding sql restriction: {}", sqlCriterion.toString()); - additionalCriteria.add(sqlCriterion); - - Object result = pjp.proceed(); - return result; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - - /** - * Sets the securedDAOs. - * @param securedDAOs the securedDAOs to set - */ - public void setSecuredDAOs(List<String> securedDAOs) - { - this.securedDAOs = securedDAOs; - } - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } -} Copied: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (from rev 656, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java) =================================================================== --- tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (rev 0) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-20 16:56:29 UTC (rev 670) @@ -0,0 +1,154 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.aop; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.context.SecurityContextHolder; +import org.apache.commons.lang.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.hibernate.Filter; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id: $ + */ +@Aspect +public class AOPSecurity +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AOPSecurity.class); + + private SecurityRuleManager securityRuleManager; + + private List<String> securedDAOs; + + private boolean enabled; + + /** + * @param pjp The proceeding joinpoint + * @param filter The entity we are going to filter + * @param additionalCriteria The additional criteria list, cannot be null + * @return The execution invocation result + * @throws Throwable Any exception occurring in the invoked method + */ + @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " + + // + " args(filter, .., additionalCriteria)") + public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) + throws Throwable + { + if (!enabled) + { + log.debug("DAO security disabled, proceeding."); + return pjp.proceed(); + } + + if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) + { + log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); + return pjp.proceed(); + } + + log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) + { + throw new SecurityException("Authentication is not valid"); + } + GrantedAuthority[] authorities = authentication.getAuthorities(); + List<String> roles = new ArrayList<String>(); + for (int i = 0; i < authorities.length; i++) + { + roles.add(authorities[i].getAuthority()); + } + + String entity = filter.getClass().getCanonicalName(); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); + + if (rules.isEmpty()) + { + if (log.isWarnEnabled()) + { + String grantedRoles = StringUtils.EMPTY; + for (int i = 0; i < authorities.length; i++) + { + grantedRoles += authorities[i].getAuthority() + " "; + } + log.warn( + "No rules found. Access is denied on " + entity + ", for user {} with roles {}", + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), + grantedRoles); + } + throw new SecurityException("Access denied"); + } + + Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); + + Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter + .getFilterDefinition() + .getDefaultFilterCondition()); + + log.debug("Adding sql restriction: {}", sqlCriterion.toString()); + additionalCriteria.add(sqlCriterion); + + Object result = pjp.proceed(); + return result; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } + + /** + * Sets the securedDAOs. + * @param securedDAOs the securedDAOs to set + */ + public void setSecuredDAOs(List<String> securedDAOs) + { + this.securedDAOs = securedDAOs; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } +} Deleted: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-19 18:28:34 UTC (rev 645) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-20 16:56:29 UTC (rev 670) @@ -1,215 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.apache.commons.lang.StringUtils; -import org.hibernate.Filter; -import org.hibernate.HibernateException; -import org.hibernate.engine.FilterDefinition; - - -/** - * @author fcarone - * @version $Id: $ - */ -public class JavaBeanFilter implements Filter -{ - - private FilterDefinition filterDefinition; - - /** - * @param bean The bean to set rules for - * @param securityRules The list of {@link SecurityRule}s to apply. - * @throws ClassNotFoundException If the bean class has not been found - * @throws InstantiationException If the bean doesn't contain the no-arg constructor - * @throws IllegalAccessException If the bean properties cannot be accessed - * @throws SecurityException If the bean class cannot be accessed - * @throws NoSuchFieldException If the property contained in the security rule refers to a bean non-existent field - */ - @SuppressWarnings("unchecked") - public JavaBeanFilter(String bean, List<SecurityRule> securityRules) - throws ClassNotFoundException, - InstantiationException, - IllegalAccessException, - SecurityException, - NoSuchFieldException - { - Class< ? extends Object> beanClass = Class.forName(bean, true, this.getClass().getClassLoader()); - - if (!beanClass.isAnnotationPresent(Entity.class)) - { - throw new IllegalArgumentException("Class " + bean + " must contain the @Entity annotation."); - } - if (!(beanClass.isAnnotationPresent(Table.class) || beanClass - .isAnnotationPresent(org.hibernate.annotations.Table.class))) - { - throw new IllegalArgumentException("Class " + bean + " must contain the @Table annotation."); - } - - Map<String, String> propertyColumnMap = new HashMap<String, String>(); - - StringBuffer filterDefCondition = new StringBuffer(); - String filterName = StringUtils.EMPTY; - - Map<String, List<SecurityRule>> roleRuleMap = new LinkedHashMap<String, List<SecurityRule>>(); - for (SecurityRule securityRule : securityRules) - { - if (!roleRuleMap.containsKey(securityRule.getRole())) - { - roleRuleMap.put(securityRule.getRole(), new ArrayList<SecurityRule>()); - } - roleRuleMap.get(securityRule.getRole()).add(securityRule); - } - - for (Map.Entry<String, List<SecurityRule>> entry : roleRuleMap.entrySet()) - { - filterName += entry.getKey(); - - List<SecurityRule> rules = entry.getValue(); - if (!StringUtils.isEmpty(filterDefCondition.toString())) - { - filterDefCondition.append(" OR "); - } - filterDefCondition.append("("); - StringBuffer subFilterCond = new StringBuffer(); - for (SecurityRule securityRule : rules) - { - String property = securityRule.getProperty(); - filterName += property; - - Field field = beanClass.getDeclaredField(property); - - // @todo: annotations may also be defined on getters/setters... - propertyColumnMap.put(property, field.getAnnotation(Column.class).name()); - if (!StringUtils.isEmpty(subFilterCond.toString())) - { - subFilterCond.append(" AND "); - } - String modifier = null; - String startQuote = null; - String endQuote = null; - - if (field.getType().isAssignableFrom(String.class)) - { - startQuote = "\'"; - endQuote = startQuote; - } - else if (field.getType().getSuperclass().isAssignableFrom(Number.class)) - { - startQuote = StringUtils.EMPTY; - endQuote = StringUtils.EMPTY; - } - - switch (securityRule.getModifier()) - { - case EQUALS : - modifier = " = "; - break; - - case NOT : - modifier = " != "; - break; - - default : - throw new IllegalArgumentException("Modifier " + securityRule.getModifier() + "not recognized."); - } - subFilterCond.append(field.getAnnotation(Column.class).name()); - subFilterCond.append(modifier); - if (StringUtils.isNotEmpty(startQuote)) - { - subFilterCond.append(startQuote); - } - subFilterCond.append(securityRule.getValue()); - if (StringUtils.isNotEmpty(endQuote)) - { - subFilterCond.append(endQuote); - } - - filterName += securityRule.getValue(); - } - filterDefCondition.append(subFilterCond); - filterDefCondition.append(")"); - } - - // filtername is unique, but untraceable - this.filterDefinition = new FilterDefinition(Integer.toString(filterName.hashCode()), filterDefCondition - .toString(), new HashMap()); - } - - /** - * {@inheritDoc} - */ - public FilterDefinition getFilterDefinition() - { - return this.filterDefinition; - } - - /** - * {@inheritDoc} - */ - public String getName() - { - return this.filterDefinition.getFilterName(); - } - - /** - * {@inheritDoc} - */ - public Filter setParameter(String name, Object value) - { - return this; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public Filter setParameterList(String name, Collection values) - { - return this; - } - - /** - * {@inheritDoc} - */ - public Filter setParameterList(String name, Object[] values) - { - return this; - } - - /** - * {@inheritDoc} - */ - public void validate() throws HibernateException - { - // - } - -} Copied: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java (from rev 659, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java) =================================================================== --- tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java (rev 0) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-20 16:56:29 UTC (rev 670) @@ -0,0 +1,258 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.filter; + +import it.openutils.hibernate.security.dataobject.PermissionEnum; +import it.openutils.hibernate.security.dataobject.SecurityRule; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Filter; +import org.hibernate.HibernateException; +import org.hibernate.engine.FilterDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class JavaBeanFilter implements Filter +{ + + private FilterDefinition filterDefinition; + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(JavaBeanFilter.class); + + + /** + * @param bean The bean to set rules for + * @param securityRules The list of {@link SecurityRule}s to apply. + * @throws ClassNotFoundException If the bean class has not been found + * @throws InstantiationException If the bean doesn't contain the no-arg constructor + * @throws IllegalAccessException If the bean properties cannot be accessed + * @throws SecurityException If the bean class cannot be accessed + * @throws NoSuchFieldException If the property contained in the security rule refers to a bean non-existent field + */ + @SuppressWarnings("unchecked") + public JavaBeanFilter(String bean, List<SecurityRule> securityRules) + throws ClassNotFoundException, + InstantiationException, + IllegalAccessException, + SecurityException, + NoSuchFieldException + { + Class< ? extends Object> beanClass = Class.forName(bean, true, this.getClass().getClassLoader()); + + if (!beanClass.isAnnotationPresent(Entity.class)) + { + throw new IllegalArgumentException("Class " + bean + " must contain the @Entity annotation."); + } + if (!(beanClass.isAnnotationPresent(Table.class) || beanClass + .isAnnotationPresent(org.hibernate.annotations.Table.class))) + { + throw new IllegalArgumentException("Class " + bean + " must contain the @Table annotation."); + } + + Map<String, String> propertyColumnMap = new HashMap<String, String>(); + + StringBuffer filterDefCondition = new StringBuffer(); + String filterName = StringUtils.EMPTY; + + Map<String, List<SecurityRule>> roleRuleMap = new LinkedHashMap<String, List<SecurityRule>>(); + for (SecurityRule securityRule : securityRules) + { + if (!roleRuleMap.containsKey(securityRule.getRole())) + { + roleRuleMap.put(securityRule.getRole(), new ArrayList<SecurityRule>()); + } + roleRuleMap.get(securityRule.getRole()).add(securityRule); + } + + for (Map.Entry<String, List<SecurityRule>> entry : roleRuleMap.entrySet()) + { + filterName += entry.getKey(); + + List<SecurityRule> rules = entry.getValue(); + if (rules == null || rules.isEmpty()) + { + log.debug("No rules defined for role {}", entry.getKey()); + continue; + } + + if (!rulesContainLoad(rules)) + { + log.debug("No LOAD rules defined for role {}", entry.getKey()); + continue; + } + + if (!StringUtils.isEmpty(filterDefCondition.toString())) + { + filterDefCondition.append(" OR "); + } + filterDefCondition.append("("); + StringBuffer subFilterCond = new StringBuffer(); + for (SecurityRule securityRule : rules) + { + if (!securityRule.getPermissions().contains(PermissionEnum.LOAD)) + { + log.debug("Skipping rule {} since it is not related to LOAD.", securityRule); + continue; + } + String property = securityRule.getProperty(); + filterName += property; + + Field field = beanClass.getDeclaredField(property); + + // @todo: annotations may also be defined on getters/setters... + propertyColumnMap.put(property, field.getAnnotation(Column.class).name()); + if (!StringUtils.isEmpty(subFilterCond.toString())) + { + subFilterCond.append(" AND "); + } + String modifier = null; + String startQuote = null; + String endQuote = null; + + if (String.class.isAssignableFrom(field.getType())) + { + startQuote = "\'"; + endQuote = startQuote; + } + else if (Number.class.isAssignableFrom(field.getType())) + { + startQuote = StringUtils.EMPTY; + endQuote = StringUtils.EMPTY; + } + + switch (securityRule.getModifier()) + { + case EQUALS : + modifier = " = "; + break; + + case NOT : + modifier = " != "; + break; + + default : + throw new IllegalArgumentException("Modifier " + securityRule.getModifier() + "not recognized."); + } + subFilterCond.append(field.getAnnotation(Column.class).name()); + subFilterCond.append(modifier); + if (StringUtils.isNotEmpty(startQuote)) + { + subFilterCond.append(startQuote); + } + subFilterCond.append(StringEscapeUtils.escapeSql(securityRule.getValue())); + if (StringUtils.isNotEmpty(endQuote)) + { + subFilterCond.append(endQuote); + } + + filterName += securityRule.getValue(); + } + filterDefCondition.append(subFilterCond); + filterDefCondition.append(")"); + } + + // filtername is unique, but untraceable + this.filterDefinition = new FilterDefinition(Integer.toString(filterName.hashCode()), filterDefCondition + .toString(), new HashMap()); + } + + /** + * @param rules + * @return + */ + private boolean rulesContainLoad(List<SecurityRule> rules) + { + for (SecurityRule rule : rules) + { + if (rule.getPermissions().contains(PermissionEnum.LOAD)) + { + return true; + } + } + return false; + } + + /** + * {@inheritDoc} + */ + public FilterDefinition getFilterDefinition() + { + return this.filterDefinition; + } + + /** + * {@inheritDoc} + */ + public String getName() + { + return this.filterDefinition.getFilterName(); + } + + /** + * {@inheritDoc} + */ + public Filter setParameter(String name, Object value) + { + return this; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Filter setParameterList(String name, Collection values) + { + return this; + } + + /** + * {@inheritDoc} + */ + public Filter setParameterList(String name, Object[] values) + { + return this; + } + + /** + * {@inheritDoc} + */ + public void validate() throws HibernateException + { + // + } + +} Deleted: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java 2008-02-19 18:28:34 UTC (rev 645) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java 2008-02-20 16:56:29 UTC (rev 670) @@ -1,222 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.ModifierEnum; -import it.openutils.hibernate.security.dataobject.PermissionEnum; -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.ConfigAttribute; -import org.acegisecurity.ConfigAttributeDefinition; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.vote.AccessDecisionVoter; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aop.framework.ReflectiveMethodInvocation; - - -/** - * @author fcarone - * @version $Id: $ - */ -public class SecurityRuleAccessDecisionVoter implements AccessDecisionVoter -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(SecurityRuleAccessDecisionVoter.class); - - private SecurityRuleManager securityRuleManager; - - /** - * {@inheritDoc} - */ - public boolean supports(ConfigAttribute attribute) - { - log.debug("Evaluating attribute {}", attribute.getAttribute()); - - if (attribute.getAttribute() != null) - { - for (PermissionEnum permission : PermissionEnum.values()) - { - if (StringUtils.equals(permission.getValue(), attribute.getAttribute())) - { - log.debug("Support ok."); - return true; - } - } - } - log.debug("Not supporting attribute."); - return false; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public boolean supports(Class clazz) - { - return true; - } - - /** - * {@inheritDoc} - */ - public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) - { - List<String> roles = new ArrayList<String>(); - roles.addAll(getRolesFromAuthentication(authentication)); - - if (object instanceof ReflectiveMethodInvocation) - { - ReflectiveMethodInvocation methodInvocation = ((ReflectiveMethodInvocation) object); - for (Object argument : methodInvocation.getArguments()) - { - log.debug("Evaluating argument {}", argument); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(argument.getClass().getName(), roles); - boolean permissionMatches = checkPermissions(rules, config); - if (!permissionMatches) - { - return ACCESS_DENIED; - } - - boolean areRulesMatching = checkRules(rules, argument); - if (!areRulesMatching) - { - return ACCESS_DENIED; - } - } - } - - return ACCESS_GRANTED; - } - - /** - * @param authentication - * @return - */ - private Collection< ? extends String> getRolesFromAuthentication(Authentication authentication) - { - List<String> roles = new ArrayList<String>(); - for (GrantedAuthority authority : authentication.getAuthorities()) - { - log.debug("Granted authority for user {}: {}", authentication.getName(), authority.getAuthority()); - roles.add(authority.getAuthority()); - } - return roles; - } - - /** - * @param rules - * @param argument - * @return - */ - private boolean checkRules(List<SecurityRule> rules, Object argument) - { - log.debug("Evaluating rules."); - try - { - for (SecurityRule rule : rules) - { - String objProperty = BeanUtils.getSimpleProperty(argument, rule.getProperty()); - if (rule.getModifier() == ModifierEnum.EQUALS) - { - if (StringUtils.equals(objProperty, rule.getValue())) - { - log.debug("Matching rule found: {}", rule); - return true; - } - } - else if (rule.getModifier() == ModifierEnum.NOT) - { - if (!StringUtils.equals(objProperty, rule.getValue())) - { - log.debug("Matching rule found: {}", rule); - return true; - } - } - else - { - throw new RuntimeException("Modifier " + rule.getModifier() + " is not recognized"); - } - } - } - catch (NoSuchMethodException e) - { - log.error("{}", e); - } - catch (IllegalAccessException e) - { - log.error("{}", e); - } - catch (InvocationTargetException e) - { - log.error("{}", e); - } - log.debug("No matching rules found."); - return false; - } - - /** - * @param rules - * @param config - * @return - */ - @SuppressWarnings("unchecked") - private boolean checkPermissions(List<SecurityRule> rules, ConfigAttributeDefinition config) - { - log.debug("Evaluation permissions"); - Iterator iterator = config.getConfigAttributes(); - while (iterator.hasNext()) - { - String attribute = ((ConfigAttribute) iterator.next()).getAttribute(); - for (SecurityRule rule : rules) - { - for (PermissionEnum permission : rule.getPermissions()) - { - if (StringUtils.equals(permission.getValue(), attribute)) - { - log.debug("Matching permission: {}", permission.getValue()); - return true; - } - } - } - } - log.debug("No matching permissions found."); - return false; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - -} Copied: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java (from rev 668, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java) =================================================================== --- tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java (rev 0) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java 2008-02-20 16:56:29 UTC (rev 670) @@ -0,0 +1,87 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.filter; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.filter.utils.SecurityRuleUtils; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.ConfigAttributeDefinition; +import org.acegisecurity.vote.AccessDecisionVoter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.ReflectiveMethodInvocation; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class SecurityRuleAccessDecisionVoter extends SecurityRuleBaseHandler implements AccessDecisionVoter +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(SecurityRuleAccessDecisionVoter.class); + + private SecurityRuleManager securityRuleManager; + + private SecurityRuleUtils ruleUtils = new SecurityRuleUtils(); + + /** + * {@inheritDoc} + */ + public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) + { + List<String> roles = ruleUtils.getRolesFromAuthentication(authentication); + + if (object instanceof ReflectiveMethodInvocation) + { + ReflectiveMethodInvocation methodInvocation = ((ReflectiveMethodInvocation) object); + for (Object argument : methodInvocation.getArguments()) + { + log.debug("Evaluating argument {}", argument); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(ruleUtils.getClassName(argument), roles); + boolean permissionMatches = ruleUtils.checkPermissions(rules, config); + if (!permissionMatches) + { + return ACCESS_DENIED; + } + + boolean areRulesMatching = ruleUtils.checkRules(rules, argument); + if (!areRulesMatching) + { + return ACCESS_DENIED; + } + } + } + + return ACCESS_GRANTED; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } +} Copied: tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java (from rev 667, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java) =================================================================== --- tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java (rev 0) +++ tags/openutils-hibernate-security-0.0.3/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java 2008-02-20 16:56:29 UTC (rev 670) @@ -0,0 +1,70 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.filter; + +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.acegisecurity.AccessDeniedException; +import org.acegisecurity.Authentication; +import org.acegisecurity.ConfigAttributeDefinition; +import org.acegisecurity.afterinvocation.AfterInvocationProvider; +import org.apache.commons.collections.CollectionUtils; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class SecurityRuleAfterInvocationHandler extends SecurityRuleBaseHandler implements AfterInvocationProvider +{ + + private SecurityRuleManager securityRuleManager; + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, + Object returnedObject) throws AccessDeniedException + { ... [truncated message content] |
From: <fc...@us...> - 2008-02-21 14:57:20
|
Revision: 680 http://openutils.svn.sourceforge.net/openutils/?rev=680&view=rev Author: fcarone Date: 2008-02-21 06:57:26 -0800 (Thu, 21 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-hibernate-security-0.0.4 Added Paths: ----------- tags/openutils-hibernate-security-0.0.4/ tags/openutils-hibernate-security-0.0.4/pom.xml tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java Removed Paths: ------------- tags/openutils-hibernate-security-0.0.4/pom.xml tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java Copied: tags/openutils-hibernate-security-0.0.4 (from rev 673, trunk/openutils-hibernate-security) Deleted: tags/openutils-hibernate-security-0.0.4/pom.xml =================================================================== --- trunk/openutils-hibernate-security/pom.xml 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/pom.xml 2008-02-21 14:57:26 UTC (rev 680) @@ -1,223 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>openutils</artifactId> - <groupId>net.sourceforge.openutils</groupId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-hibernate-security</artifactId> - <name>openutils hibernate security</name> - <version>0.0.4-SNAPSHOT</version> - <description>Hibernate Security classes</description> - <properties> - <spring.version>2.5.1</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <!-- already imported cglib-nodep by spring --> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.5.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <artifactId>spring-remoting</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-jdbc</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-support</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>1.8.0.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-hibernate-security-0.0.4/pom.xml (from rev 679, trunk/openutils-hibernate-security/pom.xml) =================================================================== --- tags/openutils-hibernate-security-0.0.4/pom.xml (rev 0) +++ tags/openutils-hibernate-security-0.0.4/pom.xml 2008-02-21 14:57:26 UTC (rev 680) @@ -0,0 +1,229 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-hibernate-security</artifactId> + <name>openutils hibernate security</name> + <version>0.0.4</version> + <description>Hibernate Security classes</description> + <properties> + <spring.version>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <!-- already imported cglib-nodep by spring --> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.5.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <artifactId>spring-remoting</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-support</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.8.0.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-hibernate-security-0.0.4</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 14:57:26 UTC (rev 680) @@ -1,154 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.aop; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.ArrayList; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.context.SecurityContextHolder; -import org.apache.commons.lang.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Filter; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -@Aspect -public class AOPSecurity -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AOPSecurity.class); - - private SecurityRuleManager securityRuleManager; - - private List<String> securedDAOs; - - private boolean enabled; - - /** - * @param pjp The proceeding joinpoint - * @param filter The entity we are going to filter - * @param additionalCriteria The additional criteria list, cannot be null - * @return The execution invocation result - * @throws Throwable Any exception occurring in the invoked method - */ - @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " - + // - " args(filter, .., additionalCriteria)") - public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) - throws Throwable - { - if (!enabled) - { - log.debug("DAO security disabled, proceeding."); - return pjp.proceed(); - } - - if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) - { - log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); - return pjp.proceed(); - } - - log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) - { - throw new SecurityException("Authentication is not valid"); - } - GrantedAuthority[] authorities = authentication.getAuthorities(); - List<String> roles = new ArrayList<String>(); - for (int i = 0; i < authorities.length; i++) - { - roles.add(authorities[i].getAuthority()); - } - - String entity = filter.getClass().getCanonicalName(); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); - - if (rules.isEmpty()) - { - if (log.isWarnEnabled()) - { - String grantedRoles = StringUtils.EMPTY; - for (int i = 0; i < authorities.length; i++) - { - grantedRoles += authorities[i].getAuthority() + " "; - } - log.warn( - "No rules found. Access is denied on " + entity + ", for user {} with roles {}", - SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), - grantedRoles); - } - throw new SecurityException("Access denied"); - } - - Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); - - Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter - .getFilterDefinition() - .getDefaultFilterCondition()); - - log.debug("Adding sql restriction: {}", sqlCriterion.toString()); - additionalCriteria.add(sqlCriterion); - - Object result = pjp.proceed(); - return result; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - - /** - * Sets the securedDAOs. - * @param securedDAOs the securedDAOs to set - */ - public void setSecuredDAOs(List<String> securedDAOs) - { - this.securedDAOs = securedDAOs; - } - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } -} Copied: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (from rev 675, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java) =================================================================== --- tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (rev 0) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 14:57:26 UTC (rev 680) @@ -0,0 +1,154 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.aop; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.context.SecurityContextHolder; +import org.apache.commons.lang.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.hibernate.Filter; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id$ + */ +@Aspect +public class AOPSecurity +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AOPSecurity.class); + + private SecurityRuleManager securityRuleManager; + + private List<String> securedDAOs; + + private boolean enabled; + + /** + * @param pjp The proceeding joinpoint + * @param filter The entity we are going to filter + * @param additionalCriteria The additional criteria list, cannot be null + * @return The execution invocation result + * @throws Throwable Any exception occurring in the invoked method + */ + @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " + + // + " args(filter, .., additionalCriteria)") + public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) + throws Throwable + { + if (!enabled) + { + log.debug("DAO security disabled, proceeding."); + return pjp.proceed(); + } + + if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) + { + log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); + return pjp.proceed(); + } + + log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) + { + throw new SecurityException("Authentication is not valid"); + } + GrantedAuthority[] authorities = authentication.getAuthorities(); + List<String> roles = new ArrayList<String>(); + for (int i = 0; i < authorities.length; i++) + { + roles.add(authorities[i].getAuthority()); + } + + String entity = filter.getClass().getCanonicalName(); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(filter, roles); + + if (rules.isEmpty()) + { + if (log.isWarnEnabled()) + { + String grantedRoles = StringUtils.EMPTY; + for (int i = 0; i < authorities.length; i++) + { + grantedRoles += authorities[i].getAuthority() + " "; + } + log.warn( + "No rules found. Access is denied on " + entity + ", for user {} with roles {}", + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), + grantedRoles); + } + throw new SecurityException("Access denied"); + } + + Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); + + Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter + .getFilterDefinition() + .getDefaultFilterCondition()); + + log.debug("Adding sql restriction: {}", sqlCriterion.toString()); + additionalCriteria.add(sqlCriterion); + + Object result = pjp.proceed(); + return result; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } + + /** + * Sets the securedDAOs. + * @param securedDAOs the securedDAOs to set + */ + public void setSecuredDAOs(List<String> securedDAOs) + { + this.securedDAOs = securedDAOs; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } +} Deleted: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 14:57:26 UTC (rev 680) @@ -1,258 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.PermissionEnum; -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Filter; -import org.hibernate.HibernateException; -import org.hibernate.engine.FilterDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -public class JavaBeanFilter implements Filter -{ - - private FilterDefinition filterDefinition; - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(JavaBeanFilter.class); - - - /** - * @param bean The bean to set rules for - * @param securityRules The list of {@link SecurityRule}s to apply. - * @throws ClassNotFoundException If the bean class has not been found - * @throws InstantiationException If the bean doesn't contain the no-arg constructor - * @throws IllegalAccessException If the bean properties cannot be accessed - * @throws SecurityException If the bean class cannot be accessed - * @throws NoSuchFieldException If the property contained in the security rule refers to a bean non-existent field - */ - @SuppressWarnings("unchecked") - public JavaBeanFilter(String bean, List<SecurityRule> securityRules) - throws ClassNotFoundException, - InstantiationException, - IllegalAccessException, - SecurityException, - NoSuchFieldException - { - Class< ? extends Object> beanClass = Class.forName(bean, true, this.getClass().getClassLoader()); - - if (!beanClass.isAnnotationPresent(Entity.class)) - { - throw new IllegalArgumentException("Class " + bean + " must contain the @Entity annotation."); - } - if (!(beanClass.isAnnotationPresent(Table.class) || beanClass - .isAnnotationPresent(org.hibernate.annotations.Table.class))) - { - throw new IllegalArgumentException("Class " + bean + " must contain the @Table annotation."); - } - - Map<String, String> propertyColumnMap = new HashMap<String, String>(); - - StringBuffer filterDefCondition = new StringBuffer(); - String filterName = StringUtils.EMPTY; - - Map<String, List<SecurityRule>> roleRuleMap = new LinkedHashMap<String, List<SecurityRule>>(); - for (SecurityRule securityRule : securityRules) - { - if (!roleRuleMap.containsKey(securityRule.getRole())) - { - roleRuleMap.put(securityRule.getRole(), new ArrayList<SecurityRule>()); - } - roleRuleMap.get(securityRule.getRole()).add(securityRule); - } - - for (Map.Entry<String, List<SecurityRule>> entry : roleRuleMap.entrySet()) - { - filterName += entry.getKey(); - - List<SecurityRule> rules = entry.getValue(); - if (rules == null || rules.isEmpty()) - { - log.debug("No rules defined for role {}", entry.getKey()); - continue; - } - - if (!rulesContainLoad(rules)) - { - log.debug("No LOAD rules defined for role {}", entry.getKey()); - continue; - } - - if (!StringUtils.isEmpty(filterDefCondition.toString())) - { - filterDefCondition.append(" OR "); - } - filterDefCondition.append("("); - StringBuffer subFilterCond = new StringBuffer(); - for (SecurityRule securityRule : rules) - { - if (!securityRule.getPermissions().contains(PermissionEnum.LOAD)) - { - log.debug("Skipping rule {} since it is not related to LOAD.", securityRule); - continue; - } - String property = securityRule.getProperty(); - filterName += property; - - Field field = beanClass.getDeclaredField(property); - - // @todo: annotations may also be defined on getters/setters... - propertyColumnMap.put(property, field.getAnnotation(Column.class).name()); - if (!StringUtils.isEmpty(subFilterCond.toString())) - { - subFilterCond.append(" AND "); - } - String modifier = null; - String startQuote = null; - String endQuote = null; - - if (String.class.isAssignableFrom(field.getType())) - { - startQuote = "\'"; - endQuote = startQuote; - } - else if (Number.class.isAssignableFrom(field.getType())) - { - startQuote = StringUtils.EMPTY; - endQuote = StringUtils.EMPTY; - } - - switch (securityRule.getModifier()) - { - case EQUALS : - modifier = " = "; - break; - - case NOT : - modifier = " != "; - break; - - default : - throw new IllegalArgumentException("Modifier " + securityRule.getModifier() + "not recognized."); - } - subFilterCond.append(field.getAnnotation(Column.class).name()); - subFilterCond.append(modifier); - if (StringUtils.isNotEmpty(startQuote)) - { - subFilterCond.append(startQuote); - } - subFilterCond.append(StringEscapeUtils.escapeSql(securityRule.getValue())); - if (StringUtils.isNotEmpty(endQuote)) - { - subFilterCond.append(endQuote); - } - - filterName += securityRule.getValue(); - } - filterDefCondition.append(subFilterCond); - filterDefCondition.append(")"); - } - - // filtername is unique, but untraceable - this.filterDefinition = new FilterDefinition(Integer.toString(filterName.hashCode()), filterDefCondition - .toString(), new HashMap()); - } - - /** - * @param rules - * @return - */ - private boolean rulesContainLoad(List<SecurityRule> rules) - { - for (SecurityRule rule : rules) - { - if (rule.getPermissions().contains(PermissionEnum.LOAD)) - { - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - */ - public FilterDefinition getFilterDefinition() - { - return this.filterDefinition; - } - - /** - * {@inheritDoc} - */ - public String getName() - { - return this.filterDefinition.getFilterName(); - } - - /** - * {@inheritDoc} - */ - public Filter setParameter(String name, Object value) - { - return this; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public Filter setParameterList(String name, Collection values) - { - return this; - } - - /** - * {@inheritDoc} - */ - public Filter setParameterList(String name, Object[] values) - { - return this; - } - - /** - * {@inheritDoc} - */ - public void validate() throws HibernateException - { - // - } - -} Copied: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java (from rev 674, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java) =================================================================== --- tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java (rev 0) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 14:57:26 UTC (rev 680) @@ -0,0 +1,259 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.filter; + +import it.openutils.hibernate.security.dataobject.PermissionEnum; +import it.openutils.hibernate.security.dataobject.SecurityRule; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.acegisecurity.util.FieldUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Filter; +import org.hibernate.HibernateException; +import org.hibernate.engine.FilterDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id$ + */ +public class JavaBeanFilter implements Filter +{ + + private FilterDefinition filterDefinition; + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(JavaBeanFilter.class); + + + /** + * @param bean The bean to set rules for + * @param securityRules The list of {@link SecurityRule}s to apply. + * @throws ClassNotFoundException If the bean class has not been found + * @throws InstantiationException If the bean doesn't contain the no-arg constructor + * @throws IllegalAccessException If the bean properties cannot be accessed + * @throws SecurityException If the bean class cannot be accessed + * @throws NoSuchFieldException If the property contained in the security rule refers to a bean non-existent field + */ + @SuppressWarnings("unchecked") + public JavaBeanFilter(String bean, List<SecurityRule> securityRules) + throws ClassNotFoundException, + InstantiationException, + IllegalAccessException, + SecurityException, + NoSuchFieldException + { + Class< ? extends Object> beanClass = Class.forName(bean, true, this.getClass().getClassLoader()); + + if (!beanClass.isAnnotationPresent(Entity.class)) + { + throw new IllegalArgumentException("Class " + bean + " must contain the @Entity annotation."); + } + if (!(beanClass.isAnnotationPresent(Table.class) || beanClass + .isAnnotationPresent(org.hibernate.annotations.Table.class))) + { + throw new IllegalArgumentException("Class " + bean + " must contain the @Table annotation."); + } + + Map<String, String> propertyColumnMap = new HashMap<String, String>(); + + StringBuffer filterDefCondition = new StringBuffer(); + String filterName = StringUtils.EMPTY; + + Map<String, List<SecurityRule>> roleRuleMap = new LinkedHashMap<String, List<SecurityRule>>(); + for (SecurityRule securityRule : securityRules) + { + if (!roleRuleMap.containsKey(securityRule.getRole())) + { + roleRuleMap.put(securityRule.getRole(), new ArrayList<SecurityRule>()); + } + roleRuleMap.get(securityRule.getRole()).add(securityRule); + } + + for (Map.Entry<String, List<SecurityRule>> entry : roleRuleMap.entrySet()) + { + filterName += entry.getKey(); + + List<SecurityRule> rules = entry.getValue(); + if (rules == null || rules.isEmpty()) + { + log.debug("No rules defined for role {}", entry.getKey()); + continue; + } + + if (!rulesContainLoad(rules)) + { + log.debug("No LOAD rules defined for role {}", entry.getKey()); + continue; + } + + if (!StringUtils.isEmpty(filterDefCondition.toString())) + { + filterDefCondition.append(" OR "); + } + filterDefCondition.append("("); + StringBuffer subFilterCond = new StringBuffer(); + for (SecurityRule securityRule : rules) + { + if (!securityRule.getPermissions().contains(PermissionEnum.LOAD)) + { + log.debug("Skipping rule {} since it is not related to LOAD.", securityRule); + continue; + } + String property = securityRule.getProperty(); + filterName += property; + + Field field = FieldUtils.getField(beanClass, property); + + // @todo: annotations may also be defined on getters/setters... + propertyColumnMap.put(property, field.getAnnotation(Column.class).name()); + if (!StringUtils.isEmpty(subFilterCond.toString())) + { + subFilterCond.append(" AND "); + } + String modifier = null; + String startQuote = null; + String endQuote = null; + + if (String.class.isAssignableFrom(field.getType())) + { + startQuote = "\'"; + endQuote = startQuote; + } + else if (Number.class.isAssignableFrom(field.getType())) + { + startQuote = StringUtils.EMPTY; + endQuote = StringUtils.EMPTY; + } + + switch (securityRule.getModifier()) + { + case EQUALS : + modifier = " = "; + break; + + case NOT : + modifier = " != "; + break; + + default : + throw new IllegalArgumentException("Modifier " + securityRule.getModifier() + "not recognized."); + } + subFilterCond.append(field.getAnnotation(Column.class).name()); + subFilterCond.append(modifier); + if (StringUtils.isNotEmpty(startQuote)) + { + subFilterCond.append(startQuote); + } + subFilterCond.append(StringEscapeUtils.escapeSql(securityRule.getValue())); + if (StringUtils.isNotEmpty(endQuote)) + { + subFilterCond.append(endQuote); + } + + filterName += securityRule.getValue(); + } + filterDefCondition.append(subFilterCond); + filterDefCondition.append(")"); + } + + // filtername is unique, but untraceable + this.filterDefinition = new FilterDefinition(Integer.toString(filterName.hashCode()), filterDefCondition + .toString(), new HashMap()); + } + + /** + * @param rules + * @return + */ + private boolean rulesContainLoad(List<SecurityRule> rules) + { + for (SecurityRule rule : rules) + { + if (rule.getPermissions().contains(PermissionEnum.LOAD)) + { + return true; + } + } + return false; + } + + /** + * {@inheritDoc} + */ + public FilterDefinition getFilterDefinition() + { + return this.filterDefinition; + } + + /** + * {@inheritDoc} + */ + public String getName() + { + return this.filterDefinition.getFilterName(); + } + + /** + * {@inheritDoc} + */ + public Filter setParameter(String name, Object value) + { + return this; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Filter setParameterList(String name, Collection values) + { + return this; + } + + /** + * {@inheritDoc} + */ + public Filter setParameterList(String name, Object[] values) + { + return this; + } + + /** + * {@inheritDoc} + */ + public void validate() throws HibernateException + { + // + } + +} Deleted: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java 2008-02-21 14:57:26 UTC (rev 680) @@ -1,67 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.filter.utils.SecurityRuleUtils; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.ConfigAttributeDefinition; -import org.apache.commons.collections.Predicate; - - -/** - * @author fcarone - * @version $Id$ - */ -public class SecurityRulePredicate implements Predicate -{ - - private Authentication authentication; - - private SecurityRuleManager securityRuleManager; - - private ConfigAttributeDefinition configAttribute; - - private SecurityRuleUtils ruleUtils = new SecurityRuleUtils(); - - /** - * @param authentication The current authentication - * @param configAttribute The config attribute of the current method invocation interceptor - * @param securityRuleManager The security rule manager to retrieve rules from - */ - public SecurityRulePredicate( - Authentication authentication, - ConfigAttributeDefinition configAttribute, - SecurityRuleManager securityRuleManager) - { - this.authentication = authentication; - this.securityRuleManager = securityRuleManager; - this.configAttribute = configAttribute; - } - - /** - * {@inheritDoc} - * If we return false here, the element will be removed from the original collection. - */ - @SuppressWarnings("unchecked") - public boolean evaluate(Object object) - { - List<String> roles = ruleUtils.getRolesFromAuthentication(authentication); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(ruleUtils.getClassName(object), roles); - - // @todo: this should be configurable - // denyAll by default - if (rules == null || rules.isEmpty()) - { - return false; - } - return (ruleUtils.checkPermissions(rules, configAttribute) && ruleUtils.checkRules(rules, object)); - } - - -} Copied: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java (from rev 677, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java) =================================================================== --- tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java (rev 0) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java 2008-02-21 14:57:26 UTC (rev 680) @@ -0,0 +1,85 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.filter; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.filter.utils.SecurityRuleUtils; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.ConfigAttributeDefinition; +import org.apache.commons.collections.Predicate; +import org.apache.commons.lang.StringUtils; + + +/** + * @author fcarone + * @version $Id$ + */ +public class SecurityRulePredicate implements Predicate +{ + + private Authentication authentication; + + private SecurityRuleManager securityRuleManager; + + private ConfigAttributeDefinition configAttribute; + + private SecurityRuleUtils ruleUtils = new SecurityRuleUtils(); + + /** + * @param authentication The current authentication + * @param configAttribute The config attribute of the current method invocation interceptor + * @param securityRuleManager The security rule manager to retrieve rules from + */ + public SecurityRulePredicate( + Authentication authentication, + ConfigAttributeDefinition configAttribute, + SecurityRuleManager securityRuleManager) + { + this.authentication = authentication; + this.securityRuleManager = securityRuleManager; + this.configAttribute = configAttribute; + } + + /** + * {@inheritDoc} If we return false here, the element will be removed from the original collection. + */ + @SuppressWarnings("unchecked") + public boolean evaluate(Object object) + { + List<String> roles = ruleUtils.getRolesFromAuthentication(authentication); + List<SecurityRule> rules = findAllRules(object, roles); + + // @todo: this should be configurable + // denyAll by default + if (rules == null || rules.isEmpty()) + { + return false; + } + return (ruleUtils.checkPermissions(rules, configAttribute) && ruleUtils.checkRules(rules, object)); + } + + @SuppressWarnings("unchecked") + // @todo: needs unit test methods + private List<SecurityRule> findAllRules(Object object, List<String> roles) + { + List<SecurityRule> result = new ArrayList<SecurityRule>(); + + Class objectClass = object.getClass(); + while (!objectClass.isAssignableFrom(Object.class)) + { + result.addAll(securityRuleManager.getRulesForRoles( + StringUtils.substringBefore(objectClass.getName(), "$$"), + roles)); + + objectClass = objectClass.getSuperclass(); + } + return result; + } + +} Deleted: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java 2008-02-21 14:57:26 UTC (rev 680) @@ -1,84 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.services; - -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.util.List; - -import org.hibernate.Filter; - - -/** - * @author fcarone - * @version $Id$ - */ -public interface SecurityRuleManager -{ - - /** - * @return All the defined {@link SecurityRule}s. - */ - List<SecurityRule> findAll(); - - /** - * @param filter The {@link SecurityRule} to use as search filter - * @return The list of matching {@link SecurityRule}s. - */ - List<SecurityRule> findFiltered(SecurityRule filter); - - /** - * @param id The id of the {@link SecurityRule} to load - * @return The {@link SecurityRule} with the given id - */ - SecurityRule load(Long id); - - /** - * @param id The id of the {@link SecurityRule} to load - * @return The {@link SecurityRule} with the given id, or null if it is not found - */ - SecurityRule loadIfAvailable(Long id); - - /** - * @param id The security rule id - * @return The removed {@link SecurityRule} - */ - boolean delete(Long id); - - /** - * @param securityRule The {@link SecurityRule} to save or update - */ - void saveOrUpdate(SecurityRule securityRule); - - /** - * @param securityRule The {@link SecurityRule} to save - * @return The id of the saved {@link SecurityRule} - */ - Long save(SecurityRule securityRule); - - /** - * @param securityRule The {@link SecurityRule} to update - */ - void update(SecurityRule securityRule); - - /** - * @param entity The entity to apply rules for - * @param rules The list of rules to apply - * @return The Hibernate Filter responding to the given criteria - * @throws SecurityException - * @throws ClassNotFoundException - * @throws InstantiationException - * @throws IllegalAccessException - * @throws NoSuchFieldException - */ - public Filter getEntityFilterFromRules(String entity, List<SecurityRule> rules) throws SecurityException, - ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException; - - /** - * @param entity The entity we want rules for - * @param roles The list of roles - * @return The list of security rules matching entity - roles - */ - List<SecurityRule> getRulesForRoles(String entity, List<String> roles); -} Copied: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java (from rev 678, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java) =================================================================== --- tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java (rev 0) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java 2008-02-21 14:57:26 UTC (rev 680) @@ -0,0 +1,92 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.services; + +import it.openutils.hibernate.security.dataobject.SecurityRule; + +import java.util.List; + +import org.hibernate.Filter; + + +/** + * @author fcarone + * @version $Id$ + */ +public interface SecurityRuleManager +{ + + /** + * @return All the defined {@link SecurityRule}s. + */ + List<SecurityRule> findAll(); + + /** + * @param filter The {@link SecurityRule} to use as search filter + * @return The list of matching {@link SecurityRule}s. + */ + List<SecurityRule> findFiltered(SecurityRule filter); + + /** + * @param id The id of the {@link SecurityRule} to load + * @return The {@link SecurityRule} with the given id + */ + SecurityRule load(Long id); + + /** + * @param id The id of the {@link SecurityRule} to load + * @return The {@link SecurityRule} with the given id, or null if it is not found + */ + SecurityRule loadIfAvailable(Long id); + + /** + * @param id The security rule id + * @return The removed {@link SecurityRule} + */ + boolean delete(Long id); + + /** + * @param securityRule The {@link SecurityRule} to save or update + */ + void saveOrUpdate(SecurityRule securityRule); + + /** + * @param securityRule The {@link SecurityRule} to save + * @return The id of the saved {@link SecurityRule} + */ + Long save(SecurityRule securityRule); + + /** + * @param securityRule The {@link SecurityRule} to update + */ + void update(SecurityRule securityRule); + + /** + * @param entity The entity to apply rules for + * @param rules The list of rules to apply + * @return The Hibernate Filter responding to the given criteria + * @throws SecurityException + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws NoSuchFieldException + */ + public Filter getEntityFilterFromRules(String entity, List<SecurityRule> rules) throws SecurityException, + ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException; + + /** + * @param entity The entity name we want rules for + * @param roles The list of roles + * @return The list of security rules matching entity - roles + */ + List<SecurityRule> getRulesForRoles(String entity, List<String> roles); + + /** + * @param entity The entity we want rules for + * @param roles The list of roles + * @return The list of security rules matching entity - roles + */ + List<SecurityRule> getRulesForRoles(Object entity, List<String> roles); + +} Deleted: tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.4/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java 2008-02-21 14:57:26 UTC (rev 680) @@ -1,122 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.services.impl; - -import it.openutils.hibernate.security.dao.SecurityRuleDAO; -import ... [truncated message content] |
From: <fg...@us...> - 2008-02-21 21:03:47
|
Revision: 684 http://openutils.svn.sourceforge.net/openutils/?rev=684&view=rev Author: fgiust Date: 2008-02-21 13:03:49 -0800 (Thu, 21 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-2.0.3 Added Paths: ----------- tags/openutils-dbmigration-2.0.3/ tags/openutils-dbmigration-2.0.3/pom.xml tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleViewCreateOrUpdateTask.java tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java tags/openutils-dbmigration-2.0.3/src/site/changes/changes.xml Removed Paths: ------------- tags/openutils-dbmigration-2.0.3/pom.xml tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java tags/openutils-dbmigration-2.0.3/src/site/changes/changes.xml Copied: tags/openutils-dbmigration-2.0.3 (from rev 681, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-2.0.3/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2008-02-21 14:57:33 UTC (rev 681) +++ tags/openutils-dbmigration-2.0.3/pom.xml 2008-02-21 21:03:49 UTC (rev 684) @@ -1,96 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration</name> - <version>2.0.3-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi</artifactId> - <version>3.0-FINAL</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.3/pom.xml (from rev 683, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-2.0.3/pom.xml (rev 0) +++ tags/openutils-dbmigration-2.0.3/pom.xml 2008-02-21 21:03:49 UTC (rev 684) @@ -0,0 +1,102 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration</name> + <version>2.0.3</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>3.0-FINAL</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-2.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java 2008-02-21 14:57:33 UTC (rev 681) +++ tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java 2008-02-21 21:03:49 UTC (rev 684) @@ -1,134 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.migration.oracle; - -import it.openutils.migration.task.setup.DbTask; - -import java.text.MessageFormat; -import java.util.List; - -import javax.sql.DataSource; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; - - -/** - * Db tasks that handles the initial setup of sequences. - * @author fgiust - * @version $Id$ - */ -public class OracleSequenceCreationTask implements DbTask -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(OracleSequenceCreationTask.class); - - private List<String> sequences; - - private String creationQuery; - - private String selectUserSequences; - - private String selectAllSequences; - - private int startsWith; - - /** - * Sets the sequences. - * @param sequences the sequences to set - */ - public void setSequences(List<String> sequences) - { - this.sequences = sequences; - } - - /** - * Sets the creationQuery. - * @param creationQuery the creationQuery to set - */ - public void setCreationQuery(String creationQuery) - { - this.creationQuery = creationQuery; - } - - /** - * Sets the selectAllSequences. - * @param selectAllSequences the selectAllSequences to set - */ - public void setSelectAllSequences(String selectAllSequences) - { - this.selectAllSequences = selectAllSequences; - } - - /** - * Sets the startsWith. - * @param startsWith the startsWith to set - */ - public void setStartsWith(int startsWith) - { - this.startsWith = startsWith; - } - - /** - * Sets the selectUserSequences. - * @param selectUserSequences the selectUserSequences to set - */ - public void setSelectUserSequences(String selectUserSequences) - { - this.selectUserSequences = selectUserSequences; - } - - /** - * {@inheritDoc} - */ - public String getDescription() - { - return "Checking Sequences"; - } - - /** - * {@inheritDoc} - */ - public void execute(DataSource dataSource) - { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); - for (String sequenceName : sequences) - { - int result = 0; - - if (StringUtils.contains(sequenceName, ".")) - { - String[] tokens = StringUtils.split(sequenceName, "."); - result = jdbcTemplate.queryForInt(selectAllSequences, new Object[]{tokens[1], tokens[0]}); - } - else - { - result = jdbcTemplate.queryForInt(selectUserSequences, sequenceName); - } - - if (result <= 0) - { - log.info("Creating new {}", sequenceName); - jdbcTemplate.update(MessageFormat.format(creationQuery, new Object[]{sequenceName, startsWith})); - } - } - } -} \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java (from rev 682, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java 2008-02-21 21:03:49 UTC (rev 684) @@ -0,0 +1,145 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.migration.oracle; + +import it.openutils.migration.task.setup.DbTask; + +import java.text.MessageFormat; +import java.util.List; + +import javax.sql.DataSource; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * Db tasks that handles the initial setup of sequences. + * @author fgiust + * @version $Id$ + */ +public class OracleSequenceCreationTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OracleSequenceCreationTask.class); + + private List<String> sequences; + + private String creationQuery; + + private String dropQuery; + + private String selectUserSequences; + + private String selectAllSequences; + + private int startsWith; + + /** + * Sets the sequences. + * @param sequences the sequences to set + */ + public void setSequences(List<String> sequences) + { + this.sequences = sequences; + } + + /** + * Sets the creationQuery. + * @param creationQuery the creationQuery to set + */ + public void setCreationQuery(String creationQuery) + { + this.creationQuery = creationQuery; + } + + /** + * Sets the dropQuery. + * @param dropQuery the dropQuery to set + */ + public void setDropQuery(String dropQuery) + { + this.dropQuery = dropQuery; + } + + /** + * Sets the selectAllSequences. + * @param selectAllSequences the selectAllSequences to set + */ + public void setSelectAllSequences(String selectAllSequences) + { + this.selectAllSequences = selectAllSequences; + } + + /** + * Sets the startsWith. + * @param startsWith the startsWith to set + */ + public void setStartsWith(int startsWith) + { + this.startsWith = startsWith; + } + + /** + * Sets the selectUserSequences. + * @param selectUserSequences the selectUserSequences to set + */ + public void setSelectUserSequences(String selectUserSequences) + { + this.selectUserSequences = selectUserSequences; + } + + /** + * {@inheritDoc} + */ + public String getDescription() + { + return "Checking Sequences"; + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + for (String sequenceName : sequences) + { + int result = 0; + + if (StringUtils.contains(sequenceName, ".")) + { + String[] tokens = StringUtils.split(sequenceName, "."); + result = jdbcTemplate.queryForInt(selectAllSequences, new Object[]{tokens[1], tokens[0]}); + } + else + { + result = jdbcTemplate.queryForInt(selectUserSequences, sequenceName); + } + + if (result <= 0) + { + log.info("Creating new {}", sequenceName); + jdbcTemplate.update(MessageFormat.format(creationQuery, new Object[]{sequenceName, startsWith})); + } + } + } +} \ No newline at end of file Copied: tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleViewCreateOrUpdateTask.java (from rev 682, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleViewCreateOrUpdateTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleViewCreateOrUpdateTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/oracle/OracleViewCreateOrUpdateTask.java 2008-02-21 21:03:49 UTC (rev 684) @@ -0,0 +1,242 @@ +package it.openutils.migration.oracle; + +import it.openutils.migration.task.setup.DbTask; + +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * <p> + * Db tasks that handles the initial setup of views. + * </p> + * <p> + * Limitations: + * </p> + * <ol> + * <li> * not supported in field list</li> + * <li> fields must be enclosed in quotes</li> + * </ol> + * @author albertoq + * @version $Id$ + */ +public class OracleViewCreateOrUpdateTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OracleViewCreateOrUpdateTask.class); + + /** + * Script list to execute + */ + protected List<Resource> scripts; + + /** + * Query to verify view existence + */ + private String selectUserViewExistence; + + /** + * Query to retrieve view ddl + */ + private String selectUserViewDDL; + + /** + * Statement to drop a view + */ + private String dropView; + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + for (Resource script : scripts) + { + String viewName = this.objectNameFromFileName(script); + + int result = jdbcTemplate.queryForInt(getSelectUserViewExistence(), viewName); + + String scriptContent = readFully(script); + + if (scriptContent == null) + { + continue; + } + + if (result == 0) + { + log.info("View {} not existing. Creating new view", viewName); + + createView(jdbcTemplate, scriptContent); + } + else + { + String scriptBody = extractViewBody(scriptContent); + if (scriptBody == null) + { + continue; + } + + String previousDDl = (String) jdbcTemplate.getJdbcOperations().queryForObject( + getSelectUserViewDDL(), + new Object[]{viewName}, + String.class); + + if (!StringUtils.equals(previousDDl.trim(), scriptBody.trim())) + { + log.info( + "Previous definition of view {} differs from actual. Dropping and recreating view", + new Object[]{viewName}); + + jdbcTemplate.update(MessageFormat.format(getDropView(), new Object[]{viewName})); + + createView(jdbcTemplate, scriptContent); + } + } + } + + } + + /** + * @param script The script resource + * @return The script name + */ + protected String objectNameFromFileName(Resource script) + { + return StringUtils.substringBeforeLast(script.getFilename(), "."); + } + + /** + * @param scriptContent + * @return + */ + private String extractViewBody(String scriptContent) + { + Pattern pattern = Pattern.compile(".*\\s+AS\\s+(.*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + Matcher matcher = pattern.matcher(scriptContent); + boolean bodyFound = matcher.find(); + if (bodyFound) + { + return matcher.group(1); + } + else + { + return null; + } + } + + /** + * @param jdbcTemplate + * @param script + * @return + */ + private void createView(SimpleJdbcTemplate jdbcTemplate, String script) + { + + String[] ddls = StringUtils.split(script, ";"); + + for (String ddl : ddls) + { + if (StringUtils.isNotBlank(ddl)) + { + log.debug("Executing:\n{}", ddl); + jdbcTemplate.update(ddl); + } + } + } + + /** + * @param script + * @return + */ + private String readFully(Resource script) + { + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return null; + } + + String scriptContent; + InputStream is = null; + + try + { + is = script.getInputStream(); + scriptContent = IOUtils.toString(is, "UTF8"); + } + catch (IOException e) + { + log.error("Unable to execute db task \"{}\", script \"{}\" can't be read.", getDescription(), script); + return null; + } + finally + { + IOUtils.closeQuietly(is); + } + return scriptContent; + } + + public String getDescription() + { + return "Checking Views"; + } + + public List<Resource> getScripts() + { + return scripts; + } + + public void setScripts(List<Resource> scripts) + { + this.scripts = scripts; + } + + public String getSelectUserViewExistence() + { + return selectUserViewExistence; + } + + public void setSelectUserViewExistence(String selectUserViewExistence) + { + this.selectUserViewExistence = selectUserViewExistence; + } + + public String getSelectUserViewDDL() + { + return selectUserViewDDL; + } + + public void setSelectUserViewDDL(String selectUserViewDDL) + { + this.selectUserViewDDL = selectUserViewDDL; + } + + public String getDropView() + { + return dropView; + } + + public void setDropView(String dropView) + { + this.dropView = dropView; + } +} Deleted: tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2008-02-21 14:57:33 UTC (rev 681) +++ tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2008-02-21 21:03:49 UTC (rev 684) @@ -1,527 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.migration.task.setup; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.jdbc.core.ColumnMapRowMapper; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; - - -/** - * @author fgiust - * @version $Id$ - */ -public class ExcelConfigurationTask extends BaseDbTask implements DbTask -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); - - private Resource script; - - private Map<String, ExcelConfigurationTask.QueryConfig> config; - - /** - * If true, when a record already exists and an updated query is defined it will be updated. Set it to false to only - * insert new records. - */ - private boolean updateEnabled = true; - - /** - * Sets the script. - * @param script the script to set - */ - public void setScript(Resource script) - { - this.script = script; - } - - /** - * Sets the config. - * @param config the config to set - */ - public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) - { - this.config = config; - } - - /** - * Sets the updateEnabled. - * @param updateEnabled the updateEnabled to set - */ - public void setUpdateEnabled(boolean updateEnabled) - { - this.updateEnabled = updateEnabled; - } - - /** - * {@inheritDoc} - */ - public void execute(DataSource dataSource) - { - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - InputStream is = null; - try - { - is = script.getInputStream(); - POIFSFileSystem fs = new POIFSFileSystem(is); - HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); - int sheetNums = hssfworkbook.getNumberOfSheets(); - for (int j = 0; j < sheetNums; j++) - { - HSSFSheet sheet = hssfworkbook.getSheetAt(j); - String tableName = hssfworkbook.getSheetName(j); - - QueryConfig conf = config.get(tableName); - if (conf == null) - { - log.error("Unable to handle table {}", tableName); - continue; - } - processSheet(sheet, tableName, conf, dataSource); - - } - - } - catch (IOException e) - { - log.error(e.getMessage(), e); - } - finally - { - IOUtils.closeQuietly(is); - } - - } - - /** - * @param sheet - * @param tableName - */ - private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) - { - final List<String> columns = new ArrayList<String>(); - - HSSFRow row = sheet.getRow(0); - for (short k = 0; k < row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - if (cell != null) - { - String columnName = cell.getStringCellValue(); - if (StringUtils.isNotBlank(columnName)) - { - columns.add(StringUtils.trim(columnName)); - } - else - { - break; - } - } - } - - log.debug("Table: {}, Columns: {}", tableName, columns); - - final List<Integer> types = new ArrayList<Integer>(); - - boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - for (String column : columns) - { - ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); - if (res.next()) - { - types.add(res.getInt("DATA_TYPE")); - } - else - { - log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); - return false; - } - res.close(); - } - return true; - } - }); - - if (!result) - { - log.warn("Skipping sheet {} ", tableName); - } - - String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); - String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); - String selectStatement = StringUtils.remove(StringUtils.trim(con.getSelectQuery()), "\n"); - String updateStatement = StringUtils.remove(StringUtils.trim(con.getUpdateQuery()), "\n"); - - processRecords( - sheet, - columns, - ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), - checkStatement, - insertStatement, - selectStatement, - updateStatement, - dataSource, - tableName); - } - - /** - * @param sheet - * @param columns - * @param checkStatement - * @param insertStatement - * @param updateStatement - * @param selectStatement - */ - @SuppressWarnings("unchecked") - private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, - String insertStatement, String selectStatement, String updateStatement, DataSource dataSource, String tableName) - { - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - int checkNum = StringUtils.countMatches(checkStatement, "?"); - int insertNum = StringUtils.countMatches(insertStatement, "?"); - int selectNum = StringUtils.countMatches(selectStatement, "?"); - int updateNum = StringUtils.countMatches(updateStatement, "?"); - - HSSFRow row; - for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) - { - row = sheet.getRow(rowNum); - if (row == null) - { - return; - } - - List<String> values = new ArrayList<String>(); - - for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - String value = null; - - if (cell == null) - { - value = StringUtils.EMPTY; - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) - { - value = cell.getStringCellValue(); - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) - { - double valueDouble = cell.getNumericCellValue(); - // when need to really check if it is a double or an int - double fraction = valueDouble % 1; - if (fraction == 0) - { - value = Integer.toString((int) valueDouble); - } - else - { - value = Double.toString(valueDouble); - } - } - - if (StringUtils.isEmpty(value)) - { - value = StringUtils.EMPTY; - } - - if ("<NULL>".equalsIgnoreCase(value)) - { - value = null; - } - - values.add(value); - } - - Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); - for (int i = 0; i < checkParams.length; i++) - { - if (StringUtils.isEmpty((String) checkParams[i])) - { - return; - } - } - - int existing; - try - { - existing = jdbcTemplate.queryForInt(checkStatement, checkParams); - } - catch (BadSqlGrammarException bsge) - { - log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge - .getMessage(), checkStatement); - return; - } - - if (existing == 0) - { - Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); - int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); - if (log.isDebugEnabled()) - { - log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils - .toString(insertParams)); - } - - if (insertParams.length != insertTypes.length) - { - log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ - tableName, - insertParams.length, - insertTypes.length }); - } - - try - { - jdbcTemplate.update(insertStatement, insertParams, insertTypes); - } - catch (DataIntegrityViolationException bsge) - { - log - .error( - "Error executing update, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", - new Object[]{ - tableName, - rowNum + 1, - insertStatement, - ArrayUtils.toString(insertParams), - bsge.getMessage() }); - continue; - } - } - else if (updateEnabled - && StringUtils.isNotBlank(updateStatement) - && StringUtils.isNotBlank(selectStatement)) - { - try - { - RowMapper rowMapper = new ColumnMapRowMapper(); - Object[] selectParams = ArrayUtils.subarray(values.toArray(), 0, selectNum); - List<Map<String, Object>> selectResult = jdbcTemplate.query( - selectStatement, - selectParams, - rowMapper); - Map<String, Object> fetchedColumns = selectResult.get(0); - int i = 0; - boolean updateNeeded = false; - for (String columnName : columns) - { - Object columnObject = fetchedColumns.get(columnName); - if (columnObject == null) - { - continue; - } - String columnValue = ObjectUtils.toString(fetchedColumns.get(columnName)); - if (!StringUtils.equals(columnValue, values.get(i))) - { - updateNeeded = true; - break; - } - i++; - } - if (updateNeeded) - { - Object[] updateParams = ArrayUtils.subarray(values.toArray(), 0, updateNum); - int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); - if (log.isDebugEnabled()) - { - log.debug( - "Missing record with key {}; updating {}", - ArrayUtils.toString(checkParams), - ArrayUtils.toString(updateParams)); - } - - if (updateParams.length != insertTypes.length) - { - log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ - tableName, - updateParams.length, - insertTypes.length }); - } - - try - { - Object[] compoundUpdateParams = new Object[checkParams.length + updateParams.length]; - System.arraycopy(updateParams, 0, compoundUpdateParams, 0, updateParams.length); - System.arraycopy( - checkParams, - 0, - compoundUpdateParams, - compoundUpdateParams.length - 1, - checkParams.length); - jdbcTemplate.update(updateStatement, compoundUpdateParams); - } - catch (DataIntegrityViolationException bsge) - { - log - .error( - "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", - new Object[]{ - tableName, - rowNum + 1, - insertStatement, - ArrayUtils.toString(updateParams), - bsge.getMessage() }); - continue; - } - } - } - catch (BadSqlGrammarException bsge) - { - log - .error( - "Error executing query to load row values, current possible update of row will be skipped. {} Query in error: {}", - bsge.getMessage(), - checkStatement); - return; - } - // 1 check if it is the same - // 2 update only if they differ - } - - } - } - - /** - * @author fgiust - * @version $Id$ - */ - public static class QueryConfig - { - - private String checkQuery; - - private String insertQuery; - - private String selectQuery; - - private String updateQuery; - - /** - * Returns the selectQuery. - * @return the selectQuery - */ - public String getSelectQuery() - { - return selectQuery; - } - - /** - * Sets the selectQuery. - * @param selectQuery the selectQuery to set - */ - public void setSelectQuery(String selectQuery) - { - this.selectQuery = selectQuery; - } - - /** - * Returns the checkQuery. - * @return the checkQuery - */ - public String getCheckQuery() - { - return checkQuery; - } - - /** - * Sets the checkQuery. - * @param checkQuery the checkQuery to set - */ - public void setCheckQuery(String checkQuery) - { - this.checkQuery = checkQuery; - } - - /** - * Returns the insertQuery. - * @return the insertQuery - */ - public String getInsertQuery() - { - return insertQuery; - } - - /** - * Sets the insertQuery. - * @param insertQuery the insertQuery to set - */ - public void setInsertQuery(String insertQuery) - { - this.insertQuery = insertQuery; - } - - /** - * Returns the updateQuery. - * @return the updateQuery - */ - public String getUpdateQuery() - { - return updateQuery; - } - - /** - * Sets the updateQuery. - * @param updateQuery the updateQuery to set - */ - public void setUpdateQuery(String updateQuery) - { - this.updateQuery = updateQuery; - } - } -} Copied: tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (from rev 682, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java) =================================================================== --- tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (rev 0) +++ tags/openutils-dbmigration-2.0.3/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2008-02-21 21:03:49 UTC (rev 684) @@ -0,0 +1,667 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.migration.task.setup; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.core.ColumnMapRowMapper; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ExcelConfigurationTask extends BaseDbTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); + + private Resource script; + + private Map<String, ExcelConfigurationTask.QueryConfig> config; + + /** + * Enable this task. + */ + private boolean enabled = true; + + /** + * If true, when a record already exists and an updated query is defined it will be updated. Set it to false to only + * insert new records. + */ + private boolean updateEnabled = true; + + /** + * Date format for ISO dates + */ + private SimpleDateFormat isodateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + + /** + * Sets the script. + * @param script the script to set + */ + public void setScript(Resource script) + { + this.script = script; + } + + /** + * Sets the config. + * @param config the config to set + */ + public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) + { + this.config = config; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + /** + * Sets the updateEnabled. + * @param updateEnabled the updateEnabled to set + */ + public void setUpdateEnabled(boolean updateEnabled) + { + this.updateEnabled = updateEnabled; + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + if (!enabled) + { + return; + } + + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + InputStream is = null; + try + { + is = script.getInputStream(); + POIFSFileSystem fs = new POIFSFileSystem(is); + HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); + int sheetNums = hssfworkbook.getNumberOfSheets(); + for (int j = 0; j < sheetNums; j++) + { + HSSFSheet sheet = hssfworkbook.getSheetAt(j); + String tableName = hssfworkbook.getSheetName(j); + + QueryConfig conf = config.get(tableName); + if (conf == null) + { + suggestSheetConfig(sheet, tableName, conf, dataSource); + continue; + } + processSheet(sheet, tableName, conf, dataSource); + + } + + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + finally + { + IOUtils.closeQuietly(is); + } + + } + + public void suggestSheetConfig(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) + { + log.error("Unable to handle table {}", tableName); + + if (!log.isDebugEnabled()) + { + return; + } + + final List<String> columns = new ArrayList<String>(); + + HSSFRow row = sheet.getRow(0); + for (short k = 0; k < row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + if (cell != null) + { + String columnName = cell.getStringCellValue(); + if (StringUtils.isNotBlank(columnName)) + { + columns.add(StringUtils.trim(columnName)); + } + else + { + break; + } + } + } + + if (columns.isEmpty()) + { + return; + } + + StringBuffer buffer = new StringBuffer(); + + buffer.append(" <entry key=\""); + buffer.append(tableName); + buffer.append("\">\n" + + " <bean class=\"it.openutils.migration.task.setup.ExcelConfigurationTask$QueryConfig\">\n" + + " <property name=\"checkQuery\">\n" + + " <value>"); + + String initialCol = columns.get(0); + buffer.append("select count(" + initialCol + ") from " + tableName + " where " + initialCol + " = ?"); + buffer.append("</value>\n" + + " </property>\n" + + " <property name=\"insertQuery\">\n" + + " <value>"); + + buffer.append("INSERT INTO "); + buffer.append(tableName); + buffer.append(" ("); + + StringBuffer colNames = new StringBuffer(); + StringBuffer parNames = new StringBuffer(); + + for (Iterator<String> iterator = columns.iterator(); iterator.hasNext();) + { + String string = iterator.next(); + colNames.append(string); + parNames.append("?"); + if (iterator.hasNext()) + { + colNames.append(", "); + parNames.append(", "); + } + + } + + buffer.append(colNames); + buffer.append(") VALUES ("); + buffer.append(parNames); + buffer.append(")"); + buffer.append("</value>\n" + " </property>\n" + " </bean>\n" + " </entry>"); + + log.debug("You can use the following suggested config as template:\n{}", buffer.toString()); + } + + /** + * @param sheet + * @param tableName + */ + private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) + { + final List<String> columns = new ArrayList<String>(); + + HSSFRow row = sheet.getRow(0); + for (short k = 0; k < row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + if (cell != null) + { + String columnName = cell.getStringCellValue(); + if (StringUtils.isNotBlank(columnName)) + { + columns.add(StringUtils.trim(columnName)); + } + else + { + break; + } + } + } + + log.debug("Table: {}, Columns: {}", tableName, columns); + + final List<Integer> types = new ArrayList<Integer>(); + + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + for (String column : columns) + { + ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); + if (res.next()) + { + types.add(res.getInt("DATA_TYPE")); + } + else + { + log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); + return false; + } + res.close(); + } + return true; + } + }); + + if (!result) + { + log.warn("Skipping sheet {} ", tableName); + } + + String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); + String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); + String selectStatement = StringUtils.remove(StringUtils.trim(con.getSelectQuery()), "\n"); + String updateStatement = StringUtils.remove(StringUtils.trim(con.getUpdateQuery()), "\n"); + + processRecords( + sheet, + columns, + ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), + checkStatement, + insertStatement, + selectStatement, + updateStatement, + dataSource, + tableName); + } + + /** + * @param sheet + * @param columns + * @param checkStatement + * @param insertStatement + * @param updateStatement + * @param selectStatement + */ + @SuppressWarnings("unchecked") + private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, + String insertStatement, String selectStatement, String updateStatement, DataSource dataSource, String tableName) + { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + int checkNum = StringUtils.countMatches(checkStatement, "?"); + int insertNum = StringUtils.countMatches(insertStatement, "?"); + int selectNum = StringUtils.countMatches(selectStatement, "?"); + int updateNum = StringUtils.countMatches(updateStatement, "?"); + + HSSFRow row; + for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) + { + row = sheet.getRow(rowNum); + if (row == null) + { + return; + } + + List<String> values = new ArrayList<String>(); + + for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + String value = null; + + if (cell == null) + { + value = StringUtils.EMPTY; + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) + { + value = cell.getStringCellValue(); + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) + { + double valueDouble = cell.getNumericCellValue(); + // when need to really check if it is a double or an int + double fraction = valueDouble % 1; + if (fraction == 0) + { + value = Integer.toString((int) valueDouble); + } + else + { + value = Double.toString(valueDouble); + } + } + + if (StringUtils.isEmpty(value)) + { + value = StringUtils.EMPTY; + } + + if ("<NULL>".equalsIgnoreCase(value)) + { + value = null; + } + + values.add(value); + } + + Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); + for (int i = 0; i < checkParams.length; i++) + { + if (StringUtils.isEmpty((String) checkParams[i])) + { + return; + } + } + + int existing; + try + { + existing = jdbcTemplate.queryForInt(checkStatement, checkParams); + } + catch (BadSqlGrammarException bsge) + { + log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge + .getMessage(), checkStatement); + return; + } + + if (existing == 0) + { + Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + + // empty strings must be converted to nulls if the columns is numeric or date + // Cannot convert class java.lang.String to SQL type requested due to java.lang.NumberFormatException - + // For input string: "" + for (int j = 0; j < insertTypes.length; j++) + { + int tip = insertTypes[j]; + if (tip != Types.CHAR + && tip != Types.LONGNVARCHAR + && tip != Types.LONGVARCHAR + && tip != Types.NCHAR + && tip != Types.NVARCHAR + && tip != Types.VARCHAR + && "".equals(insertParams[j])) + { + insertParams[j] = null; + } + + if (tip == Types.DATE || tip == Types.TIME || tip == Types.TIMESTAMP && insertParams[j] != null) + { + synchronized (isodateformat) + { + try + { + insertParams[j] = isodateformat.parse((String) insertParams[j]); + } + catch (ParseException e) + { + log.debug("Cannot parse date \"{}\"", insertParams[j]); + } + } + } + } + + if (log.isDebugEnabled()) + { + log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils + .toString(insertParams)); + } + + if (insertParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + insertParams.length, + insertTypes.length}); + } + + try + { + jdbcTemplate.update(insertStatement, insertParams, insertTypes); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing update, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(insertParams), + bsge.getMessage()}); + continue; + } + } + else if (updateEnabled + && StringUtils.isNotBlank(updateStatement) + && StringUtils.isNotBlank(selectStatement)) + { + try + { + RowMapper rowMapper = new ColumnMapRowMapper(); + Object[] selectParams = ArrayUtils.subarray(values.toArray(), 0, selectNum); + List<Map<String, Object>> selectResult = jdbcTemplate.query( + selectStatement, + selectParams, + rowMapper); + Map<String, Object> fetchedColumns = selectResult.get(0); + int i = 0; + boolean updateNeeded = false; + for (String columnName : columns) + ... [truncated message content] |
From: <fc...@us...> - 2008-02-25 14:08:27
|
Revision: 698 http://openutils.svn.sourceforge.net/openutils/?rev=698&view=rev Author: fcarone Date: 2008-02-25 06:08:00 -0800 (Mon, 25 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-hibernate-security-0.0.5 Added Paths: ----------- tags/openutils-hibernate-security-0.0.5/ tags/openutils-hibernate-security-0.0.5/pom.xml tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.5/src/site/apt/ tags/openutils-hibernate-security-0.0.5/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.5/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.5/src/test/resources/spring-security.xml Removed Paths: ------------- tags/openutils-hibernate-security-0.0.5/pom.xml tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.5/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.5/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.5/src/test/resources/spring-security.xml Copied: tags/openutils-hibernate-security-0.0.5 (from rev 673, trunk/openutils-hibernate-security) Deleted: tags/openutils-hibernate-security-0.0.5/pom.xml =================================================================== --- trunk/openutils-hibernate-security/pom.xml 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/pom.xml 2008-02-25 14:08:00 UTC (rev 698) @@ -1,223 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>openutils</artifactId> - <groupId>net.sourceforge.openutils</groupId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-hibernate-security</artifactId> - <name>openutils hibernate security</name> - <version>0.0.4-SNAPSHOT</version> - <description>Hibernate Security classes</description> - <properties> - <spring.version>2.5.1</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <!-- already imported cglib-nodep by spring --> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.5.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <artifactId>spring-remoting</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-jdbc</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-support</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>1.8.0.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-hibernate-security-0.0.5/pom.xml (from rev 697, trunk/openutils-hibernate-security/pom.xml) =================================================================== --- tags/openutils-hibernate-security-0.0.5/pom.xml (rev 0) +++ tags/openutils-hibernate-security-0.0.5/pom.xml 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,229 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-hibernate-security</artifactId> + <name>openutils hibernate security</name> + <version>0.0.5</version> + <description>Hibernate Security classes</description> + <properties> + <spring.version>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <!-- already imported cglib-nodep by spring --> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.5.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <artifactId>spring-remoting</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-support</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.8.0.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.5</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.5</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-hibernate-security-0.0.5</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,154 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.aop; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.ArrayList; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.context.SecurityContextHolder; -import org.apache.commons.lang.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Filter; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -@Aspect -public class AOPSecurity -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AOPSecurity.class); - - private SecurityRuleManager securityRuleManager; - - private List<String> securedDAOs; - - private boolean enabled; - - /** - * @param pjp The proceeding joinpoint - * @param filter The entity we are going to filter - * @param additionalCriteria The additional criteria list, cannot be null - * @return The execution invocation result - * @throws Throwable Any exception occurring in the invoked method - */ - @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " - + // - " args(filter, .., additionalCriteria)") - public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) - throws Throwable - { - if (!enabled) - { - log.debug("DAO security disabled, proceeding."); - return pjp.proceed(); - } - - if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) - { - log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); - return pjp.proceed(); - } - - log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) - { - throw new SecurityException("Authentication is not valid"); - } - GrantedAuthority[] authorities = authentication.getAuthorities(); - List<String> roles = new ArrayList<String>(); - for (int i = 0; i < authorities.length; i++) - { - roles.add(authorities[i].getAuthority()); - } - - String entity = filter.getClass().getCanonicalName(); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); - - if (rules.isEmpty()) - { - if (log.isWarnEnabled()) - { - String grantedRoles = StringUtils.EMPTY; - for (int i = 0; i < authorities.length; i++) - { - grantedRoles += authorities[i].getAuthority() + " "; - } - log.warn( - "No rules found. Access is denied on " + entity + ", for user {} with roles {}", - SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), - grantedRoles); - } - throw new SecurityException("Access denied"); - } - - Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); - - Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter - .getFilterDefinition() - .getDefaultFilterCondition()); - - log.debug("Adding sql restriction: {}", sqlCriterion.toString()); - additionalCriteria.add(sqlCriterion); - - Object result = pjp.proceed(); - return result; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - - /** - * Sets the securedDAOs. - * @param securedDAOs the securedDAOs to set - */ - public void setSecuredDAOs(List<String> securedDAOs) - { - this.securedDAOs = securedDAOs; - } - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (from rev 687, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,175 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.aop; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.context.SecurityContextHolder; +import org.apache.commons.lang.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.hibernate.Filter; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id$ + */ +@Aspect +public class AOPSecurity +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AOPSecurity.class); + + private boolean denyIfNoRulesFound = true; + + private SecurityRuleManager securityRuleManager; + + private List<String> securedDAOs; + + private boolean enabled; + + /** + * @param pjp The proceeding joinpoint + * @param filter The entity we are going to filter + * @param additionalCriteria The additional criteria list, cannot be null + * @return The execution invocation result + * @throws Throwable Any exception occurring in the invoked method + */ + @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " + + // + " args(filter, .., additionalCriteria)") + public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) + throws Throwable + { + if (!enabled) + { + log.debug("DAO security disabled, proceeding."); + return pjp.proceed(); + } + + if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) + { + log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); + return pjp.proceed(); + } + + log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) + { + throw new SecurityException("Authentication is not valid"); + } + GrantedAuthority[] authorities = authentication.getAuthorities(); + List<String> roles = new ArrayList<String>(); + for (int i = 0; i < authorities.length; i++) + { + roles.add(authorities[i].getAuthority()); + } + + String entity = filter.getClass().getCanonicalName(); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(filter, roles); + + if (rules.isEmpty()) + { + if (log.isWarnEnabled()) + { + String grantedRoles = StringUtils.EMPTY; + for (int i = 0; i < authorities.length; i++) + { + grantedRoles += authorities[i].getAuthority() + " "; + } + log.warn( + "No rules found for " + entity + ", user {} with roles {}", + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), + grantedRoles); + } + if (denyIfNoRulesFound) + { + log.debug("denyIfNoRulesFound is true, denying access."); + throw new SecurityException("Access denied"); + } + else + { + log.debug("denyIfNoRulesFound is false, allowing access."); + return pjp.proceed(); + } + } + + Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); + + Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter + .getFilterDefinition() + .getDefaultFilterCondition()); + + log.debug("Adding sql restriction: {}", sqlCriterion.toString()); + additionalCriteria.add(sqlCriterion); + + Object result = pjp.proceed(); + return result; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } + + /** + * Sets the securedDAOs. + * @param securedDAOs the securedDAOs to set + */ + public void setSecuredDAOs(List<String> securedDAOs) + { + this.securedDAOs = securedDAOs; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + + /** + * Sets the denyIfNoRulesFound. + * @param denyIfNoRulesFound the denyIfNoRulesFound to set + */ + public void setDenyIfNoRulesFound(boolean denyIfNoRulesFound) + { + this.denyIfNoRulesFound = denyIfNoRulesFound; + } +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,17 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao; - -import it.openutils.dao.hibernate.HibernateDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> -{ - -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,29 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao; + +import it.openutils.dao.hibernate.HibernateDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> +{ + +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,27 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao.impl; - -import it.openutils.dao.hibernate.HibernateDAOImpl; -import it.openutils.hibernate.security.dao.SecurityRuleDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO -{ - - /** - * {@inheritDoc} - */ - @Override - protected Class<SecurityRule> getReferenceClass() - { - return SecurityRule.class; - } - -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,39 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao.impl; + +import it.openutils.dao.hibernate.HibernateDAOImpl; +import it.openutils.hibernate.security.dao.SecurityRuleDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO +{ + + /** + * {@inheritDoc} + */ + @Override + protected Class<SecurityRule> getReferenceClass() + { + return SecurityRule.class; + } + +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum ModifierEnum { - - /** - * Equals - */ - EQUALS("equals"), - - /** - * Not - */ - NOT("not"); - - private String value; - - /** - * @param value The literal value of the modifier - */ - ModifierEnum(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum ModifierEnum { + + /** + * Equals + */ + EQUALS("equals"), + + /** + * Not + */ + NOT("not"); + + private String value; + + /** + * @param value The literal value of the modifier + */ + ModifierEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum PermissionEnum { - - /** - * Load, Create, Modify, Delete permissions - */ - LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); - - private String value; - - /** - * @param value The literal value for the needed enumeration object - */ - PermissionEnum(String value) - { - this.value = value; - } - - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum PermissionEnum { + + /** + * Load, Create, Modify, Delete permissions + */ + LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); + + private String value; + + /** + * @param value The literal value for the needed enumeration object + */ + PermissionEnum(String value) + { + this.value = value; + } + + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,212 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -import java.io.Serializable; -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Table; - -import org.hibernate.annotations.CollectionOfElements; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.apache.commons.lang.builder.ToStringBuilder; - - -/** - * @author fcarone - * @version $Id$ A security rule - */ -@Entity -@Table(name = "SECURITY_RULE") -public class SecurityRule implements Serializable -{ - - /** - * Generated serial version UID - */ - private static final long serialVersionUID = -4820683448073404349L; - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "ID_SECURITY_RULE") - private Long id; - - @Column(name = "ROLE", length = 64, nullable = false) - private String role; - - @Column(name = "ENTITY", length = 512, nullable = false) - private String entity; - - @Column(name = "PROPERTY", length = 512, nullable = false) - private String property; - - @Column(name = "VALUE", nullable = false) - private String value; - - @Enumerated(EnumType.STRING) - @Column(name = "MODIFIER", nullable = false) - private ModifierEnum modifier; - - @CollectionOfElements(fetch = FetchType.EAGER) - @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) - @Column(name = "PERMISSION", nullable = false) - @Enumerated(EnumType.STRING) - @Fetch(FetchMode.SUBSELECT) - private List<PermissionEnum> permissions; - - /** - * Returns the role. - * @return the role - */ - public String getRole() - { - return role; - } - - /** - * Sets the role. - * @param role the role to set - */ - public void setRole(String role) - { - this.role = role; - } - - /** - * Returns the entity. - * @return the entity - */ - public String getEntity() - { - return entity; - } - - /** - * Sets the entity. - * @param entity the entity to set - */ - public void setEntity(String entity) - { - this.entity = entity; - } - - /** - * Returns the property. - * @return the property - */ - public String getProperty() - { - return property; - } - - /** - * Sets the property. - * @param property the property to set - */ - public void setProperty(String property) - { - this.property = property; - } - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - - /** - * Sets the value. - * @param value the value to set - */ - public void setValue(String value) - { - this.value = value; - } - - /** - * Returns the modifier. - * @return the modifier - */ - public ModifierEnum getModifier() - { - return modifier; - } - - /** - * Sets the modifier. - * @param modifier the modifier to set - */ - public void setModifier(ModifierEnum modifier) - { - this.modifier = modifier; - } - - /** - * Returns the permissions. - * @return the permissions - */ - public List<PermissionEnum> getPermissions() - { - return permissions; - } - - /** - * Sets the permissions. - * @param permissions the permissions to set - */ - public void setPermissions(List<PermissionEnum> permissions) - { - this.permissions = permissions; - } - - /** - * Returns the id. - * @return the id - */ - public Long getId() - { - return id; - } - - /** - * Sets the id. - * @param id the id to set - */ - public void setId(Long id) - { - this.id = id; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return new ToStringBuilder(this) - .append("id", this.id) - .append("role", this.role) - .append("entity", this.entity) - .append("property", this.property) - .append("value", this.value) - .append("modifier", this.modifier) - .append("permissions", this.permissions) - .toString(); - } - -} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (from rev 696, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,301 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.dataobject; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Table; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.FilterDefs; +import org.hibernate.annotations.Filters; +import org.apache.commons.lang.builder.ToStringBuilder; + + +/** + * @author fcarone + * @version $Id$ A security rule + */ +@Entity +@Table(name = "SECURITY_RULE") +@FilterDefs({@FilterDef(name = "notDeletedRules", defaultCondition = "DELETED != '1'") }) +@Filters({@Filter(name = "notDeletedRules") }) +public class SecurityRule implements Serializable +{ + + /** + * Generated serial version UID + */ + private static final long serialVersionUID = -4820683448073404349L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID_SECURITY_RULE") + private Long id; + + @Column(name = "ROLE", length = 64, nullable = false) + private String role; + + @Column(name = "ENTITY", length = 512, nullable = false) + private String entity; + + @Column(name = "PROPERTY", length = 512, nullable = false) + private String property; + + @Column(name = "VALUE", nullable = false) + private String value; + + @Enumerated(EnumType.STRING) + @Column(name = "MODIFIER", nullable = false) + private ModifierEnum modifier; + + @CollectionOfElements(fetch = FetchType.EAGER) + @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "PERMISSION", nullable = false) + @Enumerated(EnumType.STRING) + @Fetch(FetchMode.SUBSELECT) + private List<PermissionEnum> permissions; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private StatusEnum status; + + @Column(name = "DELETED", length = 1, nullable = false) + private Boolean deleted; + + @CollectionOfElements(fetch = FetchType.EAGER) + @org.hibernate.annotations.MapKey(columns = @Column(name = "NAME")) + @JoinTable(name = "SECRULE_ENTITY", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "VALUE", length = 256) + @Fetch(FetchMode.SUBSELECT) + private Map<String, String> entities; + + /** + * Returns the role. + * @return the role + */ + public String getRole() + { + return role; + } + + /** + * Sets the role. + * @param role the role to set + */ + public void setRole(String role) + { + this.role = role; + } + + /** + * Returns the entity. + * @return the entity + */ + public String getEntity() + { + return entity; + } + + /** + * Sets the entity. + * @param entity the entity to set + */ + public void setEntity(String entity) + { + this.entity = entity; + } + + /** + * Returns the property. + * @return the property + */ + public String getProperty() + { + return property; + } + + /** + * Sets the property. + * @param property the property to set + */ + public void setProperty(String property) + { + this.property = property; + } + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + + /** + * Sets the value. + * @param value the value to set + */ + public void setValue(String value) + { + this.value = value; + } + + /** + * Returns the modifier. + * @return the modifier + */ + public ModifierEnum getModifier() + { + return modifier; + } + + /** + * Sets the modifier. + * @param modifier the modifier to set + */ + public void setModifier(ModifierEnum modifier) + { + this.modifier = modifier; + } + + /** + * Returns the permissions. + * @return the permissions + */ + public List<PermissionEnum> getPermissions() + { + return permissions; + } + + /** + * Sets the permissions. + * @param permissions the permissions to set + */ + public void setPermissions(List<PermissionEnum> permissions) + { + this.permissions = permissions; + } + + /** + * Returns the id. + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * Sets the id. + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return new ToStringBuilder(this) + .append("id", this.id) + .append("role", this.role) + .append("entity", this.entity) + .append("property", this.property) + .append("value", this.value) + .append("modifier", this.modifier) + .append("permissions", this.permissions) + .toString(); + } + + /** + * Returns the status. + * @return the status + */ + public StatusEnum getStatus() + { + return status; + } + + /** + * Sets the status. + * @param status the status to set + */ + public void setStatus(StatusEnum status) + { + this.status = status; + } + + /** + * @return True if the rule is enabled + */ + public boolean isEnabled() + { + if (status == null) + { + return false; + } + return status.equals(StatusEnum.ENABLED); + } + + /** + * Returns the entities. + * @return the entities + */ + public Map<String, String> getEntities() + { + return entities; + } + + /** + * Sets the entities. + * @param entities the entities to set + */ + public void setEntities(Map<String, String> entities) + { + this.entities = entities; + } + + + /** + * Returns the deleted. + * @return the deleted + */ + public Boolean getDeleted() + { + return deleted; + } + + + /** + * Sets the deleted. + * @param deleted the deleted to set + */ + public void setDeleted(Boolean deleted) + { + this.deleted = deleted; + } + +} Copied: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (from rev 688, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java 2008-02-25 14:08:00 UTC (rev 698) @@ -0,0 +1,46 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + + +/** + * @author fcarone + * @version $Id: $ + */ +public enum StatusEnum { + + /** + * Enabled + */ + ENABLED("enabled"), + + /** + * Disabled + */ + DISABLED("disabled"); + + private String value; + + private StatusEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} Deleted: tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.5/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-25 14:08:00 UTC (rev 698) @@ -1,258 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.PermissionEnum; -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Filter; -import org.hibernate.HibernateException; -import org.hibernate.engine.FilterDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -public class JavaBeanFilter implements Filter -{ - - private FilterDefinitio... [truncated message content] |
From: <fc...@us...> - 2008-02-26 10:56:51
|
Revision: 705 http://openutils.svn.sourceforge.net/openutils/?rev=705&view=rev Author: fcarone Date: 2008-02-26 02:56:55 -0800 (Tue, 26 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-hibernate-security-0.0.6 Added Paths: ----------- tags/openutils-hibernate-security-0.0.6/ tags/openutils-hibernate-security-0.0.6/pom.xml tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.6/src/site/apt/ tags/openutils-hibernate-security-0.0.6/src/site/apt/index.apt tags/openutils-hibernate-security-0.0.6/src/site/apt/rbac-acegi.apt tags/openutils-hibernate-security-0.0.6/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.6/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.6/src/test/resources/spring-security.xml Removed Paths: ------------- tags/openutils-hibernate-security-0.0.6/pom.xml tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.6/src/site/apt/index.apt tags/openutils-hibernate-security-0.0.6/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.6/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.6/src/test/resources/spring-security.xml Copied: tags/openutils-hibernate-security-0.0.6 (from rev 673, trunk/openutils-hibernate-security) Deleted: tags/openutils-hibernate-security-0.0.6/pom.xml =================================================================== --- trunk/openutils-hibernate-security/pom.xml 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/pom.xml 2008-02-26 10:56:55 UTC (rev 705) @@ -1,223 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>openutils</artifactId> - <groupId>net.sourceforge.openutils</groupId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-hibernate-security</artifactId> - <name>openutils hibernate security</name> - <version>0.0.4-SNAPSHOT</version> - <description>Hibernate Security classes</description> - <properties> - <spring.version>2.5.1</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <!-- already imported cglib-nodep by spring --> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.5.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <artifactId>spring-remoting</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-jdbc</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-support</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>1.8.0.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-hibernate-security-0.0.6/pom.xml (from rev 704, trunk/openutils-hibernate-security/pom.xml) =================================================================== --- tags/openutils-hibernate-security-0.0.6/pom.xml (rev 0) +++ tags/openutils-hibernate-security-0.0.6/pom.xml 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,229 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-hibernate-security</artifactId> + <name>openutils hibernate security</name> + <version>0.0.6</version> + <description>Hibernate Security classes</description> + <properties> + <spring.version>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <!-- already imported cglib-nodep by spring --> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.5.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <artifactId>spring-remoting</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-support</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.8.0.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.6</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.6</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-hibernate-security-0.0.6</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,154 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.aop; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.ArrayList; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.context.SecurityContextHolder; -import org.apache.commons.lang.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Filter; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -@Aspect -public class AOPSecurity -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AOPSecurity.class); - - private SecurityRuleManager securityRuleManager; - - private List<String> securedDAOs; - - private boolean enabled; - - /** - * @param pjp The proceeding joinpoint - * @param filter The entity we are going to filter - * @param additionalCriteria The additional criteria list, cannot be null - * @return The execution invocation result - * @throws Throwable Any exception occurring in the invoked method - */ - @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " - + // - " args(filter, .., additionalCriteria)") - public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) - throws Throwable - { - if (!enabled) - { - log.debug("DAO security disabled, proceeding."); - return pjp.proceed(); - } - - if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) - { - log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); - return pjp.proceed(); - } - - log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) - { - throw new SecurityException("Authentication is not valid"); - } - GrantedAuthority[] authorities = authentication.getAuthorities(); - List<String> roles = new ArrayList<String>(); - for (int i = 0; i < authorities.length; i++) - { - roles.add(authorities[i].getAuthority()); - } - - String entity = filter.getClass().getCanonicalName(); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); - - if (rules.isEmpty()) - { - if (log.isWarnEnabled()) - { - String grantedRoles = StringUtils.EMPTY; - for (int i = 0; i < authorities.length; i++) - { - grantedRoles += authorities[i].getAuthority() + " "; - } - log.warn( - "No rules found. Access is denied on " + entity + ", for user {} with roles {}", - SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), - grantedRoles); - } - throw new SecurityException("Access denied"); - } - - Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); - - Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter - .getFilterDefinition() - .getDefaultFilterCondition()); - - log.debug("Adding sql restriction: {}", sqlCriterion.toString()); - additionalCriteria.add(sqlCriterion); - - Object result = pjp.proceed(); - return result; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - - /** - * Sets the securedDAOs. - * @param securedDAOs the securedDAOs to set - */ - public void setSecuredDAOs(List<String> securedDAOs) - { - this.securedDAOs = securedDAOs; - } - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (from rev 687, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,175 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.aop; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.context.SecurityContextHolder; +import org.apache.commons.lang.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.hibernate.Filter; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id$ + */ +@Aspect +public class AOPSecurity +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AOPSecurity.class); + + private boolean denyIfNoRulesFound = true; + + private SecurityRuleManager securityRuleManager; + + private List<String> securedDAOs; + + private boolean enabled; + + /** + * @param pjp The proceeding joinpoint + * @param filter The entity we are going to filter + * @param additionalCriteria The additional criteria list, cannot be null + * @return The execution invocation result + * @throws Throwable Any exception occurring in the invoked method + */ + @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " + + // + " args(filter, .., additionalCriteria)") + public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) + throws Throwable + { + if (!enabled) + { + log.debug("DAO security disabled, proceeding."); + return pjp.proceed(); + } + + if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) + { + log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); + return pjp.proceed(); + } + + log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) + { + throw new SecurityException("Authentication is not valid"); + } + GrantedAuthority[] authorities = authentication.getAuthorities(); + List<String> roles = new ArrayList<String>(); + for (int i = 0; i < authorities.length; i++) + { + roles.add(authorities[i].getAuthority()); + } + + String entity = filter.getClass().getCanonicalName(); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(filter, roles); + + if (rules.isEmpty()) + { + if (log.isWarnEnabled()) + { + String grantedRoles = StringUtils.EMPTY; + for (int i = 0; i < authorities.length; i++) + { + grantedRoles += authorities[i].getAuthority() + " "; + } + log.warn( + "No rules found for " + entity + ", user {} with roles {}", + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), + grantedRoles); + } + if (denyIfNoRulesFound) + { + log.debug("denyIfNoRulesFound is true, denying access."); + throw new SecurityException("Access denied"); + } + else + { + log.debug("denyIfNoRulesFound is false, allowing access."); + return pjp.proceed(); + } + } + + Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); + + Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter + .getFilterDefinition() + .getDefaultFilterCondition()); + + log.debug("Adding sql restriction: {}", sqlCriterion.toString()); + additionalCriteria.add(sqlCriterion); + + Object result = pjp.proceed(); + return result; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } + + /** + * Sets the securedDAOs. + * @param securedDAOs the securedDAOs to set + */ + public void setSecuredDAOs(List<String> securedDAOs) + { + this.securedDAOs = securedDAOs; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + + /** + * Sets the denyIfNoRulesFound. + * @param denyIfNoRulesFound the denyIfNoRulesFound to set + */ + public void setDenyIfNoRulesFound(boolean denyIfNoRulesFound) + { + this.denyIfNoRulesFound = denyIfNoRulesFound; + } +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,17 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao; - -import it.openutils.dao.hibernate.HibernateDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> -{ - -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,29 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao; + +import it.openutils.dao.hibernate.HibernateDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> +{ + +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,27 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao.impl; - -import it.openutils.dao.hibernate.HibernateDAOImpl; -import it.openutils.hibernate.security.dao.SecurityRuleDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO -{ - - /** - * {@inheritDoc} - */ - @Override - protected Class<SecurityRule> getReferenceClass() - { - return SecurityRule.class; - } - -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,39 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao.impl; + +import it.openutils.dao.hibernate.HibernateDAOImpl; +import it.openutils.hibernate.security.dao.SecurityRuleDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO +{ + + /** + * {@inheritDoc} + */ + @Override + protected Class<SecurityRule> getReferenceClass() + { + return SecurityRule.class; + } + +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum ModifierEnum { - - /** - * Equals - */ - EQUALS("equals"), - - /** - * Not - */ - NOT("not"); - - private String value; - - /** - * @param value The literal value of the modifier - */ - ModifierEnum(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum ModifierEnum { + + /** + * Equals + */ + EQUALS("equals"), + + /** + * Not + */ + NOT("not"); + + private String value; + + /** + * @param value The literal value of the modifier + */ + ModifierEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum PermissionEnum { - - /** - * Load, Create, Modify, Delete permissions - */ - LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); - - private String value; - - /** - * @param value The literal value for the needed enumeration object - */ - PermissionEnum(String value) - { - this.value = value; - } - - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum PermissionEnum { + + /** + * Load, Create, Modify, Delete permissions + */ + LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); + + private String value; + + /** + * @param value The literal value for the needed enumeration object + */ + PermissionEnum(String value) + { + this.value = value; + } + + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,212 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -import java.io.Serializable; -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Table; - -import org.hibernate.annotations.CollectionOfElements; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.apache.commons.lang.builder.ToStringBuilder; - - -/** - * @author fcarone - * @version $Id$ A security rule - */ -@Entity -@Table(name = "SECURITY_RULE") -public class SecurityRule implements Serializable -{ - - /** - * Generated serial version UID - */ - private static final long serialVersionUID = -4820683448073404349L; - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "ID_SECURITY_RULE") - private Long id; - - @Column(name = "ROLE", length = 64, nullable = false) - private String role; - - @Column(name = "ENTITY", length = 512, nullable = false) - private String entity; - - @Column(name = "PROPERTY", length = 512, nullable = false) - private String property; - - @Column(name = "VALUE", nullable = false) - private String value; - - @Enumerated(EnumType.STRING) - @Column(name = "MODIFIER", nullable = false) - private ModifierEnum modifier; - - @CollectionOfElements(fetch = FetchType.EAGER) - @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) - @Column(name = "PERMISSION", nullable = false) - @Enumerated(EnumType.STRING) - @Fetch(FetchMode.SUBSELECT) - private List<PermissionEnum> permissions; - - /** - * Returns the role. - * @return the role - */ - public String getRole() - { - return role; - } - - /** - * Sets the role. - * @param role the role to set - */ - public void setRole(String role) - { - this.role = role; - } - - /** - * Returns the entity. - * @return the entity - */ - public String getEntity() - { - return entity; - } - - /** - * Sets the entity. - * @param entity the entity to set - */ - public void setEntity(String entity) - { - this.entity = entity; - } - - /** - * Returns the property. - * @return the property - */ - public String getProperty() - { - return property; - } - - /** - * Sets the property. - * @param property the property to set - */ - public void setProperty(String property) - { - this.property = property; - } - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - - /** - * Sets the value. - * @param value the value to set - */ - public void setValue(String value) - { - this.value = value; - } - - /** - * Returns the modifier. - * @return the modifier - */ - public ModifierEnum getModifier() - { - return modifier; - } - - /** - * Sets the modifier. - * @param modifier the modifier to set - */ - public void setModifier(ModifierEnum modifier) - { - this.modifier = modifier; - } - - /** - * Returns the permissions. - * @return the permissions - */ - public List<PermissionEnum> getPermissions() - { - return permissions; - } - - /** - * Sets the permissions. - * @param permissions the permissions to set - */ - public void setPermissions(List<PermissionEnum> permissions) - { - this.permissions = permissions; - } - - /** - * Returns the id. - * @return the id - */ - public Long getId() - { - return id; - } - - /** - * Sets the id. - * @param id the id to set - */ - public void setId(Long id) - { - this.id = id; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return new ToStringBuilder(this) - .append("id", this.id) - .append("role", this.role) - .append("entity", this.entity) - .append("property", this.property) - .append("value", this.value) - .append("modifier", this.modifier) - .append("permissions", this.permissions) - .toString(); - } - -} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (from rev 696, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,301 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.dataobject; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Table; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.FilterDefs; +import org.hibernate.annotations.Filters; +import org.apache.commons.lang.builder.ToStringBuilder; + + +/** + * @author fcarone + * @version $Id$ A security rule + */ +@Entity +@Table(name = "SECURITY_RULE") +@FilterDefs({@FilterDef(name = "notDeletedRules", defaultCondition = "DELETED != '1'") }) +@Filters({@Filter(name = "notDeletedRules") }) +public class SecurityRule implements Serializable +{ + + /** + * Generated serial version UID + */ + private static final long serialVersionUID = -4820683448073404349L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID_SECURITY_RULE") + private Long id; + + @Column(name = "ROLE", length = 64, nullable = false) + private String role; + + @Column(name = "ENTITY", length = 512, nullable = false) + private String entity; + + @Column(name = "PROPERTY", length = 512, nullable = false) + private String property; + + @Column(name = "VALUE", nullable = false) + private String value; + + @Enumerated(EnumType.STRING) + @Column(name = "MODIFIER", nullable = false) + private ModifierEnum modifier; + + @CollectionOfElements(fetch = FetchType.EAGER) + @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "PERMISSION", nullable = false) + @Enumerated(EnumType.STRING) + @Fetch(FetchMode.SUBSELECT) + private List<PermissionEnum> permissions; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private StatusEnum status; + + @Column(name = "DELETED", length = 1, nullable = false) + private Boolean deleted; + + @CollectionOfElements(fetch = FetchType.EAGER) + @org.hibernate.annotations.MapKey(columns = @Column(name = "NAME")) + @JoinTable(name = "SECRULE_ENTITY", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "VALUE", length = 256) + @Fetch(FetchMode.SUBSELECT) + private Map<String, String> entities; + + /** + * Returns the role. + * @return the role + */ + public String getRole() + { + return role; + } + + /** + * Sets the role. + * @param role the role to set + */ + public void setRole(String role) + { + this.role = role; + } + + /** + * Returns the entity. + * @return the entity + */ + public String getEntity() + { + return entity; + } + + /** + * Sets the entity. + * @param entity the entity to set + */ + public void setEntity(String entity) + { + this.entity = entity; + } + + /** + * Returns the property. + * @return the property + */ + public String getProperty() + { + return property; + } + + /** + * Sets the property. + * @param property the property to set + */ + public void setProperty(String property) + { + this.property = property; + } + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + + /** + * Sets the value. + * @param value the value to set + */ + public void setValue(String value) + { + this.value = value; + } + + /** + * Returns the modifier. + * @return the modifier + */ + public ModifierEnum getModifier() + { + return modifier; + } + + /** + * Sets the modifier. + * @param modifier the modifier to set + */ + public void setModifier(ModifierEnum modifier) + { + this.modifier = modifier; + } + + /** + * Returns the permissions. + * @return the permissions + */ + public List<PermissionEnum> getPermissions() + { + return permissions; + } + + /** + * Sets the permissions. + * @param permissions the permissions to set + */ + public void setPermissions(List<PermissionEnum> permissions) + { + this.permissions = permissions; + } + + /** + * Returns the id. + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * Sets the id. + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return new ToStringBuilder(this) + .append("id", this.id) + .append("role", this.role) + .append("entity", this.entity) + .append("property", this.property) + .append("value", this.value) + .append("modifier", this.modifier) + .append("permissions", this.permissions) + .toString(); + } + + /** + * Returns the status. + * @return the status + */ + public StatusEnum getStatus() + { + return status; + } + + /** + * Sets the status. + * @param status the status to set + */ + public void setStatus(StatusEnum status) + { + this.status = status; + } + + /** + * @return True if the rule is enabled + */ + public boolean isEnabled() + { + if (status == null) + { + return false; + } + return status.equals(StatusEnum.ENABLED); + } + + /** + * Returns the entities. + * @return the entities + */ + public Map<String, String> getEntities() + { + return entities; + } + + /** + * Sets the entities. + * @param entities the entities to set + */ + public void setEntities(Map<String, String> entities) + { + this.entities = entities; + } + + + /** + * Returns the deleted. + * @return the deleted + */ + public Boolean getDeleted() + { + return deleted; + } + + + /** + * Sets the deleted. + * @param deleted the deleted to set + */ + public void setDeleted(Boolean deleted) + { + this.deleted = deleted; + } + +} Copied: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (from rev 688, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java 2008-02-26 10:56:55 UTC (rev 705) @@ -0,0 +1,46 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + + +/** + * @author fcarone + * @version $Id: $ + */ +public enum StatusEnum { + + /** + * Enabled + */ + ENABLED("enabled"), + + /** + * Disabled + */ + DISABLED("disabled"); + + private String value; + + private StatusEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} Deleted: tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.6/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-26 10:56:55 UTC (rev 705) @@ -1,258 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.PermissionEnum; -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Filter; -import org.hibernate.HibernateException; -import org.hibernate.engine.Fil... [truncated message content] |
From: <fc...@us...> - 2008-03-06 09:10:23
|
Revision: 721 http://openutils.svn.sourceforge.net/openutils/?rev=721&view=rev Author: fcarone Date: 2008-03-06 01:10:21 -0800 (Thu, 06 Mar 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-bshd5-2.0.2 Added Paths: ----------- tags/openutils-bshd5-2.0.2/ tags/openutils-bshd5-2.0.2/pom.xml Removed Paths: ------------- tags/openutils-bshd5-2.0.2/pom.xml Copied: tags/openutils-bshd5-2.0.2 (from rev 719, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-2.0.2/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2008-03-05 17:17:33 UTC (rev 719) +++ tags/openutils-bshd5-2.0.2/pom.xml 2008-03-06 09:10:21 UTC (rev 721) @@ -1,108 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>2.0.2-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-2.0.2/pom.xml (from rev 720, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-2.0.2/pom.xml (rev 0) +++ tags/openutils-bshd5-2.0.2/pom.xml 2008-03-06 09:10:21 UTC (rev 721) @@ -0,0 +1,114 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>2.0.2</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-2.0.2</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-03-06 09:15:26
|
Revision: 725 http://openutils.svn.sourceforge.net/openutils/?rev=725&view=rev Author: fcarone Date: 2008-03-06 01:15:32 -0800 (Thu, 06 Mar 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-usermanagement-2.0.1 Added Paths: ----------- tags/openutils-usermanagement-2.0.1/ tags/openutils-usermanagement-2.0.1/pom.xml Removed Paths: ------------- tags/openutils-usermanagement-2.0.1/pom.xml Copied: tags/openutils-usermanagement-2.0.1 (from rev 719, trunk/openutils-usermanagement) Deleted: tags/openutils-usermanagement-2.0.1/pom.xml =================================================================== --- trunk/openutils-usermanagement/pom.xml 2008-03-05 17:17:33 UTC (rev 719) +++ tags/openutils-usermanagement-2.0.1/pom.xml 2008-03-06 09:15:32 UTC (rev 725) @@ -1,173 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <packaging>jar</packaging> - <name>openutils-usermanagement</name> - <version>2.0.1-SNAPSHOT</version> - <description>Usermanagement classes</description> - <properties> - <spring.version>2.5.1</spring.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.3</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-remoting</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring-support</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.2.2.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-usermanagement-2.0.1/pom.xml (from rev 724, trunk/openutils-usermanagement/pom.xml) =================================================================== --- tags/openutils-usermanagement-2.0.1/pom.xml (rev 0) +++ tags/openutils-usermanagement-2.0.1/pom.xml 2008-03-06 09:15:32 UTC (rev 725) @@ -0,0 +1,179 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <packaging>jar</packaging> + <name>openutils-usermanagement</name> + <version>2.0.1</version> + <description>Usermanagement classes</description> + <properties> + <spring.version>2.5.1</spring.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-2.0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-usermanagement-2.0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-usermanagement-2.0.1</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fc...@us...> - 2008-03-06 09:26:44
|
Revision: 729 http://openutils.svn.sourceforge.net/openutils/?rev=729&view=rev Author: fcarone Date: 2008-03-06 01:26:46 -0800 (Thu, 06 Mar 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-hibernate-security-0.0.7 Added Paths: ----------- tags/openutils-hibernate-security-0.0.7/ tags/openutils-hibernate-security-0.0.7/pom.xml tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.7/src/site/apt/ tags/openutils-hibernate-security-0.0.7/src/site/apt/index.apt tags/openutils-hibernate-security-0.0.7/src/site/apt/rbac-acegi.apt tags/openutils-hibernate-security-0.0.7/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.7/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.7/src/test/resources/spring-security.xml Removed Paths: ------------- tags/openutils-hibernate-security-0.0.7/pom.xml tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAccessDecisionVoter.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleAfterInvocationHandler.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRuleBaseHandler.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/SecurityRulePredicate.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/utils/SecurityRuleUtils.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/services/SecurityRuleManager.java tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/services/impl/SecurityRuleManagerImpl.java tags/openutils-hibernate-security-0.0.7/src/site/apt/index.apt tags/openutils-hibernate-security-0.0.7/src/test/java/it/openutils/hibernate/security/filter/JavaBeanFilterTest.java tags/openutils-hibernate-security-0.0.7/src/test/resources/SecurityIntegrationTest-load.xml tags/openutils-hibernate-security-0.0.7/src/test/resources/spring-security.xml Copied: tags/openutils-hibernate-security-0.0.7 (from rev 673, trunk/openutils-hibernate-security) Deleted: tags/openutils-hibernate-security-0.0.7/pom.xml =================================================================== --- trunk/openutils-hibernate-security/pom.xml 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/pom.xml 2008-03-06 09:26:46 UTC (rev 729) @@ -1,223 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>openutils</artifactId> - <groupId>net.sourceforge.openutils</groupId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-hibernate-security</artifactId> - <name>openutils hibernate security</name> - <version>0.0.4-SNAPSHOT</version> - <description>Hibernate Security classes</description> - <properties> - <spring.version>2.5.1</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <!-- already imported cglib-nodep by spring --> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-usermanagement-dataobjects</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-bshd5</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.0.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.5.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>org.acegisecurity</groupId> - <artifactId>acegi-security</artifactId> - <version>1.0.6</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <artifactId>spring-remoting</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-jdbc</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - <exclusion> - <artifactId>spring-support</artifactId> - <groupId>org.springframework</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <version>1.8.0.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-hibernate-security-0.0.7/pom.xml (from rev 728, trunk/openutils-hibernate-security/pom.xml) =================================================================== --- tags/openutils-hibernate-security-0.0.7/pom.xml (rev 0) +++ tags/openutils-hibernate-security-0.0.7/pom.xml 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,229 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-hibernate-security</artifactId> + <name>openutils hibernate security</name> + <version>0.0.7</version> + <description>Hibernate Security classes</description> + <properties> + <spring.version>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <!-- already imported cglib-nodep by spring --> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-usermanagement-dataobjects</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-bshd5</artifactId> + <version>2.0.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.5.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.acegisecurity</groupId> + <artifactId>acegi-security</artifactId> + <version>1.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <artifactId>spring-remoting</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-jdbc</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + <exclusion> + <artifactId>spring-support</artifactId> + <groupId>org.springframework</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.8.0.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.7</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-hibernate-security-0.0.7</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-hibernate-security-0.0.7</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,154 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.aop; - -import it.openutils.hibernate.security.dataobject.SecurityRule; -import it.openutils.hibernate.security.services.SecurityRuleManager; - -import java.util.ArrayList; -import java.util.List; - -import org.acegisecurity.Authentication; -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.context.SecurityContextHolder; -import org.apache.commons.lang.StringUtils; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Filter; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.Restrictions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id$ - */ -@Aspect -public class AOPSecurity -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AOPSecurity.class); - - private SecurityRuleManager securityRuleManager; - - private List<String> securedDAOs; - - private boolean enabled; - - /** - * @param pjp The proceeding joinpoint - * @param filter The entity we are going to filter - * @param additionalCriteria The additional criteria list, cannot be null - * @return The execution invocation result - * @throws Throwable Any exception occurring in the invoked method - */ - @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " - + // - " args(filter, .., additionalCriteria)") - public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) - throws Throwable - { - if (!enabled) - { - log.debug("DAO security disabled, proceeding."); - return pjp.proceed(); - } - - if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) - { - log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); - return pjp.proceed(); - } - - log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) - { - throw new SecurityException("Authentication is not valid"); - } - GrantedAuthority[] authorities = authentication.getAuthorities(); - List<String> roles = new ArrayList<String>(); - for (int i = 0; i < authorities.length; i++) - { - roles.add(authorities[i].getAuthority()); - } - - String entity = filter.getClass().getCanonicalName(); - List<SecurityRule> rules = securityRuleManager.getRulesForRoles(entity, roles); - - if (rules.isEmpty()) - { - if (log.isWarnEnabled()) - { - String grantedRoles = StringUtils.EMPTY; - for (int i = 0; i < authorities.length; i++) - { - grantedRoles += authorities[i].getAuthority() + " "; - } - log.warn( - "No rules found. Access is denied on " + entity + ", for user {} with roles {}", - SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), - grantedRoles); - } - throw new SecurityException("Access denied"); - } - - Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); - - Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter - .getFilterDefinition() - .getDefaultFilterCondition()); - - log.debug("Adding sql restriction: {}", sqlCriterion.toString()); - additionalCriteria.add(sqlCriterion); - - Object result = pjp.proceed(); - return result; - } - - /** - * Sets the securityRuleManager. - * @param securityRuleManager the securityRuleManager to set - */ - public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) - { - this.securityRuleManager = securityRuleManager; - } - - /** - * Sets the securedDAOs. - * @param securedDAOs the securedDAOs to set - */ - public void setSecuredDAOs(List<String> securedDAOs) - { - this.securedDAOs = securedDAOs; - } - - /** - * Sets the enabled. - * @param enabled the enabled to set - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (from rev 687, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/aop/AOPSecurity.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,175 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.aop; + +import it.openutils.hibernate.security.dataobject.SecurityRule; +import it.openutils.hibernate.security.services.SecurityRuleManager; + +import java.util.ArrayList; +import java.util.List; + +import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; +import org.acegisecurity.context.SecurityContextHolder; +import org.apache.commons.lang.StringUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.hibernate.Filter; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fcarone + * @version $Id$ + */ +@Aspect +public class AOPSecurity +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AOPSecurity.class); + + private boolean denyIfNoRulesFound = true; + + private SecurityRuleManager securityRuleManager; + + private List<String> securedDAOs; + + private boolean enabled; + + /** + * @param pjp The proceeding joinpoint + * @param filter The entity we are going to filter + * @param additionalCriteria The additional criteria list, cannot be null + * @return The execution invocation result + * @throws Throwable Any exception occurring in the invoked method + */ + @Around("execution(* it.openutils.dao.hibernate.*.*(Object, .., java.util.List<org.hibernate.criterion.Criterion>)) && " + + // + " args(filter, .., additionalCriteria)") + public Object applySecurityRules(ProceedingJoinPoint pjp, Object filter, List<Criterion> additionalCriteria) + throws Throwable + { + if (!enabled) + { + log.debug("DAO security disabled, proceeding."); + return pjp.proceed(); + } + + if (!securedDAOs.contains(pjp.getTarget().getClass().getCanonicalName())) + { + log.debug("The intercepted DAO {} is not secured, proceeding.", pjp.getTarget().toString()); + return pjp.proceed(); + } + + log.debug("applying security rules for {} with criteria {}", filter.toString(), additionalCriteria); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) + { + throw new SecurityException("Authentication is not valid"); + } + GrantedAuthority[] authorities = authentication.getAuthorities(); + List<String> roles = new ArrayList<String>(); + for (int i = 0; i < authorities.length; i++) + { + roles.add(authorities[i].getAuthority()); + } + + String entity = filter.getClass().getCanonicalName(); + List<SecurityRule> rules = securityRuleManager.getRulesForRoles(filter, roles); + + if (rules.isEmpty()) + { + if (log.isWarnEnabled()) + { + String grantedRoles = StringUtils.EMPTY; + for (int i = 0; i < authorities.length; i++) + { + grantedRoles += authorities[i].getAuthority() + " "; + } + log.warn( + "No rules found for " + entity + ", user {} with roles {}", + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(), + grantedRoles); + } + if (denyIfNoRulesFound) + { + log.debug("denyIfNoRulesFound is true, denying access."); + throw new SecurityException("Access denied"); + } + else + { + log.debug("denyIfNoRulesFound is false, allowing access."); + return pjp.proceed(); + } + } + + Filter hibernateFilter = securityRuleManager.getEntityFilterFromRules(entity, rules); + + Criterion sqlCriterion = Restrictions.sqlRestriction(hibernateFilter + .getFilterDefinition() + .getDefaultFilterCondition()); + + log.debug("Adding sql restriction: {}", sqlCriterion.toString()); + additionalCriteria.add(sqlCriterion); + + Object result = pjp.proceed(); + return result; + } + + /** + * Sets the securityRuleManager. + * @param securityRuleManager the securityRuleManager to set + */ + public void setSecurityRuleManager(SecurityRuleManager securityRuleManager) + { + this.securityRuleManager = securityRuleManager; + } + + /** + * Sets the securedDAOs. + * @param securedDAOs the securedDAOs to set + */ + public void setSecuredDAOs(List<String> securedDAOs) + { + this.securedDAOs = securedDAOs; + } + + /** + * Sets the enabled. + * @param enabled the enabled to set + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + + /** + * Sets the denyIfNoRulesFound. + * @param denyIfNoRulesFound the denyIfNoRulesFound to set + */ + public void setDenyIfNoRulesFound(boolean denyIfNoRulesFound) + { + this.denyIfNoRulesFound = denyIfNoRulesFound; + } +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,17 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao; - -import it.openutils.dao.hibernate.HibernateDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> -{ - -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/SecurityRuleDAO.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,29 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao; + +import it.openutils.dao.hibernate.HibernateDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public interface SecurityRuleDAO extends HibernateDAO<SecurityRule, Long> +{ + +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,27 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dao.impl; - -import it.openutils.dao.hibernate.HibernateDAOImpl; -import it.openutils.hibernate.security.dao.SecurityRuleDAO; -import it.openutils.hibernate.security.dataobject.SecurityRule; - - -/** - * @author fcarone - * @version $Id$ - */ -public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO -{ - - /** - * {@inheritDoc} - */ - @Override - protected Class<SecurityRule> getReferenceClass() - { - return SecurityRule.class; - } - -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dao/impl/SecurityRuleDAOImpl.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,39 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dao.impl; + +import it.openutils.dao.hibernate.HibernateDAOImpl; +import it.openutils.hibernate.security.dao.SecurityRuleDAO; +import it.openutils.hibernate.security.dataobject.SecurityRule; + + +/** + * @author fcarone + * @version $Id$ + */ +public class SecurityRuleDAOImpl extends HibernateDAOImpl<SecurityRule, Long> implements SecurityRuleDAO +{ + + /** + * {@inheritDoc} + */ + @Override + protected Class<SecurityRule> getReferenceClass() + { + return SecurityRule.class; + } + +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum ModifierEnum { - - /** - * Equals - */ - EQUALS("equals"), - - /** - * Not - */ - NOT("not"); - - private String value; - - /** - * @param value The literal value of the modifier - */ - ModifierEnum(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/ModifierEnum.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum ModifierEnum { + + /** + * Equals + */ + EQUALS("equals"), + + /** + * Not + */ + NOT("not"); + + private String value; + + /** + * @param value The literal value of the modifier + */ + ModifierEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,37 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -/** - * @author fcarone - * @version $Id$ - */ -public enum PermissionEnum { - - /** - * Load, Create, Modify, Delete permissions - */ - LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); - - private String value; - - /** - * @param value The literal value for the needed enumeration object - */ - PermissionEnum(String value) - { - this.value = value; - } - - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (from rev 693, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/PermissionEnum.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,49 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + +/** + * @author fcarone + * @version $Id$ + */ +public enum PermissionEnum { + + /** + * Load, Create, Modify, Delete permissions + */ + LOAD("LOAD"), CREATE("CREATE"), MODIFY("MODIFY"), DELETE("DELETE"); + + private String value; + + /** + * @param value The literal value for the needed enumeration object + */ + PermissionEnum(String value) + { + this.value = value; + } + + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,212 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.hibernate.security.dataobject; - -import java.io.Serializable; -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.Table; - -import org.hibernate.annotations.CollectionOfElements; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.apache.commons.lang.builder.ToStringBuilder; - - -/** - * @author fcarone - * @version $Id$ A security rule - */ -@Entity -@Table(name = "SECURITY_RULE") -public class SecurityRule implements Serializable -{ - - /** - * Generated serial version UID - */ - private static final long serialVersionUID = -4820683448073404349L; - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "ID_SECURITY_RULE") - private Long id; - - @Column(name = "ROLE", length = 64, nullable = false) - private String role; - - @Column(name = "ENTITY", length = 512, nullable = false) - private String entity; - - @Column(name = "PROPERTY", length = 512, nullable = false) - private String property; - - @Column(name = "VALUE", nullable = false) - private String value; - - @Enumerated(EnumType.STRING) - @Column(name = "MODIFIER", nullable = false) - private ModifierEnum modifier; - - @CollectionOfElements(fetch = FetchType.EAGER) - @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) - @Column(name = "PERMISSION", nullable = false) - @Enumerated(EnumType.STRING) - @Fetch(FetchMode.SUBSELECT) - private List<PermissionEnum> permissions; - - /** - * Returns the role. - * @return the role - */ - public String getRole() - { - return role; - } - - /** - * Sets the role. - * @param role the role to set - */ - public void setRole(String role) - { - this.role = role; - } - - /** - * Returns the entity. - * @return the entity - */ - public String getEntity() - { - return entity; - } - - /** - * Sets the entity. - * @param entity the entity to set - */ - public void setEntity(String entity) - { - this.entity = entity; - } - - /** - * Returns the property. - * @return the property - */ - public String getProperty() - { - return property; - } - - /** - * Sets the property. - * @param property the property to set - */ - public void setProperty(String property) - { - this.property = property; - } - - /** - * Returns the value. - * @return the value - */ - public String getValue() - { - return value; - } - - /** - * Sets the value. - * @param value the value to set - */ - public void setValue(String value) - { - this.value = value; - } - - /** - * Returns the modifier. - * @return the modifier - */ - public ModifierEnum getModifier() - { - return modifier; - } - - /** - * Sets the modifier. - * @param modifier the modifier to set - */ - public void setModifier(ModifierEnum modifier) - { - this.modifier = modifier; - } - - /** - * Returns the permissions. - * @return the permissions - */ - public List<PermissionEnum> getPermissions() - { - return permissions; - } - - /** - * Sets the permissions. - * @param permissions the permissions to set - */ - public void setPermissions(List<PermissionEnum> permissions) - { - this.permissions = permissions; - } - - /** - * Returns the id. - * @return the id - */ - public Long getId() - { - return id; - } - - /** - * Sets the id. - * @param id the id to set - */ - public void setId(Long id) - { - this.id = id; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return new ToStringBuilder(this) - .append("id", this.id) - .append("role", this.role) - .append("entity", this.entity) - .append("property", this.property) - .append("value", this.value) - .append("modifier", this.modifier) - .append("permissions", this.permissions) - .toString(); - } - -} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (from rev 696, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/SecurityRule.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,301 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.hibernate.security.dataobject; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Table; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.FilterDefs; +import org.hibernate.annotations.Filters; +import org.apache.commons.lang.builder.ToStringBuilder; + + +/** + * @author fcarone + * @version $Id$ A security rule + */ +@Entity +@Table(name = "SECURITY_RULE") +@FilterDefs({@FilterDef(name = "notDeletedRules", defaultCondition = "DELETED != '1'") }) +@Filters({@Filter(name = "notDeletedRules") }) +public class SecurityRule implements Serializable +{ + + /** + * Generated serial version UID + */ + private static final long serialVersionUID = -4820683448073404349L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID_SECURITY_RULE") + private Long id; + + @Column(name = "ROLE", length = 64, nullable = false) + private String role; + + @Column(name = "ENTITY", length = 512, nullable = false) + private String entity; + + @Column(name = "PROPERTY", length = 512, nullable = false) + private String property; + + @Column(name = "VALUE", nullable = false) + private String value; + + @Enumerated(EnumType.STRING) + @Column(name = "MODIFIER", nullable = false) + private ModifierEnum modifier; + + @CollectionOfElements(fetch = FetchType.EAGER) + @JoinTable(name = "SECRULE_PERMISSION", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "PERMISSION", nullable = false) + @Enumerated(EnumType.STRING) + @Fetch(FetchMode.SUBSELECT) + private List<PermissionEnum> permissions; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private StatusEnum status; + + @Column(name = "DELETED", length = 1, nullable = false) + private Boolean deleted; + + @CollectionOfElements(fetch = FetchType.EAGER) + @org.hibernate.annotations.MapKey(columns = @Column(name = "NAME")) + @JoinTable(name = "SECRULE_ENTITY", joinColumns = {@JoinColumn(name = "ID_SECURITY_RULE") }) + @Column(name = "VALUE", length = 256) + @Fetch(FetchMode.SUBSELECT) + private Map<String, String> entities; + + /** + * Returns the role. + * @return the role + */ + public String getRole() + { + return role; + } + + /** + * Sets the role. + * @param role the role to set + */ + public void setRole(String role) + { + this.role = role; + } + + /** + * Returns the entity. + * @return the entity + */ + public String getEntity() + { + return entity; + } + + /** + * Sets the entity. + * @param entity the entity to set + */ + public void setEntity(String entity) + { + this.entity = entity; + } + + /** + * Returns the property. + * @return the property + */ + public String getProperty() + { + return property; + } + + /** + * Sets the property. + * @param property the property to set + */ + public void setProperty(String property) + { + this.property = property; + } + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + + /** + * Sets the value. + * @param value the value to set + */ + public void setValue(String value) + { + this.value = value; + } + + /** + * Returns the modifier. + * @return the modifier + */ + public ModifierEnum getModifier() + { + return modifier; + } + + /** + * Sets the modifier. + * @param modifier the modifier to set + */ + public void setModifier(ModifierEnum modifier) + { + this.modifier = modifier; + } + + /** + * Returns the permissions. + * @return the permissions + */ + public List<PermissionEnum> getPermissions() + { + return permissions; + } + + /** + * Sets the permissions. + * @param permissions the permissions to set + */ + public void setPermissions(List<PermissionEnum> permissions) + { + this.permissions = permissions; + } + + /** + * Returns the id. + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * Sets the id. + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + return new ToStringBuilder(this) + .append("id", this.id) + .append("role", this.role) + .append("entity", this.entity) + .append("property", this.property) + .append("value", this.value) + .append("modifier", this.modifier) + .append("permissions", this.permissions) + .toString(); + } + + /** + * Returns the status. + * @return the status + */ + public StatusEnum getStatus() + { + return status; + } + + /** + * Sets the status. + * @param status the status to set + */ + public void setStatus(StatusEnum status) + { + this.status = status; + } + + /** + * @return True if the rule is enabled + */ + public boolean isEnabled() + { + if (status == null) + { + return false; + } + return status.equals(StatusEnum.ENABLED); + } + + /** + * Returns the entities. + * @return the entities + */ + public Map<String, String> getEntities() + { + return entities; + } + + /** + * Sets the entities. + * @param entities the entities to set + */ + public void setEntities(Map<String, String> entities) + { + this.entities = entities; + } + + + /** + * Returns the deleted. + * @return the deleted + */ + public Boolean getDeleted() + { + return deleted; + } + + + /** + * Sets the deleted. + * @param deleted the deleted to set + */ + public void setDeleted(Boolean deleted) + { + this.deleted = deleted; + } + +} Copied: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (from rev 688, trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java) =================================================================== --- tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java (rev 0) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/dataobject/StatusEnum.java 2008-03-06 09:26:46 UTC (rev 729) @@ -0,0 +1,46 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.hibernate.security.dataobject; + + +/** + * @author fcarone + * @version $Id: $ + */ +public enum StatusEnum { + + /** + * Enabled + */ + ENABLED("enabled"), + + /** + * Disabled + */ + DISABLED("disabled"); + + private String value; + + private StatusEnum(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} Deleted: tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java =================================================================== --- trunk/openutils-hibernate-security/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-02-21 09:17:34 UTC (rev 673) +++ tags/openutils-hibernate-security-0.0.7/src/main/java/it/openutils/hibernate/security/filter/JavaBeanFilter.java 2008-03-06 09:26:46 UTC (rev 729) @@ -1,258 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.hibernate.security.filter; - -import it.openutils.hibernate.security.dataobject.PermissionEnum; -import it.openutils.hibernate.security.dataobject.SecurityRule; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.hibernate.Filter; -import org.hibernate.HibernateException; -import org.hibernate.engine.F... [truncated message content] |
From: <fg...@us...> - 2008-03-11 15:56:24
|
Revision: 734 http://openutils.svn.sourceforge.net/openutils/?rev=734&view=rev Author: fgiust Date: 2008-03-11 08:56:29 -0700 (Tue, 11 Mar 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-log4j-2.0.1 Added Paths: ----------- tags/openutils-log4j-2.0.1/ tags/openutils-log4j-2.0.1/pom.xml tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java Removed Paths: ------------- tags/openutils-log4j-2.0.1/pom.xml tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java Copied: tags/openutils-log4j-2.0.1 (from rev 731, trunk/openutils-log4j) Deleted: tags/openutils-log4j-2.0.1/pom.xml =================================================================== --- trunk/openutils-log4j/pom.xml 2008-03-11 15:24:20 UTC (rev 731) +++ tags/openutils-log4j-2.0.1/pom.xml 2008-03-11 15:56:29 UTC (rev 734) @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-log4j</artifactId> - <packaging>jar</packaging> - <version>2.0.1-SNAPSHOT</version> - <name>openutils for Log4j</name> - <description>openutils log4j extensions</description> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.14</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>javax.mail</groupId> - <artifactId>mail</artifactId> - <version>1.4</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> Copied: tags/openutils-log4j-2.0.1/pom.xml (from rev 733, trunk/openutils-log4j/pom.xml) =================================================================== --- tags/openutils-log4j-2.0.1/pom.xml (rev 0) +++ tags/openutils-log4j-2.0.1/pom.xml 2008-03-11 15:56:29 UTC (rev 734) @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-log4j</artifactId> + <packaging>jar</packaging> + <version>2.0.1</version> + <name>openutils for Log4j</name> + <description>openutils log4j extensions</description> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.14</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + <version>1.4</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-log4j-2.0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-log4j-2.0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-log4j-2.0.1</url> + </scm> +</project> Deleted: tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java =================================================================== --- trunk/openutils-log4j/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-03-11 15:24:20 UTC (rev 731) +++ tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-03-11 15:56:29 UTC (rev 734) @@ -1,685 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.log4j; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Timer; -import java.util.TimerTask; - -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Multipart; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; -import javax.mail.internet.MimeUtility; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Layout; -import org.apache.log4j.Level; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.helpers.LogLog; -import org.apache.log4j.helpers.OptionConverter; -import org.apache.log4j.spi.ErrorCode; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.spi.TriggeringEventEvaluator; - - -/** - * An alternative of <code>org.apache.log4j.net.SMTPAppender</code> with few differences: - * <ul> - * <li>allow customizing the mail subject using a pattern</li> - * <li>can be configured with a timeout (in seconds), it will only send messages after this timeout</li> - * <li>it will send a mail for every single message (bufferSize is not supported), but it will aggregate any identical - * log event received during the timeout. Identical events are log with same message and same stack trace</li> - * </ul> - * - * <pre> - * <appender name="mail" class="it.openutils.log4j.AlternateSMTPAppender"> - * <param name="Threshold" value="ERROR" /> - * <param name="To" value="lo...@ex..." /> - * <param name="From" value="in...@ex..." /> - * <param name="SMTPHost" value="localhost" /> - * <param name="Timeout" value="180" /> - * <param name="Subject" value="[EXAMPLE] %m" /> - * <layout class="it.openutils.log4j.FilteredPatternLayout"> - * <param name="ConversionPattern" value="%-5p %c %d{dd.MM.yyyy HH:mm:ss} -- %m%n" /> - * <param name="Header" - * value=" - * =================================== - * Myapp (production environment) - * Date: %d{dd.MM.yyyy HH:mm:ss} - * =================================== - * " /> - * </layout> - * </appender> - * </pre> - * - * @author Fabrizio Giustina - * @version $Id: $ - */ -public class AlternateSMTPAppender extends AppenderSkeleton -{ - - private String to; - - private String from; - - private Layout subjectLayout; - - private String smtpHost; - - private boolean locationInfo; - - private Timer timer = new Timer("log4j mail appender", true); - - private TimerTask timerTask; - - private int timeout; - - protected Map<LoggingEventAggregator, LoggingEventAggregator> events = new LinkedHashMap<LoggingEventAggregator, LoggingEventAggregator>() - { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * {@inheritDoc} - */ - @Override - public LoggingEventAggregator put(LoggingEventAggregator key, LoggingEventAggregator value) - { - LoggingEventAggregator lea = this.get(key); - if (lea != null) - { - lea.incrementCount(); - return lea; - } - - return super.put(key, value); - } - - }; - - protected Message msg; - - protected TriggeringEventEvaluator evaluator; - - /** - * The default constructor will instantiate the appender with a {@link TriggeringEventEvaluator} that will trigger - * on events with level ERROR or higher. - */ - public AlternateSMTPAppender() - { - this(new DefaultEvaluator()); - - // force loading this class - MimeBodyPart.class.getName(); - MimeUtility.class.getName(); - } - - /** - * Use <code>evaluator</code> passed as parameter as the {@link TriggeringEventEvaluator} for this SMTPAppender. - */ - public AlternateSMTPAppender(TriggeringEventEvaluator evaluator) - { - this.evaluator = evaluator; - } - - /** - * Activate the specified options, such as the smtp host, the recipient, from, etc. - */ - @Override - public void activateOptions() - { - Properties props = new Properties(System.getProperties()); - if (smtpHost != null) - { - props.put("mail.smtp.host", smtpHost); - } - - Session session = Session.getInstance(props, null); - // session.setDebug(true); - msg = new MimeMessage(session); - - try - { - if (from != null) - { - msg.setFrom(getAddress(from)); - } - else - { - msg.setFrom(); - } - - msg.setRecipients(Message.RecipientType.TO, parseAddress(to)); - } - catch (MessagingException e) - { - LogLog.error("Could not activate SMTPAppender options.", e); - } - } - - /** - * Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the - * event triggers an e-mail to be sent. - */ - @Override - public void append(LoggingEvent event) - { - - if (!checkEntryConditions()) - { - return; - } - - event.getThreadName(); - event.getNDC(); - if (locationInfo) - { - event.getLocationInformation(); - } - - LoggingEventAggregator leg = new LoggingEventAggregator(event); - - if (evaluator.isTriggeringEvent(event)) - { - if (timeout == 0) - { - // send immediately - synchronized (events) - { - Collection<LoggingEventAggregator> le = new ArrayList<LoggingEventAggregator>(); - le.add(leg); - sendBuffer(le); - } - return; - } - else - { - events.put(leg, leg); - - if (timerTask == null) - - { - - timerTask = new TimerTask() - { - - @Override - public void run() - { - Collection<LoggingEventAggregator> le; - synchronized (events) - { - le = new ArrayList<LoggingEventAggregator>(events.values()); - events.clear(); - timerTask = null; - } - - sendBuffer(le); - } - }; - - this.timer.schedule(this.timerTask, this.timeout * 1000L); - - } - } - } - } - - /** - * This method determines if there is a sense in attempting to append. - * <p> - * It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the - * boolean value <code>false</code> is returned. - */ - protected boolean checkEntryConditions() - { - if (this.msg == null) - { - errorHandler.error("Message object not configured."); - return false; - } - - if (this.evaluator == null) - { - errorHandler.error("No TriggeringEventEvaluator is set for appender [" + name + "]."); - return false; - } - - if (this.layout == null) - { - errorHandler.error("No layout set for appender named [" + name + "]."); - return false; - } - return true; - } - - @Override - public synchronized void close() - { - this.closed = true; - } - - InternetAddress getAddress(String addressStr) - { - try - { - return new InternetAddress(addressStr); - } - catch (AddressException e) - { - errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); - return null; - } - } - - InternetAddress[] parseAddress(String addressStr) - { - try - { - return InternetAddress.parse(addressStr, true); - } - catch (AddressException e) - { - errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); - return null; - } - } - - /** - * Returns value of the <b>To</b> option. - */ - public String getTo() - { - return to; - } - - /** - * The <code>SMTPAppender</code> requires a {@link org.apache.log4j.Layout layout}. - */ - @Override - public boolean requiresLayout() - { - return true; - } - - /** - * Send the contents of the cyclic buffer as an e-mail message. - */ - protected void sendBuffer(Collection<LoggingEventAggregator> eventsCollection) - { - - // Note: this code already owns the monitor for this - // appender. This frees us from needing to synchronize on 'cb'. - try - { - - for (LoggingEventAggregator lea : eventsCollection) - { - MimeBodyPart part = new MimeBodyPart(); - - StringBuffer sbuf = new StringBuffer(); - String t = layout.getHeader(); - if (t != null) - { - t = StringUtils.replace(t, "%o", Integer.toString(lea.getCount())); - t = StringUtils.replace(t, "%n", Layout.LINE_SEP); - sbuf.append(t); - sbuf.append("\n"); - } - - LoggingEvent event = lea.getLoggingEvent(); - - if (this.subjectLayout != null) - { - String subject = this.subjectLayout.format(event); - - if (subject != null) - { - subject = subject.trim(); - if (subject.indexOf("\n") > 0) - { - subject = subject.substring(0, subject.indexOf("\n")); - } - } - - this.msg.setSubject(subject); - } - - sbuf.append(layout.format(event)); - if (layout.ignoresThrowable()) - { - String[] s = event.getThrowableStrRep(); - if (s != null) - { - for (String element : s) - { - sbuf.append(element); - } - } - } - t = layout.getFooter(); - if (t != null) - { - t = StringUtils.replace(t, "%n", Layout.LINE_SEP); - sbuf.append(t); - } - part.setContent(sbuf.toString(), layout.getContentType()); - - Multipart mp = new MimeMultipart(); - mp.addBodyPart(part); - msg.setContent(mp); - - msg.setSentDate(new Date()); - Transport.send(msg); - } - - } - catch (Exception e) - { - LogLog.error("Error occured while sending e-mail notification.", e); - } - - } - - /** - * Returns value of the <b>EvaluatorClass</b> option. - */ - public String getEvaluatorClass() - { - return evaluator == null ? null : evaluator.getClass().getName(); - } - - /** - * Returns value of the <b>From</b> option. - */ - public String getFrom() - { - return from; - } - - /** - * Returns value of the <b>Subject</b> option. - */ - public String getSubject() - { - return subjectLayout.toString(); - } - - /** - * The <b>From</b> option takes a string value which should be a e-mail address of the sender. - */ - public void setFrom(String from) - { - this.from = from; - } - - /** - * The <b>Subject</b> option takes a string value which should be a the subject of the e-mail message. - */ - public void setSubject(String subjectPattern) - { - this.subjectLayout = new PatternLayout(subjectPattern); - } - - /** - * This option is ignored! - */ - @Deprecated - public void setBufferSize(int bufferSize) - { - // kept as deprecated - LogLog.warn("BufferSize property is deprecated for " + getClass().getName()); - } - - /** - * The <b>SMTPHost</b> option takes a string value which should be a the host name of the SMTP server that will - * send the e-mail message. - */ - public void setSMTPHost(String smtpHost) - { - this.smtpHost = smtpHost; - } - - /** - * Returns value of the <b>SMTPHost</b> option. - */ - public String getSMTPHost() - { - return smtpHost; - } - - /** - * The <b>To</b> option takes a string value which should be a comma separated list of e-mail address of the - * recipients. - */ - public void setTo(String to) - { - this.to = to; - } - - /** - * Returns value of the <b>BufferSize</b> option. - */ - public int getBufferSize() - { - return 0; - } - - /** - * The <b>EvaluatorClass</b> option takes a string value representing the name of the class implementing the {@link - * TriggeringEventEvaluator} interface. A corresponding object will be instantiated and assigned as the triggering - * event evaluator for the SMTPAppender. - */ - public void setEvaluatorClass(String value) - { - evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName( - value, - TriggeringEventEvaluator.class, - evaluator); - } - - /** - * @param value - */ - public void setEvaluator(TriggeringEventEvaluator value) - { - evaluator = value; - } - - /** - * The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be - * no effort to extract the location information related to the event. As a result, the layout that formats the - * events as they are sent out in an e-mail is likely to place the wrong location information (if present in the - * format). - * <p> - * Location information extraction is comparatively very slow and should be avoided unless performance is not a - * concern. - */ - public void setLocationInfo(boolean locationInfo) - { - this.locationInfo = locationInfo; - } - - /** - * Returns value of the <b>LocationInfo</b> option. - */ - public boolean getLocationInfo() - { - return locationInfo; - } - - /** - * Returns the timeout. - * @return the timeout - */ - public int getTimeout() - { - return timeout; - } - - /** - * Sets the timeout. - * @param timeout the timeout to set - */ - public void setTimeout(int timeout) - { - this.timeout = timeout; - } -} - - -class LoggingEventAggregator -{ - - private LoggingEvent loggingEvent; - - private int count; - - public LoggingEventAggregator(LoggingEvent loggingEvent) - { - this.loggingEvent = loggingEvent; - this.count = 1; - } - - /** - * Returns the loggingEvent. - * @return the loggingEvent - */ - public LoggingEvent getLoggingEvent() - { - return loggingEvent; - } - - /** - * Returns the count. - * @return the count - */ - public int getCount() - { - return count; - } - - /** - * Sets the count. - * @param count the count to set - */ - public void setCount(int count) - { - this.count = count; - } - - public void incrementCount() - { - count++; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - - Object lem = loggingEvent.getMessage(); - String[] thstr = loggingEvent.getThrowableStrRep(); - result = prime * result + ((lem == null) ? 0 : lem.hashCode()); - result = prime * result + Arrays.hashCode(thstr); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final LoggingEventAggregator other = (LoggingEventAggregator) obj; - - Object lem = loggingEvent.getMessage(); - String[] thstr = loggingEvent.getThrowableStrRep(); - - Object otherLem = other.loggingEvent.getMessage(); - String[] otherThstr = other.loggingEvent.getThrowableStrRep(); - - int length = Math.min(otherThstr.length, thstr.length); - length = Math.min(10, length); - - otherThstr = (String[]) ArrayUtils.subarray(otherThstr, 0, length); - String[] thisThstr = (String[]) ArrayUtils.subarray(thstr, 0, length); - - if (lem == null) - { - if (otherLem != null) - { - return false; - } - } - - else if (!lem.equals(otherLem)) - { - return false; - } - if (!Arrays.equals(thisThstr, otherThstr)) - { - return false; - } - return true; - } - -} - - -class DefaultEvaluator implements TriggeringEventEvaluator -{ - - public boolean isTriggeringEvent(LoggingEvent event) - { - return event.getLevel().isGreaterOrEqual(Level.ERROR); - } -} \ No newline at end of file Copied: tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java (from rev 732, trunk/openutils-log4j/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java) =================================================================== --- tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java (rev 0) +++ tags/openutils-log4j-2.0.1/src/main/java/it/openutils/log4j/AlternateSMTPAppender.java 2008-03-11 15:56:29 UTC (rev 734) @@ -0,0 +1,685 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.log4j; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Timer; +import java.util.TimerTask; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimeUtility; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.helpers.LogLog; +import org.apache.log4j.helpers.OptionConverter; +import org.apache.log4j.spi.ErrorCode; +import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.TriggeringEventEvaluator; + + +/** + * An alternative of <code>org.apache.log4j.net.SMTPAppender</code> with few differences: + * <ul> + * <li>allow customizing the mail subject using a pattern</li> + * <li>can be configured with a timeout (in seconds), it will only send messages after this timeout</li> + * <li>it will send a mail for every single message (bufferSize is not supported), but it will aggregate any identical + * log event received during the timeout. Identical events are log with same message and same stack trace</li> + * </ul> + * + * <pre> + * <appender name="mail" class="it.openutils.log4j.AlternateSMTPAppender"> + * <param name="Threshold" value="ERROR" /> + * <param name="To" value="lo...@ex..." /> + * <param name="From" value="in...@ex..." /> + * <param name="SMTPHost" value="localhost" /> + * <param name="Timeout" value="180" /> + * <param name="Subject" value="[EXAMPLE] %m" /> + * <layout class="it.openutils.log4j.FilteredPatternLayout"> + * <param name="ConversionPattern" value="%-5p %c %d{dd.MM.yyyy HH:mm:ss} -- %m%n" /> + * <param name="Header" + * value=" + * =================================== + * Myapp (production environment) + * Date: %d{dd.MM.yyyy HH:mm:ss} + * =================================== + * " /> + * </layout> + * </appender> + * </pre> + * + * @author Fabrizio Giustina + * @version $Id$ + */ +public class AlternateSMTPAppender extends AppenderSkeleton +{ + + protected Map<LoggingEventAggregator, LoggingEventAggregator> events = new LinkedHashMap<LoggingEventAggregator, LoggingEventAggregator>() + { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * {@inheritDoc} + */ + @Override + public LoggingEventAggregator put(LoggingEventAggregator key, LoggingEventAggregator value) + { + LoggingEventAggregator lea = this.get(key); + if (lea != null) + { + lea.incrementCount(); + return lea; + } + + return super.put(key, value); + } + + }; + + protected Message msg; + + protected TriggeringEventEvaluator evaluator; + + private String to; + + private String from; + + private Layout subjectLayout; + + private String smtpHost; + + private boolean locationInfo; + + private Timer timer = new Timer("log4j mail appender", true); + + private TimerTask timerTask; + + private int timeout; + + /** + * The default constructor will instantiate the appender with a {@link TriggeringEventEvaluator} that will trigger + * on events with level ERROR or higher. + */ + public AlternateSMTPAppender() + { + this(new DefaultEvaluator()); + + // force loading this class + MimeBodyPart.class.getName(); + MimeUtility.class.getName(); + } + + /** + * Use <code>evaluator</code> passed as parameter as the {@link TriggeringEventEvaluator} for this SMTPAppender. + */ + public AlternateSMTPAppender(TriggeringEventEvaluator evaluator) + { + this.evaluator = evaluator; + } + + /** + * Activate the specified options, such as the smtp host, the recipient, from, etc. + */ + @Override + public void activateOptions() + { + Properties props = new Properties(System.getProperties()); + if (smtpHost != null) + { + props.put("mail.smtp.host", smtpHost); + } + + Session session = Session.getInstance(props, null); + // session.setDebug(true); + msg = new MimeMessage(session); + + try + { + if (from != null) + { + msg.setFrom(getAddress(from)); + } + else + { + msg.setFrom(); + } + + msg.setRecipients(Message.RecipientType.TO, parseAddress(to)); + } + catch (MessagingException e) + { + LogLog.error("Could not activate SMTPAppender options.", e); + } + } + + /** + * Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the + * event triggers an e-mail to be sent. + */ + @Override + public void append(LoggingEvent event) + { + + if (!checkEntryConditions()) + { + return; + } + + event.getThreadName(); + event.getNDC(); + if (locationInfo) + { + event.getLocationInformation(); + } + + LoggingEventAggregator leg = new LoggingEventAggregator(event); + + if (evaluator.isTriggeringEvent(event)) + { + if (timeout == 0) + { + // send immediately + synchronized (events) + { + Collection<LoggingEventAggregator> le = new ArrayList<LoggingEventAggregator>(); + le.add(leg); + sendBuffer(le); + } + return; + } + else + { + events.put(leg, leg); + + if (timerTask == null) + + { + + timerTask = new TimerTask() + { + + @Override + public void run() + { + Collection<LoggingEventAggregator> le; + synchronized (events) + { + le = new ArrayList<LoggingEventAggregator>(events.values()); + events.clear(); + timerTask = null; + } + + sendBuffer(le); + } + }; + + this.timer.schedule(this.timerTask, this.timeout * 1000L); + + } + } + } + } + + /** + * This method determines if there is a sense in attempting to append. + * <p> + * It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the + * boolean value <code>false</code> is returned. + */ + protected boolean checkEntryConditions() + { + if (this.msg == null) + { + errorHandler.error("Message object not configured."); + return false; + } + + if (this.evaluator == null) + { + errorHandler.error("No TriggeringEventEvaluator is set for appender [" + name + "]."); + return false; + } + + if (this.layout == null) + { + errorHandler.error("No layout set for appender named [" + name + "]."); + return false; + } + return true; + } + + @Override + public synchronized void close() + { + this.closed = true; + } + + InternetAddress getAddress(String addressStr) + { + try + { + return new InternetAddress(addressStr); + } + catch (AddressException e) + { + errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); + return null; + } + } + + InternetAddress[] parseAddress(String addressStr) + { + try + { + return InternetAddress.parse(addressStr, true); + } + catch (AddressException e) + { + errorHandler.error("Could not parse address [" + addressStr + "].", e, ErrorCode.ADDRESS_PARSE_FAILURE); + return null; + } + } + + /** + * Returns value of the <b>To</b> option. + */ + public String getTo() + { + return to; + } + + /** + * The <code>SMTPAppender</code> requires a {@link org.apache.log4j.Layout layout}. + */ + @Override + public boolean requiresLayout() + { + return true; + } + + /** + * Send the contents of the cyclic buffer as an e-mail message. + */ + protected void sendBuffer(Collection<LoggingEventAggregator> eventsCollection) + { + + // Note: this code already owns the monitor for this + // appender. This frees us from needing to synchronize on 'cb'. + try + { + + for (LoggingEventAggregator lea : eventsCollection) + { + MimeBodyPart part = new MimeBodyPart(); + + StringBuffer sbuf = new StringBuffer(); + String t = layout.getHeader(); + if (t != null) + { + t = StringUtils.replace(t, "%o", Integer.toString(lea.getCount())); + t = StringUtils.replace(t, "%n", Layout.LINE_SEP); + sbuf.append(t); + sbuf.append("\n"); + } + + LoggingEvent event = lea.getLoggingEvent(); + + if (this.subjectLayout != null) + { + String subject = this.subjectLayout.format(event); + + if (subject != null) + { + subject = subject.trim(); + if (subject.indexOf("\n") > 0) + { + subject = subject.substring(0, subject.indexOf("\n")); + } + } + + this.msg.setSubject(subject); + } + + sbuf.append(layout.format(event)); + if (layout.ignoresThrowable()) + { + String[] s = event.getThrowableStrRep(); + if (s != null) + { + for (String element : s) + { + sbuf.append(element); + } + } + } + t = layout.getFooter(); + if (t != null) + { + t = StringUtils.replace(t, "%n", Layout.LINE_SEP); + sbuf.append(t); + } + part.setContent(sbuf.toString(), layout.getContentType()); + + Multipart mp = new MimeMultipart(); + mp.addBodyPart(part); + msg.setContent(mp); + + msg.setSentDate(new Date()); + Transport.send(msg); + } + + } + catch (Exception e) + { + LogLog.error("Error occured while sending e-mail notification.", e); + } + + } + + /** + * Returns value of the <b>EvaluatorClass</b> option. + */ + public String getEvaluatorClass() + { + return evaluator == null ? null : evaluator.getClass().getName(); + } + + /** + * Returns value of the <b>From</b> option. + */ + public String getFrom() + { + return from; + } + + /** + * Returns value of the <b>Subject</b> option. + */ + public String getSubject() + { + return subjectLayout.toString(); + } + + /** + * The <b>From</b> option takes a string value which should be a e-mail address of the sender. + */ + public void setFrom(String from) + { + this.from = from; + } + + /** + * The <b>Subject</b> option takes a string value which should be a the subject of the e-mail message. + */ + public void setSubject(String subjectPattern) + { + this.subjectLayout = new PatternLayout(subjectPattern); + } + + /** + * This option is ignored! + */ + @Deprecated + public void setBufferSize(int bufferSize) + { + // kept as deprecated + LogLog.warn("BufferSize property is deprecated for " + getClass().getName()); + } + + /** + * The <b>SMTPHost</b> option takes a string value which should be a the host name of the SMTP server that will + * send the e-mail message. + */ + public void setSMTPHost(String smtpHost) + { + this.smtpHost = smtpHost; + } + + /** + * Returns value of the <b>SMTPHost</b> option. + */ + public String getSMTPHost() + { + return smtpHost; + } + + /** + * The <b>To</b> option takes a string value which should be a comma separated list of e-mail address of the + * recipients. + */ + public void setTo(String to) + { + this.to = to; + } + + /** + * Returns value of the <b>BufferSize</b> option. + */ + public int getBufferSize() + { + return 0; + } + + /** + * The <b>EvaluatorClass</b> option takes a string value representing the name of the class implementing the {@link + * TriggeringEventEvaluator} interface. A corresponding object will be instantiated and assigned as the triggering + * event evaluator for the SMTPAppender. + */ + public void setEvaluatorClass(String value) + { + evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName( + value, + TriggeringEventEvaluator.class, + evaluator); + } + + /** + * @param value + */ + public void setEvaluator(TriggeringEventEvaluator value) + { + evaluator = value; + } + + /** + * The <b>LocationInfo</b> option takes a boolean value. By default, it is set to false which means there will be + * no effort to extract the location information related to the event. As a result, the layout that formats the + * events as they are sent out in an e-mail is likely to place the wrong location information (if present in the + * format). + * <p> + * Location information extraction is comparatively very slow and should be avoided unless performance is not a + * concern. + */ + public void setLocationInfo(boolean locationInfo) + { + this.locationInfo = locationInfo; + } + + /** + * Returns value of the <b>LocationInfo</b> option. + */ + public boolean getLocationInfo() + { + return locationInfo; + } + + /** + * Returns the timeout. + * @return the timeout + */ + public int getTimeout() + { + return timeout; + } + + /** + * Sets the timeout. + * @param timeout the timeout to set + */ + public void setTimeout(int timeout) + { + this.timeout = timeout; + } +} + + +class LoggingEventAggregator +{ + + private LoggingEvent loggingEvent; + + private int count; + + public LoggingEventAggregator(LoggingEvent loggingEvent) + { + this.loggingEvent = loggingEvent; + this.count = 1; + } + + /** + * Returns the loggingEvent. + * @return the loggingEvent + */ + public LoggingEvent getLoggingEvent() + { + return loggingEvent; + } + + /** + * Returns the count. + * @return the count + */ + public int getCount() + { + return count; + } + + /** + * Sets the count. + * @param count the count to set + */ + public void setCount(int count) + { + this.count = count; + } + + public void incrementCount() + { + count++; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + + Object lem = loggingEvent.getMessage(); + String[] thstr = loggingEvent.getThrowableStrRep(); + result = prime * result + ((lem == null) ? 0 : lem.hashCode()); + result = prime * result + Arrays.hashCode(thstr); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final LoggingEventAggregator other = (LoggingEventAggregator) obj; + + Object lem = loggingEvent.getMessage(); + String[] thstr = loggingEvent.getThrowableStrRep(); + + Object otherLem = other.loggingEvent.getMessage(); + String[] otherThstr = other.loggingEvent.getThrowableStrRep(); + + int length = Math.min(otherThstr.length, thstr.length); + length = Math.min(10, length); + + otherThstr = (String[]) ArrayUtils.subarray(otherThstr, 0, length); + String[] thisThstr = (String[]) ArrayUtils.subarray(thstr, 0, length); + + if (lem == null) + { + if (otherLem != null) + { + return false; + } + } + + else if (!lem.equals(otherLem)) + { + return false; + } + if (!Arrays.equals(thisThstr, otherThstr)) + { + return false; + } + return true; + } + +} + + +class DefaultEvaluator implements TriggeringEventEvaluator +{ + + public boolean isTriggeringEvent(LoggingEvent event) + { + return event.getLevel().isGreaterOrEqual(Level.ERROR); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-27 09:57:03
|
Revision: 756 http://openutils.svn.sourceforge.net/openutils/?rev=756&view=rev Author: fgiust Date: 2008-04-27 02:56:43 -0700 (Sun, 27 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-2.1 Added Paths: ----------- tags/openutils-testing-2.1/ tags/openutils-testing-2.1/pom.xml tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java tags/openutils-testing-2.1/src/site/changes/changes.xml Removed Paths: ------------- tags/openutils-testing-2.1/pom.xml tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java tags/openutils-testing-2.1/src/site/changes/changes.xml Copied: tags/openutils-testing-2.1 (from rev 751, trunk/openutils-testing) Deleted: tags/openutils-testing-2.1/pom.xml =================================================================== --- trunk/openutils-testing/pom.xml 2008-03-20 17:39:12 UTC (rev 751) +++ tags/openutils-testing-2.1/pom.xml 2008-04-27 09:56:43 UTC (rev 756) @@ -1,78 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing</artifactId> - <name>openutils test utils</name> - <version>2.0.4-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>junit-addons</groupId> - <artifactId>junit-addons</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.7</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.1</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-testing-2.1/pom.xml (from rev 755, trunk/openutils-testing/pom.xml) =================================================================== --- tags/openutils-testing-2.1/pom.xml (rev 0) +++ tags/openutils-testing-2.1/pom.xml 2008-04-27 09:56:43 UTC (rev 756) @@ -0,0 +1,83 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing</artifactId> + <name>openutils test utils</name> + <version>2.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.7</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.3</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-2.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-2.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-03-20 17:39:12 UTC (rev 751) +++ tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-04-27 09:56:43 UTC (rev 756) @@ -1,83 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.dbunit.dataset.datatype.IDataTypeFactory; -import org.dbunit.operation.DatabaseOperation; - - -/** - * @author fgiust - * @version $Id$ - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -@Documented -public @interface DbUnitExecution { - - /** - * The resource locations to use for loading dbunit dataset. - */ - String[] datasets() default { - - }; - - /** - * The name of the datasource to use. If can be left unset only if there is only one DataSource available in the - * Spring context. - */ - String dataSource() default ""; - - /** - * Db schema name that will be given to dbUnit. Can be left unset if not needed (database specific) - */ - String schema() default ""; - - /** - * The datatype factory (DatabaseConfig.PROPERTY_DATATYPE_FACTORY) to use. Can be left unset if not needed. - */ - Class< ? extends IDataTypeFactory> dataTypeFactory(); - - /** - * A regexp that can match table names. Any table matching this regular expression will not be considered by DbUnit. - * By default tables starting with BIN$ are ignored (oracle recycle bin). - */ - String excludedTables() default "^BIN\\$(.*)"; // oracle recycle bin - - /** - * If true, <strong>all</strong> the tables in the database will be truncated before loading any dataset. - */ - boolean truncateAll() default true; - - /** - * The database operation that will be used to truncate tables. Defaults to org.dbunit.operation.DeleteAllOperation - */ - Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.DeleteAllOperation.class; - - /** - * The database operation that will be used to load datasets. Defaults to org.dbunit.operation.InsertOperation - */ - Class< ? extends DatabaseOperation> insertOperation() default org.dbunit.operation.InsertOperation.class; - -} \ No newline at end of file Copied: tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java (from rev 752, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitExecution.java) =================================================================== --- tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java (rev 0) +++ tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitExecution.java 2008-04-27 09:56:43 UTC (rev 756) @@ -0,0 +1,84 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.dbunit.dataset.datatype.DefaultDataTypeFactory; +import org.dbunit.dataset.datatype.IDataTypeFactory; +import org.dbunit.operation.DatabaseOperation; + + +/** + * @author fgiust + * @version $Id$ + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +@Documented +public @interface DbUnitExecution { + + /** + * The resource locations to use for loading dbunit dataset. + */ + String[] datasets() default { + + }; + + /** + * The name of the datasource to use. If can be left unset only if there is only one DataSource available in the + * Spring context. + */ + String dataSource() default ""; + + /** + * Db schema name that will be given to dbUnit. Can be left unset if not needed (database specific) + */ + String schema() default ""; + + /** + * The datatype factory (DatabaseConfig.PROPERTY_DATATYPE_FACTORY) to use. Can be left unset if not needed. + */ + Class< ? extends IDataTypeFactory> dataTypeFactory() default DefaultDataTypeFactory.class; + + /** + * A regexp that can match table names. Any table matching this regular expression will not be considered by DbUnit. + * By default tables starting with BIN$ are ignored (oracle recycle bin). + */ + String excludedTables() default "^BIN\\$(.*)"; // oracle recycle bin + + /** + * If true, <strong>all</strong> the tables in the database will be truncated before loading any dataset. + */ + boolean truncateAll() default true; + + /** + * The database operation that will be used to truncate tables. Defaults to org.dbunit.operation.DeleteAllOperation + */ + Class< ? extends DatabaseOperation> truncateOperation() default org.dbunit.operation.DeleteAllOperation.class; + + /** + * The database operation that will be used to load datasets. Defaults to org.dbunit.operation.InsertOperation + */ + Class< ? extends DatabaseOperation> insertOperation() default org.dbunit.operation.InsertOperation.class; + +} \ No newline at end of file Deleted: tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-03-20 17:39:12 UTC (rev 751) +++ tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-04-27 09:56:43 UTC (rev 756) @@ -1,336 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing; - -import java.io.IOException; -import java.net.URL; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.dbunit.DatabaseUnitException; -import org.dbunit.database.DatabaseConfig; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.DatabaseSequenceFilter; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.DataSetException; -import org.dbunit.dataset.FilteredDataSet; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.datatype.IDataTypeFactory; -import org.dbunit.dataset.filter.ITableFilter; -import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.operation.DatabaseOperation; -import org.dbunit.operation.DeleteAllOperation; -import org.dbunit.operation.DeleteOperation; -import org.dbunit.operation.InsertOperation; -import org.dbunit.operation.RefreshOperation; -import org.dbunit.operation.TruncateTableOperation; -import org.dbunit.operation.UpdateOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DbUnitTestContext -{ - - /** - * Truncate dataset cache. This is kept as a static attribute since the creation of the dataset is very expensive - * and it doesn't change across tests. - */ - protected static Map<String, IDataSet> truncateDataSetCache = new HashMap<String, IDataSet>(); - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(DbUnitTestContext.class); - - /** - * The test instance. - */ - private Object testcase; - - /** - * Spring application context. - */ - private ApplicationContext applicationContext; - - /** - * Dataset cache. - */ - private Map<String, IDataSet> datasetCache = new HashMap<String, IDataSet>(); - - /** - * Instantiates a new DbUnitTestContext - * @param testcase test instance - * @param applicationContext Spring application context - */ - public DbUnitTestContext(Object testcase, ApplicationContext applicationContext) - { - this.testcase = testcase; - this.applicationContext = applicationContext; - } - - /** - * Setup the Database before running the test method. - * @throws Exception Any exception. - */ - @SuppressWarnings("unchecked") - public void setUpDbUnit() throws Exception - { - DbUnitExecution singleDbUnitExecution = testcase.getClass().getAnnotation(DbUnitExecution.class); - - DbUnitExecution[] executions = null; - if (singleDbUnitExecution != null) - { - executions = new DbUnitExecution[]{singleDbUnitExecution }; - } - else - { - DbUnitConfiguration dbUnitConfiguration = testcase.getClass().getAnnotation(DbUnitConfiguration.class); - if (dbUnitConfiguration != null) - { - executions = dbUnitConfiguration.dbUnitExecutions(); - } - } - if (executions != null) - { - for (DbUnitExecution dbUnitExecution : executions) - { - String[] datasets = dbUnitExecution.datasets(); - String dataSourceName = dbUnitExecution.dataSource(); - String schema = dbUnitExecution.schema(); - if (StringUtils.isEmpty(schema)) - { - schema = null; - } - - IDatabaseConnection connection = new DatabaseConnection( - getDatasource(dataSourceName).getConnection(), - schema); - - if (dbUnitExecution.dataTypeFactory() != null) - { - IDataTypeFactory dataTypeFactory = dbUnitExecution.dataTypeFactory().newInstance(); - connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dataTypeFactory); - } - - try - { - ITableFilter tableFilter = new RegExpTableFilter(dbUnitExecution.excludedTables()); - - if (dbUnitExecution.truncateAll()) - { - truncateAll(connection, tableFilter, dataSourceName, getDatabaseOperation(dbUnitExecution - .truncateOperation())); - } - - DatabaseOperation dbOperation = getDatabaseOperation(dbUnitExecution.insertOperation()); - for (String datasetFile : datasets) - { - importDataSet(createDataset(datasetFile), connection, tableFilter, dataSourceName, dbOperation); - } - } - finally - { - connection.close(); - } - } - } - } - - /** - * Instantiates the givec Database Operation. Standard operations in the <code>org.dbunit.operation</code> package - * have protected constructors and needs to be accessed using the public static fields in - * <code>org.dbunit.operation.DatabaseOperation</code>. - * @param dboperationClass db operation class - * @return db operation instance - * @throws InstantiationException if the given db operation class cannot be instantiated - * @throws IllegalAccessException if the given db operation class cannot be instantiated - */ - private DatabaseOperation getDatabaseOperation(Class< ? extends DatabaseOperation> dboperationClass) - throws InstantiationException, IllegalAccessException - { - if (UpdateOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.UPDATE; - } - else if (InsertOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.INSERT; - } - else if (RefreshOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.REFRESH; - } - else if (DeleteOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.DELETE; - } - else if (DeleteAllOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.DELETE_ALL; - } - else if (TruncateTableOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.TRUNCATE_TABLE; - } - else if (DeleteOperation.class.equals(dboperationClass)) - { - return DatabaseOperation.UPDATE; - } - - return dboperationClass.newInstance(); - - } - - /** - * Creates a dataset instance by fetching a file from the classpath - * @param datasetFile name of the file, will be loaded from the classpath - * @return IDataSet instance - * @throws IOException - * @throws DataSetException - */ - private IDataSet createDataset(String datasetFile) throws IOException, DataSetException - { - IDataSet dataSet = datasetCache.get(datasetFile); - if (dataSet == null) - { - URL datasetUrl = getClass().getResource(datasetFile); - if (datasetUrl == null) - { - throw new IllegalArgumentException("Dataset " + datasetFile + " not found"); - } - dataSet = DbUnitUtils.loadDataset(datasetUrl); - datasetCache.put(datasetFile, dataSet); - } - return dataSet; - } - - private void importDataSet(IDataSet dataSet, IDatabaseConnection connection, ITableFilter tableFilter, - String dataSourceName, DatabaseOperation databaseOperation) throws SQLException, DataSetException, - DatabaseUnitException - { - - if (dataSet == null) - { - throw new IllegalArgumentException("dataSet is null"); - } - - IDataSet orderedDataset = new FilteredDataSet(tableFilter, dataSet); - if (log.isDebugEnabled()) - { - log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); - } - - // if a sorted dataset is available, use table sequence for sorting - IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema()); - if (truncateDataSet != null) - { - ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); - orderedDataset = new FilteredDataSet(filter, dataSet); - } - - if (dataSet != null) - { - databaseOperation.execute(connection, orderedDataset); - } - - } - - /** - * @param connection - * @param tableFilter - * @throws SQLException - * @throws DataSetException - * @throws DatabaseUnitException - */ - private void truncateAll(IDatabaseConnection connection, ITableFilter tableFilter, String dataSourceName, - DatabaseOperation databaseOperation) throws SQLException, DataSetException, DatabaseUnitException - { - IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema()); - if (truncateDataSet == null) - { - log.debug("Generating sorted dataset for initial cleanup"); - IDataSet unsortedDataSet = connection.createDataSet(); - - if (log.isDebugEnabled()) - { - log.debug("Unfiltered truncateDataSet: {}", ArrayUtils.toString(unsortedDataSet.getTableNames())); - } - - // excluded unwanted tables - unsortedDataSet = new FilteredDataSet(tableFilter, unsortedDataSet); - - // sort tables - ITableFilter sortingFilter = new DatabaseSequenceFilter(connection, unsortedDataSet.getTableNames()); - truncateDataSet = new FilteredDataSet(sortingFilter, unsortedDataSet); - - storeTruncateDataset(dataSourceName, connection.getSchema(), truncateDataSet); - log.debug("Sorted dataset generated"); - } - - if (truncateDataSet != null) - { - if (log.isDebugEnabled()) - { - log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); - } - databaseOperation.execute(connection, truncateDataSet); - } - } - - private IDataSet getTruncateDataset(String datasourceName, String schema) - { - return truncateDataSetCache.get(datasourceName + "_" + StringUtils.defaultString(schema)); - } - - private IDataSet storeTruncateDataset(String datasourceName, String schema, IDataSet dataset) - { - return truncateDataSetCache.put(datasourceName + "_" + StringUtils.defaultString(schema), dataset); - } - - /** - * Loads a named datasource from the spring context. - * @param name datasource name. - * @return Datasource instance - */ - @SuppressWarnings("unchecked") - protected DataSource getDatasource(String name) - { - if (StringUtils.isEmpty(name)) - { - Map<String, DataSource> dsMap = applicationContext.getBeansOfType(DataSource.class); - if (dsMap == null || dsMap.size() != 1) - { - throw new RuntimeException( - "Unable to find a datasource in spring applicationContext, please specify the datasource bean name " - + "using the \"datasource\" attribute of @DbUnitConfiguration"); - } - return dsMap.values().iterator().next(); - } - return (DataSource) applicationContext.getBean(name); - } - -} Copied: tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java (from rev 753, trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitTestContext.java) =================================================================== --- tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java (rev 0) +++ tags/openutils-testing-2.1/src/main/java/it/openutils/testing/DbUnitTestContext.java 2008-04-27 09:56:43 UTC (rev 756) @@ -0,0 +1,335 @@ +/* + * Copyright Openmind http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing; + +import java.io.IOException; +import java.net.URL; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.dbunit.DatabaseUnitException; +import org.dbunit.database.DatabaseConfig; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.DatabaseSequenceFilter; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.FilteredDataSet; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.datatype.IDataTypeFactory; +import org.dbunit.dataset.filter.ITableFilter; +import org.dbunit.dataset.filter.SequenceTableFilter; +import org.dbunit.operation.DatabaseOperation; +import org.dbunit.operation.DeleteAllOperation; +import org.dbunit.operation.DeleteOperation; +import org.dbunit.operation.InsertOperation; +import org.dbunit.operation.RefreshOperation; +import org.dbunit.operation.TruncateTableOperation; +import org.dbunit.operation.UpdateOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DbUnitTestContext +{ + + /** + * Truncate dataset cache. This is kept as a static attribute since the creation of the dataset is very expensive + * and it doesn't change across tests. + */ + protected static Map<String, IDataSet> truncateDataSetCache = new HashMap<String, IDataSet>(); + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(DbUnitTestContext.class); + + /** + * The test instance. + */ + private Object testcase; + + /** + * Spring application context. + */ + private ApplicationContext applicationContext; + + /** + * Dataset cache. + */ + private Map<String, IDataSet> datasetCache = new HashMap<String, IDataSet>(); + + /** + * Instantiates a new DbUnitTestContext + * @param testcase test instance + * @param applicationContext Spring application context + */ + public DbUnitTestContext(Object testcase, ApplicationContext applicationContext) + { + this.testcase = testcase; + this.applicationContext = applicationContext; + } + + /** + * Setup the Database before running the test method. + * @throws Exception Any exception. + */ + public void setUpDbUnit() throws Exception + { + DbUnitExecution singleDbUnitExecution = testcase.getClass().getAnnotation(DbUnitExecution.class); + + DbUnitExecution[] executions = null; + if (singleDbUnitExecution != null) + { + executions = new DbUnitExecution[]{singleDbUnitExecution }; + } + else + { + DbUnitConfiguration dbUnitConfiguration = testcase.getClass().getAnnotation(DbUnitConfiguration.class); + if (dbUnitConfiguration != null) + { + executions = dbUnitConfiguration.dbUnitExecutions(); + } + } + if (executions != null) + { + for (DbUnitExecution dbUnitExecution : executions) + { + String[] datasets = dbUnitExecution.datasets(); + String dataSourceName = dbUnitExecution.dataSource(); + String schema = dbUnitExecution.schema(); + if (StringUtils.isEmpty(schema)) + { + schema = null; + } + + IDatabaseConnection connection = new DatabaseConnection( + getDatasource(dataSourceName).getConnection(), + schema); + + if (dbUnitExecution.dataTypeFactory() != null) + { + IDataTypeFactory dataTypeFactory = dbUnitExecution.dataTypeFactory().newInstance(); + connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dataTypeFactory); + } + + try + { + ITableFilter tableFilter = new RegExpTableFilter(dbUnitExecution.excludedTables()); + + if (dbUnitExecution.truncateAll()) + { + truncateAll(connection, tableFilter, dataSourceName, getDatabaseOperation(dbUnitExecution + .truncateOperation())); + } + + DatabaseOperation dbOperation = getDatabaseOperation(dbUnitExecution.insertOperation()); + for (String datasetFile : datasets) + { + importDataSet(createDataset(datasetFile), connection, tableFilter, dataSourceName, dbOperation); + } + } + finally + { + connection.close(); + } + } + } + } + + /** + * Instantiates the givec Database Operation. Standard operations in the <code>org.dbunit.operation</code> package + * have protected constructors and needs to be accessed using the public static fields in + * <code>org.dbunit.operation.DatabaseOperation</code>. + * @param dboperationClass db operation class + * @return db operation instance + * @throws InstantiationException if the given db operation class cannot be instantiated + * @throws IllegalAccessException if the given db operation class cannot be instantiated + */ + private DatabaseOperation getDatabaseOperation(Class< ? extends DatabaseOperation> dboperationClass) + throws InstantiationException, IllegalAccessException + { + if (UpdateOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.UPDATE; + } + else if (InsertOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.INSERT; + } + else if (RefreshOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.REFRESH; + } + else if (DeleteOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.DELETE; + } + else if (DeleteAllOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.DELETE_ALL; + } + else if (TruncateTableOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.TRUNCATE_TABLE; + } + else if (DeleteOperation.class.equals(dboperationClass)) + { + return DatabaseOperation.UPDATE; + } + + return dboperationClass.newInstance(); + + } + + /** + * Creates a dataset instance by fetching a file from the classpath + * @param datasetFile name of the file, will be loaded from the classpath + * @return IDataSet instance + * @throws IOException + * @throws DataSetException + */ + private IDataSet createDataset(String datasetFile) throws IOException, DataSetException + { + IDataSet dataSet = datasetCache.get(datasetFile); + if (dataSet == null) + { + URL datasetUrl = getClass().getResource(datasetFile); + if (datasetUrl == null) + { + throw new IllegalArgumentException("Dataset " + datasetFile + " not found"); + } + dataSet = DbUnitUtils.loadDataset(datasetUrl); + datasetCache.put(datasetFile, dataSet); + } + return dataSet; + } + + private void importDataSet(IDataSet dataSet, IDatabaseConnection connection, ITableFilter tableFilter, + String dataSourceName, DatabaseOperation databaseOperation) throws SQLException, DataSetException, + DatabaseUnitException + { + + if (dataSet == null) + { + throw new IllegalArgumentException("dataSet is null"); + } + + IDataSet orderedDataset = new FilteredDataSet(tableFilter, dataSet); + if (log.isDebugEnabled()) + { + log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); + } + + // if a sorted dataset is available, use table sequence for sorting + IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema()); + if (truncateDataSet != null) + { + ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); + orderedDataset = new FilteredDataSet(filter, dataSet); + } + + if (dataSet != null) + { + databaseOperation.execute(connection, orderedDataset); + } + + } + + /** + * @param connection + * @param tableFilter + * @throws SQLException + * @throws DataSetException + * @throws DatabaseUnitException + */ + private void truncateAll(IDatabaseConnection connection, ITableFilter tableFilter, String dataSourceName, + DatabaseOperation databaseOperation) throws SQLException, DataSetException, DatabaseUnitException + { + IDataSet truncateDataSet = getTruncateDataset(dataSourceName, connection.getSchema()); + if (truncateDataSet == null) + { + log.debug("Generating sorted dataset for initial cleanup"); + IDataSet unsortedDataSet = connection.createDataSet(); + + if (log.isDebugEnabled()) + { + log.debug("Unfiltered truncateDataSet: {}", ArrayUtils.toString(unsortedDataSet.getTableNames())); + } + + // excluded unwanted tables + unsortedDataSet = new FilteredDataSet(tableFilter, unsortedDataSet); + + // sort tables + ITableFilter sortingFilter = new DatabaseSequenceFilter(connection, unsortedDataSet.getTableNames()); + truncateDataSet = new FilteredDataSet(sortingFilter, unsortedDataSet); + + storeTruncateDataset(dataSourceName, connection.getSchema(), truncateDataSet); + log.debug("Sorted dataset generated"); + } + + if (truncateDataSet != null) + { + if (log.isDebugEnabled()) + { + log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); + } + databaseOperation.execute(connection, truncateDataSet); + } + } + + private IDataSet getTruncateDataset(String datasourceName, String schema) + { + return truncateDataSetCache.get(datasourceName + "_" + StringUtils.defaultString(schema)); + } + + private IDataSet storeTruncateDataset(String datasourceName, String schema, IDataSet dataset) + { + return truncateDataSetCache.put(datasourceName + "_" + StringUtils.defaultString(schema), dataset); + } + + /** + * Loads a named datasource from the spring context. + * @param name datasource name. + * @return Datasource instance + */ + @SuppressWarnings("unchecked") + protected DataSource getDatasource(String name) + { + if (StringUtils.isEmpty(name)) + { + Map<String, DataSource> dsMap = applicationContext.getBeansOfType(DataSource.class); + if (dsMap == null || dsMap.size() != 1) + { + throw new RuntimeException( + "Unable to find a datasource in spring applicationContext, please specify the datasource bean name " + + "using the \"datasource\" attribute of @DbUnitConfiguration"); + } + return dsMap.values().iterator().next(); + } + return (DataSource) applicationContext.getBean(name); + } + +} Deleted: tags/openutils-testing-2.1/src/site/changes/changes.xml =================================================================== --- trunk/openutils-testing/src/site/changes/changes.xml 2008-03-20 17:39:12 UTC (rev 751) +++ tags/openutils-testing-2.1/src/site/changes/changes.xml 2008-04-27 09:56:43 UTC (rev 756) @@ -1,40 +0,0 @@ -<?xml version="1.0"?> -<!-- - "type" attribute can be: add, remove, update or fix. ---> -<document> - <properties> - <title>Changes</title> - <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> - </properties> - <body> - <release version="2.0.3" date="in svn" description="2.0.3"> - <action type="fix" dev="fgiust"> excludedTables in DbUnitExecution now defaults to "^BIN\\$(.*)", properly excluding - tables in oracle recycle bin.</action> - </release> - <release version="2.0.3" date="2008-02-19" description="2.0.3"> - <action type="update" dev="fgiust"> it.openutils.testing.DateAssert is now thread safe. Failure messages have been - improved.</action> - <action type="add" dev="fcarone"> New option for DbUnitExection to specify the - DatabaseConfig.PROPERTY_DATATYPE_FACTORY added.</action> - </release> - <release version="2.0.2" date="2008-01-31" description="2.0.2"> - <action type="add" dev="fgiust"> New dbunit operation classes for mssql and mysql (extension of standard dbunit - operation, but refactored so that they can be used in annotations). See the javadocs in the - it.openutils.testing.dbunit package</action> - <action type="update" dev="fgiust"> truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of - DbUnitOperation.TRUNCATE.</action> - <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the - provided connection</action> - <action type="add" dev="fgiust">new DbUnitUtils.exportTablesToDir() utility method</action> - </release> - <release version="2.0.1" date="2008-01-30" description="2.0.1"> - <action type="fix" dev="fgiust"> (junit version only). - it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests was totally broken due to the setup method - being protected. Fixed + added tests</action> - </release> - <release version="2.0" date="2008-01-20" description="2.0 release"> - <action type="update" dev="fgiust">Totally reworked dbunit test framework.</action> - </release> - </body> -</document> \ No newline at end of file Copied: tags/openutils-testing-2.1/src/site/changes/changes.xml (from rev 754, trunk/openutils-testing/src/site/changes/changes.xml) =================================================================== --- tags/openutils-testing-2.1/src/site/changes/changes.xml (rev 0) +++ tags/openutils-testing-2.1/src/site/changes/changes.xml 2008-04-27 09:56:43 UTC (rev 756) @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<!-- + "type" attribute can be: add, remove, update or fix. +--> +<document> + <properties> + <title>Changes</title> + <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + </properties> + <body> + <release version="2.1" date="2008-04-27" description="2.1"> + <action type="update" dev="fgiust">Legacy base test classes (DbUnitTestCase, GenericsDbUnitTestCase) have been + dropped. Stick with 2.0.x if you are still use them or upgrade to 2.1 for a forced migration</action> + <action type="update" dev="fgiust">Updated spring, slf4j and commons-lang dependencies</action> + <action type="fix" dev="fgiust"> excludedTables in DbUnitExecution now defaults to "^BIN\\$(.*)", properly excluding + tables in oracle recycle bin.</action> + <action type="add" dev="fcarone"> New option for DbUnitExection to specify the + DatabaseConfig.PROPERTY_DATATYPE_FACTORY added.</action> + </release> + <release version="2.0.3" date="2008-02-19" description="2.0.3"> + <action type="update" dev="fgiust"> it.openutils.testing.DateAssert is now thread safe. Failure messages have been + improved.</action> + </release> + <release version="2.0.2" date="2008-01-31" description="2.0.2"> + <action type="add" dev="fgiust"> New dbunit operation classes for mssql and mysql (extension of standard dbunit + operation, but refactored so that they can be used in annotations). See the javadocs in the + it.openutils.testing.dbunit package</action> + <action type="update" dev="fgiust"> truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of + DbUnitOperation.TRUNCATE.</action> + <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the + provided connection</action> + <action type="add" dev="fgiust">new DbUnitUtils.exportTablesToDir() utility method</action> + </release> + <release version="2.0.1" date="2008-01-30" description="2.0.1"> + <action type="fix" dev="fgiust"> (junit version only). + it.openutils.testing.junit.AbstractDbUnitJunitSpringContextTests was totally broken due to the setup method + being protected. Fixed + added tests</action> + </release> + <release version="2.0" date="2008-01-20" description="2.0 release"> + <action type="update" dev="fgiust">Totally reworked dbunit test framework.</action> + </release> + </body> +</document> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-27 12:22:05
|
Revision: 765 http://openutils.svn.sourceforge.net/openutils/?rev=765&view=rev Author: fgiust Date: 2008-04-27 05:22:10 -0700 (Sun, 27 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-junit-2.1 Added Paths: ----------- tags/openutils-testing-junit-2.1/ tags/openutils-testing-junit-2.1/pom.xml Removed Paths: ------------- tags/openutils-testing-junit-2.1/pom.xml Copied: tags/openutils-testing-junit-2.1 (from rev 763, trunk/openutils-testing-junit) Deleted: tags/openutils-testing-junit-2.1/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2008-04-27 12:20:46 UTC (rev 763) +++ tags/openutils-testing-junit-2.1/pom.xml 2008-04-27 12:22:10 UTC (rev 765) @@ -1,122 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>7</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-junit</artifactId> - <name>openutils test utils (junit)</name> - <version>2.0.3-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <exclusion> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>junit-addons</groupId> - <artifactId>junit-addons</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>10.2.2.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-dbcp</groupId> - <artifactId>commons-dbcp</artifactId> - <version>1.2.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <artifactId>xerces</artifactId> - <groupId>xerces</groupId> - </exclusion> - <exclusion> - <artifactId>xml-apis</artifactId> - <groupId>xml-apis</groupId> - </exclusion> - <exclusion> - <artifactId>commons-logging</artifactId> - <groupId>commons-logging</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.3</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-testing-junit-2.1/pom.xml (from rev 764, trunk/openutils-testing-junit/pom.xml) =================================================================== --- tags/openutils-testing-junit-2.1/pom.xml (rev 0) +++ tags/openutils-testing-junit-2.1/pom.xml 2008-04-27 12:22:10 UTC (rev 765) @@ -0,0 +1,127 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>7</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-junit</artifactId> + <name>openutils test utils (junit)</name> + <version>2.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.2.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + <version>1.2.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <artifactId>xerces</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>xml-apis</artifactId> + <groupId>xml-apis</groupId> + </exclusion> + <exclusion> + <artifactId>commons-logging</artifactId> + <groupId>commons-logging</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.3</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-2.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-2.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-2.1</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-27 13:18:49
|
Revision: 775 http://openutils.svn.sourceforge.net/openutils/?rev=775&view=rev Author: fgiust Date: 2008-04-27 06:18:47 -0700 (Sun, 27 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-bshd5-2.0.3 Added Paths: ----------- tags/openutils-bshd5-2.0.3/ tags/openutils-bshd5-2.0.3/pom.xml Removed Paths: ------------- tags/openutils-bshd5-2.0.3/pom.xml Copied: tags/openutils-bshd5-2.0.3 (from rev 773, trunk/openutils-bshd5) Deleted: tags/openutils-bshd5-2.0.3/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2008-04-27 13:16:06 UTC (rev 773) +++ tags/openutils-bshd5-2.0.3/pom.xml 2008-04-27 13:18:47 UTC (rev 775) @@ -1,109 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>8</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-bshd5</artifactId> - <name>openutils base Spring-Hibernate DAO for java 5.0</name> - <version>2.0.3-SNAPSHOT</version> - <description>openutils base Spring-Hibernate DAO for java 5.0</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.5.0</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - <version>1.5.0</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate</artifactId> - <version>3.2.1.ga</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>cglib</groupId> - <artifactId>cglib</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.7.0</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - </dependencies> - <properties> - <spring.version>2.5.3</spring.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-bshd5-2.0.3/pom.xml (from rev 774, trunk/openutils-bshd5/pom.xml) =================================================================== --- tags/openutils-bshd5-2.0.3/pom.xml (rev 0) +++ tags/openutils-bshd5-2.0.3/pom.xml 2008-04-27 13:18:47 UTC (rev 775) @@ -0,0 +1,114 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>8</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-bshd5</artifactId> + <name>openutils base Spring-Hibernate DAO for java 5.0</name> + <version>2.0.3</version> + <description>openutils base Spring-Hibernate DAO for java 5.0</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.5.0</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.7.0</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + </dependencies> + <properties> + <spring.version>2.5.3</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.3</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-bshd5-2.0.3</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-bshd5-2.0.3</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-27 20:50:12
|
Revision: 787 http://openutils.svn.sourceforge.net/openutils/?rev=787&view=rev Author: fgiust Date: 2008-04-27 13:48:55 -0700 (Sun, 27 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnltasks-3.5 Added Paths: ----------- tags/openutils-mgnltasks-3.5/ tags/openutils-mgnltasks-3.5/pom.xml Removed Paths: ------------- tags/openutils-mgnltasks-3.5/pom.xml Copied: tags/openutils-mgnltasks-3.5 (from rev 784, trunk/openutils-mgnltasks) Deleted: tags/openutils-mgnltasks-3.5/pom.xml =================================================================== --- trunk/openutils-mgnltasks/pom.xml 2008-04-27 20:42:00 UTC (rev 784) +++ tags/openutils-mgnltasks-3.5/pom.xml 2008-04-27 20:48:55 UTC (rev 787) @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>8</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <packaging>jar</packaging> - <artifactId>openutils-mgnltasks</artifactId> - <name>openutils-mgnltasks</name> - <version>3.5-SNAPSHOT</version> - <description>A collection of useful magnolia update tasks that can be reused in custom modules</description> - <licenses> - <license> - <name>GPLv3</name> - <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> - </license> - </licenses> - <build> - <resources> - <resource> - <filtering>false</filtering> - <directory>src/main/resources</directory> - <includes> - <include>**/*</include> - </includes> - </resource> - <resource> - <filtering>true</filtering> - <directory>src/main/resources</directory> - <includes> - <include>META-INF/magnolia/*</include> - </includes> - </resource> - </resources> - </build> - <dependencies> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-core</artifactId> - <version>3.5.4</version> - </dependency> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-module-admininterface</artifactId> - <version>3.5.4</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jsp-api</artifactId> - <version>2.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.7</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <repositories> - <repository> - <id>repository.magnolia.info</id> - <name>magnolia repository</name> - <url>http://repo.magnolia.info/m2</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - </repositories> -</project> Copied: tags/openutils-mgnltasks-3.5/pom.xml (from rev 786, trunk/openutils-mgnltasks/pom.xml) =================================================================== --- tags/openutils-mgnltasks-3.5/pom.xml (rev 0) +++ tags/openutils-mgnltasks-3.5/pom.xml 2008-04-27 20:48:55 UTC (rev 787) @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>8</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <artifactId>openutils-mgnltasks</artifactId> + <name>openutils-mgnltasks</name> + <version>3.5</version> + <description>A collection of useful magnolia update tasks that can be reused in custom modules</description> + <licenses> + <license> + <name>GPLv3</name> + <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> + </license> + </licenses> + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <filtering>true</filtering> + <directory>src/main/resources</directory> + <includes> + <include>META-INF/magnolia/*</include> + </includes> + </resource> + </resources> + </build> + <dependencies> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>3.5.4</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-module-admininterface</artifactId> + <version>3.5.4</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.7</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <repositories> + <repository> + <id>repository.magnolia.info</id> + <name>magnolia repository</name> + <url>http://repo.magnolia.info/m2</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnltasks-3.5</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnltasks-3.5</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnltasks-3.5</url> + </scm> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-27 21:21:55
|
Revision: 792 http://openutils.svn.sourceforge.net/openutils/?rev=792&view=rev Author: fgiust Date: 2008-04-27 14:21:43 -0700 (Sun, 27 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-maven-skin-1.1 Added Paths: ----------- tags/openutils-maven-skin-1.1/ tags/openutils-maven-skin-1.1/pom.xml tags/openutils-maven-skin-1.1/src/main/resources/css/maven-base.css tags/openutils-maven-skin-1.1/src/main/resources/css/maven-theme.css tags/openutils-maven-skin-1.1/src/main/resources/css/print.css tags/openutils-maven-skin-1.1/src/main/resources/images/logos/ Removed Paths: ------------- tags/openutils-maven-skin-1.1/pom.xml tags/openutils-maven-skin-1.1/src/main/resources/css/site.css Copied: tags/openutils-maven-skin-1.1 (from rev 779, trunk/openutils-maven-skin) Deleted: tags/openutils-maven-skin-1.1/pom.xml =================================================================== --- trunk/openutils-maven-skin/pom.xml 2008-04-27 16:35:14 UTC (rev 779) +++ tags/openutils-maven-skin-1.1/pom.xml 2008-04-27 21:21:43 UTC (rev 792) @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>8</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-maven-skin</artifactId> - <packaging>jar</packaging> - <version>1.1-SNAPSHOT</version> - <name>maven skin for openutils site</name> - <description>maven skin for openutils site</description> -</project> Copied: tags/openutils-maven-skin-1.1/pom.xml (from rev 791, trunk/openutils-maven-skin/pom.xml) =================================================================== --- tags/openutils-maven-skin-1.1/pom.xml (rev 0) +++ tags/openutils-maven-skin-1.1/pom.xml 2008-04-27 21:21:43 UTC (rev 792) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>8</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-maven-skin</artifactId> + <packaging>jar</packaging> + <version>1.1</version> + <name>openutils maven skin</name> + <description>openutils maven skin</description> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-maven-skin-1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-maven-skin-1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-maven-skin-1.1</url> + </scm> +</project> \ No newline at end of file Copied: tags/openutils-maven-skin-1.1/src/main/resources/css/maven-base.css (from rev 789, trunk/openutils-maven-skin/src/main/resources/css/maven-base.css) =================================================================== --- tags/openutils-maven-skin-1.1/src/main/resources/css/maven-base.css (rev 0) +++ tags/openutils-maven-skin-1.1/src/main/resources/css/maven-base.css 2008-04-27 21:21:43 UTC (rev 792) @@ -0,0 +1,148 @@ +body { + margin: 0px; + padding: 0px; +} +img { + border:none; +} +table { + padding:0px; + width: 100%; + margin-left: -2px; + margin-right: -2px; +} +acronym { + cursor: help; + border-bottom: 1px dotted #feb; +} +table.bodyTable th, table.bodyTable td { + padding: 2px 4px 2px 4px; + vertical-align: top; +} +div.clear{ + clear:both; + visibility: hidden; +} +div.clear hr{ + display: none; +} +#bannerLeft, #bannerRight { + font-size: xx-large; + font-weight: bold; +} +#bannerLeft img, #bannerRight img { + margin: 0px; +} +.xleft, #bannerLeft img { + float:left; + text-shadow: #7CFC00; +} +.xright, #bannerRight img { + float:right; + text-shadow: #7CFC00; +} +#banner { + padding: 0px; +} +#banner img { + border: none; +} +#breadcrumbs { + padding: 3px 10px 3px 10px; +} +#leftColumn { + width: 170px; + float:left; + overflow: auto; +} +#bodyColumn { + margin-right: 1.5em; + margin-left: 197px; +} +#legend { + padding: 8px 0 8px 0; +} +#navcolumn { + padding: 8px 4px 0 8px; +} +#navcolumn h5 { + margin: 0; + padding: 0; + font-size: small; +} +#navcolumn ul { + margin: 0; + padding: 0; + font-size: small; +} +#navcolumn li { + list-style-type: none; + background-image: none; + background-repeat: no-repeat; + background-position: 0 0.4em; + padding-left: 16px; + list-style-position: outside; + line-height: 1.2em; + font-size: smaller; +} +#navcolumn li.expanded { + background-image: url(../images/expanded.gif); +} +#navcolumn li.collapsed { + background-image: url(../images/collapsed.gif); +} +#poweredBy { + text-align: center; +} +#navcolumn img { + margin-top: 10px; + margin-bottom: 3px; +} +#poweredBy img { + display:block; + margin: 20px 0 20px 17px; + border: 1px solid black; + width: 90px; + height: 30px; +} +#search img { + margin: 0px; + display: block; +} +#search #q, #search #btnG { + border: 1px solid #999; + margin-bottom:10px; +} +#search form { + margin: 0px; +} +#lastPublished { + font-size: x-small; +} +.navSection { + margin-bottom: 2px; + padding: 8px; +} +.navSectionHead { + font-weight: bold; + font-size: x-small; +} +.section { + padding: 4px; +} +#footer { + padding: 3px 10px 3px 10px; + font-size: x-small; +} +#breadcrumbs { + font-size: x-small; + margin: 0pt; +} +.source { + padding: 12px; + margin: 1em 7px 1em 7px; +} +.source pre { + margin: 0px; + padding: 0px; +} Copied: tags/openutils-maven-skin-1.1/src/main/resources/css/maven-theme.css (from rev 789, trunk/openutils-maven-skin/src/main/resources/css/maven-theme.css) =================================================================== --- tags/openutils-maven-skin-1.1/src/main/resources/css/maven-theme.css (rev 0) +++ tags/openutils-maven-skin-1.1/src/main/resources/css/maven-theme.css 2008-04-27 21:21:43 UTC (rev 792) @@ -0,0 +1,316 @@ +body { + background-color: #1B87CA; + font-family: Verdana, Helvetica, Arial, sans-serif; + margin-left: auto; + margin-right: auto; + background-repeat: repeat-y; + font-size: 13px; + padding: 0px; +} + +#leftColumn { + width: 170px; + float: left; +} + +#bodyColumn { + margin-right: 0 !important; + margin-left: 0; + min-height: 600px; + background-color: #fff; + padding-left: 207px; + padding-right: 10px; +} + +td,select,input,li { + font-family: Verdana, Helvetica, Arial, sans-serif; + font-size: 12px; + color: #333; +} + +code { + font-size: 12px; +} + +a { + text-decoration: underline; +} + +#leftColumn a { + text-decoration: none; +} + +#leftColumn a.poweredBy { + border: none; +} + +a:link { + color: #47a; +} + +a:visited { + color: #666; +} + +a:active,a:hover { + color: #900; +} + +#legend li.externalLink { + background: url(../images/ico_external.png) left top no-repeat; + padding-left: 10px; +} + +a.externalLink,a.externalLink:link,a.externalLink:visited,a.externalLink:active,a.externalLink:hover { + background: url(../images/ico_external.png) right center no-repeat; + padding-right: 10px; +} + +#legend li.newWindow { + background: url(../images/ico_newwindow.png) left top no-repeat; + padding-left: 10px; +} + +a.newWindow,a.newWindow:link,a.newWindow:visited,a.newWindow:active,a.newWindow:hover { + background: url(../images/ico_newwindow.png) right center no-repeat; + padding-right: 10px; +} + +h2 { + font-family: Arial, Helvetica, sans-serif; + font-size: 28px; + color: #666; + background: none; + font-weight: normal; + padding-left: 0; + border: none; + border-bottom: 1px dotted #ccc; +} + +h3 { + font-family: Arial, Helvetica, sans-serif; + padding: 4px 4px 4px 0; + color: #999 !important; + background: none; + font-weight: none; + font-size: 20px; + border: none; + border-bottom: 1px dotted #ccc; +} + +p { + line-height: 1.3em; + font-size: 12px; + color: #000; +} + +#breadcrumbs { + overflow: hidden; + padding: 4px 10px 4px 20px; + background-image: url(../images/breadcrumbs.png); + background-repeat: repeat-x; + border: none; + background-color: #fff !important; +} + +#breadcrumbs a { + font-weight: bold; + color: #000; + text-decoration: underline; +} + +#leftColumn { + margin: 10px 0 10px 10px; + border: 1px solid #6bb521; + padding-right: 0; + padding-left: 0; + width: 180px; + background-color: #efc; +} + +#navcolumn { + margin: 0 !important; + padding: 0 !important; +} + +#navcolumn h5 { + font-size: 11px; + padding: 1px 0 1px 12px; + color: #fff; + background-position: left 5px; + font-variant: small-caps; + border: none; + border-bottom: 1px solid #ccc; + background-color: #6bb521; +} + +#navcolumn #lastPublished { + font-size: 10px; + margin: 20px 0pt 10px 15px; +} + +table.bodyTable th { + color: white; + background-color: #1B87CA; + text-align: left; + font-weight: normal; +} + +table.bodyTable th,table.bodyTable td { + font-size: 11px; +} + +table.bodyTable tr.a { + background-color: #ddd; +} + +table.bodyTable tr.b { + background-color: #eee; +} + +.source { + border: 1px solid #999; + overflow: auto; + background-color: #eee; +} + +dt { + padding: 4px 4px 4px 24px; + color: #333333; + background-color: #ccc; + font-weight: bold; + font-size: 14px; +} + +.subsectionTitle { + font-size: 13px; + font-weight: bold; + color: #666; +} + +table { + font-size: 10px; +} + +.xright a:link,.xright a:visited,.xright a:active { + color: #666; +} + +.xright a:hover { + color: #003300; +} + +#banner { + height: 93px; + background-color: #fff; + background-image: url(../images/header-background.png); +} + +#banner a#bannerRight img { + margin: 10px 10px 0 0 !important; +} + +#banner a#bannerLeft img { + margin: 10px 0 0 10px !important; +} + +#navcolumn ul { + margin: 3px 0 5px -0em; +} + +#navcolumn ul a { + color: #333333; +} + +#navcolumn ul a:hover { + color: red; +} + +#navcolumn ul li { + background-image: url(../images/list.png); + background-position: top left; + background-repeat: no-repeat; + margin-bottom: 2px; +} + +#navcolumn ul li.expanded { + background-image: none; + font-weight: bold; + color: #666; +} + +#navcolumn ul li.expanded ul { + margin-top: 0; + margin-bottom: 0; +} + +#navcolumn ul li.expanded ul li { + font-weight: normal; +} + +#intro { + border: solid #ccc 1px; + margin: 6px 0px 0px 0px; + padding: 10px 40px 10px 40px; +} + +.subsection { + margin-left: 3px; + color: #333333; +} + +.subsection p { + font-size: 12px; +} + +#footer { + padding: 10px; + margin: 0 0px 20px 0px; + border-top: solid #ccc 1px; + color: #fff; + background-color: #1B87CA; + background-image: url(../images/footer-background.png); + background-repeat: repeat-x; +} + +#footer div { + color: #fff; +} + +dl { + border: 1px dotted #ccc; + background-color: transparent; +} + +dt { + background-color: transparent; + font-family: Arial, Helvetica, sans-serif; + color: #999 !important; + font-weight: bold; + font-size: 16px; +} + +hr { + border: none; + border-bottom: 1px solid #ccc; + background-color: transparent; + height: 1px; +} + +#breadcrumbs,#footer,#navcolumn li { + font-size: 10px; +} + +a.poweredBy { + margin-left: 20px; +} + +.source { + margin: 10px 0; + padding: 12px; + border: 1px solid #1B87CA; +} + +#navcolumn li.collapsed { + background-image: url(../images/ico-collapsed.png); +} Copied: tags/openutils-maven-skin-1.1/src/main/resources/css/print.css (from rev 789, trunk/openutils-maven-skin/src/main/resources/css/print.css) =================================================================== --- tags/openutils-maven-skin-1.1/src/main/resources/css/print.css (rev 0) +++ tags/openutils-maven-skin-1.1/src/main/resources/css/print.css 2008-04-27 21:21:43 UTC (rev 792) @@ -0,0 +1,7 @@ +#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { + display: none !important; +} +#bodyColumn, body.docs div.docs { + margin: 0 !important; + border: none !important +} Deleted: tags/openutils-maven-skin-1.1/src/main/resources/css/site.css =================================================================== --- trunk/openutils-maven-skin/src/main/resources/css/site.css 2008-04-27 16:35:14 UTC (rev 779) +++ tags/openutils-maven-skin-1.1/src/main/resources/css/site.css 2008-04-27 21:21:43 UTC (rev 792) @@ -1,314 +0,0 @@ -body { - background-color: #1B87CA; - font-family: Verdana, Helvetica, Arial, sans-serif; - margin-left: auto; - margin-right: auto; - background-repeat: repeat-y; - font-size: 13px; - padding: 0px; -} - -#leftColumn { - width: 170px; - float: left; -} - -#bodyColumn { - margin-right: 0 !important; - margin-left: 0; - min-height: 600px; - background-color: #fff; - padding-left: 207px; - padding-right: 10px; -} - -td,select,input,li { - font-family: Verdana, Helvetica, Arial, sans-serif; - font-size: 12px; - color: #333; -} - -code { - font-size: 12px; -} - -a { - text-decoration: underline; -} - -#leftColumn a { - text-decoration: none; -} - -#leftColumn a.poweredBy { - border: none; -} - -a:link { - color: #47a; -} - -a:visited { - color: #666; -} - -a:active,a:hover { - color: #900; -} - -#legend li.externalLink { - background: url(../images/ico_external.png) left top no-repeat; - padding-left: 10px; -} - -a.externalLink,a.externalLink:link,a.externalLink:visited,a.externalLink:active,a.externalLink:hover { - background: url(../images/ico_external.png) right center no-repeat; - padding-right: 10px; -} - -#legend li.newWindow { - background: url(../images/ico_newwindow.png) left top no-repeat; - padding-left: 10px; -} - -a.newWindow,a.newWindow:link,a.newWindow:visited,a.newWindow:active,a.newWindow:hover { - background: url(../images/ico_newwindow.png) right center no-repeat; - padding-right: 10px; -} - -h2 { - font-family: Arial, Helvetica, sans-serif; - font-size: 28px; - color: #666; - background: none; - font-weight: normal; - padding-left: 0; - border: none; - border-bottom: 1px dotted #ccc; -} - -h3 { - font-family: Arial, Helvetica, sans-serif; - padding: 4px 4px 4px 0; - color: #999 !important; - background: none; - font-weight: none; - font-size: 20px; - border: none; - border-bottom: 1px dotted #ccc; -} - -p { - line-height: 1.3em; - font-size: 12px; - color: #000; -} - -#breadcrumbs { - overflow: hidden; - padding: 4px 10px 4px 20px; - background-image: url(../images/breadcrumbs.png); - background-repeat: repeat-x; - border: none; - background-color: #fff !important; -} - -#breadcrumbs a { - font-weight: bold; - color: #000; - text-decoration: underline; -} - -#leftColumn { - margin: 10px 0 10px 10px; - border: 1px solid #6bb521; - padding-right: 0; - padding-left: 0; - width: 180px; - background-color: #efc; -} - -#navcolumn { - margin: 0 !important; - padding: 0 !important; -} - -#navcolumn h5 { - font-size: 11px; - padding: 1px 0 1px 12px; - color: #fff; - background-position: left 5px; - font-variant: small-caps; - border: none; - border-bottom: 1px solid #ccc; - background-color: #6bb521; -} - -#navcolumn #lastPublished { - font-size: 10px; - margin: 20px 0pt 10px 15px; -} - -table.bodyTable th { - color: white; - background-color: #1B87CA; - text-align: left; - font-weight: normal; -} - -table.bodyTable th,table.bodyTable td { - font-size: 11px; -} - -table.bodyTable tr.a { - background-color: #ddd; -} - -table.bodyTable tr.b { - background-color: #eee; -} - -.source { - border: 1px solid #999; - overflow: auto; - background-color: #eee; -} - -dt { - padding: 4px 4px 4px 24px; - color: #333333; - background-color: #ccc; - font-weight: bold; - font-size: 14px; -} - -.subsectionTitle { - font-size: 13px; - font-weight: bold; - color: #666; -} - -table { - font-size: 10px; -} - -.xright a:link,.xright a:visited,.xright a:active { - color: #666; -} - -.xright a:hover { - color: #003300; -} - -#banner { - height: 93px; - background-color: #fff; - background-image: url(../images/header-background.png); -} - -#banner a#bannerRight img { - margin: 10px 10px 0 0 !important; -} - -#banner a#bannerLeft img { - margin: 10px 0 0 10px !important; -} - -#navcolumn ul { - margin: 3px 0 5px -0em; -} - -#navcolumn ul a { - color: #333333; -} - -#navcolumn ul a:hover { - color: red; -} - -#navcolumn ul li { - background-image: url(../images/list.png); - background-position: top left; -} - -#navcolumn ul li.expanded { - background-image: none; - font-weight: bold; - color: #666; -} - -#navcolumn ul li.expanded ul { - margin-top: 0; - margin-bottom: 0; -} - -#navcolumn ul li.expanded ul li { - font-weight: normal; -} - -#intro { - border: solid #ccc 1px; - margin: 6px 0px 0px 0px; - padding: 10px 40px 10px 40px; -} - -.subsection { - margin-left: 3px; - color: #333333; -} - -.subsection p { - font-size: 12px; -} - -#footer { - padding: 10px; - margin: 0 0px 20px 0px; - border-top: solid #ccc 1px; - color: #fff; - background-color: #1B87CA; - background-image: url(../images/footer-background.png); - background-repeat: repeat-x; -} - -#footer div { - color: #fff; -} - -dl { - border: 1px dotted #ccc; - background-color: transparent; -} - -dt { - background-color: transparent; - font-family: Arial, Helvetica, sans-serif; - color: #999 !important; - font-weight: bold; - font-size: 16px; -} - -hr { - border: none; - border-bottom: 1px solid #ccc; - background-color: transparent; - height: 1px; -} - -#breadcrumbs,#footer,#navcolumn li { - font-size: 10px; -} - -a.poweredBy { - margin-left: 20px; -} - -.source { - margin: 10px 0; - padding: 12px; - border: 1px solid #1B87CA; -} - -#navcolumn li.collapsed { - background-image: url(../images/ico-collapsed.png); -} \ No newline at end of file Copied: tags/openutils-maven-skin-1.1/src/main/resources/images/logos (from rev 789, trunk/openutils-maven-skin/src/main/resources/images/logos) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-04-28 22:19:32
|
Revision: 801 http://openutils.svn.sourceforge.net/openutils/?rev=801&view=rev Author: fgiust Date: 2008-04-28 15:19:38 -0700 (Mon, 28 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnltasks-3.5.1 Added Paths: ----------- tags/openutils-mgnltasks-3.5.1/ tags/openutils-mgnltasks-3.5.1/pom.xml tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml tags/openutils-mgnltasks-3.5.1/src/site/site.xml Removed Paths: ------------- tags/openutils-mgnltasks-3.5.1/pom.xml tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml tags/openutils-mgnltasks-3.5.1/src/site/site.xml Copied: tags/openutils-mgnltasks-3.5.1 (from rev 784, trunk/openutils-mgnltasks) Deleted: tags/openutils-mgnltasks-3.5.1/pom.xml =================================================================== --- trunk/openutils-mgnltasks/pom.xml 2008-04-27 20:42:00 UTC (rev 784) +++ tags/openutils-mgnltasks-3.5.1/pom.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>8</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <packaging>jar</packaging> - <artifactId>openutils-mgnltasks</artifactId> - <name>openutils-mgnltasks</name> - <version>3.5-SNAPSHOT</version> - <description>A collection of useful magnolia update tasks that can be reused in custom modules</description> - <licenses> - <license> - <name>GPLv3</name> - <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> - </license> - </licenses> - <build> - <resources> - <resource> - <filtering>false</filtering> - <directory>src/main/resources</directory> - <includes> - <include>**/*</include> - </includes> - </resource> - <resource> - <filtering>true</filtering> - <directory>src/main/resources</directory> - <includes> - <include>META-INF/magnolia/*</include> - </includes> - </resource> - </resources> - </build> - <dependencies> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-core</artifactId> - <version>3.5.4</version> - </dependency> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-module-admininterface</artifactId> - <version>3.5.4</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jsp-api</artifactId> - <version>2.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.7</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <repositories> - <repository> - <id>repository.magnolia.info</id> - <name>magnolia repository</name> - <url>http://repo.magnolia.info/m2</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - </repositories> -</project> Copied: tags/openutils-mgnltasks-3.5.1/pom.xml (from rev 800, trunk/openutils-mgnltasks/pom.xml) =================================================================== --- tags/openutils-mgnltasks-3.5.1/pom.xml (rev 0) +++ tags/openutils-mgnltasks-3.5.1/pom.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>8</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <artifactId>openutils-mgnltasks</artifactId> + <name>openutils-mgnltasks</name> + <version>3.5.1</version> + <description>A collection of useful magnolia update tasks that can be reused in custom modules</description> + <licenses> + <license> + <name>GPLv3</name> + <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> + </license> + </licenses> + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <filtering>true</filtering> + <directory>src/main/resources</directory> + <includes> + <include>META-INF/magnolia/*</include> + </includes> + </resource> + </resources> + </build> + <dependencies> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>3.5.4</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-module-admininterface</artifactId> + <version>3.5.4</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.7</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <repositories> + <repository> + <id>repository.magnolia.info</id> + <name>magnolia repository</name> + <url>http://repo.magnolia.info/m2</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnltasks-3.5.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnltasks-3.5.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnltasks-3.5.1</url> + </scm> +</project> Copied: tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java (from rev 799, trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java) =================================================================== --- tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java (rev 0) +++ tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java 2008-04-28 22:19:38 UTC (rev 801) @@ -0,0 +1,85 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.module.DefaultModuleVersionHandler; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.Delta; +import info.magnolia.module.delta.DeltaBuilder; +import info.magnolia.module.model.Version; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.ObjectUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A base module version handler that re-bootstrap its configuration each time the version number changes. Can be used + * as is or subclassed (usually overriding getStartupTasks() for configuration tweacks). + * @author fgiust + * @version $Id: $ + */ +public class SimpleModuleVersionHandler extends DefaultModuleVersionHandler +{ + + /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(getClass()); + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public List<Delta> getDeltas(InstallContext ctx, Version from) + { + if (from == null) + { + log.info("Actual version not set"); + return super.getDeltas(ctx, from); + } + + Version to = ctx.getCurrentModuleDefinition().getVersionDefinition(); + + List<Delta> deltas = new ArrayList<Delta>(); + + if (!to.isEquivalent(from) + || "${project.version}".equals(ObjectUtils.toString(from)) + || "SNAPSHOT".equals(from.getClassifier())) + { + log.info("Updating from version {}", from); + + Delta delta = DeltaBuilder.update(to, "Update to current version"); + delta.getTasks().add(new ModuleConfigBootstrapTask(ctx.getCurrentModuleDefinition().getName())); + delta.getTasks().add(new UpdateModuleVersionTask()); + + deltas.add(delta); + } + else + { + log.info("Version {} already installed, no update tasks to run", from); + } + + return deltas; + } + +} Copied: tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java (from rev 798, trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java) =================================================================== --- tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java (rev 0) +++ tags/openutils-mgnltasks-3.5.1/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java 2008-04-28 22:19:38 UTC (rev 801) @@ -0,0 +1,63 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import javax.jcr.RepositoryException; + + +/** + * A task that updates the current version of a module stored in the config repository. + * @author fgiust + * @version $Id: $ + */ +public class UpdateModuleVersionTask extends AbstractRepositoryTask +{ + + public UpdateModuleVersionTask() + { + super("Version number", "Sets installed module version number"); + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException + { + // make sure we have the /modules node + if (!ctx.hasModulesNode()) + { + final HierarchyManager hm = ctx.getConfigHierarchyManager(); + hm.createContent("/", "modules", ItemType.CONTENT.getSystemName()); + } + + final Content moduleNode = ctx.getOrCreateCurrentModuleNode(); + final NodeData nodeData = NodeDataUtil.getOrCreate(moduleNode, "version"); + nodeData.setValue(ctx.getCurrentModuleDefinition().getVersionDefinition().toString()); + } + +} \ No newline at end of file Deleted: tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-04-27 20:42:00 UTC (rev 784) +++ tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -1,16 +0,0 @@ -<?xml version="1.0"?> -<!-- - "type" attribute can be: add, remove, update or fix. ---> -<document> - <properties> - <title>Changes</title> - <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> - </properties> - <body> - <release version="3.5" date="2008-04-27" description="first release"> - <action type="add" dev="fgiust">First public release. The version is labeled "3.5" in order to make clear which - version of magnolia is required.</action> - </release> - </body> -</document> \ No newline at end of file Copied: tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml (from rev 798, trunk/openutils-mgnltasks/src/site/changes/changes.xml) =================================================================== --- tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml (rev 0) +++ tags/openutils-mgnltasks-3.5.1/src/site/changes/changes.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- + "type" attribute can be: add, remove, update or fix. +--> +<document> + <properties> + <title>Changes</title> + <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + </properties> + <body> + <release version="3.5.1" date="2008-04-28" description="3.5.1"> + <action type="add" dev="fgiust">Added UpdateModuleVersionTask.</action> + <action type="add" dev="fgiust">Added SimpleModuleVersionHandler.</action> + </release> + <release version="3.5" date="2008-04-27" description="first release"> + <action type="add" dev="fgiust">First public release. The version is labeled "3.5" in order to make clear which + version of magnolia is required.</action> + </release> + </body> +</document> \ No newline at end of file Deleted: tags/openutils-mgnltasks-3.5.1/src/site/site.xml =================================================================== --- trunk/openutils-mgnltasks/src/site/site.xml 2008-04-27 20:42:00 UTC (rev 784) +++ tags/openutils-mgnltasks-3.5.1/src/site/site.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="Openutils mgnltasks"> - <publishDate position="navigation-bottom" format="yyyy-MM-dd" /> - <version position="navigation-bottom" /> - <bannerRight> - <name>Openutils</name> - <src>http://openutils.sourceforge.net/images/openutils-logo.png</src> - <href>http://openutils.sourceforge.net</href> - </bannerRight> - <bannerLeft> - <name>Sourceforge</name> - <src>http://sourceforge.net/sflogo.php?group_id=150467&amp;type=2</src> - <href>http://www.sourceforge.net/projects/openutils</href> - </bannerLeft> - <body> - <head> - <link rel="icon" href="images/favicon.ico" /> - </head> - <breadcrumbs> - <item name="openutils" href="http://openutils.sourceforge.net/" /> - <item name="openutils-mgnltasks" href="http://openutils.sourceforge.net/openutils-mgnltasks" /> - </breadcrumbs> - <menu name="openutils mgnltasks"> - <item name="Introduction" href="index.html"></item> - </menu> - <menu ref="modules" inherit="bottom" /> - <menu ref="reports" inherit="bottom" /> - </body> - <skin> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-maven-skin</artifactId> - <version>1.0</version> - </skin> -</project> Copied: tags/openutils-mgnltasks-3.5.1/src/site/site.xml (from rev 794, trunk/openutils-mgnltasks/src/site/site.xml) =================================================================== --- tags/openutils-mgnltasks-3.5.1/src/site/site.xml (rev 0) +++ tags/openutils-mgnltasks-3.5.1/src/site/site.xml 2008-04-28 22:19:38 UTC (rev 801) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="Openutils mgnltasks"> + <publishDate position="navigation-bottom" format="yyyy-MM-dd" /> + <version position="navigation-bottom" /> + <bannerRight> + <name>Openutils</name> + <src>http://openutils.sourceforge.net/images/openutils-logo.png</src> + <href>http://openutils.sourceforge.net</href> + </bannerRight> + <bannerLeft> + <name>Sourceforge</name> + <src>http://sourceforge.net/sflogo.php?group_id=150467&amp;type=2</src> + <href>http://www.sourceforge.net/projects/openutils</href> + </bannerLeft> + <body> + <head> + <link rel="icon" href="images/favicon.ico" /> + </head> + <breadcrumbs> + <item name="openutils" href="http://openutils.sourceforge.net/" /> + <item name="openutils-mgnltasks" href="http://openutils.sourceforge.net/openutils-mgnltasks" /> + </breadcrumbs> + <menu name="openutils mgnltasks"> + <item name="Introduction" href="index.html"></item> + </menu> + <menu ref="modules" inherit="bottom" /> + <menu ref="reports" inherit="bottom" /> + </body> + <skin> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-maven-skin</artifactId> + <version>1.1</version> + </skin> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |