|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, 2024 Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2018, 2025 Oracle and/or its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -307,9 +307,7 @@ public class Jwt {
|
307 | 307 | this.cHash = JwtUtil.getByteArray(payloadJson, C_HASH, "c_hash value");
|
308 | 308 | this.nonce = JwtUtil.getString(payloadJson, NONCE);
|
309 | 309 | this.scopes = JwtUtil.toScopes(payloadJson);
|
310 |
| - this.userPrincipal = JwtUtil.getString(payloadJson, USER_PRINCIPAL) |
311 |
| - .or(() -> preferredUsername) |
312 |
| - .or(() -> subject); |
| 310 | + this.userPrincipal = JwtUtil.getString(payloadJson, USER_PRINCIPAL); |
313 | 311 | }
|
314 | 312 |
|
315 | 313 | private Jwt(Builder builder) {
|
@@ -357,9 +355,7 @@ private Jwt(Builder builder) {
|
357 | 355 | this.scopes = builder.scopes;
|
358 | 356 |
|
359 | 357 | this.userPrincipal = builder.userPrincipal
|
360 |
| - .or(() -> toOptionalString(builder.payloadClaims, USER_PRINCIPAL)) |
361 |
| - .or(() -> preferredUsername) |
362 |
| - .or(() -> subject); |
| 358 | + .or(() -> toOptionalString(builder.payloadClaims, USER_PRINCIPAL)); |
363 | 359 |
|
364 | 360 | this.userGroups = builder.userGroups;
|
365 | 361 | }
|
@@ -663,11 +659,14 @@ public Optional<String> subject() {
|
663 | 659 |
|
664 | 660 | /**
|
665 | 661 | * User principal claim ("upn" from microprofile specification).
|
| 662 | + * Falls back "preferred_username" then "sub" claim. |
666 | 663 | *
|
667 |
| - * @return user principal or empty if claim is not defined |
| 664 | + * @return user principal or empty if claim and fallbacks are not defined |
668 | 665 | */
|
669 | 666 | public Optional<String> userPrincipal() {
|
670 |
| - return userPrincipal; |
| 667 | + return userPrincipal |
| 668 | + .or(() -> preferredUsername) |
| 669 | + .or(() -> subject); |
671 | 670 | }
|
672 | 671 |
|
673 | 672 | /**
|
@@ -1682,8 +1681,7 @@ public Builder subject(String subject) {
|
1682 | 1681 | * User principal claim as defined by Microprofile JWT Auth spec.
|
1683 | 1682 | * Uses "upn" claim.
|
1684 | 1683 | *
|
1685 |
| - * @param principal name of the principal, falls back to {@link #preferredUsername(String)} and then to |
1686 |
| - * {@link #subject(String)} |
| 1684 | + * @param principal name of the principal |
1687 | 1685 | * @return updated builder instance
|
1688 | 1686 | */
|
1689 | 1687 | public Builder userPrincipal(String principal) {
|
|
0 commit comments