You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractRepositoriesAdminAction.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package org.apache.maven.archiva.web.action.admin.repositories;
  2. /*
  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
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  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
  18. * under the License.
  19. */
  20. import org.apache.maven.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.maven.archiva.configuration.Configuration;
  22. import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
  23. import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
  24. import org.apache.maven.archiva.security.ArchivaRoleConstants;
  25. import org.codehaus.plexus.redback.rbac.Resource;
  26. import org.codehaus.plexus.redback.struts2.interceptor.SecureAction;
  27. import org.codehaus.plexus.redback.struts2.interceptor.SecureActionBundle;
  28. import org.codehaus.plexus.redback.struts2.interceptor.SecureActionException;
  29. import org.codehaus.plexus.registry.RegistryException;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32. import org.apache.maven.archiva.web.action.PlexusActionSupport;
  33. /**
  34. * Abstract AdminRepositories Action base.
  35. *
  36. * Base class for all repository administrative functions.
  37. * This should be neutral to the type of action (add/edit/delete) and type of repo (managed/remote)
  38. *
  39. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  40. * @version $Id$
  41. */
  42. public abstract class AbstractRepositoriesAdminAction
  43. extends PlexusActionSupport
  44. implements SecureAction
  45. {
  46. /**
  47. * @plexus.requirement
  48. */
  49. protected ArchivaConfiguration archivaConfiguration;
  50. public ArchivaConfiguration getArchivaConfiguration()
  51. {
  52. return archivaConfiguration;
  53. }
  54. public SecureActionBundle getSecureActionBundle()
  55. throws SecureActionException
  56. {
  57. SecureActionBundle bundle = new SecureActionBundle();
  58. bundle.setRequiresAuthentication( true );
  59. bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
  60. return bundle;
  61. }
  62. public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
  63. {
  64. this.archivaConfiguration = archivaConfiguration;
  65. }
  66. /**
  67. * Save the configuration.
  68. *
  69. * @param configuration the configuration to save.
  70. * @return the webwork result code to issue.
  71. * @throws IOException thrown if unable to save file to disk.
  72. * @throws InvalidConfigurationException thrown if configuration is invalid.
  73. * @throws RegistryException thrown if configuration subsystem has a problem saving the configuration to disk.
  74. */
  75. protected String saveConfiguration( Configuration configuration )
  76. {
  77. try
  78. {
  79. archivaConfiguration.save( configuration );
  80. addActionMessage( "Successfully saved configuration" );
  81. }
  82. catch ( IndeterminateConfigurationException e )
  83. {
  84. addActionError( e.getMessage() );
  85. return INPUT;
  86. }
  87. catch ( RegistryException e )
  88. {
  89. addActionError( "Configuration Registry Exception: " + e.getMessage() );
  90. return INPUT;
  91. }
  92. return SUCCESS;
  93. }
  94. /**
  95. * Get the list of ProxyConnectors that are present in the configuration.
  96. *
  97. * @return a new list of ProxyConnectors present in the configuration.
  98. */
  99. protected List<ProxyConnectorConfiguration> getProxyConnectors()
  100. {
  101. return new ArrayList<ProxyConnectorConfiguration>( archivaConfiguration.getConfiguration().getProxyConnectors() );
  102. }
  103. }