]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1506] api to configure RemoteRepository : add auditListener call
authorOlivier Lamy <olamy@apache.org>
Sun, 4 Sep 2011 14:54:52 +0000 (14:54 +0000)
committerOlivier Lamy <olamy@apache.org>
Sun, 4 Sep 2011 14:54:52 +0000 (14:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165044 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java

index b749963da51b83c156a06b08efb66105c1eec4ac..c106c8e62911b9182ba62406e357d7a1f0467584 100644 (file)
@@ -18,8 +18,10 @@ package org.apache.archiva.admin.repository.remote;
  * under the License.
  */
 
+import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.audit.AuditEvent;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
@@ -68,9 +70,10 @@ public class DefaultRemoteRepositoryAdmin
         return null;
     }
 
-    public Boolean addRemoteRepository( RemoteRepository remoteRepository )
+    public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
         throws RepositoryAdminException
     {
+        triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation );
         getRepositoryCommonValidator().basicValidation( remoteRepository, false );
 
         //TODO we can validate it's a good uri/url
@@ -94,12 +97,17 @@ public class DefaultRemoteRepositoryAdmin
         Configuration configuration = getArchivaConfiguration().getConfiguration();
         configuration.addRemoteRepository( remoteRepositoryConfiguration );
         saveConfiguration( configuration );
+
+
         return Boolean.TRUE;
     }
 
-    public Boolean deleteRemoteRepository( String repositoryId )
+    public Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
         throws RepositoryAdminException
     {
+
+        triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation );
+
         Configuration configuration = getArchivaConfiguration().getConfiguration();
 
         RemoteRepositoryConfiguration remoteRepositoryConfiguration =
@@ -127,7 +135,7 @@ public class DefaultRemoteRepositoryAdmin
         return Boolean.TRUE;
     }
 
-    public Boolean updateRemoteRepository( RemoteRepository remoteRepository )
+    public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
         throws RepositoryAdminException
     {
         return null;  //To change body of implemented methods use File | Settings | File Templates.
index 6a23ea9f4525022b984ddabea8a58f798ce5c34a..3adde318ff92d85a3d40ffe1aa651a0b15f7418d 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.admin.repository.remote;
  */
 
 
+import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
 
 import java.util.List;
@@ -35,12 +36,12 @@ public interface RemoteRepositoryAdmin
     RemoteRepository getRemoteRepository( String repositoryId )
         throws RepositoryAdminException;
 
-    Boolean deleteRemoteRepository( String repositoryId )
+    Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
         throws RepositoryAdminException;
 
-    Boolean addRemoteRepository( RemoteRepository remoteRepository )
+    Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
         throws RepositoryAdminException;
 
-    Boolean updateRemoteRepository( RemoteRepository remoteRepository )
+    Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
         throws RepositoryAdminException;
 }
index 02e72d35706e979b51839f518587155fb883ca1f..2c5ae5cabb426c85037d11aa58f93f87787fbe38 100644 (file)
@@ -19,12 +19,18 @@ package org.apache.archiva.admin.repository;
  */
 
 import junit.framework.TestCase;
+import org.apache.archiva.admin.AuditInformation;
+import org.apache.archiva.admin.mock.MockAuditListener;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.memory.SimpleUser;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import javax.inject.Inject;
+
 /**
  * @author Olivier Lamy
  */
@@ -36,5 +42,30 @@ public abstract class AbstractRepositoryAdminTest
     protected Logger log = LoggerFactory.getLogger( getClass() );
 
     public static final String APPSERVER_BASE_PATH = System.getProperty( "appserver.base" );
-    // no op
+
+    @Inject
+    protected MockAuditListener mockAuditListener;
+
+    protected AuditInformation getFakeAuditInformation()
+    {
+        AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
+        return auditInformation;
+    }
+
+    protected User getFakeUser()
+    {
+        SimpleUser user = new SimpleUser()
+        {
+            @Override
+            public Object getPrincipal()
+            {
+                return "root";
+            }
+
+        };
+
+        user.setUsername( "root" );
+        user.setFullName( "The top user" );
+        return user;
+    }
 }
index 517d8c7df333a431ce7825ac4ef7e6b236c5a6f3..58166025167f6f0d514a48e34b30301922552ebf 100644 (file)
@@ -44,8 +44,7 @@ public class ManagedRepositoryAdminTest
     @Inject
     private ManagedRepositoryAdmin managedRepositoryAdmin;
 
-    @Inject
-    private MockAuditListener mockAuditListener;
+
 
     @Inject
     protected RoleManager roleManager;
@@ -416,28 +415,7 @@ public class ManagedRepositoryAdminTest
         return null;
     }
 
-    AuditInformation getFakeAuditInformation()
-    {
-        AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
-        return auditInformation;
-    }
 
-    User getFakeUser()
-    {
-        SimpleUser user = new SimpleUser()
-        {
-            @Override
-            public Object getPrincipal()
-            {
-                return "root";
-            }
-
-        };
-
-        user.setUsername( "root" );
-        user.setFullName( "The top user" );
-        return user;
-    }
 
     ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
     {
index 1da181adf273168a01144aed5273ddf2a7c67432..77ff94d73566bf1564c21d64b23bf83308079ba3 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.admin.repository.remote;
  */
 
 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.apache.archiva.audit.AuditEvent;
 import org.junit.Test;
 
 import javax.inject.Inject;
@@ -60,11 +61,12 @@ public class RemoteRepositoryAdminTest
     public void addAndDelete()
         throws Exception
     {
+        mockAuditListener.clearEvents();
         int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
 
         RemoteRepository remoteRepository = getRemoteRepository();
 
-        remoteRepositoryAdmin.addRemoteRepository( remoteRepository );
+        remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
 
         assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
 
@@ -76,12 +78,22 @@ public class RemoteRepositoryAdminTest
         assertEquals( getRemoteRepository().getName(), repo.getName() );
         assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
 
-        remoteRepositoryAdmin.deleteRemoteRepository( "foo" );
+        remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
 
         assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
 
         repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
         assertNull( repo );
+
+        assertEquals( 2, mockAuditListener.getAuditEvents().size() );
+
+        assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
+        assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
+        assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
+
+        assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
+        assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
+
     }