|
1 | 1 | /** |
2 | 2 | * SSO implementation, based on this doc: |
3 | | - * https://developers.staffbase.com/api/plugin-sso/ |
| 3 | + * https://developers.staffbase.com/guide/customplugin-overview |
4 | 4 | * |
5 | | - * @copyright 2017 Staffbase GmbH. |
| 5 | + * @copyright 2020 Staffbase GmbH. |
6 | 6 | * @author Thilo Schmalfuß |
7 | 7 | * @author Vitaliy Ivanov |
8 | 8 | * @license http://www.apache.org/licenses/LICENSE-2.0 |
@@ -74,13 +74,23 @@ public class SSOData { |
74 | 74 | */ |
75 | 75 | public static final String KEY_USER_EXTERNAL_ID = "external_id"; |
76 | 76 |
|
| 77 | + /** |
| 78 | + * The key in the JWT claims for fetching the requesting user's username. |
| 79 | + */ |
| 80 | + public static final String KEY_USER_USERNAME= "username"; |
| 81 | + |
| 82 | + /** |
| 83 | + * The key in the JWT claims for fetching the requesting user's primary email address. |
| 84 | + */ |
| 85 | + public static final String KEY_USER_PRIMARY_EMAIL_ADDRESS = "primary_email_address"; |
| 86 | + |
77 | 87 | /** |
78 | 88 | * The key in the JWT claims for fetching the requesting user's first name. |
79 | 89 | */ |
80 | 90 | public static final String KEY_USER_FIRST_NAME = "given_name"; |
81 | 91 |
|
82 | 92 | /** |
83 | | - * The key in the JWT claims for fetching the requesting users last name. |
| 93 | + * The key in the JWT claims for fetching the requesting user's last name. |
84 | 94 | */ |
85 | 95 | public static final String KEY_USER_LAST_NAME = "family_name"; |
86 | 96 |
|
@@ -215,6 +225,16 @@ public class SSOData { |
215 | 225 | */ |
216 | 226 | private final String userExternalID; |
217 | 227 |
|
| 228 | + /** |
| 229 | + * The username of the requesting user, if given. |
| 230 | + */ |
| 231 | + private final String userUsername; |
| 232 | + |
| 233 | + /** |
| 234 | + * The primary email address of the requesting user, if given. |
| 235 | + */ |
| 236 | + private final String userPrimaryEmailAddress; |
| 237 | + |
218 | 238 | /** |
219 | 239 | * The first, i.e. given name of the user making the request using staffbase's SSO. |
220 | 240 | */ |
@@ -264,6 +284,8 @@ public SSOData(final JwtClaims jwtClaims) throws MalformedClaimException { |
264 | 284 | this.sessionID = jwtClaims.getClaimValue(KEY_SESSION_ID, String.class); |
265 | 285 | this.userID = jwtClaims.getClaimValue(KEY_USER_ID, String.class); |
266 | 286 | this.userExternalID = jwtClaims.getClaimValue(KEY_USER_EXTERNAL_ID, String.class); |
| 287 | + this.userUsername = jwtClaims.getClaimValue(KEY_USER_USERNAME, String.class); |
| 288 | + this.userPrimaryEmailAddress = jwtClaims.getClaimValue(KEY_USER_PRIMARY_EMAIL_ADDRESS, String.class); |
267 | 289 | this.userFirstName = jwtClaims.getClaimValue(KEY_USER_FIRST_NAME, String.class); |
268 | 290 | this.userLastName = jwtClaims.getClaimValue(KEY_USER_LAST_NAME, String.class); |
269 | 291 | this.userRole = jwtClaims.getClaimValue(KEY_USER_ROLE, String.class); |
@@ -403,6 +425,26 @@ public Optional<String> getUserExternalID() { |
403 | 425 | return Optional.ofNullable(this.userExternalID); |
404 | 426 | } |
405 | 427 |
|
| 428 | + /** |
| 429 | + * Get the username of the requesting user, if given. |
| 430 | + * |
| 431 | + * @see #userUsername |
| 432 | + * @return the requesting user's username |
| 433 | + */ |
| 434 | + public Optional<String> getUserUsername() { |
| 435 | + return Optional.ofNullable(this.userUsername); |
| 436 | + } |
| 437 | + |
| 438 | + /** |
| 439 | + * Get the primary email address of the requesting user, if given. |
| 440 | + * |
| 441 | + * @see #userPrimaryEmailAddress |
| 442 | + * @return the requesting user's primary email address |
| 443 | + */ |
| 444 | + public Optional<String> getUserPrimaryEmailAddress() { |
| 445 | + return Optional.ofNullable(this.userPrimaryEmailAddress); |
| 446 | + } |
| 447 | + |
406 | 448 | /** |
407 | 449 | * Get the first, i.e. given name of the user making the request using staffbase's |
408 | 450 | * SSO. |
@@ -502,6 +544,8 @@ public String toString() { |
502 | 544 | ", branchSlug="+ this.branchSlug+ |
503 | 545 | ", userID="+ this.userID+ |
504 | 546 | ", userExternalID="+ this.userExternalID+ |
| 547 | + ", userUsername="+ this.userUsername+ |
| 548 | + ", userPrimaryEmailAddress="+ this.userPrimaryEmailAddress+ |
505 | 549 | ", userFirstName="+ this.userFirstName+ |
506 | 550 | ", userLastName="+ this.userLastName+ |
507 | 551 | ", userRole="+ this.userRole+ |
|
0 commit comments