mitreid-connect
クラス | 公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService クラス
org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService の継承関係図
Inheritance graph
org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService 連携図
Collaboration graph

クラス

class  SectorIdentifierLoader
 

公開メンバ関数

ClientDetailsEntity saveNewClient (ClientDetailsEntity client)
 
ClientDetailsEntity getClientById (Long id)
 
ClientDetailsEntity loadClientByClientId (String clientId) throws OAuth2Exception, InvalidClientException, IllegalArgumentException
 
void deleteClient (ClientDetailsEntity client) throws InvalidClientException
 
ClientDetailsEntity updateClient (ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException
 
Collection< ClientDetailsEntitygetAllClients ()
 
ClientDetailsEntity generateClientId (ClientDetailsEntity client)
 
ClientDetailsEntity generateClientSecret (ClientDetailsEntity client)
 

非公開メンバ関数

void ensureKeyConsistency (ClientDetailsEntity client)
 
void ensureNoReservedScopes (ClientDetailsEntity client)
 
void checkSectorIdentifierUri (ClientDetailsEntity client)
 
void ensureRefreshTokenConsistency (ClientDetailsEntity client)
 
void checkHeartMode (ClientDetailsEntity client)
 

非公開変数類

OAuth2ClientRepository clientRepository
 
OAuth2TokenRepository tokenRepository
 
ApprovedSiteService approvedSiteService
 
WhitelistedSiteService whitelistedSiteService
 
BlacklistedSiteService blacklistedSiteService
 
SystemScopeService scopeService
 
StatsService statsService
 
ResourceSetService resourceSetService
 
ConfigurationPropertiesBean config
 
LoadingCache< String, List< String > > sectorRedirects
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(DefaultOAuth2ClientDetailsEntityService.class)
 

詳解

関数詳解

◆ checkHeartMode()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.checkHeartMode ( ClientDetailsEntity  client)
inlineprivate

If HEART mode is enabled, make sure the client meets the requirements:

  • Only one of authorization_code, implicit, or client_credentials can be used at a time
  • A redirect_uri must be registered with either authorization_code or implicit
  • A key must be registered
  • A client secret must not be generated
  • authorization_code and client_credentials must use the private_key authorization method
    引数
    client
222  {
223  if (config.isHeartMode()) {
224  if (client.getGrantTypes().contains("authorization_code")) {
225  // make sure we don't have incompatible grant types
226  if (client.getGrantTypes().contains("implicit") || client.getGrantTypes().contains("client_credentials")) {
227  throw new IllegalArgumentException("[HEART mode] Incompatible grant types");
228  }
229 
230  // make sure we've got the right authentication method
231  if (client.getTokenEndpointAuthMethod() == null || !client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY)) {
232  throw new IllegalArgumentException("[HEART mode] Authorization code clients must use the private_key authentication method");
233  }
234 
235  // make sure we've got a redirect URI
236  if (client.getRedirectUris().isEmpty()) {
237  throw new IllegalArgumentException("[HEART mode] Authorization code clients must register at least one redirect URI");
238  }
239  }
240 
241  if (client.getGrantTypes().contains("implicit")) {
242  // make sure we don't have incompatible grant types
243  if (client.getGrantTypes().contains("authorization_code") || client.getGrantTypes().contains("client_credentials") || client.getGrantTypes().contains("refresh_token")) {
244  throw new IllegalArgumentException("[HEART mode] Incompatible grant types");
245  }
246 
247  // make sure we've got the right authentication method
248  if (client.getTokenEndpointAuthMethod() == null || !client.getTokenEndpointAuthMethod().equals(AuthMethod.NONE)) {
249  throw new IllegalArgumentException("[HEART mode] Implicit clients must use the none authentication method");
250  }
251 
252  // make sure we've got a redirect URI
253  if (client.getRedirectUris().isEmpty()) {
254  throw new IllegalArgumentException("[HEART mode] Implicit clients must register at least one redirect URI");
255  }
256  }
257 
258  if (client.getGrantTypes().contains("client_credentials")) {
259  // make sure we don't have incompatible grant types
260  if (client.getGrantTypes().contains("authorization_code") || client.getGrantTypes().contains("implicit") || client.getGrantTypes().contains("refresh_token")) {
261  throw new IllegalArgumentException("[HEART mode] Incompatible grant types");
262  }
263 
264  // make sure we've got the right authentication method
265  if (client.getTokenEndpointAuthMethod() == null || !client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY)) {
266  throw new IllegalArgumentException("[HEART mode] Client credentials clients must use the private_key authentication method");
267  }
268 
269  // make sure we've got a redirect URI
270  if (!client.getRedirectUris().isEmpty()) {
271  throw new IllegalArgumentException("[HEART mode] Client credentials clients must not register a redirect URI");
272  }
273 
274  }
275 
276  if (client.getGrantTypes().contains("password")) {
277  throw new IllegalArgumentException("[HEART mode] Password grant type is forbidden");
278  }
279 
280  // make sure we don't have a client secret
281  if (!Strings.isNullOrEmpty(client.getClientSecret())) {
282  throw new IllegalArgumentException("[HEART mode] Client secrets are not allowed");
283  }
284 
285  // make sure we've got a key registered
286  if (client.getJwks() == null && Strings.isNullOrEmpty(client.getJwksUri())) {
287  throw new IllegalArgumentException("[HEART mode] All clients must have a key registered");
288  }
289 
290  // make sure our redirect URIs each fit one of the allowed categories
291  if (client.getRedirectUris() != null && !client.getRedirectUris().isEmpty()) {
292  boolean localhost = false;
293  boolean remoteHttps = false;
294  boolean customScheme = false;
295  for (String uri : client.getRedirectUris()) {
296  UriComponents components = UriComponentsBuilder.fromUriString(uri).build();
297  if (components.getScheme() == null) {
298  // this is a very unknown redirect URI
299  customScheme = true;
300  } else if (components.getScheme().equals("http")) {
301  // http scheme, check for localhost
302  if (components.getHost().equals("localhost") || components.getHost().equals("127.0.0.1")) {
303  localhost = true;
304  } else {
305  throw new IllegalArgumentException("[HEART mode] Can't have an http redirect URI on non-local host");
306  }
307  } else if (components.getScheme().equals("https")) {
308  remoteHttps = true;
309  } else {
310  customScheme = true;
311  }
312  }
313 
314  // now we make sure the client has a URI in only one of each of the three categories
315  if (!((localhost ^ remoteHttps ^ customScheme)
316  && !(localhost && remoteHttps && customScheme))) {
317  throw new IllegalArgumentException("[HEART mode] Can't have more than one class of redirect URI");
318  }
319  }
320 
321  }
322  }
ConfigurationPropertiesBean config
Definition: DefaultOAuth2ClientDetailsEntityService.java:101
boolean isHeartMode()
Definition: ConfigurationPropertiesBean.java:250

◆ checkSectorIdentifierUri()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.checkSectorIdentifierUri ( ClientDetailsEntity  client)
inlineprivate

Load the sector identifier URI if it exists and check the redirect URIs against it

引数
client
182  {
183  if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) {
184  try {
185  List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri());
186 
187  if (client.getRegisteredRedirectUri() != null) {
188  for (String uri : client.getRegisteredRedirectUri()) {
189  if (!redirects.contains(uri)) {
190  throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects);
191  }
192  }
193  }
194 
195  } catch (UncheckedExecutionException | ExecutionException e) {
196  throw new IllegalArgumentException("Unable to load sector identifier URI " + client.getSectorIdentifierUri() + ": " + e.getMessage());
197  }
198  }
199  }
LoadingCache< String, List< String > > sectorRedirects
Definition: DefaultOAuth2ClientDetailsEntityService.java:104

◆ deleteClient()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.deleteClient ( ClientDetailsEntity  client) throws InvalidClientException
inline

Delete a client and all its associated tokens

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

356  {
357 
358  if (clientRepository.getById(client.getId()) == null) {
359  throw new InvalidClientException("Client with id " + client.getClientId() + " was not found");
360  }
361 
362  // clean out any tokens that this client had issued
364 
365  // clean out any approved sites for this client
367 
368  // clear out any whitelisted sites for this client
369  WhitelistedSite whitelistedSite = whitelistedSiteService.getByClientId(client.getClientId());
370  if (whitelistedSite != null) {
371  whitelistedSiteService.remove(whitelistedSite);
372  }
373 
374  // clear out resource sets registered for this client
375  Collection<ResourceSet> resourceSets = resourceSetService.getAllForClient(client);
376  for (ResourceSet rs : resourceSets) {
378  }
379 
380  // take care of the client itself
382 
384 
385  }
WhitelistedSiteService whitelistedSiteService
Definition: DefaultOAuth2ClientDetailsEntityService.java:86
void remove(WhitelistedSite whitelistedSite)
void clearTokensForClient(ClientDetailsEntity client)
void deleteClient(ClientDetailsEntity client)
ApprovedSiteService approvedSiteService
Definition: DefaultOAuth2ClientDetailsEntityService.java:83
ResourceSetService resourceSetService
Definition: DefaultOAuth2ClientDetailsEntityService.java:98
OAuth2TokenRepository tokenRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:80
WhitelistedSite getByClientId(String clientId)
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77
StatsService statsService
Definition: DefaultOAuth2ClientDetailsEntityService.java:95
Collection< ResourceSet > getAllForClient(ClientDetailsEntity client)
void clearApprovedSitesForClient(ClientDetails client)

◆ ensureKeyConsistency()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.ensureKeyConsistency ( ClientDetailsEntity  client)
inlineprivate

Make sure the client has only one type of key registered

引数
client
159  {
160  if (client.getJwksUri() != null && client.getJwks() != null) {
161  // a client can only have one key type or the other, not both
162  throw new IllegalArgumentException("A client cannot have both JWKS URI and JWKS value");
163  }
164  }

◆ ensureNoReservedScopes()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.ensureNoReservedScopes ( ClientDetailsEntity  client)
inlineprivate

Make sure the client doesn't request any system reserved scopes

169  {
170  // make sure a client doesn't get any special system scopes
171  Set<SystemScope> requestedScope = scopeService.fromStrings(client.getScope());
172 
173  requestedScope = scopeService.removeReservedScopes(requestedScope);
174 
175  client.setScope(scopeService.toStrings(requestedScope));
176  }
Set< SystemScope > removeReservedScopes(Set< SystemScope > scopes)
Set< SystemScope > fromStrings(Set< String > scope)
Set< String > toStrings(Set< SystemScope > scope)
SystemScopeService scopeService
Definition: DefaultOAuth2ClientDetailsEntityService.java:92

◆ ensureRefreshTokenConsistency()

void org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.ensureRefreshTokenConsistency ( ClientDetailsEntity  client)
inlineprivate

Make sure the client has the appropriate scope and grant type.

引数
client
205  {
206  if (client.getAuthorizedGrantTypes().contains("refresh_token")
207  || client.getScope().contains(SystemScopeService.OFFLINE_ACCESS)) {
208  client.getScope().add(SystemScopeService.OFFLINE_ACCESS);
209  client.getAuthorizedGrantTypes().add("refresh_token");
210  }
211  }

◆ generateClientId()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.generateClientId ( ClientDetailsEntity  client)
inline

Generates a clientId for the given client and sets it to the client's clientId field. Returns the client that was passed in, now with id set.

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

443  {
444  client.setClientId(UUID.randomUUID().toString());
445  return client;
446  }

◆ generateClientSecret()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.generateClientSecret ( ClientDetailsEntity  client)
inline

Generates a new clientSecret for the given client and sets it to the client's clientSecret field. Returns the client that was passed in, now with secret set.

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

452  {
453  if (config.isHeartMode()) {
454  logger.error("[HEART mode] Can't generate a client secret, skipping step; client won't be saved due to invalid configuration");
455  client.setClientSecret(null);
456  } else {
457  client.setClientSecret(Base64.encodeBase64URLSafeString(new BigInteger(512, new SecureRandom()).toByteArray()).replace("=", ""));
458  }
459  return client;
460  }
static final Logger logger
Definition: DefaultOAuth2ClientDetailsEntityService.java:74
ConfigurationPropertiesBean config
Definition: DefaultOAuth2ClientDetailsEntityService.java:101
boolean isHeartMode()
Definition: ConfigurationPropertiesBean.java:250

◆ getAllClients()

Collection<ClientDetailsEntity> org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.getAllClients ( )
inline

Get all clients in the system

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

435  {
437  }
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77
Collection< ClientDetailsEntity > getAllClients()

◆ getClientById()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.getClientById ( Long  id)
inline

Get the client by its internal ID

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

328  {
329  ClientDetailsEntity client = clientRepository.getById(id);
330 
331  return client;
332  }
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77

◆ loadClientByClientId()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.loadClientByClientId ( String  clientId) throws OAuth2Exception, InvalidClientException, IllegalArgumentException
inline

Get the client for the given ClientID

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

338  {
339  if (!Strings.isNullOrEmpty(clientId)) {
340  ClientDetailsEntity client = clientRepository.getClientByClientId(clientId);
341  if (client == null) {
342  throw new InvalidClientException("Client with id " + clientId + " was not found");
343  }
344  else {
345  return client;
346  }
347  }
348 
349  throw new IllegalArgumentException("Client id must not be empty!");
350  }
ClientDetailsEntity getClientByClientId(String clientId)
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77

◆ saveNewClient()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.saveNewClient ( ClientDetailsEntity  client)
inline

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

110  {
111  if (client.getId() != null) { // if it's not null, it's already been saved, this is an error
112  throw new IllegalArgumentException("Tried to save a new client with an existing ID: " + client.getId());
113  }
114 
115  if (client.getRegisteredRedirectUri() != null) {
116  for (String uri : client.getRegisteredRedirectUri()) {
118  throw new IllegalArgumentException("Client URI is blacklisted: " + uri);
119  }
120  }
121  }
122 
123  // assign a random clientid if it's empty
124  // NOTE: don't assign a random client secret without asking, since public clients have no secret
125  if (Strings.isNullOrEmpty(client.getClientId())) {
126  client = generateClientId(client);
127  }
128 
129  // make sure that clients with the "refresh_token" grant type have the "offline_access" scope, and vice versa
131 
132  // make sure we don't have both a JWKS and a JWKS URI
133  ensureKeyConsistency(client);
134 
135  // check consistency when using HEART mode
136  checkHeartMode(client);
137 
138  // timestamp this to right now
139  client.setCreatedAt(new Date());
140 
141 
142  // check the sector URI
143  checkSectorIdentifierUri(client);
144 
145 
146  ensureNoReservedScopes(client);
147 
148  ClientDetailsEntity c = clientRepository.saveClient(client);
149 
151 
152  return c;
153  }
BlacklistedSiteService blacklistedSiteService
Definition: DefaultOAuth2ClientDetailsEntityService.java:89
ClientDetailsEntity saveClient(ClientDetailsEntity client)
void ensureKeyConsistency(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:159
void ensureRefreshTokenConsistency(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:205
void checkHeartMode(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:222
void ensureNoReservedScopes(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:169
void checkSectorIdentifierUri(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:182
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77
StatsService statsService
Definition: DefaultOAuth2ClientDetailsEntityService.java:95
ClientDetailsEntity generateClientId(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:443

◆ updateClient()

ClientDetailsEntity org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.updateClient ( ClientDetailsEntity  oldClient,
ClientDetailsEntity  newClient 
) throws IllegalArgumentException
inline

Update the oldClient with information from the newClient. The id from oldClient is retained.

Checks to make sure the refresh grant type and the scopes are set appropriately.

Checks to make sure the redirect URIs aren't blacklisted.

Attempts to load the redirect URI (possibly cached) to check the sector identifier against the contents there.

org.mitre.oauth2.service.ClientDetailsEntityServiceを実装しています。

402  {
403  if (oldClient != null && newClient != null) {
404 
405  for (String uri : newClient.getRegisteredRedirectUri()) {
407  throw new IllegalArgumentException("Client URI is blacklisted: " + uri);
408  }
409  }
410 
411  // if the client is flagged to allow for refresh tokens, make sure it's got the right scope
413 
414  // make sure we don't have both a JWKS and a JWKS URI
415  ensureKeyConsistency(newClient);
416 
417  // check consistency when using HEART mode
418  checkHeartMode(newClient);
419 
420  // check the sector URI
421  checkSectorIdentifierUri(newClient);
422 
423  // make sure a client doesn't get any special system scopes
424  ensureNoReservedScopes(newClient);
425 
426  return clientRepository.updateClient(oldClient.getId(), newClient);
427  }
428  throw new IllegalArgumentException("Neither old client or new client can be null!");
429  }
BlacklistedSiteService blacklistedSiteService
Definition: DefaultOAuth2ClientDetailsEntityService.java:89
ClientDetailsEntity updateClient(Long id, ClientDetailsEntity client)
void ensureKeyConsistency(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:159
void ensureRefreshTokenConsistency(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:205
void checkHeartMode(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:222
void ensureNoReservedScopes(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:169
void checkSectorIdentifierUri(ClientDetailsEntity client)
Definition: DefaultOAuth2ClientDetailsEntityService.java:182
OAuth2ClientRepository clientRepository
Definition: DefaultOAuth2ClientDetailsEntityService.java:77

メンバ詳解

◆ approvedSiteService

ApprovedSiteService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.approvedSiteService
private

◆ blacklistedSiteService

BlacklistedSiteService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.blacklistedSiteService
private

◆ clientRepository

OAuth2ClientRepository org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.clientRepository
private

◆ config

ConfigurationPropertiesBean org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.config
private

◆ logger

final Logger org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.logger = LoggerFactory.getLogger(DefaultOAuth2ClientDetailsEntityService.class)
staticprivate

Logger for this class

◆ resourceSetService

ResourceSetService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.resourceSetService
private

◆ scopeService

SystemScopeService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.scopeService
private

◆ sectorRedirects

LoadingCache<String, List<String> > org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.sectorRedirects
private
初期値:
= CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.HOURS)
.maximumSize(100)
.build(new SectorIdentifierLoader(HttpClientBuilder.create().useSystemProperties().build()))

◆ statsService

StatsService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.statsService
private

◆ tokenRepository

OAuth2TokenRepository org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.tokenRepository
private

◆ whitelistedSiteService

WhitelistedSiteService org.mitre.oauth2.service.impl.DefaultOAuth2ClientDetailsEntityService.whitelistedSiteService
private

このクラス詳解は次のファイルから抽出されました: