1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.pkix

File ChainingCertificateProvider.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

8
25
5
1
100
61
9
0.36
5
5
1.8

Classes

Class Line # Actions
ChainingCertificateProvider 35 25 0% 9 18
0.526315852.6%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package org.xwiki.crypto.pkix;
22   
23    import java.math.BigInteger;
24    import java.util.Collection;
25   
26    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
27    import org.xwiki.crypto.pkix.params.PrincipalIndentifier;
28   
29    /**
30    * Chain two or more certificate provider, asking each of them until found for the requested certificate.
31    *
32    * @version $Id: 77a43f57520bac84f947fcc6caf2197d5023cc5b $
33    * @since 6.0RC1
34    */
 
35    public class ChainingCertificateProvider implements CertificateProvider
36    {
37    private final CertificateProvider[] providers;
38   
39    /**
40    * Create a new chaining certificate provider from the given providers.
41    *
42    * @param providers providers to be chained in order.
43    */
 
44  7 toggle public ChainingCertificateProvider(CertificateProvider... providers)
45    {
46  7 this.providers = providers;
47    }
48   
 
49  12 toggle @Override
50    public CertifiedPublicKey getCertificate(byte[] keyIdentifier)
51    {
52  12 CertifiedPublicKey result = null;
53  12 for (CertificateProvider provider : this.providers) {
54  24 result = provider.getCertificate(keyIdentifier);
55  24 if (result != null) {
56  12 break;
57    }
58    }
59  12 return result;
60    }
61   
 
62  6 toggle @Override
63    public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial)
64    {
65  6 CertifiedPublicKey result = null;
66  6 for (CertificateProvider provider : this.providers) {
67  11 result = provider.getCertificate(issuer, serial);
68  11 if (result != null) {
69  6 break;
70    }
71    }
72  6 return result;
73    }
74   
 
75  0 toggle @Override
76    public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial, byte[] keyIdentifier)
77    {
78  0 CertifiedPublicKey result = null;
79  0 for (CertificateProvider provider : this.providers) {
80  0 result = provider.getCertificate(issuer, serial, keyIdentifier);
81  0 if (result != null) {
82  0 break;
83    }
84    }
85  0 return result;
86    }
87   
 
88  0 toggle @Override
89    public Collection<CertifiedPublicKey> getCertificate(PrincipalIndentifier subject)
90    {
91  0 Collection<CertifiedPublicKey> result = null;
92  0 for (CertificateProvider provider : this.providers) {
93  0 result = provider.getCertificate(subject);
94  0 if (result != null) {
95  0 break;
96    }
97    }
98  0 return result;
99    }
100    }