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 return value.getRawFragment() == null; 089 090 } 091 092 093 /** 094 * Creates a new issuer identifier with the specified value. 095 * 096 * @param value The issuer identifier value. Must not be {@code null} 097 * or empty string. 098 */ 099 public Issuer(final String value) { 100 101 super(value); 102 } 103 104 105 /** 106 * Creates a new issuer identifier with the specified URI value. 107 * 108 * @param value The URI value. Must not be {@code null}. 109 */ 110 public Issuer(final URI value) { 111 112 super(value.toString()); 113 } 114 115 116 /** 117 * Creates a new issuer identifier with the specified value. 118 * 119 * @param value The value. Must not be {@code null}. 120 */ 121 public Issuer(final Identifier value) { 122 123 super(value.getValue()); 124 } 125 126 127 /** 128 * Checks if this issuer is a valid identifier. This method is 129 * {@code null}-safe. 130 * 131 * @return {@code true} if the value is a valid identifier, else 132 * {@code false}. 133 */ 134 public boolean isValid() { 135 136 return Issuer.isValid(this); 137 } 138 139 140 @Override 141 public boolean equals(final Object object) { 142 143 return object instanceof Issuer && this.toString().equals(object.toString()); 144 } 145}