diff options
author | Olivier Lamy <olamy@apache.org> | 2011-08-29 21:42:38 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-08-29 21:42:38 +0000 |
commit | 48ef3f20f2388ee5deec3264948e1d6089c6872c (patch) | |
tree | 1bae0376fc8e1b7bd8dec3645f7b4501865a8ca0 /archiva-modules/archiva-base | |
parent | 8eba376fb80721809fbffcee92ae91574f27a4ee (diff) | |
download | archiva-48ef3f20f2388ee5deec3264948e1d6089c6872c.tar.gz archiva-48ef3f20f2388ee5deec3264948e1d6089c6872c.zip |
introduce an AuditInformation bean to have more easily extensible audit mechanism
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1163027 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
4 files changed, 86 insertions, 16 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/AuditInformation.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/AuditInformation.java new file mode 100644 index 000000000..d01ec4bda --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/AuditInformation.java @@ -0,0 +1,58 @@ +package org.apache.archiva.admin; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.codehaus.plexus.redback.users.User; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class AuditInformation +{ + private User user; + + private String remoteAddr; + + public AuditInformation( User user, String remoteAddr ) + { + this.user = user; + this.remoteAddr = remoteAddr; + } + + public User getUser() + { + return user; + } + + public void setUser( User user ) + { + this.user = user; + } + + public String getRemoteAddr() + { + return remoteAddr; + } + + public void setRemoteAddr( String remoteAddr ) + { + this.remoteAddr = remoteAddr; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index 26f0bb69f..95b97b301 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.managed; * under the License. */ +import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.RepositoryAdminException; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; @@ -133,7 +134,8 @@ public class DefaultManagedRepositoryAdmin return null; } - public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, User user ) + public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, + AuditInformation auditInformation ) throws RepositoryAdminException { return @@ -252,7 +254,7 @@ public class DefaultManagedRepositoryAdmin } - public Boolean deleteManagedRepository( String repositoryId, User user ) + public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation ) throws RepositoryAdminException { Configuration config = archivaConfiguration.getConfiguration(); @@ -325,7 +327,8 @@ public class DefaultManagedRepositoryAdmin } - public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, User user ) + public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, + AuditInformation auditInformation ) throws RepositoryAdminException { // Ensure that the fields are valid. @@ -358,7 +361,7 @@ public class DefaultManagedRepositoryAdmin try { - triggerAuditEvent( managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, user ); + triggerAuditEvent( managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation ); addRepositoryRoles( managedRepositoryConfiguration ); // FIXME this staging part !! @@ -423,12 +426,12 @@ public class DefaultManagedRepositoryAdmin // utils methods //-------------------------- - protected void triggerAuditEvent( String repositoryId, String resource, String action, User user ) + protected void triggerAuditEvent( String repositoryId, String resource, String action, + AuditInformation auditInformation ) { - log.warn( "no user found in triggerAuditEvent" ); + User user = auditInformation == null ? null : auditInformation.getUser(); AuditEvent event = new AuditEvent( repositoryId, user == null ? "null" : user.getUsername(), resource, action ); - // FIXME use a thread local through cxf interceptors to store this - //event.setRemoteIP( getRemoteAddr() ); + event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() ); for ( AuditListener listener : auditListeners ) { diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java index 3c97583ef..cdcc18408 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java @@ -19,8 +19,8 @@ package org.apache.archiva.admin.repository.managed; */ +import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.RepositoryAdminException; -import org.codehaus.plexus.redback.users.User; import java.util.List; @@ -36,14 +36,16 @@ public interface ManagedRepositoryAdmin ManagedRepository getManagedRepository( String repositoryId ) throws RepositoryAdminException; - Boolean deleteManagedRepository( String repositoryId, User user ) + Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation ) throws RepositoryAdminException; - Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, User user ) + Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, + AuditInformation auditInformation ) throws RepositoryAdminException; - Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, User user ) + Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo, + AuditInformation auditInformation ) throws RepositoryAdminException; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java index bab5e5e83..dd932ce6a 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java @@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.managed; * under the License. */ +import org.apache.archiva.admin.AuditInformation; import org.apache.commons.lang.StringUtils; import org.codehaus.plexus.redback.users.User; import org.codehaus.plexus.redback.users.memory.SimpleUser; @@ -74,14 +75,14 @@ public class ManagedRepositoryAdminTest repo.setId( "test-new-one" ); repo.setName( "test repo" ); repo.setLocation( APPSERVER_BASE_PATH + repo.getId() ); - managedRepositoryAdmin.addManagedRepository( repo, false, getFakeUser() ); + managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); assertEquals( initialSize + 1, repos.size() ); assertNotNull( managedRepositoryAdmin.getManagedRepository( "test-new-one" ) ); - managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeUser() ); + managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); @@ -101,7 +102,7 @@ public class ManagedRepositoryAdminTest repo.setId( "test-new-one" ); repo.setName( "test repo" ); repo.setLocation( APPSERVER_BASE_PATH + repo.getId() ); - managedRepositoryAdmin.addManagedRepository( repo, false, getFakeUser() ); + managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); repos = managedRepositoryAdmin.getManagedRepositories(); assertNotNull( repos ); assertEquals( initialSize + 1, repos.size() ); @@ -112,7 +113,7 @@ public class ManagedRepositoryAdminTest repo.setLocation( APPSERVER_BASE_PATH + "new-path" ); - managedRepositoryAdmin.updateManagedRepository( repo, false, getFakeUser() ); + managedRepositoryAdmin.updateManagedRepository( repo, false, getFakeAuditInformation() ); repo = managedRepositoryAdmin.getManagedRepository( "test-new-one" ); assertNotNull( repo ); @@ -134,6 +135,12 @@ public class ManagedRepositoryAdminTest return null; } + AuditInformation getFakeAuditInformation() + { + AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" ); + return auditInformation; + } + User getFakeUser() { SimpleUser user = new SimpleUser(); |