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.model.AuditInformation;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.audit.AuditEvent;
24 import org.apache.archiva.audit.AuditListener;
25 import org.apache.archiva.configuration.ArchivaConfiguration;
26 import org.apache.archiva.configuration.Configuration;
27 import org.apache.archiva.configuration.IndeterminateConfigurationException;
28 import org.codehaus.plexus.redback.users.User;
29 import org.codehaus.plexus.registry.Registry;
30 import org.codehaus.plexus.registry.RegistryException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import javax.inject.Inject;
35 import javax.inject.Named;
36 import java.util.ArrayList;
37 import java.util.List;
40 * @author Olivier Lamy
43 public abstract class AbstractRepositoryAdmin
45 protected Logger log = LoggerFactory.getLogger( getClass() );
48 private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
52 private RepositoryCommonValidator repositoryCommonValidator;
55 private ArchivaConfiguration archivaConfiguration;
58 @Named( value = "commons-configuration" )
59 private Registry registry;
61 protected void triggerAuditEvent( String repositoryId, String resource, String action,
62 AuditInformation auditInformation )
64 User user = auditInformation == null ? null : auditInformation.getUser();
66 new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(), resource, action );
67 event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
69 for ( AuditListener listener : getAuditListeners() )
71 listener.auditEvent( event );
76 protected void saveConfiguration( Configuration config )
77 throws RepositoryAdminException
81 getArchivaConfiguration().save( config );
83 catch ( RegistryException e )
85 throw new RepositoryAdminException( "Error occurred in the registry.", e );
87 catch ( IndeterminateConfigurationException e )
89 throw new RepositoryAdminException( "Error occurred while saving the configuration.", e );
93 public List<AuditListener> getAuditListeners()
95 return auditListeners;
98 public void setAuditListeners( List<AuditListener> auditListeners )
100 this.auditListeners = auditListeners;
103 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
105 this.archivaConfiguration = archivaConfiguration;
108 public ArchivaConfiguration getArchivaConfiguration()
110 return archivaConfiguration;
113 public RepositoryCommonValidator getRepositoryCommonValidator()
115 return repositoryCommonValidator;
118 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
120 this.repositoryCommonValidator = repositoryCommonValidator;
123 public Registry getRegistry()
128 public void setRegistry( Registry registry )
130 this.registry = registry;