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