continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r433473 - in /maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi: ./ src/main/java/org/apache/maven/continuum/security/acegi/acl/ src/main/resources/org/apache/maven/continuum/security/acegi/acl/ src/test/j...
Date Tue, 22 Aug 2006 02:11:30 GMT
Author: carlos
Date: Mon Aug 21 19:11:29 2006
New Revision: 433473

URL: http://svn.apache.org/viewvc?rev=433473&view=rev
Log:
Added AclInitializer to create Acegi ACL tables

Added:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
  (with props)
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
  (with props)
Modified:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml?rev=433473&r1=433472&r2=433473&view=diff
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/pom.xml
Mon Aug 21 19:11:29 2006
@@ -30,12 +30,25 @@
       <groupId>commons-dbcp</groupId>
       <artifactId>commons-dbcp</artifactId>
       <version>1.2.1</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.acegisecurity</groupId>
       <artifactId>acegi-security</artifactId>
       <version>1.1-SNAPSHOT</version>
       <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.mojo</groupId>
+      <artifactId>sql-maven-plugin</artifactId>
+      <version>1.0-beta-2-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <version>10.1.2.1</version>
+      <scope>test</scope>
     </dependency>
   </dependencies>
 
@@ -60,26 +73,6 @@
             </goals>
           </execution>
         </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>sql-maven-plugin</artifactId>
-        <dependencies>
-          <dependency>
-            <groupId>org.apache.derby</groupId>
-            <artifactId>derby</artifactId>
-            <version>10.1.2.1</version>
-          </dependency>
-        </dependencies>
-        <configuration>
-          <url>jdbc:derby:${basedir}/target/database;create=true</url>
-          <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
-          <username>sa</username>
-          <password></password>
-          <srcFiles>
-            <srcFile>src/main/resources/org/apache/maven/continuum/security/acegi/acl/acegi-acl-derby.sql</srcFile>
-          </srcFiles>
-        </configuration>
       </plugin>
     </plugins>
   </build>

Added: 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=433473&view=auto
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
(added)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
Mon Aug 21 19:11:29 2006
@@ -0,0 +1,91 @@
+package org.apache.maven.continuum.security.acegi.acl;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import org.acegisecurity.acl.basic.NamedEntityObjectIdentity;
+import org.acegisecurity.acl.basic.SimpleAclEntry;
+import org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.mojo.sql.SqlExecMojo;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+/**
+ * Initialize the ACL system with some default values.
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class AclInitializer
+    extends AbstractLogEnabled
+    implements Initializable
+{
+
+    private JdbcExtendedDaoImpl dao;
+
+    private SqlExecMojo sqlMojo;
+
+    public void setDao( JdbcExtendedDaoImpl dao )
+    {
+        this.dao = dao;
+    }
+
+    public JdbcExtendedDaoImpl getDao()
+    {
+        return dao;
+    }
+
+    public void setSqlMojo( SqlExecMojo sqlMojo )
+    {
+        this.sqlMojo = sqlMojo;
+    }
+
+    public SqlExecMojo getSqlMojo()
+    {
+        return sqlMojo;
+    }
+
+    public void initialize()
+        throws InitializationException
+    {
+        try
+        {
+            getSqlMojo().execute();
+        }
+        catch ( MojoExecutionException e )
+        {
+            throw new InitializationException( e.getMessage(), e );
+        }
+
+        /* poor check to see if this is the first time initializing the database */
+        if ( getSqlMojo().getSuccessfulStatements() >= 2 )
+        {
+            /* tables were created, insert default values */
+            getLogger().info( "Initializing ACL database" );
+
+            /* admin can do anything with project number 1 */
+            SimpleAclEntry aclEntry = new SimpleAclEntry();
+            aclEntry.setAclObjectIdentity( new NamedEntityObjectIdentity( Project.class.getName(),
"1" ) );
+            aclEntry.setRecipient( "ROLE_ADMIN" );
+            aclEntry.addPermission( SimpleAclEntry.ADMINISTRATION );
+            getDao().create( aclEntry );
+        }
+
+    }
+}

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclInitializer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=433473&r1=433472&r2=433473&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
Mon Aug 21 19:11:29 2006
@@ -1,7 +1,7 @@
 CREATE SCHEMA sa;
 
 CREATE TABLE acl_object_identity (
-     id INTEGER NOT NULL CONSTRAINT acl_object_identity_PK PRIMARY KEY,
+     id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY CONSTRAINT acl_object_identity_PK PRIMARY
KEY,
      object_identity VARCHAR(250) NOT NULL,
      parent_object INTEGER,
      acl_class VARCHAR(250) NOT NULL,
@@ -18,15 +18,15 @@
      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 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_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);
-INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (2, 'marissa', 2);
-INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (3, 'scott', 14);
-INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (6, 'scott', 1);
+--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);
+--INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (2, 'marissa',
2);
+--INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (3, 'scott', 14);
+--INSERT INTO acl_permission (acl_object_identity, recipient, mask) VALUES (6, 'scott', 1);

Added: 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=433473&view=auto
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
(added)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
Mon Aug 21 19:11:29 2006
@@ -0,0 +1,84 @@
+package org.apache.maven.continuum.security.acegi.acl;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.File;
+
+import javax.sql.DataSource;
+
+import junit.framework.TestCase;
+
+import org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.codehaus.mojo.sql.SqlExecMojo;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+
+/**
+ * Test for {@link AclInitializer}
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class AclInitializerTest
+    extends TestCase
+{
+
+    private AclInitializer initializer;
+    
+    private SqlExecMojo sqlMojo;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        initializer = new AclInitializer();
+        initializer.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) );
+
+        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 );
+
+        JdbcExtendedDaoImpl dao = new JdbcExtendedDaoImpl();
+        dao.setDataSource( getDataSource() );
+        initializer.setDao( dao );
+
+        dao.afterPropertiesSet();
+    }
+
+    public void testInitialize()
+        throws Exception
+    {
+        initializer.initialize();
+        initializer.initialize();
+    }
+
+    private DataSource getDataSource()
+    {
+        BasicDataSource dataSource = new BasicDataSource();
+        dataSource.setDriverClassName( sqlMojo.getDriver() );
+        dataSource.setUrl( sqlMojo.getUrl() );
+        dataSource.setUsername( sqlMojo.getUsername() );
+        return dataSource;
+    }
+}

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclInitializerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message