continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r433825 - in /maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src: main/java/org/apache/maven/continuum/security/acegi/acl/ main/resources/org/apache/maven/continuum/security/acegi/acl/ test/java/org/apa...
Date Wed, 23 Aug 2006 01:36:55 GMT
Author: carlos
Date: Tue Aug 22 18:36:49 2006
New Revision: 433825

URL: http://svn.apache.org/viewvc?rev=433825&view=rev
Log:
[CONTINUUM-825] Make AclInitializer read SQL statements from classpath

Modified:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.java
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.xml

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java?rev=433825&r1=433824&r2=433825&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
Tue Aug 22 18:36:49 2006
@@ -16,6 +16,9 @@
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.acegisecurity.acl.basic.NamedEntityObjectIdentity;
 import org.acegisecurity.acl.basic.SimpleAclEntry;
 import org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl;
@@ -25,6 +28,7 @@
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.IOUtil;
 
 /**
  * Initialize the ACL system with some default values.
@@ -42,6 +46,8 @@
 
     private SqlExecMojo sqlMojo;
 
+    private String sqlClasspathResource;
+
     public void setDao( JdbcExtendedDaoImpl dao )
     {
         this.dao = dao;
@@ -62,9 +68,57 @@
         return sqlMojo;
     }
 
+    public void setSqlClasspathResource( String sqlClasspathResource )
+    {
+        this.sqlClasspathResource = sqlClasspathResource;
+    }
+
+    /**
+     * Classpath resource that contains the SQL to be executed.
+     * 
+     * @return
+     */
+    public String getSqlClasspathResource()
+    {
+        return sqlClasspathResource;
+    }
+
     public void initialize()
         throws InitializationException
     {
+
+        InputStream is = null;
+        String sql = null;
+        try
+        {
+            is = this.getClass().getClassLoader().getResourceAsStream( getSqlClasspathResource()
);
+            if ( is == null )
+            {
+                throw new InitializationException( getSqlClasspathResource() + " does not
exist in the classpath" );
+            }
+            sql = IOUtil.toString( is );
+        }
+        catch ( IOException e )
+        {
+            throw new InitializationException( "Unable to read sql file from classpath: "
+ getSqlClasspathResource(),
+                                               e );
+        }
+        finally
+        {
+            if ( is != null )
+            {
+                try
+                {
+                    is.close();
+                }
+                catch ( IOException e )
+                {
+                    // nothing to do here
+                }
+            }
+        }
+
+        getSqlMojo().addText( sql );
 
         if ( getSqlMojo().getPassword() == null )
         {

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql?rev=433825&r1=433824&r2=433825&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql
Tue Aug 22 18:36:49 2006
@@ -18,12 +18,12 @@
      FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id)
 );
 
---INSERT INTO acl_object_identity VALUES (1, 'org.apache.maven.continuum.model.project.Project:1',
null, 'org.acegisecurity.acl.basic.SimpleAclEntry');
---INSERT INTO acl_object_identity VALUES (2, 'org.apache.maven.continuum.model.project.Project:2',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
---INSERT INTO acl_object_identity VALUES (3, 'org.apache.maven.continuum.model.project.Project:3',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
---INSERT INTO acl_object_identity VALUES (4, 'org.apache.maven.continuum.model.project.Project:4',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
---INSERT INTO acl_object_identity VALUES (5, 'org.apache.maven.continuum.model.project.Project:5',
3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
---INSERT INTO acl_object_identity VALUES (6, 'org.apache.maven.continuum.model.project.Project:6',
3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:1',
null, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:2',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:3',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:4',
1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:5',
3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
+--INSERT INTO acl_object_identity (object_identity, parent_object, acl_class) VALUES ('org.apache.maven.continuum.model.project.ProjectGroup:6',
3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
 
 --INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (1, 'ROLE_ADMIN',
1);
 --INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (2, 'ROLE_ADMIN',
0);

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.java?rev=433825&r1=433824&r2=433825&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.java
Tue Aug 22 18:36:49 2006
@@ -16,16 +16,7 @@
  * limitations under the License.
  */
 
-import java.io.File;
-
-import javax.sql.DataSource;
-
-import org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.codehaus.mojo.sql.SqlExecMojo;
 import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.console.ConsoleLogger;
 
 /**
  * Test for {@link AclInitializer} using Plexus to inject dependencies

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java?rev=433825&r1=433824&r2=433825&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
Tue Aug 22 18:36:49 2006
@@ -16,8 +16,6 @@
  * limitations under the License.
  */
 
-import java.io.File;
-
 import javax.sql.DataSource;
 
 import junit.framework.TestCase;
@@ -48,14 +46,13 @@
         super.setUp();
         initializer = new AclInitializer();
         initializer.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) );
+        initializer.setSqlClasspathResource( "org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql"
);
 
         sqlMojo = new SqlExecMojo();
         sqlMojo.setUsername( "sa" );
         sqlMojo.setPassword( "" );
         sqlMojo.setDriver( "org.apache.derby.jdbc.EmbeddedDriver" );
         sqlMojo.setUrl( "jdbc:derby:target/acl-initializer-database;create=true" );
-        sqlMojo.setSrcFiles( new File[] { new File( "src/main/resources/"
-            + "org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql" ) } );
         sqlMojo.setOnError( SqlExecMojo.ON_ERROR_CONTINUE );
         initializer.setSqlMojo( sqlMojo );
 

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.xml?rev=433825&r1=433824&r2=433825&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.xml
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclInitializerPlexusTest.xml
Tue Aug 22 18:36:49 2006
@@ -15,6 +15,9 @@
           <field-name>dao</field-name>
         </requirement>
       </requirements>
+      <configuration>
+        <sqlClasspathResource>org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql</sqlClasspathResource>
+      </configuration>
     </component>
 
     <component>
@@ -48,9 +51,6 @@
         <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
         <url>jdbc:derby:${plexus.home}/database;create=true</url>
         <onError>continue</onError>
-        <srcFiles>
-          <file>src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql</file>
-        </srcFiles>
       </configuration>
     </component>
 



Mime
View raw message