diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-07-02 05:01:08 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-07-02 05:01:08 +0000 |
commit | 61b55ed6376037af3b71e2ee7689fdf3c76f50fc (patch) | |
tree | c2a1582a112f30fef0556e6f29deb8f8d7928fbe | |
parent | b5b378703bd5781c1b4151b7058076692d15c32f (diff) | |
download | archiva-61b55ed6376037af3b71e2ee7689fdf3c76f50fc.tar.gz archiva-61b55ed6376037af3b71e2ee7689fdf3c76f50fc.zip |
[MRM-810]
-implemented the Auditable for UploadAction
-cleaned up the logging config
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@673280 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 60 insertions, 11 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java index 399c820e5..b56af8cc3 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java @@ -37,6 +37,8 @@ public class AuditEvent public static final String MODIFY_FILE = "Modify File"; + public static final String UPLOAD_FILE = "Uploaded File"; + private String repositoryId; private String userId; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index 7f7dfb440..eabcc1518 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -42,6 +42,9 @@ import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; +import org.apache.maven.archiva.repository.audit.AuditEvent; +import org.apache.maven.archiva.repository.audit.AuditListener; +import org.apache.maven.archiva.repository.audit.Auditable; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader; @@ -55,6 +58,7 @@ import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.ArchivaXworkUser; import org.codehaus.plexus.xwork.action.PlexusActionSupport; +import com.opensymphony.webwork.ServletActionContext; import com.opensymphony.xwork.ActionContext; import com.opensymphony.xwork.Preparable; import com.opensymphony.xwork.Validateable; @@ -69,7 +73,7 @@ import com.opensymphony.xwork.Validateable; */ public class UploadAction extends PlexusActionSupport - implements Validateable, Preparable + implements Validateable, Preparable, Auditable { /** * @plexus.requirement @@ -161,6 +165,11 @@ public class UploadAction */ private RepositoryContentFactory repositoryFactory; + /** + * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener" + */ + private List<AuditListener> auditListeners = new ArrayList<AuditListener>(); + private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ProjectModelWriter pomWriter = new ProjectModel400Writer(); @@ -383,9 +392,8 @@ public class UploadAction String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version + "\' was successfully deployed to repository \'" + repositoryId + "\'"; - - //TODO: MRM-810 (this writes to archiva.log, should be audit.log) - getLogger().info( msg + " by " + getPrincipal() ); + + triggerAuditEvent( getPrincipal(), repositoryId, groupId + ":" + artifactId + ":" + version, AuditEvent.UPLOAD_FILE ); addActionMessage( msg ); @@ -536,4 +544,30 @@ public class UploadAction addActionError( ae.getMessage() ); } } + + public void addAuditListener( AuditListener listener ) + { + this.auditListeners.add( listener ); + } + + public void clearAuditListeners() + { + this.auditListeners.clear(); + } + + public void removeAuditListener( AuditListener listener ) + { + this.auditListeners.remove( listener ); + } + + private void triggerAuditEvent( String user, String repositoryId, String resource, String action ) + { + AuditEvent event = new AuditEvent( repositoryId, user, resource, action ); + event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() ); + + for ( AuditListener listener : auditListeners ) + { + listener.auditEvent( event ); + } + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/log4j.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/log4j.xml index 1fe1a88d5..284f1bcc7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/log4j.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/log4j.xml @@ -22,16 +22,14 @@ </appender> <!-- Help identify bugs during testing --> - <logger name="org.apache.maven"> - <level value="info"/> - </logger> - <logger name="org.apache.maven.archiva"> - <level value="info" /> + <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.apache.maven.archiva.repository.scanner"> <level value="info" /> + <appender-ref ref="rolling" /> </logger> <logger name="org.apache.archiva.AuditLog"> @@ -41,72 +39,87 @@ <logger name="org.codehaus.plexus.security"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <!-- squelch noisy objects (for now) --> <logger name="org.apache.commons"> <level value="warn"/> + <appender-ref ref="rolling" /> </logger> <logger name="net.sf.ehcache"> <level value="warn"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.codehaus.plexus.mailsender.MailSender"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.codehaus.plexus.velocity"> <level value="error"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.quartz"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.apache.jasper"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="com.opensymphony.xwork"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="com.opensymphony.webwork"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.codehaus.plexus.PlexusContainer"> <level value="info"/> + <appender-ref ref="rolling" /> </logger> <logger name="JPOX"> <level value="warn"/> + <appender-ref ref="rolling" /> </logger> <logger name="JPOX.MetaData"> <level value="error"/> + <appender-ref ref="rolling" /> </logger> <logger name="JPOX.RDBMS.SQL"> <level value="error"/> + <appender-ref ref="rolling" /> </logger> <logger name="SQL"> <level value="error"/> + <appender-ref ref="rolling" /> </logger> <logger name="freemarker"> <level value="warn"/> + <appender-ref ref="rolling" /> </logger> <logger name="org.codehaus.plexus.component.manager.ClassicSingletonComponentManager"> <level value="error"/> + <appender-ref ref="rolling" /> </logger> <root> <priority value ="info" /> - <appender-ref ref="rolling" /> </root> -</log4j:configuration> +</log4j:configuration>
\ No newline at end of file |