ISSUE: Some changes to Authorization
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / authorization / IResourceAuthorization.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.authorization;
11
12 import java.util.List;
13 import java.util.Set;
14
15 import org.opendaylight.controller.sal.utils.Status;
16
17 /**
18  * Interface for applications which maintain an authorization
19  * database for their resources. Respective application web bundle
20  * and User Manager make use of this interface to retrieve
21  * authorization information at user or and role level
22  */
23 public interface IResourceAuthorization {
24
25     /**
26      * Create a Role name for the application
27      *
28      * @param role      the role name
29      * @param userLevel the user level in the application context
30          * @return the status of the request
31          */
32     public Status createRole(String role, AppRoleLevel userLevel);
33
34     /**
35      * Remove a Role
36      * 
37      * @param role the role name
38      * @return the status of the request
39      */
40     public Status removeRole(String role);
41     
42     /**
43      * Return the list of roles configured for the application
44      *
45      * @return the list of roles
46      */
47     public List<String> getRoles();
48
49     /**
50      * Returns the application role level for the specified role
51      * If the role is not known to this application <code>NOUSER<code>
52      * will be returned as specified in {@link AppRoleLevel}
53      *
54      * @param roleName the role name to query
55      * @return the application level of the given role in the application context as specified by {@link AppRoleLevel}
56      *                  if the role is not part of this application's roles, <code>NOUSER<code> is returned
57      */
58     public AppRoleLevel getApplicationRoleLevel(String roleName);
59
60     /**
61      * Returns whether the specified role is part of this application's roles
62      *
63      * @param roleName the role name to test
64      * @return  true if the role belongs to this application, false otherwise
65      */
66     public boolean isApplicationRole(String roleName);
67
68     /**
69      * Create a resource group for application
70      *
71      * @param groupName the name for the resource group
72      * @param resources the list of resources for the group
73      * @return the status of the request
74      */
75     public Status createResourceGroup(String groupName, List<Object> resources);
76
77     /**
78      * Removes a resource group
79      *
80      * @param groupName the name of the group
81      * @return the status of the request
82      */
83     public Status removeResourceGroup(String groupName);
84
85     /**
86      * Returns the list of resource groups configured for the application
87      *
88      * @return the list of resource group names
89      */
90     public List<String> getResourceGroups();
91
92     /**
93      * Assign a resource group to a user group (role)
94      *
95      * @param groupName the object expressing the resource group name and the access privilege
96      * @param role the user group (role) name
97      * @return the status of the request
98      */
99     public Status assignResourceGroupToRole(String groupName,
100             Privilege privilege, String role);
101
102     /**
103      * Unassign the passed resource group from the specified role
104      * 
105      * @param group
106      * @param role
107      * @return the status of the request
108      */
109     public Status unassignResourceGroupFromRole(String group, String role);
110     
111     /**
112      * Returns the list of resource groups the given Role is authorized to use
113      * The returning object expresses the resource group name and the access
114      * its privilege for the given user role
115      *
116      * @param role
117      * @return list of resources
118      */
119     public List<ResourceGroup> getAuthorizedGroups(String role);
120
121     /**
122      * Returns the list of resources contained in the given resource group
123      *
124      * @param groupName the resource group name
125      * @return
126      */
127     public List<Object> getResources(String groupName);
128
129     /**
130      * Returns the list of authorized resources for the given role
131      * For each resource only the highest privilege occurrence is returned
132      * @param role
133      * @return the list of Resource
134      */
135     public List<Resource> getAuthorizedResources(String role);
136
137     /*
138      * Per user name API
139      */
140     /**
141      * Returns the controller user role level the passed user name is associated with
142      *
143      * @param userName the user name
144      * @return the user role level as specified in {@link UserLevel}
145      */
146     public UserLevel getUserLevel(String userName);
147
148     /**
149      * Returns the application context user role level the passed user name is associated with
150      *
151      * @param userName the user name
152      * @return the user role level as specified in {@link AppRoleLevel}
153      */
154     public AppRoleLevel getUserApplicationLevel(String userName);
155
156     /**
157      * Returns the list of resources (resource + privilege) associated
158      * with the passed user name for this application context
159      * For each resource only the highest privilege occurrence is returned
160      *
161      * @param userName the user name
162      * @return the list of resources associated with this user name in this application context
163      */
164     public Set<Resource> getAllResourcesforUser(String userName);
165
166     /**
167      * Returns the highest privilege that the user has on the specified
168      * resource in this application context
169      *
170      * @param userName
171      * @param resource
172      * @return the privilege the user has on the passed resource
173      */
174     public Privilege getResourcePrivilege(String userName, Object resource);
175
176 }