001package com.nimbusds.openid.connect.sdk.id;
002
003
004import java.net.URI;
005
006import com.nimbusds.oauth2.sdk.id.Identifier;
007import net.jcip.annotations.Immutable;
008
009
010/**
011 * Sector identifier.
012 *
013 * <p>Related specifications:
014 *
015 * <ul>
016 *     <li>OpenID Connect Core 1.0, section 8.1.
017 * </ul>
018 */
019@Immutable
020public final class SectorID extends Identifier {
021
022
023        /**
024         * Ensures the specified URI has a {@code https} scheme.
025         *
026         * @param sectorURI The URI. Must have a {@code https} scheme and not
027         *                  be {@code null}.
028         */
029        public static void ensureHTTPScheme(final URI sectorURI) {
030
031                if (! "https".equalsIgnoreCase(sectorURI.getScheme())) {
032                        throw new IllegalArgumentException("The URI must have a https scheme");
033                }
034        }
035
036
037        /**
038         * Ensures the specified URI contains a host component.
039         *
040         * @param sectorURI The URI. Must contain a host component and not be
041         *                  {@code null}.
042         *
043         * @return The host component.
044         */
045        public static String ensureHostComponent(final URI sectorURI) {
046
047                String host = sectorURI.getHost();
048
049                if (host == null) {
050                        throw new IllegalArgumentException("The URI must contain a host component");
051                }
052
053                return host;
054        }
055        
056
057        /**
058         * Creates a new sector identifier for the specified host.
059         *
060         * @param host The host. Must not be empty or {@code null}.
061         */
062        public SectorID(final String host) {
063                super(host);
064        }
065
066
067        /**
068         * Creates a new sector identifier for the specified URI.
069         *
070         * @param sectorURI The sector URI. Must contain a host component and
071         *                  must not be {@code null}.
072         */
073        public SectorID(final URI sectorURI) {
074                super(ensureHostComponent(sectorURI));
075        }
076}