mitreid-connect
公開メンバ関数 | 静的公開変数類 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint クラス
org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint 連携図
Collaboration graph

公開メンバ関数

String registerNewProtectedResource (@RequestBody String jsonString, Model m)
 
String readResourceConfiguration (@PathVariable("id") String clientId, Model m, OAuth2Authentication auth)
 
String updateProtectedResource (@PathVariable("id") String clientId, @RequestBody String jsonString, Model m, OAuth2Authentication auth)
 
String deleteResource (@PathVariable("id") String clientId, Model m, OAuth2Authentication auth)
 

静的公開変数類

static final String URL = "resource"
 

非公開メンバ関数

ClientDetailsEntity validateScopes (ClientDetailsEntity newClient) throws ValidationException
 
ClientDetailsEntity validateAuth (ClientDetailsEntity newClient) throws ValidationException
 
OAuth2AccessTokenEntity fetchValidRegistrationToken (OAuth2Authentication auth, ClientDetailsEntity client)
 

非公開変数類

ClientDetailsEntityService clientService
 
OAuth2TokenEntityService tokenService
 
SystemScopeService scopeService
 
ConfigurationPropertiesBean config
 
OIDCTokenService connectTokenService
 

静的非公開変数類

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

詳解

関数詳解

◆ deleteResource()

String org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.deleteResource ( @PathVariable("id") String  clientId,
Model  m,
OAuth2Authentication  auth 
)
inline

Delete the indicated client from the system.

引数
clientId
m
auth
戻り値
392  {
393 
394  ClientDetailsEntity client = clientService.loadClientByClientId(clientId);
395 
396  if (client != null && client.getClientId().equals(auth.getOAuth2Request().getClientId())) {
397 
398  clientService.deleteClient(client);
399 
400  m.addAttribute(HttpCodeView.CODE, HttpStatus.NO_CONTENT); // http 204
401 
402  return HttpCodeView.VIEWNAME;
403  } else {
404  // client mismatch
405  logger.error("readClientConfiguration failed, client ID mismatch: "
406  + clientId + " and " + auth.getOAuth2Request().getClientId() + " do not match.");
407  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN); // http 403
408 
409  return HttpCodeView.VIEWNAME;
410  }
411  }
ClientDetailsEntityService clientService
Definition: ProtectedResourceRegistrationEndpoint.java:68
static final Logger logger
Definition: ProtectedResourceRegistrationEndpoint.java:85
void deleteClient(ClientDetailsEntity client)
ClientDetailsEntity loadClientByClientId(String clientId)

◆ fetchValidRegistrationToken()

OAuth2AccessTokenEntity org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.fetchValidRegistrationToken ( OAuth2Authentication  auth,
ClientDetailsEntity  client 
)
inlineprivate
440  {
441 
442  OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails();
443  OAuth2AccessTokenEntity token = tokenService.readAccessToken(details.getTokenValue());
444 
445  if (config.getRegTokenLifeTime() != null) {
446 
447  try {
448  // Re-issue the token if it has been issued before [currentTime - validity]
449  Date validToDate = new Date(System.currentTimeMillis() - config.getRegTokenLifeTime() * 1000);
450  if(token.getJwt().getJWTClaimsSet().getIssueTime().before(validToDate)) {
451  logger.info("Rotating the registration access token for " + client.getClientId());
453  OAuth2AccessTokenEntity newToken = connectTokenService.createResourceAccessToken(client);
454  tokenService.saveAccessToken(newToken);
455  return newToken;
456  } else {
457  // it's not expired, keep going
458  return token;
459  }
460  } catch (ParseException e) {
461  logger.error("Couldn't parse a known-valid token?", e);
462  return token;
463  }
464  } else {
465  // tokens don't expire, just return it
466  return token;
467  }
468  }
OAuth2TokenEntityService tokenService
Definition: ProtectedResourceRegistrationEndpoint.java:71
ConfigurationPropertiesBean config
Definition: ProtectedResourceRegistrationEndpoint.java:77
OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity accessToken)
static final Logger logger
Definition: ProtectedResourceRegistrationEndpoint.java:85
Long getRegTokenLifeTime()
Definition: ConfigurationPropertiesBean.java:153
OAuth2AccessTokenEntity createResourceAccessToken(ClientDetailsEntity client)
OIDCTokenService connectTokenService
Definition: ProtectedResourceRegistrationEndpoint.java:80
OAuth2AccessTokenEntity readAccessToken(String accessTokenValue)
void revokeAccessToken(OAuth2AccessTokenEntity accessToken)

◆ readResourceConfiguration()

String org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.readResourceConfiguration ( @PathVariable("id") String  clientId,
Model  m,
OAuth2Authentication  auth 
)
inline

Get the meta information for a client.

引数
clientId
m
auth
戻り値
229  {
230 
231  ClientDetailsEntity client = clientService.loadClientByClientId(clientId);
232 
233  if (client != null && client.getClientId().equals(auth.getOAuth2Request().getClientId())) {
234 
235 
236 
237  try {
238  // possibly update the token
239  OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, client);
240 
241  RegisteredClient registered = new RegisteredClient(client, token.getValue(), config.getIssuer() + "resource/" + UriUtils.encodePathSegment(client.getClientId(), "UTF-8"));
242 
243  // send it all out to the view
244  m.addAttribute("client", registered);
245  m.addAttribute(HttpCodeView.CODE, HttpStatus.OK); // http 200
246 
247  return ClientInformationResponseView.VIEWNAME;
248  } catch (UnsupportedEncodingException e) {
249  logger.error("Unsupported encoding", e);
250  m.addAttribute(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR);
251  return HttpCodeView.VIEWNAME;
252  }
253  } else {
254  // client mismatch
255  logger.error("readResourceConfiguration failed, client ID mismatch: "
256  + clientId + " and " + auth.getOAuth2Request().getClientId() + " do not match.");
257  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN); // http 403
258 
259  return HttpCodeView.VIEWNAME;
260  }
261  }
ConfigurationPropertiesBean config
Definition: ProtectedResourceRegistrationEndpoint.java:77
OAuth2AccessTokenEntity fetchValidRegistrationToken(OAuth2Authentication auth, ClientDetailsEntity client)
Definition: ProtectedResourceRegistrationEndpoint.java:440
ClientDetailsEntityService clientService
Definition: ProtectedResourceRegistrationEndpoint.java:68
static final Logger logger
Definition: ProtectedResourceRegistrationEndpoint.java:85
ClientDetailsEntity loadClientByClientId(String clientId)
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100

◆ registerNewProtectedResource()

String org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.registerNewProtectedResource ( @RequestBody String  jsonString,
Model  m 
)
inline

Create a new Client, issue a client ID, and create a registration access token.

引数
jsonString
m
p
戻り値
95  {
96 
97  ClientDetailsEntity newClient = null;
98  try {
99  newClient = ClientDetailsEntityJsonProcessor.parse(jsonString);
100  } catch (JsonSyntaxException e) {
101  // bad parse
102  // didn't parse, this is a bad request
103  logger.error("registerNewProtectedResource failed; submitted JSON is malformed");
104  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); // http 400
105  return HttpCodeView.VIEWNAME;
106  }
107 
108  if (newClient != null) {
109  // it parsed!
110 
111  //
112  // Now do some post-processing consistency checks on it
113  //
114 
115  // clear out any spurious id/secret (clients don't get to pick)
116  newClient.setClientId(null);
117  newClient.setClientSecret(null);
118 
119  // do validation on the fields
120  try {
121  newClient = validateScopes(newClient);
122  newClient = validateAuth(newClient);
123  } catch (ValidationException ve) {
124  // validation failed, return an error
125  m.addAttribute(JsonErrorView.ERROR, ve.getError());
126  m.addAttribute(JsonErrorView.ERROR_MESSAGE, ve.getErrorDescription());
127  m.addAttribute(HttpCodeView.CODE, ve.getStatus());
128  return JsonErrorView.VIEWNAME;
129  }
130 
131 
132  // no grant types are allowed
133  newClient.setGrantTypes(new HashSet<String>());
134  newClient.setResponseTypes(new HashSet<String>());
135  newClient.setRedirectUris(new HashSet<String>());
136 
137  // don't issue tokens to this client
138  newClient.setAccessTokenValiditySeconds(0);
139  newClient.setIdTokenValiditySeconds(0);
140  newClient.setRefreshTokenValiditySeconds(0);
141 
142  // clear out unused fields
143  newClient.setDefaultACRvalues(new HashSet<String>());
144  newClient.setDefaultMaxAge(null);
145  newClient.setIdTokenEncryptedResponseAlg(null);
146  newClient.setIdTokenEncryptedResponseEnc(null);
147  newClient.setIdTokenSignedResponseAlg(null);
148  newClient.setInitiateLoginUri(null);
149  newClient.setPostLogoutRedirectUris(null);
150  newClient.setRequestObjectSigningAlg(null);
151  newClient.setRequireAuthTime(null);
152  newClient.setReuseRefreshToken(false);
153  newClient.setSectorIdentifierUri(null);
154  newClient.setSubjectType(null);
155  newClient.setUserInfoEncryptedResponseAlg(null);
156  newClient.setUserInfoEncryptedResponseEnc(null);
157  newClient.setUserInfoSignedResponseAlg(null);
158 
159  // this client has been dynamically registered (obviously)
160  newClient.setDynamicallyRegistered(true);
161 
162  // this client has access to the introspection endpoint
163  newClient.setAllowIntrospection(true);
164 
165  // now save it
166  try {
167  ClientDetailsEntity savedClient = clientService.saveNewClient(newClient);
168 
169  // generate the registration access token
170  OAuth2AccessTokenEntity token = connectTokenService.createResourceAccessToken(savedClient);
172 
173  // send it all out to the view
174 
175  RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "resource/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));
176  m.addAttribute("client", registered);
177  m.addAttribute(HttpCodeView.CODE, HttpStatus.CREATED); // http 201
178 
179  return ClientInformationResponseView.VIEWNAME;
180  } catch (UnsupportedEncodingException e) {
181  logger.error("Unsupported encoding", e);
182  m.addAttribute(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR);
183  return HttpCodeView.VIEWNAME;
184  } catch (IllegalArgumentException e) {
185  logger.error("Couldn't save client", e);
186 
187  m.addAttribute(JsonErrorView.ERROR, "invalid_client_metadata");
188  m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client due to invalid or inconsistent metadata.");
189  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); // http 400
190 
191  return JsonErrorView.VIEWNAME;
192  }
193  } else {
194  // didn't parse, this is a bad request
195  logger.error("registerNewClient failed; submitted JSON is malformed");
196  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); // http 400
197 
198  return HttpCodeView.VIEWNAME;
199  }
200 
201  }
OAuth2TokenEntityService tokenService
Definition: ProtectedResourceRegistrationEndpoint.java:71
ConfigurationPropertiesBean config
Definition: ProtectedResourceRegistrationEndpoint.java:77
OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity accessToken)
ClientDetailsEntity saveNewClient(ClientDetailsEntity client)
ClientDetailsEntity validateAuth(ClientDetailsEntity newClient)
Definition: ProtectedResourceRegistrationEndpoint.java:413
ClientDetailsEntityService clientService
Definition: ProtectedResourceRegistrationEndpoint.java:68
static final Logger logger
Definition: ProtectedResourceRegistrationEndpoint.java:85
OAuth2AccessTokenEntity createResourceAccessToken(ClientDetailsEntity client)
OIDCTokenService connectTokenService
Definition: ProtectedResourceRegistrationEndpoint.java:80
ClientDetailsEntity validateScopes(ClientDetailsEntity newClient)
Definition: ProtectedResourceRegistrationEndpoint.java:203
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100

◆ updateProtectedResource()

String org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.updateProtectedResource ( @PathVariable("id") String  clientId,
@RequestBody String  jsonString,
Model  m,
OAuth2Authentication  auth 
)
inline

Update the metainformation for a given client.

引数
clientId
jsonString
m
auth
戻り値
273  {
274 
275 
276  ClientDetailsEntity newClient = null;
277  try {
278  newClient = ClientDetailsEntityJsonProcessor.parse(jsonString);
279  } catch (JsonSyntaxException e) {
280  // bad parse
281  // didn't parse, this is a bad request
282  logger.error("updateProtectedResource failed; submitted JSON is malformed");
283  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); // http 400
284  return HttpCodeView.VIEWNAME;
285  }
286 
287  ClientDetailsEntity oldClient = clientService.loadClientByClientId(clientId);
288 
289  if (newClient != null && oldClient != null // we have an existing client and the new one parsed
290  && oldClient.getClientId().equals(auth.getOAuth2Request().getClientId()) // the client passed in the URI matches the one in the auth
291  && oldClient.getClientId().equals(newClient.getClientId()) // the client passed in the body matches the one in the URI
292  ) {
293 
294  // a client can't ask to update its own client secret to any particular value
295  newClient.setClientSecret(oldClient.getClientSecret());
296 
297  newClient.setCreatedAt(oldClient.getCreatedAt());
298 
299  // no grant types are allowed
300  newClient.setGrantTypes(new HashSet<String>());
301  newClient.setResponseTypes(new HashSet<String>());
302  newClient.setRedirectUris(new HashSet<String>());
303 
304  // don't issue tokens to this client
305  newClient.setAccessTokenValiditySeconds(0);
306  newClient.setIdTokenValiditySeconds(0);
307  newClient.setRefreshTokenValiditySeconds(0);
308 
309  // clear out unused fields
310  newClient.setDefaultACRvalues(new HashSet<String>());
311  newClient.setDefaultMaxAge(null);
312  newClient.setIdTokenEncryptedResponseAlg(null);
313  newClient.setIdTokenEncryptedResponseEnc(null);
314  newClient.setIdTokenSignedResponseAlg(null);
315  newClient.setInitiateLoginUri(null);
316  newClient.setPostLogoutRedirectUris(null);
317  newClient.setRequestObjectSigningAlg(null);
318  newClient.setRequireAuthTime(null);
319  newClient.setReuseRefreshToken(false);
320  newClient.setSectorIdentifierUri(null);
321  newClient.setSubjectType(null);
322  newClient.setUserInfoEncryptedResponseAlg(null);
323  newClient.setUserInfoEncryptedResponseEnc(null);
324  newClient.setUserInfoSignedResponseAlg(null);
325 
326  // this client has been dynamically registered (obviously)
327  newClient.setDynamicallyRegistered(true);
328 
329  // this client has access to the introspection endpoint
330  newClient.setAllowIntrospection(true);
331 
332  // do validation on the fields
333  try {
334  newClient = validateScopes(newClient);
335  newClient = validateAuth(newClient);
336  } catch (ValidationException ve) {
337  // validation failed, return an error
338  m.addAttribute(JsonErrorView.ERROR, ve.getError());
339  m.addAttribute(JsonErrorView.ERROR_MESSAGE, ve.getErrorDescription());
340  m.addAttribute(HttpCodeView.CODE, ve.getStatus());
341  return JsonErrorView.VIEWNAME;
342  }
343 
344 
345  try {
346  // save the client
347  ClientDetailsEntity savedClient = clientService.updateClient(oldClient, newClient);
348 
349  // possibly update the token
350  OAuth2AccessTokenEntity token = fetchValidRegistrationToken(auth, savedClient);
351 
352  RegisteredClient registered = new RegisteredClient(savedClient, token.getValue(), config.getIssuer() + "resource/" + UriUtils.encodePathSegment(savedClient.getClientId(), "UTF-8"));
353 
354  // send it all out to the view
355  m.addAttribute("client", registered);
356  m.addAttribute(HttpCodeView.CODE, HttpStatus.OK); // http 200
357 
358  return ClientInformationResponseView.VIEWNAME;
359  } catch (UnsupportedEncodingException e) {
360  logger.error("Unsupported encoding", e);
361  m.addAttribute(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR);
362  return HttpCodeView.VIEWNAME;
363  } catch (IllegalArgumentException e) {
364  logger.error("Couldn't save client", e);
365 
366  m.addAttribute(JsonErrorView.ERROR, "invalid_client_metadata");
367  m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Unable to save client due to invalid or inconsistent metadata.");
368  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); // http 400
369 
370  return JsonErrorView.VIEWNAME;
371  }
372  } else {
373  // client mismatch
374  logger.error("updateProtectedResource" +
375  " failed, client ID mismatch: "
376  + clientId + " and " + auth.getOAuth2Request().getClientId() + " do not match.");
377  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN); // http 403
378 
379  return HttpCodeView.VIEWNAME;
380  }
381  }
ConfigurationPropertiesBean config
Definition: ProtectedResourceRegistrationEndpoint.java:77
OAuth2AccessTokenEntity fetchValidRegistrationToken(OAuth2Authentication auth, ClientDetailsEntity client)
Definition: ProtectedResourceRegistrationEndpoint.java:440
void setClientSecret(String clientSecret)
Definition: ClientDetailsEntity.java:425
ClientDetailsEntity validateAuth(ClientDetailsEntity newClient)
Definition: ProtectedResourceRegistrationEndpoint.java:413
ClientDetailsEntityService clientService
Definition: ProtectedResourceRegistrationEndpoint.java:68
static final Logger logger
Definition: ProtectedResourceRegistrationEndpoint.java:85
ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient)
ClientDetailsEntity loadClientByClientId(String clientId)
ClientDetailsEntity validateScopes(ClientDetailsEntity newClient)
Definition: ProtectedResourceRegistrationEndpoint.java:203
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100

◆ validateAuth()

ClientDetailsEntity org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.validateAuth ( ClientDetailsEntity  newClient) throws ValidationException
inlineprivate
413  {
414  if (newClient.getTokenEndpointAuthMethod() == null) {
415  newClient.setTokenEndpointAuthMethod(AuthMethod.SECRET_BASIC);
416  }
417 
418  if (newClient.getTokenEndpointAuthMethod() == AuthMethod.SECRET_BASIC ||
419  newClient.getTokenEndpointAuthMethod() == AuthMethod.SECRET_JWT ||
420  newClient.getTokenEndpointAuthMethod() == AuthMethod.SECRET_POST) {
421 
422  if (Strings.isNullOrEmpty(newClient.getClientSecret())) {
423  // no secret yet, we need to generate a secret
424  newClient = clientService.generateClientSecret(newClient);
425  }
426  } else if (newClient.getTokenEndpointAuthMethod() == AuthMethod.PRIVATE_KEY) {
427  if (Strings.isNullOrEmpty(newClient.getJwksUri()) && newClient.getJwks() == null) {
428  throw new ValidationException("invalid_client_metadata", "JWK Set URI required when using private key authentication", HttpStatus.BAD_REQUEST);
429  }
430 
431  newClient.setClientSecret(null);
432  } else if (newClient.getTokenEndpointAuthMethod() == AuthMethod.NONE) {
433  newClient.setClientSecret(null);
434  } else {
435  throw new ValidationException("invalid_client_metadata", "Unknown authentication method", HttpStatus.BAD_REQUEST);
436  }
437  return newClient;
438  }
ClientDetailsEntityService clientService
Definition: ProtectedResourceRegistrationEndpoint.java:68
ClientDetailsEntity generateClientSecret(ClientDetailsEntity client)

◆ validateScopes()

ClientDetailsEntity org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.validateScopes ( ClientDetailsEntity  newClient) throws ValidationException
inlineprivate
203  {
204  // scopes that the client is asking for
205  Set<SystemScope> requestedScopes = scopeService.fromStrings(newClient.getScope());
206 
207  // the scopes that the client can have must be a subset of the dynamically allowed scopes
208  Set<SystemScope> allowedScopes = scopeService.removeRestrictedAndReservedScopes(requestedScopes);
209 
210  // if the client didn't ask for any, give them the defaults
211  if (allowedScopes == null || allowedScopes.isEmpty()) {
212  allowedScopes = scopeService.getDefaults();
213  }
214 
215  newClient.setScope(scopeService.toStrings(allowedScopes));
216 
217  return newClient;
218  }
Set< SystemScope > removeRestrictedAndReservedScopes(Set< SystemScope > scopes)
SystemScopeService scopeService
Definition: ProtectedResourceRegistrationEndpoint.java:74
Set< SystemScope > fromStrings(Set< String > scope)
Set< String > toStrings(Set< SystemScope > scope)

メンバ詳解

◆ clientService

ClientDetailsEntityService org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.clientService
private

◆ config

ConfigurationPropertiesBean org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.config
private

◆ connectTokenService

OIDCTokenService org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.connectTokenService
private

◆ logger

final Logger org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.logger = LoggerFactory.getLogger(ProtectedResourceRegistrationEndpoint.class)
staticprivate

Logger for this class

◆ scopeService

SystemScopeService org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.scopeService
private

◆ tokenService

OAuth2TokenEntityService org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.tokenService
private

◆ URL

final String org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.URL = "resource"
static

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