Path: blob/master/src/java.base/share/classes/java/security/DomainLoadStoreParameter.java
41152 views
/*1* Copyright (c) 2013, 2019, 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 java.security;2627import java.net.URI;28import java.util.*;29import static java.security.KeyStore.*;3031/**32* Configuration data that specifies the keystores in a keystore domain.33* A keystore domain is a collection of keystores that are presented as a34* single logical keystore. The configuration data is used during35* {@code KeyStore}36* {@link KeyStore#load(KeyStore.LoadStoreParameter) load} and37* {@link KeyStore#store(KeyStore.LoadStoreParameter) store} operations.38* <p>39* The following syntax is supported for configuration data:40* <pre>{@code41* domain <domainName> [<property> ...] {42* keystore <keystoreName> [<property> ...] ;43* ...44* };45* ...46* }</pre>47* where {@code domainName} and {@code keystoreName} are identifiers48* and {@code property} is a key/value pairing. The key and value are49* separated by an 'equals' symbol and the value is enclosed in double50* quotes. A property value may be either a printable string or a binary51* string of colon-separated pairs of hexadecimal digits. Multi-valued52* properties are represented as a comma-separated list of values,53* enclosed in square brackets.54* See {@link Arrays#toString(java.lang.Object[])}.55* <p>56* To ensure that keystore entries are uniquely identified, each57* entry's alias is prefixed by its {@code keystoreName} followed58* by the entry name separator and each {@code keystoreName} must be59* unique within its domain. Entry name prefixes are omitted when60* storing a keystore.61* <p>62* Properties are context-sensitive: properties that apply to63* all the keystores in a domain are located in the domain clause,64* and properties that apply only to a specific keystore are located65* in that keystore's clause.66* Unless otherwise specified, a property in a keystore clause overrides67* a property of the same name in the domain clause. All property names68* are case-insensitive. The following properties are supported:69* <dl>70* <dt> {@code keystoreType="<type>"} </dt>71* <dd> The keystore type. </dd>72* <dt> {@code keystoreURI="<url>"} </dt>73* <dd> The keystore location. </dd>74* <dt> {@code keystoreProviderName="<name>"} </dt>75* <dd> The name of the keystore's JCE provider. </dd>76* <dt> {@code keystorePasswordEnv="<environment-variable>"} </dt>77* <dd> The environment variable that stores a keystore password.78* Alternatively, passwords may be supplied to the constructor79* method in a {@code Map<String, ProtectionParameter>}. </dd>80* <dt> {@code entryNameSeparator="<separator>"} </dt>81* <dd> The separator between a keystore name prefix and an entry name.82* When specified, it applies to all the entries in a domain.83* Its default value is a space. </dd>84* </dl>85* <p>86* For example, configuration data for a simple keystore domain87* comprising three keystores is shown below:88* <pre>89*90* domain app1 {91* keystore app1-truststore92* keystoreURI="file:///app1/etc/truststore.jks";93*94* keystore system-truststore95* keystoreURI="${java.home}/lib/security/cacerts";96*97* keystore app1-keystore98* keystoreType="PKCS12"99* keystoreURI="file:///app1/etc/keystore.p12";100* };101*102* </pre>103* @since 1.8104*/105public final class DomainLoadStoreParameter implements LoadStoreParameter {106107private final URI configuration;108private final Map<String,ProtectionParameter> protectionParams;109110/**111* Constructs a DomainLoadStoreParameter for a keystore domain with112* the parameters used to protect keystore data.113*114* @param configuration identifier for the domain configuration data.115* The name of the target domain should be specified in the116* {@code java.net.URI} fragment component when it is necessary117* to distinguish between several domain configurations at the118* same location.119*120* @param protectionParams the map from keystore name to the parameter121* used to protect keystore data.122* A {@code java.util.Collections.EMPTY_MAP} should be used123* when protection parameters are not required or when they have124* been specified by properties in the domain configuration data.125* It is cloned to prevent subsequent modification.126*127* @throws NullPointerException if {@code configuration} or128* {@code protectionParams} is {@code null}129*/130public DomainLoadStoreParameter(URI configuration,131Map<String,ProtectionParameter> protectionParams) {132if (configuration == null || protectionParams == null) {133throw new NullPointerException("invalid null input");134}135this.configuration = configuration;136this.protectionParams =137Collections.unmodifiableMap(new HashMap<>(protectionParams));138}139140/**141* Gets the identifier for the domain configuration data.142*143* @return the identifier for the configuration data144*/145public URI getConfiguration() {146return configuration;147}148149/**150* Gets the keystore protection parameters for keystores in this151* domain.152*153* @return an unmodifiable map of keystore names to protection154* parameters155*/156public Map<String,ProtectionParameter> getProtectionParams() {157return protectionParams;158}159160/**161* Gets the keystore protection parameters for this domain.162* Keystore domains do not support a protection parameter.163*164* @return always returns {@code null}165*/166@Override167public KeyStore.ProtectionParameter getProtectionParameter() {168return null;169}170}171172173