forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClientLookupProvider.java
85 lines (76 loc) · 3.93 KB
/
ClientLookupProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.storage.client;
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientScopeModel;
import org.keycloak.models.RealmModel;
import java.util.Map;
import java.util.stream.Stream;
/**
* Abstraction interface for lookoup of clients by id and clientId. These methods required for participating in login flows.
*
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface ClientLookupProvider {
/**
* Exact search for a client by its internal ID.
* @param realm Realm to limit the search.
* @param id Internal ID
* @return Model of the client, or {@code null} if no client is found.
*/
ClientModel getClientById(RealmModel realm, String id);
/**
* Exact search for a client by its public client identifier.
* @param realm Realm to limit the search for clients.
* @param clientId String that identifies the client to the external parties.
* Maps to {@code client_id} in OIDC or {@code entityID} in SAML.
* @return Model of the client, or {@code null} if no client is found.
*/
ClientModel getClientByClientId(RealmModel realm, String clientId);
/**
* Case-insensitive search for clients that contain the given string in their public client identifier.
* @param realm Realm to limit the search for clients.
* @param clientId Searched substring of the public client
* identifier ({@code client_id} in OIDC or {@code entityID} in SAML.)
* @param firstResult First result to return. Ignored if negative or {@code null}.
* @param maxResults Maximum number of results to return. Ignored if negative or {@code null}.
* @return Stream of ClientModel or an empty stream if no client is found. Never returns {@code null}.
*/
Stream<ClientModel> searchClientsByClientIdStream(RealmModel realm, String clientId, Integer firstResult, Integer maxResults);
Stream<ClientModel> searchClientsByAttributes(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults);
default Stream<ClientModel> searchClientsByAuthenticationFlowBindingOverrides(RealmModel realm, Map<String, String> overrides, Integer firstResult, Integer maxResults) {
Stream<ClientModel> clients = searchClientsByAttributes(realm, Map.of(), null, null)
.filter(client -> overrides.entrySet().stream().allMatch(override -> override.getValue().equals(client.getAuthenticationFlowBindingOverrides().get(override.getKey()))));
if (firstResult != null && firstResult >= 0) {
clients = clients.skip(firstResult);
}
if (maxResults != null && maxResults >= 0 ) {
clients = clients.limit(maxResults);
}
return clients;
}
/**
* Return all default scopes (if {@code defaultScope} is {@code true}) or all optional scopes (if {@code defaultScope} is {@code false}) linked with the client
*
* @param realm Realm
* @param client Client
* @param defaultScopes if true default scopes, if false optional scopes, are returned
* @return map where key is the name of the clientScope, value is particular clientScope. Returns empty map if no scopes linked (never returns null).
*/
Map<String, ClientScopeModel> getClientScopes(RealmModel realm, ClientModel client, boolean defaultScopes);
}