001package com.nimbusds.openid.connect.sdk; 002 003 004import com.nimbusds.oauth2.sdk.ParseException; 005 006 007/** 008 * Enumeration of the subject identifier types. 009 * 010 * <p>Related specifications: 011 * 012 * <ul> 013 * <li>OpenID Connect Core 1.0, section 8. 014 * </ul> 015 */ 016public enum SubjectType { 017 018 019 /** 020 * Pairwise. 021 */ 022 PAIRWISE, 023 024 025 /** 026 * Public. 027 */ 028 PUBLIC; 029 030 031 /** 032 * Returns the string representation of this subject identifier 033 * type. 034 * 035 * @return The string representation of this subject identifier 036 * type. 037 */ 038 public String toString() { 039 040 return super.toString().toLowerCase(); 041 } 042 043 044 /** 045 * Parses a subject identifier type. 046 * 047 * @param s The string to parse. 048 * 049 * @return The subject identifier type. 050 * 051 * @throws ParseException If the parsed string is {@code null} or 052 * doesn't match a subject identifier type. 053 */ 054 public static SubjectType parse(final String s) 055 throws ParseException { 056 057 if (s == null || s.trim().isEmpty()) 058 throw new ParseException("Null or empty subject type string"); 059 060 switch (s) { 061 case "pairwise": 062 063 return PAIRWISE; 064 065 case "public": 066 067 return PUBLIC; 068 069 default: 070 071 throw new ParseException("Unknown subject type: " + s); 072 } 073 } 074}