]> source.dussan.org Git - archiva.git/commitdiff
[MRM-922] access to upload page with managed repository role
authorBrett Porter <brett@apache.org>
Wed, 11 Mar 2009 17:33:31 +0000 (17:33 +0000)
committerBrett Porter <brett@apache.org>
Wed, 11 Mar 2009 17:33:31 +0000 (17:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@752539 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/UserRepositories.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/security/UserRepositoriesStub.java

index d99b089326f6ae481ce7bea7fd743049f32452ff..3eb9166c69f181c3cce63777a1ca68e7c250557a 100644 (file)
@@ -73,7 +73,22 @@ public class DefaultUserRepositories
     public List<String> getObservableRepositoryIds( String principal )
         throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
     {
+        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
 
+        return getAccessibleRepositoryIds( principal, operation );
+    }
+
+    public List<String> getManagableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
+    {
+        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
+
+        return getAccessibleRepositoryIds( principal, operation );
+    }
+
+    private List<String> getAccessibleRepositoryIds( String principal, String operation )
+        throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException
+    {
         try
         {
             User user = securitySystem.getUserManager().findUser( principal );
@@ -100,8 +115,7 @@ public class DefaultUserRepositories
                 try
                 {
                     String repoId = repo.getId();
-                    if ( securitySystem.isAuthorized( securitySession,
-                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS, repoId ) )
+                    if ( securitySystem.isAuthorized( securitySession, operation, repoId ) )
                     {
                         repoIds.add( repoId );
                     }
index 9b3840ac67156f5de09e8fc619263a98e28bdb7a..b1d48b2c4b5e55f04c0a9ae25b53931fb1065ad3 100644 (file)
@@ -43,6 +43,18 @@ public interface UserRepositories
     public List<String> getObservableRepositoryIds( String principal )
         throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
     
+    /**
+     * Get the list of writable repository ids for the user specified.
+     * 
+     * @param principal the principle to obtain the observable repository ids from.
+     * @return the list of observable repository ids.
+     * @throws PrincipalNotFoundException
+     * @throws AccessDeniedException
+     * @throws ArchivaSecurityException
+     */
+    public List<String> getManagableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
+    
     /**
      * Create any missing repository roles for the provided repository id.
      * 
index 27110c71e5224ff769a8fe2aab1c72797c14ee61..242436882453f6b2c864334f3dd1f795dfae3668 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
 import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelWriter;
 import org.apache.maven.archiva.repository.project.writers.ProjectModel400Writer;
+import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
 import org.apache.maven.archiva.security.PrincipalNotFoundException;
 import org.apache.maven.archiva.security.UserRepositories;
@@ -295,8 +296,7 @@ public class UploadAction
 
     public void prepare()
     {
-        managedRepoIdList =
-            new ArrayList<String>( configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() );
+        managedRepoIdList = getManagableRepos();
     }
 
     public String input()
@@ -622,6 +622,28 @@ public class UploadAction
         this.auditListeners.remove( listener );
     }
     
+    private List<String> getManagableRepos()
+    {
+        try
+        {
+            return userRepositories.getManagableRepositoryIds( getPrincipal() );
+        }
+        catch ( PrincipalNotFoundException e )
+        {
+            getLogger().warn( e.getMessage(), e );
+        }
+        catch ( AccessDeniedException e )
+        {
+            getLogger().warn( e.getMessage(), e );
+            // TODO: pass this onto the screen.
+        }
+        catch ( ArchivaSecurityException e )
+        {
+            getLogger().warn( e.getMessage(), e );
+        }
+        return Collections.emptyList();
+    }
+
     private void triggerAuditEvent( String user, String repositoryId, String resource, String action )
     {
         AuditEvent event = new AuditEvent( repositoryId, user, resource, action );
index e5f4c4ff1aa958bd16949810cb1bcc89e899a0f9..52ec32bbeb163dedd380daf931c8e7204397bace 100644 (file)
@@ -80,7 +80,7 @@
       </li>
     </ul>
 
-    <redback:ifAnyAuthorized permissions="archiva-delete-artifact,archiva-manage-users,archiva-access-reports,archiva-manage-configuration">
+    <redback:ifAnyAuthorized permissions="archiva-upload-repository,archiva-delete-artifact,archiva-manage-users,archiva-access-reports,archiva-manage-configuration">
       <h5>Manage</h5>
       <ul>
         <redback:ifAuthorized permission="archiva-access-reports">
             <my:currentWWUrl action="pickReport" namespace="/report">Reports</my:currentWWUrl>
           </li>
         </redback:ifAuthorized>
-          <%-- POSTPONED to 1.1 series
-                <li class="none">
-                  <a href="#">Synchronisation</a>
-                </li>
-          --%>
         <redback:ifAuthorized permission="archiva-manage-users">
           <li class="none">
             <my:currentWWUrl action="userlist" namespace="/security">User Management</my:currentWWUrl>
           <li class="none">
             <my:currentWWUrl action="configureAppearance" namespace="/admin">Appearance</my:currentWWUrl>
           </li>
+        </redback:ifAuthorized>
+        <redback:ifAuthorized permission="archiva-upload-repository">
           <li class="none">
             <my:currentWWUrl action="upload" namespace="/">Upload Artifact</my:currentWWUrl>
           </li>
index 43f43652e2dae37d9a3378059cd1212eca67d26b..88971d44fee3182e72059ff5cd0daea6ffd29654 100644 (file)
@@ -67,4 +67,11 @@ public class UserRepositoriesStub
         return false;
     }
 
+    public List<String> getManagableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }