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.Operation;
23 import org.apache.archiva.redback.rbac.RBACManager;
24 import org.apache.archiva.redback.rbac.RbacManagerException;
25 import org.apache.archiva.redback.rbac.Resource;
26 import org.apache.archiva.redback.struts2.action.RedbackActionSupport;
27 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
28 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
29 import org.apache.archiva.redback.integration.role.RoleConstants;
30 import org.apache.archiva.redback.integration.util.OperationSorter;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Controller;
34 import javax.inject.Inject;
35 import javax.inject.Named;
36 import java.util.Arrays;
37 import java.util.Collections;
38 import java.util.List;
43 * @author Jesse McConnell <jmcconnell@apache.org>
46 @Controller( "redback-operations" )
48 public class OperationsAction
49 extends RedbackActionSupport
51 private static final String LIST = "list";
57 @Named( value = "rBACManager#cached" )
58 private RBACManager manager;
60 private String operationName;
62 private String description;
64 private List<Operation> allOperations;
70 allOperations = manager.getAllOperations();
72 if ( allOperations == null )
74 allOperations = Collections.emptyList();
77 Collections.sort( allOperations, new OperationSorter() );
79 catch ( RbacManagerException e )
81 addActionError( getText( "cannot.list.all.operations", Arrays.asList( (Object) e.getMessage() ) ) );
82 log.error( "System error:", e );
83 allOperations = Collections.emptyList();
93 Operation temp = manager.createOperation( operationName );
95 temp.setDescription( description );
97 manager.saveOperation( temp );
99 catch ( RbacManagerException e )
101 addActionError( getText( "cannot.save.operation", Arrays.asList( (Object) operationName ) ) );
102 log.error( "System error:", e );
103 allOperations = Collections.emptyList();
109 public String remove()
113 manager.removeOperation( manager.getOperation( operationName ) );
115 catch ( RbacManagerException ne )
117 addActionError( getText( "cannot.remove.operation", Arrays.asList( (Object) operationName ) ) );
123 public List<Operation> getAllOperations()
125 return allOperations;
128 public void setAllOperations( List<Operation> allOperations )
130 this.allOperations = allOperations;
133 public String getDescription()
138 public void setDescription( String description )
140 this.description = description;
143 public String getOperationName()
145 return operationName;
148 public void setOperationName( String operationName )
150 this.operationName = operationName;
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 );