1 package org.apache.archiva.redback.struts2.action.admin;
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 org.apache.archiva.redback.rbac.RBACManager;
23 import org.apache.archiva.redback.rbac.Resource;
24 import org.apache.archiva.redback.rbac.RbacManagerException;
25 import org.apache.archiva.redback.struts2.action.AbstractSecurityAction;
26 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
27 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
28 import org.apache.archiva.redback.integration.role.RoleConstants;
29 import org.apache.archiva.redback.integration.util.ResourceSorter;
30 import org.springframework.context.annotation.Scope;
31 import org.springframework.stereotype.Controller;
33 import javax.inject.Inject;
34 import javax.inject.Named;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.List;
42 * @author Jesse McConnell <jmcconnell@apache.org>
45 @Controller( "redback-resources" )
47 public class ResourcesAction
48 extends AbstractSecurityAction
50 private static final String LIST = "list";
56 @Named( value = "rBACManager#cached" )
57 private RBACManager manager;
59 private String resourceIdentifier;
61 private boolean isPattern;
63 private List<Resource> allResources;
69 allResources = manager.getAllResources();
71 if ( allResources == null )
73 allResources = Collections.emptyList();
76 Collections.sort( allResources, new ResourceSorter() );
78 catch ( RbacManagerException e )
80 addActionError( getText( "cannot.list.all.resources", Arrays.asList( (Object) e.getMessage() ) ) );
81 log.error( "System error:", e );
82 allResources = Collections.emptyList();
92 Resource temp = manager.createResource( resourceIdentifier );
94 temp.setIdentifier( resourceIdentifier );
95 temp.setPattern( isPattern );
97 manager.saveResource( temp );
99 catch ( RbacManagerException e )
101 addActionError( getText( "cannot.save.resource", Arrays.asList( (Object) e.getMessage() ) ) );
102 log.error( "System error:", e );
103 allResources = Collections.emptyList();
109 public String remove()
113 manager.removeResource( manager.getResource( resourceIdentifier ) );
115 catch ( RbacManagerException ne )
117 addActionError( getText( "cannot.remove.resource", Arrays.asList( (Object) resourceIdentifier ) ) );
123 public List<Resource> getAllResources()
128 public void setAllResources( List<Resource> allResources )
130 this.allResources = allResources;
133 public String getResourceIdentifier()
135 return resourceIdentifier;
138 public void setResourceIdentifier( String resourceIdentifier )
140 this.resourceIdentifier = resourceIdentifier;
143 public boolean isPattern()
148 public void setPattern( boolean isPattern )
150 this.isPattern = isPattern;
153 public SecureActionBundle initSecureActionBundle()
154 throws SecureActionException
156 SecureActionBundle bundle = new SecureActionBundle();
157 bundle.setRequiresAuthentication( true );
158 bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );