341 KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm.fromName(authorizationGrant.getClient().getIdTokenEncryptedResponseAlg());
342 BlockEncryptionAlgorithm blockEncryptionAlgorithm = BlockEncryptionAlgorithm.fromName(authorizationGrant.getClient().getIdTokenEncryptedResponseEnc());
343 jwe.getHeader().setType(JwtType.JWT);
344 jwe.getHeader().setAlgorithm(keyEncryptionAlgorithm);
345 jwe.getHeader().setEncryptionMethod(blockEncryptionAlgorithm);
349 jwe.getClaims().setAudience(authorizationGrant.getClient().getClientId());
352 Calendar calendar = Calendar.getInstance();
353 Date issuedAt = calendar.getTime();
354 calendar.add(Calendar.SECOND, lifeTime);
355 Date expiration = calendar.getTime();
357 jwe.getClaims().setExpirationTime(expiration);
358 jwe.getClaims().setIssuedAt(issuedAt);
360 if (preProcessing != null) {
361 preProcessing.apply(jwe);
364 if (authorizationGrant.getAcrValues() != null) {
365 jwe.getClaims().setClaim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, authorizationGrant.getAcrValues());
366 setAmrClaim(jwe, authorizationGrant.getAcrValues());
368 if (StringUtils.isNotBlank(nonce)) {
369 jwe.getClaims().setClaim(JwtClaimName.NONCE, nonce);
371 if (authorizationGrant.getAuthenticationTime() != null) {
372 jwe.getClaims().setClaim(JwtClaimName.AUTHENTICATION_TIME, authorizationGrant.getAuthenticationTime());
374 if (authorizationCode != null) {
375 String codeHash = authorizationCode.getHash(null);
376 jwe.getClaims().setClaim(JwtClaimName.CODE_HASH, codeHash);
378 if (accessToken != null) {
379 String accessTokenHash = accessToken.getHash(null);
380 jwe.getClaims().setClaim(JwtClaimName.ACCESS_TOKEN_HASH, accessTokenHash);
385 if (includeIdTokenClaims && authorizationGrant.getClient().isIncludeClaimsInIdToken()) {
386 for (String scopeName : scopes) {
389 dynamicScopes.add(scope);
393 if (scope != null && scope.getOxAuthClaims() != null) {
394 for (String claimDn : scope.getOxAuthClaims()) {
397 String claimName = gluuAttribute.getOxAuthClaimName();
398 String ldapName = gluuAttribute.getName();
399 Object attributeValue;
401 if (StringUtils.isNotBlank(claimName) && StringUtils.isNotBlank(ldapName)) {
402 if (ldapName.equals(
"uid")) {
403 attributeValue = authorizationGrant.getUser().getUserId();
405 attributeValue = authorizationGrant.getUser().getAttribute(gluuAttribute.getName(),
true);
408 if (attributeValue != null) {
409 if (attributeValue instanceof JSONArray) {
410 JSONArray jsonArray = (JSONArray) attributeValue;
411 List<String> values =
new ArrayList<String>();
412 for (
int i = 0; i < jsonArray.length(); i++) {
413 String value = jsonArray.optString(i);
418 jwe.getClaims().setClaim(claimName, values);
420 String value = attributeValue.toString();
421 jwe.getClaims().setClaim(claimName, value);
430 if (authorizationGrant.getJwtAuthorizationRequest() != null
431 && authorizationGrant.getJwtAuthorizationRequest().getIdTokenMember() != null) {
432 for (Claim claim : authorizationGrant.getJwtAuthorizationRequest().getIdTokenMember().getClaims()) {
433 boolean optional =
true;
436 if (gluuAttribute != null) {
437 Client client = authorizationGrant.getClient();
440 String ldapClaimName = gluuAttribute.getName();
441 Object attribute = authorizationGrant.getUser().getAttribute(ldapClaimName, optional);
442 if (attribute != null) {
443 if (attribute instanceof JSONArray) {
444 JSONArray jsonArray = (JSONArray) attribute;
445 List<String> values =
new ArrayList<String>();
446 for (
int i = 0; i < jsonArray.length(); i++) {
447 String value = jsonArray.optString(i);
452 jwe.getClaims().setClaim(claim.getName(), values);
454 String value = attribute.toString();
455 jwe.getClaims().setClaim(claim.getName(), value);
464 if (authorizationGrant.getClient().getSubjectType() != null &&
465 SubjectType.fromString(authorizationGrant.getClient().getSubjectType()).equals(SubjectType.PAIRWISE)) {
466 String sectorIdentifierUri;
467 if (StringUtils.isNotBlank(authorizationGrant.getClient().getSectorIdentifierUri())) {
468 sectorIdentifierUri = authorizationGrant.getClient().getSectorIdentifierUri();
470 sectorIdentifierUri = authorizationGrant.getClient().getRedirectUris()[0];
473 String userInum = authorizationGrant.getUser().getAttribute(
"inum");
474 String clientId = authorizationGrant.getClientId();
476 userInum, sectorIdentifierUri, clientId);
477 if (pairwiseIdentifier == null) {
478 pairwiseIdentifier =
new PairwiseIdentifier(sectorIdentifierUri, clientId);
479 pairwiseIdentifier.setId(UUID.randomUUID().toString());
481 pairwiseIdentifier.getId(),
485 jwe.getClaims().setSubjectIdentifier(pairwiseIdentifier.getId());
489 if (openidSubAttribute.equals(
"uid")) {
490 jwe.getClaims().setSubjectIdentifier(authorizationGrant.getUser().getUserId());
492 jwe.getClaims().setSubjectIdentifier(authorizationGrant.getUser().getAttribute(openidSubAttribute));
497 final UnmodifiableAuthorizationGrant unmodifiableAuthorizationGrant =
new UnmodifiableAuthorizationGrant(authorizationGrant);
498 DynamicScopeExternalContext dynamicScopeContext =
new DynamicScopeExternalContext(dynamicScopes, jwe, unmodifiableAuthorizationGrant);
503 if (keyEncryptionAlgorithm == KeyEncryptionAlgorithm.RSA_OAEP
504 || keyEncryptionAlgorithm == KeyEncryptionAlgorithm.RSA1_5) {
505 JSONObject jsonWebKeys = JwtUtil.getJSONWebKeys(authorizationGrant.getClient().getJwksUri());
506 AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(
appConfiguration);
507 String keyId = cryptoProvider.getKeyId(JSONWebKeySet.fromJSONObject(jsonWebKeys), SignatureAlgorithm.RS256, Use.ENCRYPTION);
508 PublicKey publicKey = cryptoProvider.getPublicKey(keyId, jsonWebKeys);
509 jwe.getHeader().setKeyId(keyId);
511 if (publicKey != null) {
512 JweEncrypter jweEncrypter =
new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, publicKey);
513 jwe = jweEncrypter.encrypt(jwe);
515 throw new InvalidJweException(
"The public key is not valid");
517 }
else if (keyEncryptionAlgorithm == KeyEncryptionAlgorithm.A128KW
518 || keyEncryptionAlgorithm == KeyEncryptionAlgorithm.A256KW) {
520 byte[] sharedSymmetricKey =
clientService.
decryptSecret(authorizationGrant.getClient().getClientSecret()).getBytes(Util.UTF8_STRING_ENCODING);
521 JweEncrypter jweEncrypter =
new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, sharedSymmetricKey);
522 jwe = jweEncrypter.encrypt(jwe);
523 }
catch (UnsupportedEncodingException e) {
524 throw new InvalidJweException(e);
525 }
catch (StringEncrypter.EncryptionException e) {
526 throw new InvalidJweException(e);
527 }
catch (Exception e) {
528 throw new InvalidJweException(e);
String getDnForPairwiseIdentifier(String oxId, String userInum)
Definition: PairwiseIdentifierService.java:107
AppConfiguration appConfiguration
Definition: IdTokenFactory.java:106
GluuAttribute getAttributeByDn(String dn)
Definition: AttributeService.java:47
PairwiseIdentifierService pairwiseIdentifierService
Definition: IdTokenFactory.java:103
GluuAttribute getByClaimName(String name)
Definition: AttributeService.java:73
org.xdi.oxauth.model.common.Scope getScopeByDisplayName(String displayName)
Definition: ScopeService.java:119
ExternalDynamicScopeService externalDynamicScopeService
Definition: IdTokenFactory.java:88
DYNAMIC
Definition: ScopeType.java:56
String getOxOpenIdConnectVersion()
Definition: AppConfiguration.java:864
boolean validateRequesteClaim(GluuAttribute gluuAttribute, String[] clientAllowedClaims, Collection< String > scopes)
Definition: IdTokenFactory.java:550
ClientService clientService
Definition: IdTokenFactory.java:94
int getIdTokenLifetime()
Definition: AppConfiguration.java:784
Definition: Scope.java:23
Definition: ScopeType.java:21
void addPairwiseIdentifier(String userInum, PairwiseIdentifier pairwiseIdentifier)
Definition: PairwiseIdentifierService.java:100
String getIssuer()
Definition: AppConfiguration.java:274
void setAmrClaim(JsonWebResponse jwt, String acrValues)
Definition: IdTokenFactory.java:312
AttributeService attributeService
Definition: IdTokenFactory.java:100
String decryptSecret(String encryptedClientSecret)
Definition: ClientService.java:390
ScopeService scopeService
Definition: IdTokenFactory.java:97
Definition: AuthenticationMethod.java:7
String getOpenidSubAttribute()
Definition: AppConfiguration.java:509
PairwiseIdentifier findPairWiseIdentifier(String userInum, String sectorIdentifierUri, String clientId)
Definition: PairwiseIdentifierService.java:59
boolean executeExternalUpdateMethods(DynamicScopeExternalContext dynamicScopeContext)
Definition: ExternalDynamicScopeService.java:95