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