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;
019
020
021import com.nimbusds.oauth2.sdk.ParseException;
022import com.nimbusds.oauth2.sdk.util.StringUtils;
023
024
025/**
026 * Enumeration of the subject identifier types.
027 *
028 * <p>Related specifications:
029 *
030 * <ul>
031 *     <li>OpenID Connect Core 1.0
032 * </ul>
033 */
034public enum SubjectType {
035
036
037        /**
038         * Pairwise.
039         */
040        PAIRWISE,
041        
042        
043        /**
044         * Public.
045         */
046        PUBLIC;
047        
048        
049        /**
050         * Returns the string representation of this subject identifier 
051         * type.
052         *
053         * @return The string representation of this subject identifier
054         *         type.
055         */
056        public String toString() {
057
058                return super.toString().toLowerCase();
059        }
060
061
062        /**
063         * Parses a subject identifier type.
064         *
065         * @param s The string to parse.
066         *
067         * @return The subject identifier type.
068         *
069         * @throws ParseException If the parsed string is {@code null} or
070         *                        doesn't match a subject identifier type.
071         */
072        public static SubjectType parse(final String s)
073                throws ParseException {
074
075                if (StringUtils.isBlank(s))
076                        throw new ParseException("Null or empty subject type string");
077
078                if ("pairwise".equals(s)) {
079                        return PAIRWISE;
080                } else if ("public".equals(s)) {
081                        return PUBLIC;
082                } else {
083                        throw new ParseException("Unknown subject type: " + s);
084                }
085        }
086}