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.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
28 import org.codehaus.plexus.redback.users.User;
29 import org.codehaus.plexus.registry.Registry;
30 import org.codehaus.plexus.registry.RegistryException;
32 import javax.inject.Inject;
33 import javax.inject.Named;
34 import java.util.ArrayList;
35 import java.util.List;
38 * @author Olivier Lamy
41 public abstract class AbstractRepositoryAdmin
45 private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
49 private RepositoryCommonValidator repositoryCommonValidator;
52 private ArchivaConfiguration archivaConfiguration;
55 @Named( value = "commons-configuration" )
56 private Registry registry;
58 protected void triggerAuditEvent( String repositoryId, String resource, String action,
59 AuditInformation auditInformation )
61 User user = auditInformation == null ? null : auditInformation.getUser();
63 new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(), resource, action );
64 event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
66 for ( AuditListener listener : getAuditListeners() )
68 listener.auditEvent( event );
73 protected void saveConfiguration( Configuration config )
74 throws RepositoryAdminException
78 getArchivaConfiguration().save( config );
80 catch ( RegistryException e )
82 throw new RepositoryAdminException( "Error occurred in the registry.", e );
84 catch ( IndeterminateConfigurationException e )
86 throw new RepositoryAdminException( "Error occurred while saving the configuration.", e );
90 protected List<ProxyConnectorConfiguration> getProxyConnectors()
92 return new ArrayList<ProxyConnectorConfiguration>(
93 archivaConfiguration.getConfiguration().getProxyConnectors() );
96 public List<AuditListener> getAuditListeners()
98 return auditListeners;
101 public void setAuditListeners( List<AuditListener> auditListeners )
103 this.auditListeners = auditListeners;
106 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
108 this.archivaConfiguration = archivaConfiguration;
111 public ArchivaConfiguration getArchivaConfiguration()
113 return archivaConfiguration;
116 public RepositoryCommonValidator getRepositoryCommonValidator()
118 return repositoryCommonValidator;
121 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
123 this.repositoryCommonValidator = repositoryCommonValidator;
126 public Registry getRegistry()
131 public void setRegistry( Registry registry )
133 this.registry = registry;