Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/util/RegisteredDomain.java
38830 views
/*1* Copyright (c) 2017, 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 sun.security.util;2627import java.util.Optional;2829/**30* A domain that is registered under a "public suffix". The public suffix is31* a top-level domain under which names can be registered. For example,32* "com" and "co.uk" are public suffixes, and "example.com" and "example.co.uk"33* are registered domains.34* <p>35* The primary purpose of this class is to determine if domains are safe to36* use in various use-cases.37*/38public interface RegisteredDomain {3940public enum Type {41/**42* An ICANN registered domain.43*/44ICANN,45/**46* A private registered domain.47*/48PRIVATE49}5051/**52* Returns the name of the registered domain.53*54* @return the name of the registered domain55*/56String name();5758/**59* Returns the type of the registered domain.60*61* @return the type of the registered domain62*/63Type type();6465/**66* Returns the public suffix of the registered domain.67*68* @return the public suffix of the registered domain69*/70String publicSuffix();7172/**73* Returns an {@code Optional<RegisteredDomain>} representing the74* registered part of the specified domain.75*76* {@implNote}77* The default implementation is based on the legacy78* {@code sun.net.RegisteredDomain} class which is no longer maintained.79* It should be updated or replaced with an appropriate implementation.80*81* @param domain the domain name82* @return an {@code Optional<RegisteredDomain>}; the {@code Optional} is83* empty if the domain is unknown or not registerable84* @throws NullPointerException if domain is null85*/86public static Optional<RegisteredDomain> from(String domain) {87if (domain == null) {88throw new NullPointerException();89}90return Optional.ofNullable(sun.net.RegisteredDomain.registeredDomain(domain));91}92}939495