]> source.dussan.org Git - archiva.git/blob
3dfded5492e8739cc5e2c8cd0b1edc9682fc1af4
[archiva.git] /
1 package org.apache.maven.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 com.opensymphony.xwork.Preparable;
23 import org.apache.commons.collections.Closure;
24 import org.apache.commons.collections.CollectionUtils;
25 import org.apache.commons.collections.Transformer;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
29 import org.apache.maven.archiva.security.ArchivaRoleConstants;
30 import org.apache.maven.archiva.web.action.admin.repositories.AdminRepositoryConfiguration;
31 import org.codehaus.plexus.redback.rbac.Resource;
32 import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
33 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
34 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
35 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
36
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 /**
43  * ProxyConnectorsAction
44  *
45  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
46  * @version $Id$
47  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="proxyConnectorsAction"
48  */
49 public class ProxyConnectorsAction
50     extends PlexusActionSupport
51     implements SecureAction, Preparable
52 {
53     /**
54      * @plexus.requirement role-hint="adminrepoconfig"
55      */
56     private Transformer repoConfigToAdmin;
57
58     /**
59      * @plexus.requirement
60      */
61     private ArchivaConfiguration archivaConfiguration;
62
63     private Map /*<String,AdminRepositoryConfiguration>*/repoMap;
64
65     /**
66      * Map of Proxy Connectors.
67      */
68     private Map /*<String,AdminProxyConnector>*/proxyConnectorMap;
69
70     public void prepare()
71         throws Exception
72     {
73         Configuration config = archivaConfiguration.getConfiguration();
74
75         repoMap = new HashMap();
76
77         Closure addToRepoMap = new Closure()
78         {
79             public void execute( Object input )
80             {
81                 AdminRepositoryConfiguration arepo =
82                     (AdminRepositoryConfiguration) repoConfigToAdmin.transform( input );
83                 repoMap.put( arepo.getId(), arepo );
84             }
85         };
86
87         CollectionUtils.forAllDo( config.getManagedRepositories(), addToRepoMap );
88         CollectionUtils.forAllDo( config.getRemoteRepositories(), addToRepoMap );
89
90         proxyConnectorMap = new HashMap();
91
92         Closure addToProxyConnectorMap = new Closure()
93         {
94             public void execute( Object input )
95             {
96                 if ( input instanceof ProxyConnectorConfiguration )
97                 {
98                     ProxyConnectorConfiguration proxyConfig = (ProxyConnectorConfiguration) input;
99                     String key = proxyConfig.getSourceRepoId();
100
101                     List connectors = (List) proxyConnectorMap.get( key );
102                     if ( connectors == null )
103                     {
104                         connectors = new ArrayList();
105                         proxyConnectorMap.put( key, connectors );
106                     }
107
108                     connectors.add( proxyConfig );
109                 }
110             }
111         };
112
113         CollectionUtils.forAllDo( config.getProxyConnectors(), addToProxyConnectorMap );
114     }
115
116     public SecureActionBundle getSecureActionBundle()
117         throws SecureActionException
118     {
119         SecureActionBundle bundle = new SecureActionBundle();
120
121         bundle.setRequiresAuthentication( true );
122         bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
123
124         return bundle;
125     }
126
127     public Map getRepoMap()
128     {
129         return repoMap;
130     }
131
132     public void setRepoMap( Map repoMap )
133     {
134         this.repoMap = repoMap;
135     }
136
137     public Map getProxyConnectorMap()
138     {
139         return proxyConnectorMap;
140     }
141
142     public void setProxyConnectorMap( Map proxyConnectorMap )
143     {
144         this.proxyConnectorMap = proxyConnectorMap;
145     }
146 }