continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r440233 - in /maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main: java/org/apache/maven/continuum/security/acegi/AcegiContinuum.java resources/META-INF/plexus/components.xml
Date Tue, 05 Sep 2006 03:17:37 GMT
Author: carlos
Date: Mon Sep  4 20:17:37 2006
New Revision: 440233

URL: http://svn.apache.org/viewvc?view=rev&rev=440233
Log:
Add first ACL creation code

Modified:
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/AcegiContinuum.java
    maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/META-INF/plexus/components.xml

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/AcegiContinuum.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/AcegiContinuum.java?view=diff&rev=440233&r1=440232&r2=440233
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/AcegiContinuum.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/java/org/apache/maven/continuum/security/acegi/AcegiContinuum.java
Mon Sep  4 20:17:37 2006
@@ -18,9 +18,14 @@
 
 import java.io.File;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.acegisecurity.acl.basic.BasicAclExtendedDao;
+import org.acegisecurity.acl.basic.NamedEntityObjectIdentity;
+import org.acegisecurity.acl.basic.SimpleAclEntry;
+import org.acegisecurity.context.SecurityContextHolder;
 import org.apache.maven.continuum.Continuum;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.configuration.ConfigurationService;
@@ -49,6 +54,8 @@
 
     private Continuum continuum;
 
+    private BasicAclExtendedDao aclDao;
+
     /**
      * Set the object to delegate to
      * 
@@ -69,6 +76,81 @@
         return continuum;
     }
 
+    public void setAclDao( BasicAclExtendedDao aclDao )
+    {
+        this.aclDao = aclDao;
+    }
+
+    public BasicAclExtendedDao getAclDao()
+    {
+        return aclDao;
+    }
+
+    /**
+     * Project has same permissions as its project group.
+     * 
+     * @param project
+     * @return
+     */
+    private SimpleAclEntry getProjectAcl( Project project )
+    {
+        NamedEntityObjectIdentity projectGroupIdentity = new NamedEntityObjectIdentity( ProjectGroup.class.getName(),
+                                                                                        Integer.toString(
project
+                                                                                        
   .getProjectGroup().getId() ) );
+        SimpleAclEntry aclEntry = new SimpleAclEntry();
+        //        aclEntry.setAclObjectIdentity( new NamedEntityObjectIdentity( Project.class.getName(),
Integer
+        //            .toString( project.getId() ) ) );
+        aclEntry.setAclObjectParentIdentity( projectGroupIdentity );
+        return aclEntry;
+    }
+
+    /**
+     * Creator of {@link ProjectGroup} has {@link SimpleAclEntry#ADMINISTRATION} permissions.
+     * 
+     * @param projectGroup
+     * @return an ACL entry for the creator of the group
+     */
+    private SimpleAclEntry getProjectGroupAcl( ProjectGroup projectGroup )
+    {
+        Object username = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        SimpleAclEntry aclEntry = new SimpleAclEntry();
+        aclEntry.setAclObjectIdentity( new NamedEntityObjectIdentity( ProjectGroup.class.getName(),
Integer
+            .toString( projectGroup.getId() ) ) );
+        aclEntry.setRecipient( username );
+        aclEntry.addPermission( SimpleAclEntry.ADMINISTRATION );
+        return aclEntry;
+    }
+
+    /**
+     * Call this method when new {@link ProjectGroup}s are created.
+     * 
+     * @param projectGroups
+     */
+    private void createNewProjectGroupsACLs( Collection projectGroups )
+    {
+        Iterator it = projectGroups.iterator();
+        while ( it.hasNext() )
+        {
+            ProjectGroup projectGroup = (ProjectGroup) it.next();
+            getAclDao().create( getProjectGroupAcl( projectGroup ) );
+        }
+    }
+
+    /**
+     * Call this method when new {@link Project}s are created.
+     * 
+     * @param projects
+     */
+    private void createNewProjectsACLs( Collection projects )
+    {
+        Iterator it = projects.iterator();
+        while ( it.hasNext() )
+        {
+            Project project = (Project) it.next();
+            getAclDao().create( getProjectAcl( project ) );
+        }
+    }
+
     /**
      * @param projectId
      * @param buildDefinition
@@ -102,7 +184,10 @@
     public ContinuumProjectBuildingResult addMavenOneProject( String metadataUrl )
         throws ContinuumException
     {
-        return getContinuum().addMavenOneProject( metadataUrl );
+        ContinuumProjectBuildingResult result = getContinuum().addMavenOneProject( metadataUrl
);
+        createNewProjectGroupsACLs( result.getProjectGroups() );
+        createNewProjectsACLs( result.getProjects() );
+        return result;
     }
 
     /**
@@ -114,7 +199,10 @@
     public ContinuumProjectBuildingResult addMavenTwoProject( String metadataUrl )
         throws ContinuumException
     {
-        return getContinuum().addMavenTwoProject( metadataUrl );
+        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject( metadataUrl
);
+        createNewProjectGroupsACLs( result.getProjectGroups() );
+        createNewProjectsACLs( result.getProjects() );
+        return result;
     }
 
     /**

Modified: maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=440233&r1=440232&r2=440233
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-security/continuum-security-acegi/src/main/resources/META-INF/plexus/components.xml
Mon Sep  4 20:17:37 2006
@@ -11,6 +11,10 @@
           <role-hint>default</role-hint>
           <field-name>continuum</field-name>
         </requirement>
+        <requirement>
+          <role>org.acegisecurity.acl.basic.BasicAclExtendedDao</role>
+          <field-name>aclDao</field-name>
+        </requirement>
       </requirements>
     </component>
 



Mime
View raw message