* 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;
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
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 =
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.
*/
+import org.apache.archiva.admin.AuditInformation;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import java.util.List;
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;
}
*/
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
*/
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;
+ }
}
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
- @Inject
- private MockAuditListener mockAuditListener;
+
@Inject
protected RoleManager roleManager;
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 )
{
*/
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.apache.archiva.audit.AuditEvent;
import org.junit.Test;
import javax.inject.Inject;
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() );
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() );
+
}