001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.openid.connect.sdk.claims; 019 020 021import java.net.URI; 022import java.util.*; 023 024import net.minidev.json.JSONObject; 025 026import com.nimbusds.langtag.LangTag; 027import com.nimbusds.oauth2.sdk.ParseException; 028import com.nimbusds.openid.connect.sdk.assurance.claims.Birthplace; 029import com.nimbusds.openid.connect.sdk.assurance.claims.CountryCode; 030 031 032/** 033 * Person-specific claims set, intended to provide common getters and setters 034 * for {@link UserInfo OpenID Connect UserInfo} and 035 * {@link com.nimbusds.openid.connect.sdk.assurance.claims.VerifiedClaimsSet 036 * OpenID Connect Identity Assurance verified claims}. 037 * 038 * <p>Related specifications: 039 * 040 * <ul> 041 * <li>OpenID Connect Core 1.0, sections 5.1 and 5.6. 042 * <li>OpenID Connect for Identity Assurance 1.0, section 3.1. 043 * </ul> 044 */ 045public class PersonClaims extends ClaimsSet { 046 047 048 /** 049 * The name claim name. 050 */ 051 public static final String NAME_CLAIM_NAME = "name"; 052 053 054 /** 055 * The given name claim name. 056 */ 057 public static final String GIVEN_NAME_CLAIM_NAME = "given_name"; 058 059 060 /** 061 * The family name claim name. 062 */ 063 public static final String FAMILY_NAME_CLAIM_NAME = "family_name"; 064 065 066 /** 067 * The middle name claim name. 068 */ 069 public static final String MIDDLE_NAME_CLAIM_NAME = "middle_name"; 070 071 072 /** 073 * The nickname claim name. 074 */ 075 public static final String NICKNAME_CLAIM_NAME = "nickname"; 076 077 078 /** 079 * The preferred username claim name. 080 */ 081 public static final String PREFERRED_USERNAME_CLAIM_NAME = "preferred_username"; 082 083 084 /** 085 * The profile claim name. 086 */ 087 public static final String PROFILE_CLAIM_NAME = "profile"; 088 089 090 /** 091 * The picture claim name. 092 */ 093 public static final String PICTURE_CLAIM_NAME = "picture"; 094 095 096 /** 097 * The website claim name. 098 */ 099 public static final String WEBSITE_CLAIM_NAME = "website"; 100 101 102 /** 103 * The email claim name. 104 */ 105 public static final String EMAIL_CLAIM_NAME = "email"; 106 107 108 /** 109 * The email verified claim name. 110 */ 111 public static final String EMAIL_VERIFIED_CLAIM_NAME = "email_verified"; 112 113 114 /** 115 * The gender claim name. 116 */ 117 public static final String GENDER_CLAIM_NAME = "gender"; 118 119 120 /** 121 * The birth date claim name. 122 */ 123 public static final String BIRTHDATE_CLAIM_NAME = "birthdate"; 124 125 126 /** 127 * The zoneinfo claim name. 128 */ 129 public static final String ZONEINFO_CLAIM_NAME = "zoneinfo"; 130 131 132 /** 133 * The locale claim name. 134 */ 135 public static final String LOCALE_CLAIM_NAME = "locale"; 136 137 138 /** 139 * The phone number claim name. 140 */ 141 public static final String PHONE_NUMBER_CLAIM_NAME = "phone_number"; 142 143 144 /** 145 * The phone number verified claim name. 146 */ 147 public static final String PHONE_NUMBER_VERIFIED_CLAIM_NAME = "phone_number_verified"; 148 149 150 /** 151 * The address claim name. 152 */ 153 public static final String ADDRESS_CLAIM_NAME = "address"; 154 155 156 /** 157 * The updated at claim name. 158 */ 159 public static final String UPDATED_AT_CLAIM_NAME = "updated_at"; 160 161 162 /** 163 * The birthplace claim name (OpenID Connect for Identity Assurance 164 * 1.0). Alternative for {@link #PLACE_OF_BIRTH_CLAIM_NAME}. 165 */ 166 @Deprecated 167 public static final String BIRTHPLACE_CLAIM_NAME = "birthplace"; 168 169 170 /** 171 * The place of birth claim name (OpenID Connect for Identity Assurance 172 * 1.0). Alternative for {@link #BIRTHPLACE_CLAIM_NAME}. 173 */ 174 public static final String PLACE_OF_BIRTH_CLAIM_NAME = "place_of_birth"; 175 176 177 /** 178 * The nationalities claim name (OpenID Connect for Identity Assurance 179 * 1.0). 180 */ 181 public static final String NATIONALITIES_CLAIM_NAME = "nationalities"; 182 183 184 /** 185 * The birth family name claim name (OpenID Connect for Identity 186 * Assurance 1.0). 187 */ 188 public static final String BIRTH_FAMILY_NAME_CLAIM_NAME = "birth_family_name"; 189 190 191 /** 192 * The birth given name claim name (OpenID Connect for Identity 193 * Assurance 1.0). 194 */ 195 public static final String BIRTH_GIVEN_NAME_CLAIM_NAME = "birth_given_name"; 196 197 198 /** 199 * The birth middle name claim name (OpenID Connect for Identity 200 * Assurance 1.0). 201 */ 202 public static final String BIRTH_MIDDLE_NAME_CLAIM_NAME = "birth_middle_name"; 203 204 205 /** 206 * The salutation claim name (OpenID Connect for Identity Assurance 207 * 1.0). 208 */ 209 public static final String SALUTATION_CLAIM_NAME = "salutation"; 210 211 212 /** 213 * The title claim name (OpenID Connect for Identity Assurance 1.0). 214 */ 215 public static final String TITLE_CLAIM_NAME = "title"; 216 217 218 /** 219 * Gets the names of the standard top-level UserInfo claims. 220 * 221 * @return The names of the standard top-level UserInfo claims 222 * (read-only set). 223 */ 224 public static Set<String> getStandardClaimNames() { 225 226 Set<String> names = new HashSet<>(ClaimsSet.getStandardClaimNames()); 227 names.addAll(Arrays.asList( 228 NAME_CLAIM_NAME, 229 GIVEN_NAME_CLAIM_NAME, 230 FAMILY_NAME_CLAIM_NAME, 231 MIDDLE_NAME_CLAIM_NAME, 232 NICKNAME_CLAIM_NAME, 233 PREFERRED_USERNAME_CLAIM_NAME, 234 PROFILE_CLAIM_NAME, 235 PICTURE_CLAIM_NAME, 236 WEBSITE_CLAIM_NAME, 237 EMAIL_CLAIM_NAME, 238 EMAIL_VERIFIED_CLAIM_NAME, 239 GENDER_CLAIM_NAME, 240 BIRTHDATE_CLAIM_NAME, 241 ZONEINFO_CLAIM_NAME, 242 LOCALE_CLAIM_NAME, 243 PHONE_NUMBER_CLAIM_NAME, 244 PHONE_NUMBER_VERIFIED_CLAIM_NAME, 245 ADDRESS_CLAIM_NAME, 246 UPDATED_AT_CLAIM_NAME, 247 BIRTHPLACE_CLAIM_NAME, 248 PLACE_OF_BIRTH_CLAIM_NAME, 249 NATIONALITIES_CLAIM_NAME, 250 BIRTH_FAMILY_NAME_CLAIM_NAME, 251 BIRTH_GIVEN_NAME_CLAIM_NAME, 252 BIRTH_MIDDLE_NAME_CLAIM_NAME, 253 SALUTATION_CLAIM_NAME, 254 TITLE_CLAIM_NAME 255 )); 256 return Collections.unmodifiableSet(names); 257 } 258 259 260 /** 261 * Creates a new empty person-specific claims set. 262 */ 263 public PersonClaims() { 264 this(new JSONObject()); 265 } 266 267 268 /** 269 * Creates a new person-specific claims set from the specified JSON 270 * object. 271 * 272 * @param jsonObject The JSON object. Must not be {@code null}. 273 */ 274 public PersonClaims(final JSONObject jsonObject) { 275 276 super(jsonObject); 277 } 278 279 280 // name 281 282 283 /** 284 * Gets the full name. Corresponds to the {@code name} claim, with no 285 * language tag. 286 * 287 * @return The full name, {@code null} if not specified. 288 */ 289 public String getName() { 290 291 return getStringClaim(NAME_CLAIM_NAME); 292 } 293 294 295 /** 296 * Gets the full name. Corresponds to the {@code name} claim, with an 297 * optional language tag. 298 * 299 * @param langTag The language tag of the entry, {@code null} to get 300 * the non-tagged entry. 301 * 302 * @return The full name, {@code null} if not specified. 303 */ 304 public String getName(final LangTag langTag) { 305 306 return getStringClaim(NAME_CLAIM_NAME, langTag); 307 } 308 309 310 /** 311 * Gets the full name entries. Correspond to the {@code name} claim. 312 * 313 * @return The full name entries, empty map if none. 314 */ 315 public Map<LangTag,String> getNameEntries() { 316 317 return getLangTaggedClaim(NAME_CLAIM_NAME, String.class); 318 } 319 320 321 /** 322 * Sets the full name. Corresponds to the {@code name} claim, with no 323 * language tag. 324 * 325 * @param name The full name. If {@code null} the claim will be 326 * removed. 327 */ 328 public void setName(final String name) { 329 330 setClaim(NAME_CLAIM_NAME, name); 331 } 332 333 334 /** 335 * Sets the full name. Corresponds to the {@code name} claim, with an 336 * optional language tag. 337 * 338 * @param name The full name. If {@code null} the claim will be 339 * removed. 340 * @param langTag The language tag, {@code null} if not specified. 341 */ 342 public void setName(final String name, final LangTag langTag) { 343 344 setClaim(NAME_CLAIM_NAME, name, langTag); 345 } 346 347 348 // given_name 349 350 351 /** 352 * Gets the given or first name. Corresponds to the {@code given_name} 353 * claim, with no language tag. 354 * 355 * @return The given or first name, {@code null} if not specified. 356 */ 357 public String getGivenName() { 358 359 return getStringClaim(GIVEN_NAME_CLAIM_NAME); 360 } 361 362 363 /** 364 * Gets the given or first name. Corresponds to the {@code given_name} 365 * claim, with an optional language tag. 366 * 367 * @param langTag The language tag of the entry, {@code null} to get 368 * the non-tagged entry. 369 * 370 * @return The given or first name, {@code null} if not specified. 371 */ 372 public String getGivenName(final LangTag langTag) { 373 374 return getStringClaim(GIVEN_NAME_CLAIM_NAME, langTag); 375 } 376 377 378 /** 379 * Gets the given or first name entries. Correspond to the 380 * {@code given_name} claim. 381 * 382 * @return The given or first name entries, empty map if none. 383 */ 384 public Map<LangTag,String> getGivenNameEntries() { 385 386 return getLangTaggedClaim(GIVEN_NAME_CLAIM_NAME, String.class); 387 } 388 389 390 /** 391 * Sets the given or first name. Corresponds to the {@code given_name} 392 * claim, with no language tag. 393 * 394 * @param givenName The given or first name. If {@code null} the claim 395 * will be removed. 396 */ 397 public void setGivenName(final String givenName) { 398 399 setClaim(GIVEN_NAME_CLAIM_NAME, givenName); 400 } 401 402 403 /** 404 * Sets the given or first name. Corresponds to the {@code given_name} 405 * claim, with an optional language tag. 406 * 407 * @param givenName The given or first full name. If {@code null} the 408 * claim will be removed. 409 * @param langTag The language tag, {@code null} if not specified. 410 */ 411 public void setGivenName(final String givenName, final LangTag langTag) { 412 413 setClaim(GIVEN_NAME_CLAIM_NAME, givenName, langTag); 414 } 415 416 417 // family_name 418 419 420 /** 421 * Gets the surname or last name. Corresponds to the 422 * {@code family_name} claim, with no language tag. 423 * 424 * @return The surname or last name, {@code null} if not specified. 425 */ 426 public String getFamilyName() { 427 428 return getStringClaim(FAMILY_NAME_CLAIM_NAME); 429 } 430 431 432 /** 433 * Gets the surname or last name. Corresponds to the 434 * {@code family_name} claim, with an optional language tag. 435 * 436 * @param langTag The language tag of the entry, {@code null} to get 437 * the non-tagged entry. 438 * 439 * @return The surname or last name, {@code null} if not specified. 440 */ 441 public String getFamilyName(final LangTag langTag) { 442 443 return getStringClaim(FAMILY_NAME_CLAIM_NAME, langTag); 444 } 445 446 447 /** 448 * Gets the surname or last name entries. Correspond to the 449 * {@code family_name} claim. 450 * 451 * @return The surname or last name entries, empty map if none. 452 */ 453 public Map<LangTag,String> getFamilyNameEntries() { 454 455 return getLangTaggedClaim(FAMILY_NAME_CLAIM_NAME, String.class); 456 } 457 458 459 /** 460 * Sets the surname or last name. Corresponds to the 461 * {@code family_name} claim, with no language tag. 462 * 463 * @param familyName The surname or last name. If {@code null} the 464 * claim will be removed. 465 */ 466 public void setFamilyName(final String familyName) { 467 468 setClaim(FAMILY_NAME_CLAIM_NAME, familyName); 469 } 470 471 472 /** 473 * Sets the surname or last name. Corresponds to the 474 * {@code family_name} claim, with an optional language tag. 475 * 476 * @param familyName The surname or last name. If {@code null} the 477 * claim will be removed. 478 * @param langTag The language tag, {@code null} if not specified. 479 */ 480 public void setFamilyName(final String familyName, final LangTag langTag) { 481 482 setClaim(FAMILY_NAME_CLAIM_NAME, familyName, langTag); 483 } 484 485 486 // middle_name 487 488 489 /** 490 * Gets the middle name. Corresponds to the {@code middle_name} claim, 491 * with no language tag. 492 * 493 * @return The middle name, {@code null} if not specified. 494 */ 495 public String getMiddleName() { 496 497 return getStringClaim(MIDDLE_NAME_CLAIM_NAME); 498 } 499 500 501 /** 502 * Gets the middle name. Corresponds to the {@code middle_name} claim, 503 * with an optional language tag. 504 * 505 * @param langTag The language tag of the entry, {@code null} to get 506 * the non-tagged entry. 507 * 508 * @return The middle name, {@code null} if not specified. 509 */ 510 public String getMiddleName(final LangTag langTag) { 511 512 return getStringClaim(MIDDLE_NAME_CLAIM_NAME, langTag); 513 } 514 515 516 /** 517 * Gets the middle name entries. Correspond to the {@code middle_name} 518 * claim. 519 * 520 * @return The middle name entries, empty map if none. 521 */ 522 public Map<LangTag,String> getMiddleNameEntries() { 523 524 return getLangTaggedClaim(MIDDLE_NAME_CLAIM_NAME, String.class); 525 } 526 527 528 /** 529 * Sets the middle name. Corresponds to the {@code middle_name} claim, 530 * with no language tag. 531 * 532 * @param middleName The middle name. If {@code null} the claim will be 533 * removed. 534 */ 535 public void setMiddleName(final String middleName) { 536 537 setClaim(MIDDLE_NAME_CLAIM_NAME, middleName); 538 } 539 540 541 /** 542 * Sets the middle name. Corresponds to the {@code middle_name} claim, 543 * with an optional language tag. 544 * 545 * @param middleName The middle name. If {@code null} the claim will be 546 * removed. 547 * @param langTag The language tag, {@code null} if not specified. 548 */ 549 public void setMiddleName(final String middleName, final LangTag langTag) { 550 551 setClaim(MIDDLE_NAME_CLAIM_NAME, middleName, langTag); 552 } 553 554 555 // nickname 556 557 558 /** 559 * Gets the casual name. Corresponds to the {@code nickname} claim, 560 * with no language tag. 561 * 562 * @return The casual name, {@code null} if not specified. 563 */ 564 public String getNickname() { 565 566 return getStringClaim(NICKNAME_CLAIM_NAME); 567 } 568 569 570 /** 571 * Gets the casual name. Corresponds to the {@code nickname} claim, 572 * with an optional language tag. 573 * 574 * @param langTag The language tag of the entry, {@code null} to get 575 * the non-tagged entry. 576 * 577 * @return The casual name, {@code null} if not specified. 578 */ 579 public String getNickname(final LangTag langTag) { 580 581 return getStringClaim(NICKNAME_CLAIM_NAME, langTag); 582 } 583 584 585 /** 586 * Gets the casual name entries. Correspond to the {@code nickname} 587 * claim. 588 * 589 * @return The casual name entries, empty map if none. 590 */ 591 public Map<LangTag,String> getNicknameEntries() { 592 593 return getLangTaggedClaim(NICKNAME_CLAIM_NAME, String.class); 594 } 595 596 597 /** 598 * Sets the casual name. Corresponds to the {@code nickname} claim, 599 * with no language tag. 600 * 601 * @param nickname The casual name. If {@code null} the claim will be 602 * removed. 603 */ 604 public void setNickname(final String nickname) { 605 606 setClaim(NICKNAME_CLAIM_NAME, nickname); 607 } 608 609 610 /** 611 * Sets the casual name. Corresponds to the {@code nickname} claim, 612 * with an optional language tag. 613 * 614 * @param nickname The casual name. If {@code null} the claim will be 615 * removed. 616 * @param langTag The language tag, {@code null} if not specified. 617 */ 618 public void setNickname(final String nickname, final LangTag langTag) { 619 620 setClaim(NICKNAME_CLAIM_NAME, nickname, langTag); 621 } 622 623 624 // preferred_username 625 626 627 /** 628 * Gets the preferred username. Corresponds to the 629 * {@code preferred_username} claim. 630 * 631 * @return The preferred username, {@code null} if not specified. 632 */ 633 public String getPreferredUsername() { 634 635 return getStringClaim(PREFERRED_USERNAME_CLAIM_NAME); 636 } 637 638 639 /** 640 * Sets the preferred username. Corresponds to the 641 * {@code preferred_username} claim. 642 * 643 * @param preferredUsername The preferred username. If {@code null} the 644 * claim will be removed. 645 */ 646 public void setPreferredUsername(final String preferredUsername) { 647 648 setClaim(PREFERRED_USERNAME_CLAIM_NAME, preferredUsername); 649 } 650 651 652 // profile 653 654 655 /** 656 * Gets the profile page. Corresponds to the {@code profile} claim. 657 * 658 * @return The profile page URI, {@code null} if not specified. 659 */ 660 public URI getProfile() { 661 662 return getURIClaim(PROFILE_CLAIM_NAME); 663 } 664 665 666 /** 667 * Sets the profile page. Corresponds to the {@code profile} claim. 668 * 669 * @param profile The profile page URI. If {@code null} the claim will 670 * be removed. 671 */ 672 public void setProfile(final URI profile) { 673 674 setURIClaim(PROFILE_CLAIM_NAME, profile); 675 } 676 677 678 // picture 679 680 681 /** 682 * Gets the picture. Corresponds to the {@code picture} claim. 683 * 684 * @return The picture URI, {@code null} if not specified. 685 */ 686 public URI getPicture() { 687 688 return getURIClaim(PICTURE_CLAIM_NAME); 689 } 690 691 692 /** 693 * Sets the picture. Corresponds to the {@code picture} claim. 694 * 695 * @param picture The picture URI. If {@code null} the claim will be 696 * removed. 697 */ 698 public void setPicture(final URI picture) { 699 700 setURIClaim(PICTURE_CLAIM_NAME, picture); 701 } 702 703 704 // website 705 706 707 /** 708 * Gets the web page or blog. Corresponds to the {@code website} claim. 709 * 710 * @return The web page or blog URI, {@code null} if not specified. 711 */ 712 public URI getWebsite() { 713 714 return getURIClaim(WEBSITE_CLAIM_NAME); 715 } 716 717 718 /** 719 * Sets the web page or blog. Corresponds to the {@code website} claim. 720 * 721 * @param website The web page or blog URI. If {@code null} the claim 722 * will be removed. 723 */ 724 public void setWebsite(final URI website) { 725 726 setURIClaim(WEBSITE_CLAIM_NAME, website); 727 } 728 729 730 // email 731 732 733 /** 734 * Gets the preferred email address. Corresponds to the {@code email} 735 * claim. 736 * 737 * @return The preferred email address, {@code null} if not specified. 738 */ 739 public String getEmailAddress() { 740 741 return getStringClaim(EMAIL_CLAIM_NAME); 742 } 743 744 745 /** 746 * Sets the preferred email address. Corresponds to the {@code email} 747 * claim. 748 * 749 * @param email The preferred email address. If {@code null} the claim 750 * will be removed. 751 */ 752 public void setEmailAddress(final String email) { 753 754 setClaim(EMAIL_CLAIM_NAME, email); 755 } 756 757 758 // email_verified 759 760 761 /** 762 * Gets the email verification status. Corresponds to the 763 * {@code email_verified} claim. 764 * 765 * @return The email verification status, {@code null} if not 766 * specified. 767 */ 768 public Boolean getEmailVerified() { 769 770 return getBooleanClaim(EMAIL_VERIFIED_CLAIM_NAME); 771 } 772 773 774 /** 775 * Sets the email verification status. Corresponds to the 776 * {@code email_verified} claim. 777 * 778 * @param emailVerified The email verification status. If {@code null} 779 * the claim will be removed. 780 */ 781 public void setEmailVerified(final Boolean emailVerified) { 782 783 setClaim(EMAIL_VERIFIED_CLAIM_NAME, emailVerified); 784 } 785 786 787 // gender 788 789 790 /** 791 * Gets the gender. Corresponds to the {@code gender} claim. 792 * 793 * @return The gender, {@code null} if not specified. 794 */ 795 public Gender getGender() { 796 797 String value = getStringClaim(GENDER_CLAIM_NAME); 798 799 if (value == null) 800 return null; 801 802 return new Gender(value); 803 } 804 805 806 /** 807 * Sets the gender. Corresponds to the {@code gender} claim. 808 * 809 * @param gender The gender. If {@code null} the claim will be removed. 810 */ 811 public void setGender(final Gender gender) { 812 813 if (gender != null) 814 setClaim(GENDER_CLAIM_NAME, gender.getValue()); 815 else 816 setClaim(GENDER_CLAIM_NAME, null); 817 } 818 819 820 // birthdate 821 822 823 /** 824 * Gets the date of birth. Corresponds to the {@code birthdate} claim. 825 * 826 * @return The date of birth, {@code null} if not specified. 827 */ 828 public String getBirthdate() { 829 830 return getStringClaim(BIRTHDATE_CLAIM_NAME); 831 } 832 833 834 /** 835 * Sets the date of birth. Corresponds to the {@code birthdate} claim. 836 * 837 * @param birthdate The date of birth. If {@code null} the claim will 838 * be removed. 839 */ 840 public void setBirthdate(final String birthdate) { 841 842 setClaim(BIRTHDATE_CLAIM_NAME, birthdate); 843 } 844 845 846 // zoneinfo 847 848 849 /** 850 * Gets the zoneinfo. Corresponds to the {@code zoneinfo} claim. 851 * 852 * @return The zoneinfo, {@code null} if not specified. 853 */ 854 public String getZoneinfo() { 855 856 return getStringClaim(ZONEINFO_CLAIM_NAME); 857 } 858 859 860 /** 861 * Sets the zoneinfo. Corresponds to the {@code zoneinfo} claim. 862 * 863 * @param zoneinfo The zoneinfo. If {@code null} the claim will be 864 * removed. 865 */ 866 public void setZoneinfo(final String zoneinfo) { 867 868 setClaim(ZONEINFO_CLAIM_NAME, zoneinfo); 869 } 870 871 872 // locale 873 874 875 /** 876 * Gets the locale. Corresponds to the {@code locale} claim. 877 * 878 * @return The locale, {@code null} if not specified. 879 */ 880 public String getLocale() { 881 882 return getStringClaim(LOCALE_CLAIM_NAME); 883 } 884 885 886 /** 887 * Sets the locale. Corresponds to the {@code locale} claim. 888 * 889 * @param locale The locale. If {@code null} the claim will be 890 * removed. 891 */ 892 public void setLocale(final String locale) { 893 894 setClaim(LOCALE_CLAIM_NAME, locale); 895 } 896 897 898 // phone_number 899 900 901 /** 902 * Gets the preferred telephone number. Corresponds to the 903 * {@code phone_number} claim. 904 * 905 * @return The preferred telephone number, {@code null} if not 906 * specified. 907 */ 908 public String getPhoneNumber() { 909 910 return getStringClaim(PHONE_NUMBER_CLAIM_NAME); 911 } 912 913 914 /** 915 * Sets the preferred telephone number. Corresponds to the 916 * {@code phone_number} claim. 917 * 918 * @param phoneNumber The preferred telephone number. If {@code null} 919 * the claim will be removed. 920 */ 921 public void setPhoneNumber(final String phoneNumber) { 922 923 setClaim(PHONE_NUMBER_CLAIM_NAME, phoneNumber); 924 } 925 926 927 // phone_number_verified 928 929 930 /** 931 * Gets the phone number verification status. Corresponds to the 932 * {@code phone_number_verified} claim. 933 * 934 * @return The phone number verification status, {@code null} if not 935 * specified. 936 */ 937 public Boolean getPhoneNumberVerified() { 938 939 return getBooleanClaim(PHONE_NUMBER_VERIFIED_CLAIM_NAME); 940 } 941 942 943 /** 944 * Sets the email verification status. Corresponds to the 945 * {@code phone_number_verified} claim. 946 * 947 * @param phoneNumberVerified The phone number verification status. If 948 * {@code null} the claim will be removed. 949 */ 950 public void setPhoneNumberVerified(final Boolean phoneNumberVerified) { 951 952 setClaim(PHONE_NUMBER_VERIFIED_CLAIM_NAME, phoneNumberVerified); 953 } 954 955 956 // address 957 958 959 /** 960 * Gets the preferred address. Corresponds to the {@code address} 961 * claim, with no language tag. 962 * 963 * @return The preferred address, {@code null} if not specified. 964 */ 965 public Address getAddress() { 966 967 return getAddress(null); 968 } 969 970 971 /** 972 * Gets the preferred address. Corresponds to the {@code address} 973 * claim, with an optional language tag. 974 * 975 * @param langTag The language tag of the entry, {@code null} to get 976 * the non-tagged entry. 977 * 978 * @return The preferred address, {@code null} if not specified. 979 */ 980 public Address getAddress(final LangTag langTag) { 981 982 String name; 983 984 if (langTag!= null) 985 name = ADDRESS_CLAIM_NAME + "#" + langTag; 986 else 987 name = ADDRESS_CLAIM_NAME; 988 989 JSONObject jsonObject = getClaim(name, JSONObject.class); 990 991 if (jsonObject == null) 992 return null; 993 994 return new Address(jsonObject); 995 } 996 997 998 /** 999 * Gets the preferred address entries. Correspond to the 1000 * {@code address} claim. 1001 * 1002 * @return The preferred address entries, empty map if none. 1003 */ 1004 public Map<LangTag,Address> getAddressEntries() { 1005 1006 Map<LangTag,JSONObject> entriesIn = getLangTaggedClaim(ADDRESS_CLAIM_NAME, JSONObject.class); 1007 1008 Map<LangTag,Address> entriesOut = new HashMap<>(); 1009 1010 for (Map.Entry<LangTag,JSONObject> en: entriesIn.entrySet()) 1011 entriesOut.put(en.getKey(), new Address(en.getValue())); 1012 1013 return entriesOut; 1014 } 1015 1016 1017 /** 1018 * Sets the preferred address. Corresponds to the {@code address} 1019 * claim, with no language tag. 1020 * 1021 * @param address The preferred address. If {@code null} the claim will 1022 * be removed. 1023 */ 1024 public void setAddress(final Address address) { 1025 1026 if (address != null) 1027 setClaim(ADDRESS_CLAIM_NAME, address.toJSONObject()); 1028 else 1029 setClaim(ADDRESS_CLAIM_NAME, null); 1030 } 1031 1032 1033 /** 1034 * Sets the preferred address. Corresponds to the {@code address} 1035 * claim, with an optional language tag. 1036 * 1037 * @param address The preferred address. If {@code null} the claim 1038 * will be removed. 1039 * @param langTag The language tag, {@code null} if not specified. 1040 */ 1041 public void setAddress(final Address address, final LangTag langTag) { 1042 1043 String key = langTag == null ? ADDRESS_CLAIM_NAME : ADDRESS_CLAIM_NAME + "#" + langTag; 1044 1045 if (address != null) 1046 setClaim(key, address.toJSONObject()); 1047 else 1048 setClaim(key, null); 1049 } 1050 1051 1052 // updated_at 1053 1054 1055 /** 1056 * Gets the time the end-user information was last updated. Corresponds 1057 * to the {@code updated_at} claim. 1058 * 1059 * @return The time the end-user information was last updated, 1060 * {@code null} if not specified. 1061 */ 1062 public Date getUpdatedTime() { 1063 1064 return getDateClaim(UPDATED_AT_CLAIM_NAME); 1065 } 1066 1067 1068 /** 1069 * Sets the time the end-user information was last updated. Corresponds 1070 * to the {@code updated_at} claim. 1071 * 1072 * @param updatedTime The time the end-user information was last 1073 * updated. If {@code null} the claim will be 1074 * removed. 1075 */ 1076 public void setUpdatedTime(final Date updatedTime) { 1077 1078 setDateClaim(UPDATED_AT_CLAIM_NAME, updatedTime); 1079 } 1080 1081 1082 // birthplace 1083 1084 1085 /** 1086 * Gets the birthplace. Corresponds to the {@code birthplace} claim. 1087 * 1088 * @see #getPlaceOfBirth() 1089 * 1090 * @return The birthplace, {@code null} if not specified. 1091 */ 1092 @Deprecated 1093 public Birthplace getBirthplace() { 1094 1095 JSONObject jsonObject = getClaim(BIRTHPLACE_CLAIM_NAME, JSONObject.class); 1096 1097 if (jsonObject == null) { 1098 return null; 1099 } 1100 1101 return new Birthplace(jsonObject); 1102 } 1103 1104 1105 /** 1106 * Sets the birthplace. Corresponds to the {@code birthplace} claim. 1107 * 1108 * @see #setPlaceOfBirth(Birthplace) 1109 * 1110 * @param birthplace The birthplace, {@code null} if not specified. 1111 */ 1112 @Deprecated 1113 public void setBirthplace(final Birthplace birthplace) { 1114 1115 if (birthplace != null) { 1116 setClaim(BIRTHPLACE_CLAIM_NAME, birthplace.toJSONObject()); 1117 } 1118 } 1119 1120 1121 // place_of_birth 1122 1123 1124 /** 1125 * Gets the birthplace. Corresponds to the {@code place_of_birth} claim 1126 * from OpenID Connect for Identity Assurance 1.0. 1127 * 1128 * @return The birthplace, {@code null} if not specified. 1129 */ 1130 public Birthplace getPlaceOfBirth() { 1131 1132 JSONObject jsonObject = getClaim(PLACE_OF_BIRTH_CLAIM_NAME, JSONObject.class); 1133 1134 if (jsonObject == null) { 1135 return null; 1136 } 1137 1138 return new Birthplace(jsonObject); 1139 } 1140 1141 1142 /** 1143 * Sets the birthplace. Corresponds to the {@code place_of_birth} claim 1144 * from OpenID Connect for Identity Assurance 1.0. 1145 * 1146 * @param birthplace The birthplace, {@code null} if not specified. 1147 */ 1148 public void setPlaceOfBirth(final Birthplace birthplace) { 1149 1150 if (birthplace != null) { 1151 setClaim(PLACE_OF_BIRTH_CLAIM_NAME, birthplace.toJSONObject()); 1152 } 1153 } 1154 1155 1156 // nationalities 1157 1158 /** 1159 * Gets the user's nationalities. Corresponds to the 1160 * {@code nationalities} claim from OpenID Connect for Identity 1161 * Assurance 1.0. 1162 * 1163 * @return The nationalities, {@code null} if not specified or parsing 1164 * failed. 1165 */ 1166 public List<CountryCode> getNationalities() { 1167 1168 List<String> values = getStringListClaim(NATIONALITIES_CLAIM_NAME); 1169 1170 if (values == null) { 1171 return null; 1172 } 1173 1174 List<CountryCode> codes = new LinkedList<>(); 1175 for (String v: values) { 1176 if (v != null) { 1177 try { 1178 codes.add(CountryCode.parse(v)); 1179 } catch (ParseException e) { 1180 return null; 1181 } 1182 } 1183 } 1184 return codes; 1185 } 1186 1187 1188 /** 1189 * Sets the user's nationalities. Corresponds to the 1190 * {@code nationalities} claim from OpenID Connect for Identity 1191 * Assurance 1.0. 1192 * 1193 * @param nationalities The nationalities, {@code null} if not 1194 * specified. 1195 */ 1196 public void setNationalities(final List<CountryCode> nationalities) { 1197 1198 List<String> values = null; 1199 1200 if (nationalities != null) { 1201 values = new LinkedList<>(); 1202 for (CountryCode code: nationalities) { 1203 if (code != null) { 1204 values.add(code.getValue()); 1205 } 1206 } 1207 } 1208 1209 setClaim(NATIONALITIES_CLAIM_NAME, values); 1210 } 1211 1212 1213 // birth_family_name 1214 1215 /** 1216 * Gets the birth family name. Corresponds to the 1217 * {@code birth_family_name} claim from OpenID Connect for Identity 1218 * Assurance 1.0, with no language tag. 1219 * 1220 * @return The birth family name, {@code null} if not specified. 1221 */ 1222 public String getBirthFamilyName() { 1223 1224 return getStringClaim(BIRTH_FAMILY_NAME_CLAIM_NAME); 1225 } 1226 1227 1228 /** 1229 * Gets the birth family name. Corresponds to the 1230 * {@code birth_family_name} claim from OpenID Connect for Identity 1231 * Assurance 1.0, with an optional language tag. 1232 * 1233 * @param langTag The language tag of the entry, {@code null} to get 1234 * the non-tagged entry. 1235 * 1236 * @return The birth family name, {@code null} if not specified. 1237 */ 1238 public String getBirthFamilyName(final LangTag langTag) { 1239 1240 return getStringClaim(BIRTH_FAMILY_NAME_CLAIM_NAME, langTag); 1241 } 1242 1243 1244 /** 1245 * Gets the birth family name entries. Correspond to the 1246 * {@code birth_family_name} claim from OpenID Connect for Identity 1247 * Assurance 1.0. 1248 * 1249 * @return The birth family name entries, empty map if none. 1250 */ 1251 public Map<LangTag,String> getBirthFamilyNameEntries() { 1252 1253 return getLangTaggedClaim(BIRTH_FAMILY_NAME_CLAIM_NAME, String.class); 1254 } 1255 1256 1257 /** 1258 * Sets the birth family name. Corresponds to the 1259 * {@code birth_family_name} claim from OpenID Connect for Identity 1260 * Assurance 1.0, with no language tag. 1261 * 1262 * @param birthFamilyName The birth family name, {@code null} if not 1263 * specified. 1264 */ 1265 public void setBirthFamilyName(final String birthFamilyName) { 1266 1267 setClaim(BIRTH_FAMILY_NAME_CLAIM_NAME, birthFamilyName); 1268 } 1269 1270 1271 /** 1272 * Sets the birth family name. Corresponds to the 1273 * {@code birth_family_name} claim from OpenID Connect for Identity 1274 * Assurance 1.0, with an optional language tag. 1275 * 1276 * @param birthFamilyName The birth family name. If {@code null} the 1277 * claim will be removed. 1278 * @param langTag The language tag, {@code null} if not 1279 * specified. 1280 */ 1281 public void setBirthFamilyName(final String birthFamilyName, final LangTag langTag) { 1282 1283 setClaim(BIRTH_FAMILY_NAME_CLAIM_NAME, birthFamilyName, langTag); 1284 } 1285 1286 // birth_given_name 1287 1288 /** 1289 * Gets the birth given name. Corresponds to the 1290 * {@code birth_given_name} claim from OpenID Connect for Identity 1291 * Assurance 1.0, with no language tag. 1292 * 1293 * @return The birth given name, {@code null} if not specified. 1294 */ 1295 public String getBirthGivenName() { 1296 1297 return getStringClaim(BIRTH_GIVEN_NAME_CLAIM_NAME); 1298 } 1299 1300 1301 /** 1302 * Gets the birth given name. Corresponds to the 1303 * {@code birth_given_name} claim from OpenID Connect for Identity 1304 * Assurance 1.0, with an optional language tag. 1305 * 1306 * @param langTag The language tag of the entry, {@code null} to get 1307 * the non-tagged entry. 1308 * 1309 * @return The birth given name, {@code null} if not specified. 1310 */ 1311 public String getBirthGivenName(final LangTag langTag) { 1312 1313 return getStringClaim(BIRTH_GIVEN_NAME_CLAIM_NAME, langTag); 1314 } 1315 1316 1317 /** 1318 * Gets the birth given name entries. Correspond to the 1319 * {@code birth_given_name} claim from OpenID Connect for Identity 1320 * Assurance 1.0. 1321 * 1322 * @return The birth given name entries, empty map if none. 1323 */ 1324 public Map<LangTag,String> getBirthGivenNameEntries() { 1325 1326 return getLangTaggedClaim(BIRTH_GIVEN_NAME_CLAIM_NAME, String.class); 1327 } 1328 1329 1330 /** 1331 * Sets the birth given name. Corresponds to the 1332 * {@code birth_given_name} claim from OpenID Connect for Identity 1333 * Assurance 1.0. 1334 * 1335 * @param birthGivenName The birth given name, {@code null} if not 1336 * specified. 1337 */ 1338 public void setBirthGivenName(final String birthGivenName) { 1339 1340 setClaim(BIRTH_GIVEN_NAME_CLAIM_NAME, birthGivenName); 1341 } 1342 1343 1344 /** 1345 * Sets the birth given name. Corresponds to the 1346 * {@code birth_given_name} claim from OpenID Connect for Identity 1347 * Assurance 1.0, with an optional language tag. 1348 * 1349 * @param birthGivenName The birth given name. If {@code null} the 1350 * claim will be removed. 1351 * @param langTag The language tag, {@code null} if not 1352 * specified. 1353 */ 1354 public void setBirthGivenName(final String birthGivenName, final LangTag langTag) { 1355 1356 setClaim(BIRTH_GIVEN_NAME_CLAIM_NAME, birthGivenName, langTag); 1357 } 1358 1359 1360 // birth_middle_name 1361 1362 1363 /** 1364 * Gets the birth middle name. Corresponds to the 1365 * {@code birth_middle_name} claim from OpenID Connect for Identity 1366 * Assurance 1.0, with no language tag. 1367 * 1368 * @return The birth middle name, {@code null} if not specified. 1369 */ 1370 public String getBirthMiddleName() { 1371 1372 return getStringClaim(BIRTH_MIDDLE_NAME_CLAIM_NAME); 1373 } 1374 1375 1376 /** 1377 * Gets the birth middle name. Corresponds to the 1378 * {@code birth_middle_name} claim from OpenID Connect for Identity 1379 * Assurance 1.0, with an optional language tag. 1380 * 1381 * @param langTag The language tag of the entry, {@code null} to get 1382 * the non-tagged entry. 1383 * 1384 * @return The birth middle name, {@code null} if not specified. 1385 */ 1386 public String getBirthMiddleName(final LangTag langTag) { 1387 1388 return getStringClaim(BIRTH_MIDDLE_NAME_CLAIM_NAME, langTag); 1389 } 1390 1391 1392 /** 1393 * Gets the birth middle name entries. Correspond to the 1394 * {@code birth_middle_name} claim from OpenID Connect for Identity 1395 * Assurance 1.0. 1396 * 1397 * @return The birth middle name entries, empty map if none. 1398 */ 1399 public Map<LangTag,String> getBirthMiddleNameEntries() { 1400 1401 return getLangTaggedClaim(BIRTH_MIDDLE_NAME_CLAIM_NAME, String.class); 1402 } 1403 1404 1405 /** 1406 * Sets the birth middle name. Corresponds to the 1407 * {@code birth_middle_name} claim from OpenID Connect for Identity 1408 * Assurance 1.0. 1409 * 1410 * @param birthMiddleName The birth middle name, {@code null} if not 1411 * specified. 1412 */ 1413 public void setBirthMiddleName(final String birthMiddleName) { 1414 1415 setClaim(BIRTH_MIDDLE_NAME_CLAIM_NAME, birthMiddleName); 1416 } 1417 1418 1419 /** 1420 * Sets the birth middle name. Corresponds to the 1421 * {@code birth_middle_name} claim from OpenID Connect for Identity 1422 * Assurance 1.0, with an optional language tag. 1423 * 1424 * @param birthMiddleName The birth middle name. If {@code null} the 1425 * claim will be removed. 1426 * @param langTag The language tag, {@code null} if not 1427 * specified. 1428 */ 1429 public void setBirthMiddleName(final String birthMiddleName, final LangTag langTag) { 1430 1431 setClaim(BIRTH_MIDDLE_NAME_CLAIM_NAME, birthMiddleName, langTag); 1432 } 1433 1434 1435 // salutation 1436 1437 1438 /** 1439 * Gets the salutation. Corresponds to the {@code salutation} claim 1440 * from OpenID Connect for Identity Assurance 1.0, with no language 1441 * tag. 1442 * 1443 * @return The salutation, {@code null} if not specified. 1444 */ 1445 public String getSalutation() { 1446 1447 return getStringClaim(SALUTATION_CLAIM_NAME); 1448 } 1449 1450 1451 /** 1452 * Gets the salutation. Corresponds to the {@code salutation} claim 1453 * from OpenID Connect for Identity Assurance 1.0, with an optional 1454 * language tag. 1455 * 1456 * @param langTag The language tag of the entry, {@code null} to get 1457 * the non-tagged entry. 1458 * 1459 * @return The salutation, {@code null} if not specified. 1460 */ 1461 public String getSalutation(final LangTag langTag) { 1462 1463 return getStringClaim(SALUTATION_CLAIM_NAME, langTag); 1464 } 1465 1466 1467 /** 1468 * Gets the salutation entries. Correspond to the {@code salutation} 1469 * claim from OpenID Connect for Identity Assurance 1.0. 1470 * 1471 * @return The salutation entries, empty map if none. 1472 */ 1473 public Map<LangTag,String> getSalutationEntries() { 1474 1475 return getLangTaggedClaim(SALUTATION_CLAIM_NAME, String.class); 1476 } 1477 1478 1479 /** 1480 * Sets the salutation. Corresponds to the {@code salutation} claim 1481 * from OpenID Connect for Identity Assurance 1.0. 1482 * 1483 * @param salutation The salutation, {@code null} if not specified. 1484 */ 1485 public void setSalutation(final String salutation) { 1486 1487 setClaim(SALUTATION_CLAIM_NAME, salutation); 1488 } 1489 1490 1491 /** 1492 * Sets the salutation. Corresponds to the {@code salutation} claim 1493 * from OpenID Connect for Identity Assurance 1.0, with an optional 1494 * language tag. 1495 * 1496 * @param salutation The salutation. If {@code null} the claim will be 1497 * removed. 1498 * @param langTag The language tag, {@code null} if not specified. 1499 */ 1500 public void setSalutation(final String salutation, final LangTag langTag) { 1501 1502 setClaim(SALUTATION_CLAIM_NAME, salutation, langTag); 1503 } 1504 1505 1506 // title 1507 1508 1509 /** 1510 * Gets the title. Corresponds to the {@code title} claim from OpenID 1511 * Connect for Identity Assurance 1.0, with no language tag. 1512 * 1513 * @return The salutation, {@code null} if not specified. 1514 */ 1515 public String getTitle() { 1516 1517 return getStringClaim(TITLE_CLAIM_NAME); 1518 } 1519 1520 1521 /** 1522 * Gets the title. Corresponds to the {@code title} claim from OpenID 1523 * Connect for Identity Assurance 1.0, with an optional language tag. 1524 * 1525 * @param langTag The language tag of the entry, {@code null} to get 1526 * the non-tagged entry. 1527 * 1528 * @return The title, {@code null} if not specified. 1529 */ 1530 public String getTitle(final LangTag langTag) { 1531 1532 return getStringClaim(TITLE_CLAIM_NAME, langTag); 1533 } 1534 1535 1536 /** 1537 * Gets the title entries. Correspond to the {@code title} claim from 1538 * OpenID Connect for Identity Assurance 1.0. 1539 * 1540 * @return The title entries, empty map if none. 1541 */ 1542 public Map<LangTag,String> getTitleEntries() { 1543 1544 return getLangTaggedClaim(TITLE_CLAIM_NAME, String.class); 1545 } 1546 1547 1548 /** 1549 * Sets the title. Corresponds to the {@code title} claim from OpenID 1550 * Connect for Identity Assurance 1.0. 1551 * 1552 * @param title The title, {@code null} if not specified. 1553 */ 1554 public void setTitle(final String title) { 1555 1556 setClaim(TITLE_CLAIM_NAME, title); 1557 } 1558 1559 1560 /** 1561 * Sets the title. Corresponds to the {@code title} claim from OpenID 1562 * Connect for Identity Assurance 1.0, with an optional language tag. 1563 * 1564 * @param title The title. If {@code null} the claim will be removed. 1565 * @param langTag The language tag, {@code null} if not specified. 1566 */ 1567 public void setTitle(final String title, final LangTag langTag) { 1568 1569 setClaim(TITLE_CLAIM_NAME, title, langTag); 1570 } 1571}