Path: blob/master/test/jdk/javax/net/ssl/TLSCommon/interop/UseCase.java
41154 views
/*1* Copyright (c) 2020, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.Collections;24import java.util.HashMap;25import java.util.Map;2627/*28* A set of specific SSL/TLS communication parameters on a peer.29*/30public class UseCase {3132// The tuple for trusted CAs and certificates.33private CertTuple certTuple;3435// The supported SSL/TLS protocols.36private Protocol[] protocols;3738// The supported cipher suites.39private CipherSuite[] cipherSuites;4041// If require client authentication.42private boolean clientAuth;4344public static UseCase newInstance() {45return new UseCase();46}4748public CertTuple getCertTuple() {49return certTuple;50}5152public UseCase setCertTuple(CertTuple certTuple) {53this.certTuple = certTuple;54return this;55}5657public Protocol[] getProtocols() {58return protocols;59}6061public Protocol getProtocol() {62return protocols != null && protocols.length > 063? protocols[0]64: null;65}6667public UseCase setProtocols(Protocol... protocols) {68this.protocols = protocols;69return this;70}7172public CipherSuite[] getCipherSuites() {73return cipherSuites;74}7576public CipherSuite getCipherSuite() {77return cipherSuites != null && cipherSuites.length > 078? cipherSuites[0]79: null;80}8182public UseCase setCipherSuites(CipherSuite... cipherSuites) {83this.cipherSuites = cipherSuites;84return this;85}8687public boolean isClientAuth() {88return clientAuth;89}9091public UseCase setClientAuth(boolean clientAuth) {92this.clientAuth = clientAuth;93return this;94}9596// The system properties used by a JDK peer.97private final Map<String, String> props = new HashMap<>();9899public UseCase addProp(String prop, String value) {100props.put(prop, value);101return this;102}103104public String getProp(String prop) {105return props.get(prop);106}107108public UseCase addAllProps(Map<String, String> props) {109this.props.putAll(props);110return this;111}112113public Map<String, String> getAllProps() {114return Collections.unmodifiableMap(props);115}116117public UseCase removeProp(String prop) {118props.remove(prop);119return this;120}121122public UseCase removeAllProps() {123props.clear();124return this;125}126127@Override128public String toString() {129return Utilities.join(Utilities.PARAM_DELIMITER,130"certTuple=[" + certTuple + "]",131Utilities.joinNameValue("protocols", Utilities.join(protocols)),132Utilities.joinNameValue("cipherSuites", Utilities.join(cipherSuites)),133Utilities.joinNameValue("clientAuth", clientAuth ? "true" : ""));134}135}136137138