All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tencent.kona.sun.security.provider.certpath.CollectionCertStore Maven / Gradle / Ivy

Go to download

A Java security provider for supporting ShangMi algorithms in public key infrastructure

There is a newer version: 1.0.15
Show newest version
/*
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package com.tencent.kona.sun.security.provider.certpath;

import java.security.InvalidAlgorithmParameterException;
import java.security.cert.Certificate;
import java.security.cert.CRL;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.HashSet;
import java.security.cert.CertSelector;
import java.security.cert.CertStore;
import java.security.cert.CertStoreException;
import java.security.cert.CertStoreParameters;
import java.security.cert.CollectionCertStoreParameters;
import java.security.cert.CRLSelector;
import java.security.cert.CertStoreSpi;

/**
 * A CertStore that retrieves Certificates and
 * CRLs from a Collection.
 * 

* Before calling the {@link #engineGetCertificates engineGetCertificates} or * {@link #engineGetCRLs engineGetCRLs} methods, the * {@link #CollectionCertStore(CertStoreParameters) * CollectionCertStore(CertStoreParameters)} constructor is called to * create the CertStore and establish the * Collection from which Certificates and * CRLs will be retrieved. If the specified * Collection contains an object that is not a * Certificate or CRL, that object will be * ignored. *

* Concurrent Access *

* As described in the javadoc for CertStoreSpi, the * engineGetCertificates and engineGetCRLs methods * must be thread-safe. That is, multiple threads may concurrently * invoke these methods on a single CollectionCertStore * object (or more than one) with no ill effects. *

* This is achieved by requiring that the Collection passed to * the {@link #CollectionCertStore(CertStoreParameters) * CollectionCertStore(CertStoreParameters)} constructor (via the * CollectionCertStoreParameters object) must have fail-fast * iterators. Simultaneous modifications to the Collection can thus be * detected and certificate or CRL retrieval can be retried. The fact that * Certificates and CRLs must be thread-safe is also * essential. * * @see java.security.cert.CertStore * * @since 1.4 * @author Steve Hanna */ public class CollectionCertStore extends CertStoreSpi { private Collection coll; /** * Creates a CertStore with the specified parameters. * For this class, the parameters object must be an instance of * CollectionCertStoreParameters. The Collection * included in the CollectionCertStoreParameters object * must be thread-safe. * * @param params the algorithm parameters * @exception InvalidAlgorithmParameterException if params is not an * instance of CollectionCertStoreParameters */ public CollectionCertStore(CertStoreParameters params) throws InvalidAlgorithmParameterException { super(params); if (!(params instanceof CollectionCertStoreParameters)) throw new InvalidAlgorithmParameterException( "parameters must be CollectionCertStoreParameters"); coll = ((CollectionCertStoreParameters) params).getCollection(); } /** * Returns a Collection of Certificates that * match the specified selector. If no Certificates * match the selector, an empty Collection will be returned. * * @param selector a CertSelector used to select which * Certificates should be returned. Specify null * to return all Certificates. * @return a Collection of Certificates that * match the specified selector * @throws CertStoreException if an exception occurs */ @Override public Collection engineGetCertificates (CertSelector selector) throws CertStoreException { if (coll == null) { throw new CertStoreException("Collection is null"); } // Tolerate a few ConcurrentModificationExceptions for (int c = 0; c < 10; c++) { try { HashSet result = new HashSet<>(); if (selector != null) { for (Object o : coll) { if ((o instanceof Certificate) && selector.match((Certificate) o)) result.add((Certificate)o); } } else { for (Object o : coll) { if (o instanceof Certificate) result.add((Certificate)o); } } return(result); } catch (ConcurrentModificationException e) { } } throw new ConcurrentModificationException("Too many " + "ConcurrentModificationExceptions"); } /** * Returns a Collection of CRLs that * match the specified selector. If no CRLs * match the selector, an empty Collection will be returned. * * @param selector a CRLSelector used to select which * CRLs should be returned. Specify null * to return all CRLs. * @return a Collection of CRLs that * match the specified selector * @throws CertStoreException if an exception occurs */ @Override public Collection engineGetCRLs(CRLSelector selector) throws CertStoreException { if (coll == null) throw new CertStoreException("Collection is null"); // Tolerate a few ConcurrentModificationExceptions for (int c = 0; c < 10; c++) { try { HashSet result = new HashSet<>(); if (selector != null) { for (Object o : coll) { if ((o instanceof CRL) && selector.match((CRL) o)) result.add((CRL)o); } } else { for (Object o : coll) { if (o instanceof CRL) result.add((CRL)o); } } return result; } catch (ConcurrentModificationException e) { } } throw new ConcurrentModificationException("Too many " + "ConcurrentModificationExceptions"); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy