Path: blob/master/src/java.base/share/classes/javax/net/ssl/SNIMatcher.java
41159 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.net.ssl;2627/**28* Instances of this class represent a matcher that performs match29* operations on an {@link SNIServerName} instance.30* <P>31* Servers can use Server Name Indication (SNI) information to decide if32* specific {@link SSLSocket} or {@link SSLEngine} instances should accept33* a connection. For example, when multiple "virtual" or "name-based"34* servers are hosted on a single underlying network address, the server35* application can use SNI information to determine whether this server is36* the exact server that the client wants to access. Instances of this37* class can be used by a server to verify the acceptable server names of38* a particular type, such as host names.39* <P>40* {@code SNIMatcher} objects are immutable. Subclasses should not provide41* methods that can change the state of an instance once it has been created.42*43* @see SNIServerName44* @see SNIHostName45* @see SSLParameters#getSNIMatchers()46* @see SSLParameters#setSNIMatchers(Collection)47*48* @since 1.849*/50public abstract class SNIMatcher {5152// the type of the server name that this matcher performs on53private final int type;5455/**56* Creates an {@code SNIMatcher} using the specified server name type.57*58* @param type59* the type of the server name that this matcher performs on60*61* @throws IllegalArgumentException if {@code type} is not in the range62* of 0 to 255, inclusive.63*/64protected SNIMatcher(int type) {65if (type < 0) {66throw new IllegalArgumentException(67"Server name type cannot be less than zero");68} else if (type > 255) {69throw new IllegalArgumentException(70"Server name type cannot be greater than 255");71}7273this.type = type;74}7576/**77* Returns the server name type of this {@code SNIMatcher} object.78*79* @return the server name type of this {@code SNIMatcher} object.80*81* @see SNIServerName82*/83public final int getType() {84return type;85}8687/**88* Attempts to match the given {@link SNIServerName}.89*90* @param serverName91* the {@link SNIServerName} instance on which this matcher92* performs match operations93*94* @return {@code true} if, and only if, the matcher matches the95* given {@code serverName}96*97* @throws NullPointerException if {@code serverName} is {@code null}98* @throws IllegalArgumentException if {@code serverName} is99* not of the given server name type of this matcher100*101* @see SNIServerName102*/103public abstract boolean matches(SNIServerName serverName);104}105106107