1 package org.apache.archiva.web.action.admin.networkproxies;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.opensymphony.xwork2.Preparable;
23 import com.opensymphony.xwork2.Validateable;
24 import org.apache.archiva.admin.model.RepositoryAdminException;
25 import org.apache.archiva.admin.model.beans.NetworkProxy;
26 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
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 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Controller;
37 import javax.inject.Inject;
40 * ConfigureNetworkProxyAction
44 @Controller( "configureNetworkProxyAction" )
46 public class ConfigureNetworkProxyAction
47 extends AbstractActionSupport
48 implements SecureAction, Preparable, Validateable
52 private NetworkProxyAdmin networkProxyAdmin;
56 private String proxyid;
58 private NetworkProxy proxy;
66 public String confirm()
71 public String delete()
72 throws RepositoryAdminException
75 String id = getProxyid();
76 if ( StringUtils.isBlank( id ) )
78 addActionError( "Unable to delete network proxy with blank id." );
82 NetworkProxy networkProxy = getNetworkProxyAdmin().getNetworkProxy( id );
83 if ( networkProxy == null )
85 addActionError( "Unable to remove network proxy, proxy with id [" + id + "] not found." );
89 getNetworkProxyAdmin().deleteNetworkProxy( id, getAuditInformation() );
90 addActionMessage( "Successfully removed network proxy [" + id + "]" );
100 public String getMode()
105 public NetworkProxy getProxy()
110 public String getProxyid()
115 public SecureActionBundle getSecureActionBundle()
116 throws SecureActionException
118 SecureActionBundle bundle = new SecureActionBundle();
120 bundle.setRequiresAuthentication( true );
121 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
126 public String input()
131 public void prepare()
134 String id = getProxyid();
136 if ( StringUtils.isNotBlank( id ) )
138 proxy = findNetworkProxy( id );
143 proxy = new NetworkProxy();
148 throws RepositoryAdminException
150 String mode = getMode();
152 String id = getProxy().getId();
154 if ( StringUtils.equalsIgnoreCase( "edit", mode ) )
156 getNetworkProxyAdmin().updateNetworkProxy( proxy, getAuditInformation() );
160 getNetworkProxyAdmin().addNetworkProxy( proxy, getAuditInformation() );
166 public void validate()
168 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
169 trimAllRequestParameterValues();
172 public void setMode( String mode )
177 public void setProxy( NetworkProxy proxy )
182 public void setProxyid( String proxyid )
184 this.proxyid = proxyid;
188 private NetworkProxy findNetworkProxy( String id )
189 throws RepositoryAdminException
191 return getNetworkProxyAdmin().getNetworkProxy( id );
194 private void trimAllRequestParameterValues()
196 if ( StringUtils.isNotEmpty( proxy.getId() ) )
198 proxy.setId( proxy.getId().trim() );
201 if ( StringUtils.isNotEmpty( proxy.getHost() ) )
203 proxy.setHost( proxy.getHost().trim() );
206 if ( StringUtils.isNotEmpty( proxy.getPassword() ) )
208 proxy.setPassword( proxy.getPassword().trim() );
211 if ( StringUtils.isNotEmpty( proxy.getProtocol() ) )
213 proxy.setProtocol( proxy.getProtocol().trim() );
216 if ( StringUtils.isNotEmpty( proxy.getUsername() ) )
218 proxy.setUsername( proxy.getUsername().trim() );
222 public NetworkProxyAdmin getNetworkProxyAdmin()
224 return networkProxyAdmin;
227 public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
229 this.networkProxyAdmin = networkProxyAdmin;