Initial opendaylight infrastructure commit!!
[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 /**
16  * Interface for applications which maintain an authorization
17  * database for their resources. Respective application web bundle
18  * and User Manager make use of this interface to retrieve
19  * authorization information at user or and role level
20  */
21 public interface IResourceAuthorization {
22
23     /**
24      * Create a Role name for the application
25      *
26      * @param role      the role name
27      * @param userLevel the user level in the application context
28      */
29     public void createRole(String role, AppRoleLevel userLevel);
30
31     /**
32      * Return the list of roles configured for the application
33      *
34      * @return the list of roles
35      */
36     public List<String> getRoles();
37
38     /**
39      * Returns the application role level for the specified role
40      * If the role is not known to this application <code>NOUSER<code>
41      * will be returned as specified in {@link AppRoleLevel}
42      *
43      * @param roleName the role name to query
44      * @return the application level of the given role in the application context as specified by {@link AppRoleLevel}
45      *                  if the role is not part of this application's roles, <code>NOUSER<code> is returned
46      */
47     public AppRoleLevel getApplicationRoleLevel(String roleName);
48
49     /**
50      * Returns whether the specified role is part of this application's roles
51      *
52      * @param roleName the role name to test
53      * @return  true if the role belongs to this application, false otherwise
54      */
55     public boolean isApplicationRole(String roleName);
56
57     /**
58      * Create a resource group for application
59      *
60      * @param groupName the name for the resource group
61      * @param resources the list of resources for the group
62      */
63     public void createResourceGroup(String groupName, List<Object> resources);
64
65     /**
66      * Removes a resource group
67      *
68      * @param groupName the name of the group
69      */
70     public void removeResourceGroup(String groupName);
71
72     /**
73      * Returns the list of resource groups configured for the application
74      *
75      * @return the list of resource group names
76      */
77     public List<String> getResourceGroups();
78
79     /**
80      * Assign a resource group to a user group (role)
81      *
82      * @param groupName the object expressing the resource group name and the access privilege
83      * @param role the user group (role) name
84      */
85     public void assignResourceGroupToRole(String groupName,
86             Privilege privilege, String role);
87
88     /**
89      * Returns the list of resource groups the given Role is authorized to use
90      * The returning object expresses the resource group name and the access
91      * its privilege for the given user role
92      *
93      * @param role
94      * @return list of resources
95      */
96     public List<ResourceGroup> getAuthorizedGroups(String role);
97
98     /**
99      * Returns the list of resources contained in the given resource group
100      *
101      * @param groupName the resource group name
102      * @return
103      */
104     public List<Object> getResources(String groupName);
105
106     /**
107      * Returns the list of authorized resources for the given role
108      * For each resource only the highest privilege occurrence is returned
109      * @param role
110      * @return the list of Resource
111      */
112     public List<Resource> getAuthorizedResources(String role);
113
114     /*
115      * Per user name API
116      */
117     /**
118      * Returns the controller user role level the passed user name is associated with
119      *
120      * @param userName the user name
121      * @return the user role level as specified in {@link UserLevel}
122      */
123     public UserLevel getUserLevel(String userName);
124
125     /**
126      * Returns the application context user role level the passed user name is associated with
127      *
128      * @param userName the user name
129      * @return the user role level as specified in {@link AppRoleLevel}
130      */
131     public AppRoleLevel getUserApplicationLevel(String userName);
132
133     /**
134      * Returns the list of resources (resource + privilege) associated
135      * with the passed user name for this application context
136      * For each resource only the highest privilege occurrence is returned
137      *
138      * @param userName the user name
139      * @return the list of resources associated with this user name in this application context
140      */
141     public Set<Resource> getAllResourcesforUser(String userName);
142
143     /**
144      * Returns the highest privilege that the user has on the specified
145      * resource in this application context
146      *
147      * @param userName
148      * @param resource
149      * @return
150      */
151     public Privilege getResourcePrivilege(String userName, Object resource);
152
153 }