001package com.nimbusds.oauth2.sdk.id; 002 003 004import java.net.URI; 005import java.net.URISyntaxException; 006 007import net.jcip.annotations.Immutable; 008 009 010/** 011 * Issuer identifier. 012 * 013 * <p>Valid issuer identifiers are URIs with "https" schema and no query or 014 * fragment component. 015 */ 016@Immutable 017public final class Issuer extends Identifier { 018 019 020 /** 021 * Checks if the specified string represents a valid issuer identifier. 022 * This method is {@code null}-safe. 023 * 024 * @param value The issuer string. 025 * 026 * @return {@code true} if the string represents a valid issuer 027 * identifier, else {@code false}. 028 */ 029 public static boolean isValid(final String value) { 030 031 if (value == null) 032 return false; 033 034 try { 035 return isValid(new URI(value)); 036 037 } catch (URISyntaxException e) { 038 039 return false; 040 } 041 } 042 043 044 /** 045 * Checks if the specified issuer is a valid identifier. This method is 046 * {@code null}-safe. 047 * 048 * @param value The issuer. 049 * 050 * @return {@code true} if the value is a valid identifier, else 051 * {@code false}. 052 */ 053 public static boolean isValid(final Issuer value) { 054 055 if (value == null) 056 return false; 057 058 try { 059 return isValid(new URI(value.getValue())); 060 061 } catch (URISyntaxException e) { 062 063 return false; 064 } 065 } 066 067 068 /** 069 * Checks if the specified URI represents a valid issuer identifier. 070 * This method is {@code null}-safe. 071 * 072 * @param value The URI. 073 * 074 * @return {@code true} if the values represents a valid issuer 075 * identifier, else {@code false}. 076 */ 077 public static boolean isValid(final URI value) { 078 079 if (value == null) 080 return false; 081 082 if (value.getScheme() == null || ! value.getScheme().equalsIgnoreCase("https")) 083 return false; 084 085 if (value.getRawQuery() != null) 086 return false; 087 088 if (value.getRawFragment() != null) 089 return false; 090 091 return true; 092 } 093 094 095 /** 096 * Creates a new issuer identifier with the specified value. 097 * 098 * @param value The issuer identifier value. Must not be {@code null} 099 * or empty string. 100 */ 101 public Issuer(final String value) { 102 103 super(value); 104 } 105 106 107 /** 108 * Creates a new issuer identifier with the specified URI value. 109 * 110 * @param value The URI value. Must not be {@code null}. 111 */ 112 public Issuer(final URI value) { 113 114 super(value.toString()); 115 } 116 117 118 /** 119 * Creates a new issuer identifier with the specified value. 120 * 121 * @param value The value. Must not be {@code null}. 122 */ 123 public Issuer(final Identifier value) { 124 125 super(value.getValue()); 126 } 127 128 129 /** 130 * Checks if this issuer is a valid identifier. This method is 131 * {@code null}-safe. 132 * 133 * @return {@code true} if the value is a valid identifier, else 134 * {@code false}. 135 */ 136 public boolean isValid() { 137 138 return Issuer.isValid(this); 139 } 140 141 142 @Override 143 public boolean equals(final Object object) { 144 145 return object instanceof Issuer && this.toString().equals(object.toString()); 146 } 147}