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.id;
019
020
021import java.net.URI;
022
023import com.nimbusds.oauth2.sdk.id.Audience;
024import com.nimbusds.oauth2.sdk.id.Identifier;
025import net.jcip.annotations.Immutable;
026
027
028/**
029 * Sector identifier.
030 *
031 * <p>Related specifications:
032 *
033 * <ul>
034 *     <li>OpenID Connect Core 1.0, section 8.1.
035 * </ul>
036 */
037@Immutable
038public final class SectorID extends Identifier {
039        
040        
041        private static final long serialVersionUID = -3769967342420085584L;
042        
043        
044        /**
045         * Ensures the specified URI has a {@code https} scheme.
046         *
047         * @param sectorURI The URI. Must have a {@code https} scheme and not
048         *                  be {@code null}.
049         */
050        public static void ensureHTTPScheme(final URI sectorURI) {
051
052                if (! "https".equalsIgnoreCase(sectorURI.getScheme())) {
053                        throw new IllegalArgumentException("The URI must have a https scheme");
054                }
055        }
056
057
058        /**
059         * Ensures the specified URI contains a host component.
060         *
061         * @param sectorURI The URI. Must contain a host component and not be
062         *                  {@code null}.
063         *
064         * @return The host component.
065         */
066        public static String ensureHostComponent(final URI sectorURI) {
067
068                String host = sectorURI.getHost();
069
070                if (host == null) {
071                        throw new IllegalArgumentException("The URI must contain a host component");
072                }
073
074                return host;
075        }
076        
077
078        /**
079         * Creates a new sector identifier for the specified host.
080         *
081         * @param host The host. Must not be empty or {@code null}.
082         */
083        public SectorID(final String host) {
084                super(host);
085        }
086
087
088        /**
089         * Creates a new sector identifier for the specified URI.
090         *
091         * @param sectorURI The sector URI. Must contain a host component and
092         *                  must not be {@code null}.
093         */
094        public SectorID(final URI sectorURI) {
095                super(ensureHostComponent(sectorURI));
096        }
097        
098        
099        /**
100         * Creates a new sector identifier for the specified audience.
101         *
102         * @param audience The audience. Must not be empty or {@code null}.
103         */
104        public SectorID(final Audience audience) {
105                super(audience.getValue());
106        }
107}