1 package org.apache.archiva.admin.repository;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.AuditInformation;
22 import org.apache.archiva.audit.AuditEvent;
23 import org.apache.archiva.audit.AuditListener;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
27 import org.codehaus.plexus.redback.users.User;
28 import org.codehaus.plexus.registry.Registry;
29 import org.codehaus.plexus.registry.RegistryException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import javax.inject.Inject;
34 import javax.inject.Named;
35 import java.util.ArrayList;
36 import java.util.List;
39 * @author Olivier Lamy
42 public abstract class AbstractRepositoryAdmin
44 protected Logger log = LoggerFactory.getLogger( getClass() );
47 private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
51 private RepositoryCommonValidator repositoryCommonValidator;
54 private ArchivaConfiguration archivaConfiguration;
57 @Named( value = "commons-configuration" )
58 private Registry registry;
60 protected void triggerAuditEvent( String repositoryId, String resource, String action,
61 AuditInformation auditInformation )
63 User user = auditInformation == null ? null : auditInformation.getUser();
65 new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(), resource, action );
66 event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
68 for ( AuditListener listener : getAuditListeners() )
70 listener.auditEvent( event );
75 protected void saveConfiguration( Configuration config )
76 throws RepositoryAdminException
80 getArchivaConfiguration().save( config );
82 catch ( RegistryException e )
84 throw new RepositoryAdminException( "Error occurred in the registry.", e );
86 catch ( IndeterminateConfigurationException e )
88 throw new RepositoryAdminException( "Error occurred while saving the configuration.", e );
92 public List<AuditListener> getAuditListeners()
94 return auditListeners;
97 public void setAuditListeners( List<AuditListener> auditListeners )
99 this.auditListeners = auditListeners;
102 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
104 this.archivaConfiguration = archivaConfiguration;
107 public ArchivaConfiguration getArchivaConfiguration()
109 return archivaConfiguration;
112 public RepositoryCommonValidator getRepositoryCommonValidator()
114 return repositoryCommonValidator;
117 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
119 this.repositoryCommonValidator = repositoryCommonValidator;
122 public Registry getRegistry()
127 public void setRegistry( Registry registry )
129 this.registry = registry;