src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/storage/implementations/SingleCertificateResolver.java
author weijun
Tue, 19 Jun 2018 08:06:35 +0800
changeset 50614 3810c9a2efa1
parent 47216 71c04702a3d5
permissions -rw-r--r--
8177334: Update xmldsig implementation to Apache Santuario 2.1.1 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    12
 * with the License. You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    21
 * under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.security.keys.storage.implementations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    25
import java.security.cert.Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Iterator;
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    28
import java.util.NoSuchElementException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This {@link StorageResolverSpi} makes a single {@link X509Certificate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * available to the {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class SingleCertificateResolver extends StorageResolverSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    38
    /** Field certificate */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    39
    private X509Certificate certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    41
    /**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    42
     * @param x509cert the single {@link X509Certificate}
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    43
     */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    44
    public SingleCertificateResolver(X509Certificate x509cert) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    45
        this.certificate = x509cert;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    46
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    48
    /** {@inheritDoc} */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    49
    public Iterator<Certificate> getIterator() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    50
        return new InternalIterator(this.certificate);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    51
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    53
    /**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    54
     * Class InternalIterator
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    55
     */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    56
    static class InternalIterator implements Iterator<Certificate> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    58
        /** Field alreadyReturned */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    59
        boolean alreadyReturned = false;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    60
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    61
        /** Field certificate */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    62
        X509Certificate certificate = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    64
        /**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    65
         * Constructor InternalIterator
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    66
         *
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    67
         * @param x509cert
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    68
         */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    69
        public InternalIterator(X509Certificate x509cert) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    70
            this.certificate = x509cert;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    71
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    73
        /** {@inheritDoc} */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    74
        public boolean hasNext() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    75
            return !this.alreadyReturned;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    76
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    78
        /** {@inheritDoc} */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    79
        public Certificate next() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    80
            if (this.alreadyReturned) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    81
                throw new NoSuchElementException();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    82
            }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    83
            this.alreadyReturned = true;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    84
            return this.certificate;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    85
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    87
        /**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    88
         * Method remove
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    89
         */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    90
        public void remove() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    91
            throw new UnsupportedOperationException("Can't remove keys from KeyStore");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    92
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 10694
diff changeset
    93
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}