From 34c163502bd8d1f564dd6583cc02147935760fd6 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 20 Mar 2009 16:35:02 +0000 Subject: [PATCH] fix test problems git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@756587 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/archiva/repository/audit/AuditLog.java | 2 +- .../maven/archiva/security/ArchivaXworkUser.java | 5 +++++ .../archiva/web/action/PlexusActionSupport.java | 14 +++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java index d99c9d7bc..7ec8af4bf 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java @@ -46,7 +46,7 @@ public class AuditLog StringBuffer msg = new StringBuffer(); msg.append( checkNull( event.getRepositoryId() ) ).append( DELIM ); msg.append( event.getUserId() ).append( DELIM ); - msg.append( event.getRemoteIP() ).append( DELIM ); + msg.append( checkNull( event.getRemoteIP() ) ).append( DELIM ); msg.append( '\"' ).append( checkNull( event.getResource() ) ).append( '\"' ).append( DELIM ); msg.append( '\"' ).append( event.getAction() ).append( '\"' ); diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java index a12f4d72c..317631825 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java @@ -40,6 +40,11 @@ public final class ArchivaXworkUser public static String getActivePrincipal( Map sessionMap ) { + if ( sessionMap == null ) + { + return UserManager.GUEST_USERNAME; + } + SecuritySession securitySession = (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java index 8780aba44..03ea5274d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.servlet.http.HttpServletRequest; + import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.AuditListener; import org.apache.maven.archiva.repository.audit.Auditable; @@ -75,7 +77,7 @@ public abstract class PlexusActionSupport protected void triggerAuditEvent( String repositoryId, String resource, String action ) { AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action ); - event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() ); + event.setRemoteIP( getRemoteAddr() ); for ( AuditListener listener : auditListeners ) { @@ -86,7 +88,7 @@ public abstract class PlexusActionSupport protected void triggerAuditEvent( String resource, String action ) { AuditEvent event = new AuditEvent( getPrincipal(), resource, action ); - event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() ); + event.setRemoteIP( getRemoteAddr() ); for ( AuditListener listener : auditListeners ) { @@ -97,7 +99,7 @@ public abstract class PlexusActionSupport protected void triggerAuditEvent( String action ) { AuditEvent event = new AuditEvent( getPrincipal(), action ); - event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() ); + event.setRemoteIP( getRemoteAddr() ); for ( AuditListener listener : auditListeners ) { @@ -105,6 +107,12 @@ public abstract class PlexusActionSupport } } + private String getRemoteAddr() + { + HttpServletRequest request = ServletActionContext.getRequest(); + return request != null ? request.getRemoteAddr() : null; + } + @SuppressWarnings( "unchecked" ) protected String getPrincipal() { -- 2.39.5