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.util.Collections;
022import java.util.Date;
023import java.util.HashSet;
024import java.util.Set;
025
026import net.minidev.json.JSONObject;
027
028import com.nimbusds.oauth2.sdk.id.Subject;
029
030
031/**
032 * Common claims set.
033 */
034public abstract class CommonClaimsSet extends ClaimsSet {
035        
036        
037        /**
038         * The subject claim name.
039         */
040        public static final String SUB_CLAIM_NAME = "sub";
041        
042        
043        /**
044         * The issue time claim name.
045         */
046        public static final String IAT_CLAIM_NAME = "iat";
047        
048        
049        /**
050         * The names of the standard top-level claims.
051         */
052        private static final Set<String> STD_CLAIM_NAMES;
053        
054        
055        static {
056                Set<String> claimNames = new HashSet<>(ClaimsSet.getStandardClaimNames());
057                claimNames.add(SUB_CLAIM_NAME);
058                claimNames.add(IAT_CLAIM_NAME);
059                STD_CLAIM_NAMES = Collections.unmodifiableSet(claimNames);
060        }
061        
062        
063        /**
064         * Gets the names of the standard top-level claims.
065         *
066         * @return The names of the standard top-level claims (read-only set).
067         */
068        public static Set<String> getStandardClaimNames() {
069                
070                return STD_CLAIM_NAMES;
071        }
072        
073        
074        /**
075         * Creates a new empty common claims set.
076         */
077        protected CommonClaimsSet() {
078                
079                super();
080        }
081        
082        
083        /**
084         * Creates a new common claims set from the specified JSON object.
085         *
086         * @param jsonObject The JSON object. Must not be {@code null}.
087         */
088        protected CommonClaimsSet(final JSONObject jsonObject) {
089                
090                super(jsonObject);
091        }
092        
093        
094        /**
095         * Gets the subject. Corresponds to the {@code sub} claim.
096         *
097         * @return The subject.
098         */
099        public Subject getSubject() {
100                
101                String val = getStringClaim(SUB_CLAIM_NAME);
102                return val != null ? new Subject(val) : null;
103        }
104        
105        
106        /**
107         * Gets the issue time. Corresponds to the {@code iss} claim.
108         *
109         * @return The issue time, {@code null} if not specified.
110         */
111        public Date getIssueTime() {
112                
113                return getDateClaim(IAT_CLAIM_NAME);
114        }
115}