1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21
22 package org.opencastproject.security.api;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Iterator;
27 import java.util.List;
28
29 /**
30 * A marker interface for federation of all {@link UserProvider}s.
31 */
32 public interface UserDirectoryService {
33
34 /**
35 * Gets all known users.
36 *
37 * @return the users
38 */
39 Iterator<User> getUsers();
40
41 /**
42 * Loads a user by username, or returns null if this user is not known to the thread's current organization.
43 *
44 * @param userName
45 * the username
46 * @return the user
47 * @throws IllegalStateException
48 * if no organization is set for the current thread
49 */
50 User loadUser(String userName);
51
52 /**
53 * Loads multiple users by a list of user names.
54 *
55 * @param userNames
56 * the user names to look for
57 * @return the users
58 * @throws IllegalStateException
59 * if no organization is set for the current thread
60 */
61 default Iterator<User> loadUsers(Collection<String> userNames) {
62 List<User> result = new ArrayList<>(userNames.size());
63 for (String userName : userNames) {
64 result.add(loadUser(userName));
65 }
66 return result.iterator();
67 }
68
69 /**
70 * Return the found user's as an iterator.
71 *
72 * @param query
73 * the query. Use the wildcards "_" to match any single character and "%" to match an arbitrary number of
74 * characters (including zero characters).
75 * @param offset
76 * the offset
77 * @param limit
78 * the limit. 0 means no limit
79 * @return an iterator of user's
80 * @throws IllegalArgumentException
81 * if the query is <code>null</code>
82 */
83 Iterator<User> findUsers(String query, int offset, int limit);
84
85 /**
86 * Returns the total number of users
87 *
88 * @return the count of users
89 */
90 long countUsers();
91
92 /**
93 * Discards any cached value for given user name.
94 *
95 * @param userName
96 * the user name
97 */
98 void invalidate(String userName);
99
100 }