jdk/src/java.base/share/classes/java/security/cert/CollectionCertStoreParameters.java
author ascarpino
Mon, 19 Oct 2015 17:35:18 -0700
changeset 33241 27eb2d6abda9
parent 25859 3317bb8137f4
permissions -rw-r--r--
8133151: Preferred provider configuration for JCE Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    33
 * Parameters used as input for the Collection {@code CertStore}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class is used to provide necessary configuration parameters
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    37
 * to implementations of the Collection {@code CertStore}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * algorithm. The only parameter included in this class is the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    39
 * {@code Collection} from which the {@code CertStore} will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * retrieve certificates and CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Unless otherwise specified, the methods defined in this class are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * thread-safe. Multiple threads that need to access a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * object concurrently should synchronize amongst themselves and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * provide the necessary locking. Multiple threads each manipulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * separate objects need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author      Steve Hanna
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see         java.util.Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see         CertStore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class CollectionCertStoreParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    implements CertStoreParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private Collection<?> coll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    61
     * Creates an instance of {@code CollectionCertStoreParameters}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * which will allow certificates and CRLs to be retrieved from the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    63
     * specified {@code Collection}. If the specified
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    64
     * {@code Collection} contains an object that is not a
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    65
     * {@code Certificate} or {@code CRL}, that object will be
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    66
     * ignored by the Collection {@code CertStore}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <p>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    68
     * The {@code Collection} is <b>not</b> copied. Instead, a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * reference is used. This allows the caller to subsequently add or
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    70
     * remove {@code Certificates} or {@code CRL}s from the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    71
     * {@code Collection}, thus changing the set of
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    72
     * {@code Certificates} or {@code CRL}s available to the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    73
     * Collection {@code CertStore}. The Collection {@code CertStore}
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    74
     * will not modify the contents of the {@code Collection}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    76
     * If the {@code Collection} will be modified by one thread while
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    77
     * another thread is calling a method of a Collection {@code CertStore}
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    78
     * that has been initialized with this {@code Collection}, the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    79
     * {@code Collection} must have fail-fast iterators.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    81
     * @param collection a {@code Collection} of
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    82
     *        {@code Certificate}s and {@code CRL}s
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    83
     * @exception NullPointerException if {@code collection} is
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    84
     * {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public CollectionCertStoreParameters(Collection<?> collection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (collection == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        coll = collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    93
     * Creates an instance of {@code CollectionCertStoreParameters} with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * the default parameter values (an empty and immutable
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    95
     * {@code Collection}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public CollectionCertStoreParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        coll = Collections.EMPTY_SET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   102
     * Returns the {@code Collection} from which {@code Certificate}s
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   103
     * and {@code CRL}s are retrieved. This is <b>not</b> a copy of the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   104
     * {@code Collection}, it is a reference. This allows the caller to
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   105
     * subsequently add or remove {@code Certificates} or
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   106
     * {@code CRL}s from the {@code Collection}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   108
     * @return the {@code Collection} (never null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public Collection<?> getCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return coll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns a copy of this object. Note that only a reference to the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   116
     * {@code Collection} is copied, and not the contents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            /* Cannot happen */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   125
            throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns a formatted string describing the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @return a formatted string describing the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 18551
diff changeset
   135
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        sb.append("CollectionCertStoreParameters: [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        sb.append("  collection: " + coll + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        sb.append("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}