1 package com.randomnoun.common.security;
2
3 /* (c) 2013 randomnoun. All Rights Reserved. This work is licensed under a
4 * BSD Simplified License. (http://www.randomnoun.com/bsd-simplified.html)
5 */
6
7 import java.io.IOException;
8 import java.util.*;
9
10 import com.randomnoun.common.security.User;
11
12 /** Security loader object.
13 *
14 * <p>An instance of this class is responsible for serialising/deserialising
15 * security information to a persistent data store. The SecurityContext object
16 * will invoke methods in this class as appropriate. Initialisation properties
17 * can be passed to the SecurityLoader using a properties map in the SecurityContext
18 * constructor.
19 *
20 *
21 * @author knoxg
22 */
23 public interface SecurityLoader
24 {
25 /**
26 * Initialise this security loader. This method will be invoked by the SecurityContext
27 * object on initialisation
28 *
29 * @param properties Initialisation properties for this loader.
30 */
31 public void initialise(Map<String, Object> properties);
32
33
34 // the loadAll() methods here were for the security editor UI, which I imagine
35 // I'm not going to implement again in the next few years. Could just remove it.
36
37 /**
38 * Return a structured list of application specific Permission objects which is used to
39 * preload the SecurityContext rolePermission cache. Each permission returned must be a
40 * role-based Permission.
41 */
42 public List<Permission> loadAllRolePermissions()
43 throws IOException;
44
45 /**
46 * Return List of Permission objects associated with a particular role
47 */
48 public List<Permission> loadRolePermissions(String role)
49 throws IOException;
50
51
52 /**
53 * Return a list of Permission objects
54 * associated with the roles possessed by a particular user.
55 *
56 * Equivalent to appending the results of calling
57 * {@link #loadRolePermissions(String)} for each role that a user
58 * is in.
59 */
60 public List<Permission> loadUserRolePermissions(User user) throws IOException;
61
62
63 /**
64 * Returns the list of permissions assigned to this user.
65 */
66 public List<Permission> loadUserPermissions(User user) throws IOException;
67
68 /**
69 * Returns the list of roles assigned to this user.
70 */
71 public List<String> loadUserRoles(User user) throws IOException;
72
73
74 /** Load a user. Will not load any role or permission data for that user.
75 *
76 * <p>Will probably throw an IOException if the user doesn't exist.
77 *
78 * @return a User object.
79 */
80 public User loadUser(long userId) throws IOException;
81
82 /**
83 * Return a list of User objects representing all users contained in this
84 * security context. Permission information relating to that user is not
85 * populated unless the 'populatePermission' parameter is set to true.
86 *
87 * <p>The information returned by this function may be cached, depending
88 * on the initialisation properties of the security context.
89 *
90 * @return A List of Users.
91 */
92 public List<User> loadAllUsers()
93 throws IOException;
94
95 /**
96 * Return a List of all resources in this security context, identified
97 * by String.
98 *
99 * <p>The information returned by this function may be cached, depending
100 * on the initialisation properties of the security context.
101 *
102 * @return A List of resources.
103 */
104 public List<String> loadAllResources()
105 throws IOException;
106
107 /**
108 * Return a List of all activities in this security context for a given
109 * resource, identified by String.
110 *
111 * <p>The information returned by this function may be cached, depending
112 * on the initialisation properties of the security context.
113 *
114 * @param resourceName The resource we wish to retrieve activities for
115 *
116 * @return A List of activities.
117 */
118 public List<String> loadAllActivities(String resourceName)
119 throws IOException;
120
121 /**
122 * Return a List of all roles in this security context, identified
123 * by String.
124 *
125 * <p>The information returned by this function may be cached, depending
126 * on the initialisation properties of the security context.
127 *
128 * @return A List of Roles, just the name.
129 */
130 public List<String> loadAllRoles()
131 throws IOException;
132
133 /**
134 * Return a List of all permissions in this security context, as Permission objects.
135 * (User, role and criteria fields will be left blank in these objects).
136 *
137 * <p>The information returned by this function may be cached, depending
138 * on the initialisation properties of the security context.
139 *
140 * @return A List of Permission objects available to this application
141 */
142 public List<Permission> loadAllPermissions()
143 throws IOException;
144
145
146
147 /**
148 * Return a List of all roles in this security context. Each role is returned
149 * as a Map containing (by default) the keys roleId, roleName, description
150 *
151 * @return A List of Roles, in Map format.
152 */
153 public List<Map<String, Object>> loadAllRoleDetails()
154 throws IOException;
155
156 /**
157 * Return a List of all users in this security context. Each user is returned
158 * as a Map containing (by default) the keys userId, name
159 *
160 * @return A List of Users, in Map format.
161 */
162 public List<Map<String, Object>> loadAllUserDetails()
163 throws IOException;
164
165 /** Informs any delegate security contexts to reset themselves. */
166 public void resetSecurityContext() throws IOException;
167
168 /** Persists the role and permission information recorded for this user to
169 * the database. Existing role and permission information in the database will be
170 * removed.
171 *
172 * @param user The user to persist
173 * @param permissions The permissions for this user
174 */
175 public void saveUserRolesAndPermissions(User user, List<String> roles, List<Permission> userPermissions)
176 throws IOException;
177
178 /** Persists the permission information for this role to
179 * the database. Existing permission information in the database will be
180 * removed.
181 *
182 * @param user The role to persist
183 * @param permissions The permissions for this role
184 */
185 public void saveRolePermissions(String role, List<Permission> rolePermissions)
186 throws IOException;
187
188 }