1 package org.apache.maven.archiva.web.action;
\r
4 * Licensed to the Apache Software Foundation (ASF) under one
\r
5 * or more contributor license agreements. See the NOTICE file
\r
6 * distributed with this work for additional information
\r
7 * regarding copyright ownership. The ASF licenses this file
\r
8 * to you under the Apache License, Version 2.0 (the
\r
9 * "License"); you may not use this file except in compliance
\r
10 * with the License. You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing,
\r
15 * software distributed under the License is distributed on an
\r
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
17 * KIND, either express or implied. See the License for the
\r
18 * specific language governing permissions and limitations
\r
19 * under the License.
\r
22 import java.util.ArrayList;
\r
23 import java.util.List;
\r
24 import java.util.Map;
\r
25 import javax.servlet.http.HttpServletRequest;
\r
27 import com.opensymphony.xwork2.ActionContext;
\r
28 import com.opensymphony.xwork2.ActionSupport;
\r
29 import org.apache.maven.archiva.repository.audit.AuditEvent;
\r
30 import org.apache.maven.archiva.repository.audit.AuditListener;
\r
31 import org.apache.maven.archiva.repository.audit.Auditable;
\r
32 import org.apache.maven.archiva.security.ArchivaXworkUser;
\r
33 import org.apache.struts2.ServletActionContext;
\r
34 import org.apache.struts2.interceptor.SessionAware;
\r
35 import org.slf4j.Logger;
\r
36 import org.slf4j.LoggerFactory;
\r
39 * LogEnabled and SessionAware ActionSupport
\r
41 public abstract class PlexusActionSupport
\r
42 extends ActionSupport
\r
43 implements SessionAware, Auditable
\r
45 protected Map<?, ?> session;
\r
47 protected Logger log = LoggerFactory.getLogger( getClass() );
\r
50 * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
\r
52 private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
\r
54 private String principal;
\r
56 @SuppressWarnings("unchecked")
\r
57 public void setSession( Map map )
\r
62 public void addAuditListener( AuditListener listener )
\r
64 this.auditListeners.add( listener );
\r
67 public void clearAuditListeners()
\r
69 this.auditListeners.clear();
\r
72 public void removeAuditListener( AuditListener listener )
\r
74 this.auditListeners.remove( listener );
\r
77 protected void triggerAuditEvent( String repositoryId, String resource, String action )
\r
79 AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );
\r
80 event.setRemoteIP( getRemoteAddr() );
\r
82 for ( AuditListener listener : auditListeners )
\r
84 listener.auditEvent( event );
\r
88 protected void triggerAuditEvent( String resource, String action )
\r
90 AuditEvent event = new AuditEvent( null, getPrincipal(), resource, action );
\r
91 event.setRemoteIP( getRemoteAddr() );
\r
93 for ( AuditListener listener : auditListeners )
\r
95 listener.auditEvent( event );
\r
99 protected void triggerAuditEvent( String action )
\r
101 AuditEvent event = new AuditEvent( null, getPrincipal(), null, action );
\r
102 event.setRemoteIP( getRemoteAddr() );
\r
104 for ( AuditListener listener : auditListeners )
\r
106 listener.auditEvent( event );
\r
110 private String getRemoteAddr()
\r
112 HttpServletRequest request = ServletActionContext.getRequest();
\r
113 return request != null ? request.getRemoteAddr() : null;
\r
116 @SuppressWarnings( "unchecked" )
\r
117 protected String getPrincipal()
\r
119 if ( principal != null )
\r
123 return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
\r
126 void setPrincipal( String principal )
\r
128 this.principal = principal;
\r
131 public void setAuditListeners( List<AuditListener> auditListeners )
\r
133 this.auditListeners = auditListeners;
\r