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