]> source.dussan.org Git - archiva.git/blob
4754fd9ce0196c3a44a4b731ad49deb1d78836c0
[archiva.git] /
1 package org.apache.archiva.web.action.admin.connectors.proxy;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ProxyConnector;
24 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
26 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
27 import org.apache.archiva.security.common.ArchivaRoleConstants;
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.archiva.web.action.AbstractActionSupport;
30 import org.apache.archiva.redback.rbac.Resource;
31 import org.apache.archiva.redback.integration.interceptor.SecureAction;
32 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
33 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
34
35 import javax.inject.Inject;
36 import java.util.List;
37 import java.util.Map;
38
39 /**
40  * AbstractProxyConnectorAction
41  *
42  *
43  */
44 public abstract class AbstractProxyConnectorAction
45     extends AbstractActionSupport
46     implements SecureAction
47 {
48     public static final String DIRECT_CONNECTION = "(direct connection)";
49
50     @Inject
51     private ProxyConnectorAdmin proxyConnectorAdmin;
52
53     @Inject
54     private RemoteRepositoryAdmin remoteRepositoryAdmin;
55
56     @Inject
57     private ManagedRepositoryAdmin managedRepositoryAdmin;
58
59     public SecureActionBundle getSecureActionBundle()
60         throws SecureActionException
61     {
62         SecureActionBundle bundle = new SecureActionBundle();
63
64         bundle.setRequiresAuthentication( true );
65         bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
66
67         return bundle;
68     }
69
70
71     protected void addProxyConnector( ProxyConnector proxyConnector )
72         throws RepositoryAdminException
73     {
74         getProxyConnectorAdmin().addProxyConnector( proxyConnector, getAuditInformation() );
75     }
76
77     protected ProxyConnector findProxyConnector( String sourceId, String targetId )
78         throws RepositoryAdminException
79     {
80         if ( StringUtils.isBlank( sourceId ) )
81         {
82             return null;
83         }
84
85         if ( StringUtils.isBlank( targetId ) )
86         {
87             return null;
88         }
89
90         return getProxyConnectorAdmin().getProxyConnector( sourceId, targetId );
91     }
92
93     protected Map<String, List<ProxyConnector>> createProxyConnectorMap()
94         throws RepositoryAdminException
95     {
96         return getProxyConnectorAdmin().getProxyConnectorAsMap();
97     }
98
99     protected void removeConnector( String sourceId, String targetId )
100         throws RepositoryAdminException
101     {
102         ProxyConnector proxyConnector = findProxyConnector( sourceId, targetId );
103         if ( proxyConnector != null )
104         {
105             getProxyConnectorAdmin().deleteProxyConnector( proxyConnector, getAuditInformation() );
106         }
107     }
108
109     protected void removeProxyConnector( ProxyConnector connector )
110         throws RepositoryAdminException
111     {
112         getProxyConnectorAdmin().deleteProxyConnector( connector, getAuditInformation() );
113     }
114
115
116     public ProxyConnectorAdmin getProxyConnectorAdmin()
117     {
118         return proxyConnectorAdmin;
119     }
120
121     public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
122     {
123         this.proxyConnectorAdmin = proxyConnectorAdmin;
124     }
125
126     public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
127     {
128         return remoteRepositoryAdmin;
129     }
130
131     public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
132     {
133         this.remoteRepositoryAdmin = remoteRepositoryAdmin;
134     }
135
136     public ManagedRepositoryAdmin getManagedRepositoryAdmin()
137     {
138         return managedRepositoryAdmin;
139     }
140
141     public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
142     {
143         this.managedRepositoryAdmin = managedRepositoryAdmin;
144     }
145 }