continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r441385 - in /maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src: main/java/org/apache/maven/continuum/security/acegi/acl/ test/java/org/apache/maven/continuum/security/acegi/acl/ test/resources/org/apa...
Date Fri, 08 Sep 2006 05:47:33 GMT
Author: carlos
Date: Thu Sep  7 22:47:32 2006
New Revision: 441385

URL: http://svn.apache.org/viewvc?view=rev&rev=441385
Log:
Added AclManager to maven-user

Added:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.java
  (with props)
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.xml
  (with props)
Modified:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandler.java

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandler.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/AclEventHandler.java?view=diff&rev=441385&r1=441384&r2=441385
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandler.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandler.java
Thu Sep  7 22:47:32 2006
@@ -20,7 +20,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.acegisecurity.acl.basic.BasicAclExtendedDao;
+import org.acegisecurity.acl.basic.BasicAclEntry;
 import org.acegisecurity.acl.basic.NamedEntityObjectIdentity;
 import org.acegisecurity.acl.basic.SimpleAclEntry;
 import org.acegisecurity.context.SecurityContextHolder;
@@ -28,6 +28,7 @@
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
+import org.apache.maven.user.acegi.AclManager;
 
 /**
  * Utility class to handle ACL manipulation on Continuum events, like adding or
@@ -37,19 +38,9 @@
  * @version $Id$
  */
 public class AclEventHandler
+    extends AclManager
 {
-
-    private BasicAclExtendedDao aclDao;
-
-    public void setAclDao( BasicAclExtendedDao aclDao )
-    {
-        this.aclDao = aclDao;
-    }
-
-    public BasicAclExtendedDao getAclDao()
-    {
-        return aclDao;
-    }
+    public static final String ROLE = AclEventHandler.class.getName();
 
     /**
      * Create ACLs for new {@link ProjectGroup} and {@link Project}s
@@ -76,13 +67,11 @@
     /**
      * Delete {@link ProjectGroup} ACLs
      * 
-     * @TODO should this cascade delete all the children ACLs ?
-     * 
      * @param projectGroupId
      */
     public void afterDeleteProjectGroup( int projectGroupId )
     {
-        getAclDao().delete( createProjectGroupObjectIdentity( projectGroupId ) );
+        delete( ProjectGroup.class, projectGroupId );
     }
 
     /**
@@ -90,7 +79,7 @@
      * 
      * @param projectGroups
      */
-    private void createNewProjectGroupsACLs( Collection projectGroups )
+    protected void createNewProjectGroupsACLs( Collection projectGroups )
     {
         Iterator it = projectGroups.iterator();
         while ( it.hasNext() )
@@ -105,7 +94,7 @@
      * 
      * @param projectGroup
      */
-    private void createNewProjectGroupACL( ProjectGroup projectGroup )
+    protected void createNewProjectGroupACL( ProjectGroup projectGroup )
     {
         User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         SimpleAclEntry aclEntry = new SimpleAclEntry();
@@ -113,7 +102,7 @@
         aclEntry.setRecipient( user.getUsername() );
         aclEntry.setAclObjectParentIdentity( AclInitializer.PARENT_PROJECT_GROUP_ACL_ID );
         aclEntry.addPermission( SimpleAclEntry.ADMINISTRATION );
-        getAclDao().create( aclEntry );
+        create( aclEntry );
     }
 
     /**
@@ -121,7 +110,7 @@
      * 
      * @param projects
      */
-    private void createNewProjectsACLs( Collection projects, ProjectGroup projectGroup )
+    protected void createNewProjectsACLs( Collection projects, ProjectGroup projectGroup
)
     {
         Iterator it = projects.iterator();
         while ( it.hasNext() )
@@ -137,13 +126,24 @@
      * @param project
      * @param projectGroup group the projects belong to
      */
-    private void createNewProjectACL( Project project, ProjectGroup projectGroup )
+    protected void createNewProjectACL( Project project, ProjectGroup projectGroup )
     {
         NamedEntityObjectIdentity projectGroupIdentity = createProjectGroupObjectIdentity(
projectGroup.getId() );
         SimpleAclEntry aclEntry = new SimpleAclEntry();
         aclEntry.setAclObjectIdentity( createProjectObjectIdentity( project.getId() ) );
         aclEntry.setAclObjectParentIdentity( projectGroupIdentity );
-        getAclDao().create( aclEntry );
+        create( aclEntry );
+    }
+
+    public void setProjectGroupPermissions( int projectGroupId, String userName, int permissions
)
+    {
+        super.setPermissions( ProjectGroup.class, projectGroupId, userName, permissions,
+                              AclInitializer.PARENT_PROJECT_GROUP_ACL_ID );
+    }
+
+    public BasicAclEntry getProjectGroupAcl( int projectGroupId, String userName )
+    {
+        return getAcl( ProjectGroup.class, projectGroupId, userName );
     }
 
     private NamedEntityObjectIdentity createProjectObjectIdentity( int projectId )
@@ -156,8 +156,8 @@
         return createObjectIdentity( ProjectGroup.class, projectGroupId );
     }
 
-    private NamedEntityObjectIdentity createObjectIdentity( Class clazz, int id )
+    public BasicAclEntry[] getProjectGroupAcls( int projectGroupId )
     {
-        return new NamedEntityObjectIdentity( clazz.getName(), Integer.toString( id ) );
+        return getAcls( ProjectGroup.class, projectGroupId );
     }
 }

Added: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.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/AclEventHandlerTest.java?view=auto&rev=441385
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.java
(added)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.java
Thu Sep  7 22:47:32 2006
@@ -0,0 +1,107 @@
+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.GrantedAuthority;
+import org.acegisecurity.acl.basic.BasicAclEntry;
+import org.acegisecurity.acl.basic.SimpleAclEntry;
+import org.acegisecurity.context.SecurityContextHolder;
+import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
+import org.acegisecurity.userdetails.User;
+import org.acegisecurity.userdetails.UserDetails;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * Test for {@link AclEventHandler}.
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class AclEventHandlerTest
+    extends PlexusTestCase
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+    }
+
+    public void testAcls()
+        throws Exception
+    {
+        lookup( AclInitializer.ROLE );
+        AclEventHandler eventHandler = (AclEventHandler) lookup( AclEventHandler.ROLE );
+
+        ProjectGroup projectGroup = new ProjectGroup();
+        projectGroup.setId( 1 );
+
+        BasicAclEntry[] acls = eventHandler.getProjectGroupAcls( projectGroup.getId() );
+        if ( acls != null )
+        {
+            eventHandler.afterDeleteProjectGroup( projectGroup.getId() );
+        }
+
+        String user1 = "user1";
+        setUser( user1 );
+
+        eventHandler.createNewProjectGroupACL( projectGroup );
+
+        String user2 = "user2";
+        setUser( user2 );
+
+        /* set permissions to create for user 2 */
+        eventHandler.setProjectGroupPermissions( projectGroup.getId(), user2, SimpleAclEntry.CREATE
);
+
+        SimpleAclEntry acl = (SimpleAclEntry) eventHandler.getProjectGroupAcl( projectGroup.getId(),
user2 );
+        assertEquals( SimpleAclEntry.CREATE, acl.getMask() );
+
+        /* set permissions to delete for user 2 */
+        eventHandler.setProjectGroupPermissions( projectGroup.getId(), user2, SimpleAclEntry.DELETE
);
+
+        acl = (SimpleAclEntry) eventHandler.getProjectGroupAcl( projectGroup.getId(), user2
);
+        assertEquals( SimpleAclEntry.DELETE, acl.getMask() );
+
+        Project project = new Project();
+        project.setId( 1 );
+        eventHandler.createNewProjectACL( project, projectGroup );
+
+        acls = eventHandler.getProjectGroupAcls( projectGroup.getId() );
+
+        assertEquals( "Wrong number of ACLs for ProjectGroup", 2, acls.length );
+
+        for ( int i = 0; i < acls.length; i++ )
+        {
+            acl = (SimpleAclEntry) acls[i];
+            System.out.println( acl.getRecipient() + " - " + acl.printPermissionsBlock()
);
+        }
+
+        /* check that user that created ProjectGroup keeps its admin permission */
+        acl = (SimpleAclEntry) eventHandler.getProjectGroupAcl( projectGroup.getId(), user1
);
+        assertEquals( SimpleAclEntry.ADMINISTRATION, acl.getMask() );
+    }
+
+    private void setUser( String username )
+    {
+        UserDetails userDetails = new User( username, "", true, true, true, true, new GrantedAuthority[0]
);
+        SecurityContextHolder.getContext().setAuthentication(
+                                                              new UsernamePasswordAuthenticationToken(
userDetails,
+                                                                                        
              null, null ) );
+    }
+}

Propchange: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/java/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.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/AclEventHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.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/AclEventHandlerTest.xml?view=auto&rev=441385
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.xml
(added)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/test/resources/org/apache/maven/continuum/security/acegi/acl/AclEventHandlerTest.xml
Thu Sep  7 22:47:32 2006
@@ -0,0 +1,29 @@
+<plexus>
+
+  <components>
+
+    <component>
+      <role>javax.sql.DataSource</role>
+      <implementation>org.apache.commons.dbcp.BasicDataSource</implementation>
+      <configuration>
+        <driverClassName>org.apache.derby.jdbc.EmbeddedDriver</driverClassName>
+        <url>jdbc:derby:${plexus.home}/database-acl-event-handler;create=true</url>
+        <username>sa</username>
+      </configuration>
+    </component>
+
+    <component>
+      <role>org.codehaus.mojo.sql.SqlExecMojo</role>
+      <implementation>org.codehaus.mojo.sql.SqlExecMojo</implementation>
+      <configuration>
+        <username>sa</username>
+        <password></password>
+        <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+        <url>jdbc:derby:${plexus.home}/database-acl-event-handler;create=true</url>
+        <onError>continue</onError>
+      </configuration>
+    </component>
+
+  </components>
+
+</plexus>

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

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



Mime
View raw message