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