mirror of https://github.com/apache/archiva.git
[MRM-1506] api to configure RemoteRepository : add auditListener call
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9b2e294e8c
commit
0a1b1d317f
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue