001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2026, 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 *     <li>OpenID Connect Ephermeral Subject Identifier 1.0
033 * </ul>
034 */
035public enum SubjectType {
036
037
038        /**
039         * Pairwise.
040         */
041        PAIRWISE,
042        
043        
044        /**
045         * Public.
046         */
047        PUBLIC,
048
049
050        /**
051         * Ephemeral.
052         */
053        EPHEMERAL;
054        
055        
056        /**
057         * Returns the string representation of this subject identifier 
058         * type.
059         *
060         * @return The string representation of this subject identifier
061         *         type.
062         */
063        public String toString() {
064
065                return super.toString().toLowerCase();
066        }
067
068
069        /**
070         * Parses a subject identifier type.
071         *
072         * @param s The string to parse.
073         *
074         * @return The subject identifier type.
075         *
076         * @throws ParseException If the parsed string is {@code null} or
077         *                        doesn't match a subject identifier type.
078         */
079        public static SubjectType parse(final String s)
080                throws ParseException {
081
082                if (StringUtils.isBlank(s))
083                        throw new ParseException("Null or empty subject type string");
084
085                switch (s) {
086                        case "pairwise":
087                                return PAIRWISE;
088                        case "public":
089                                return PUBLIC;
090                        case "ephemeral":
091                                return EPHEMERAL;
092                        default:
093                                throw new ParseException("Unknown subject type: " + s);
094                }
095        }
096}