]> source.dussan.org Git - archiva.git/blob
92272d0e91aa8fe28575477d85e397b03d826323
[archiva.git] /
1 package org.apache.archiva.redback.struts2.action.admin;
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 org.apache.archiva.redback.rbac.Resource;
23 import org.apache.archiva.redback.rbac.Role;
24 import org.apache.archiva.redback.rbac.RbacManagerException;
25 import org.apache.archiva.redback.struts2.action.AbstractUserCredentialsAction;
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.springframework.context.annotation.Scope;
30 import org.springframework.stereotype.Controller;
31
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
35
36 /**
37  * RolesAction
38  *
39  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
40  *
41  */
42 @Controller( "redback-roles" )
43 @Scope( "prototype" )
44 public class RolesAction
45     extends AbstractUserCredentialsAction
46 {
47     private static final String LIST = "list";
48
49     private List<Role> allRoles;
50
51     public String list()
52     {
53         try
54         {
55             allRoles = getFilteredRolesForCurrentUserAccess();
56         }
57         catch ( RbacManagerException e )
58         {
59             List<Object> list = new ArrayList<Object>();
60             list.add( e.getMessage() );
61             addActionError( getText( "cannot.list.all.roles", list ) );
62             log.error( "System error:", e );
63             allRoles = Collections.emptyList();
64         }
65
66         return LIST;
67     }
68
69     public List<Role> getAllRoles()
70     {
71         return allRoles;
72     }
73
74     public void setAllRoles( List<Role> allRoles )
75     {
76         this.allRoles = allRoles;
77     }
78
79     public SecureActionBundle initSecureActionBundle()
80         throws SecureActionException
81     {
82         SecureActionBundle bundle = new SecureActionBundle();
83         bundle.setRequiresAuthentication( true );
84         bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION, Resource.GLOBAL );
85         bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION, Resource.GLOBAL );
86         bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION, Resource.GLOBAL );
87         bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_ROLE_DROP_OPERATION, Resource.GLOBAL );
88         bundle.addRequiredAuthorization( RoleConstants.USER_MANAGEMENT_USER_ROLE_OPERATION, Resource.GLOBAL );
89         return bundle;
90     }
91 }