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

File X509CertificateProvider.java

 

Coverage histogram

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

Code metrics

2
10
5
1
99
54
6
0.6
2
5
1.2

Classes

Class Line # Actions
X509CertificateProvider 44 10 0% 6 7
0.588235358.8%
 

Contributing tests

This file is covered by 6 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    package org.xwiki.crypto.store.wiki.internal;
21   
22    import java.math.BigInteger;
23    import java.util.Collection;
24   
25    import org.xwiki.crypto.BinaryStringEncoder;
26    import org.xwiki.crypto.pkix.CertificateFactory;
27    import org.xwiki.crypto.pkix.CertificateProvider;
28    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
29    import org.xwiki.crypto.pkix.params.PrincipalIndentifier;
30    import org.xwiki.crypto.store.CertificateStoreException;
31    import org.xwiki.crypto.store.wiki.internal.query.X509CertificateIssuerAndSerialQuery;
32    import org.xwiki.crypto.store.wiki.internal.query.X509CertificateKeyIdentifierQuery;
33    import org.xwiki.crypto.store.wiki.internal.query.X509CertificateSubjectQuery;
34    import org.xwiki.model.reference.EntityReference;
35    import org.xwiki.model.reference.EntityReferenceSerializer;
36    import org.xwiki.query.QueryManager;
37   
38    /**
39    * Abstract class to build xwiki based certificate provider.
40    *
41    * @version $Id: f3cdd6466a0cd9577a45a822f07f45c19b9ac4d2 $
42    * @since 6.1M2
43    */
 
44    public class X509CertificateProvider implements CertificateProvider
45    {
46    private final X509CertificateKeyIdentifierQuery keyIdentifierQuery;
47   
48    private final X509CertificateIssuerAndSerialQuery issuerAndSerialQuery;
49   
50    private final X509CertificateSubjectQuery subjectQuery;
51   
52    /**
53    * Create a provider that implement the {@link CertificateProvider} interface.
54    *
55    * @param store the reference of a document or a space where the certificate should be stored.
56    * @param factory a certificate factory used to convert byte arrays to certificate.
57    * @param encoder a string encoder/decoder used to convert byte arrays to/from String.
58    * @param queryManager the query manager used to build queries.
59    * @param serializer the entity reference serializer to serialize the store reference for query
60    * @throws CertificateStoreException on error creating required queries.
61    */
 
62  6 toggle protected X509CertificateProvider(EntityReference store, CertificateFactory factory, BinaryStringEncoder encoder,
63    QueryManager queryManager, EntityReferenceSerializer<String> serializer) throws CertificateStoreException
64    {
65  6 this.keyIdentifierQuery =
66    new X509CertificateKeyIdentifierQuery(store, factory, encoder, queryManager, serializer);
67  6 this.issuerAndSerialQuery =
68    new X509CertificateIssuerAndSerialQuery(store, factory, encoder, queryManager, serializer);
69  6 this.subjectQuery = new X509CertificateSubjectQuery(store, factory, encoder, queryManager, serializer);
70    }
71   
 
72  2 toggle @Override
73    public CertifiedPublicKey getCertificate(byte[] keyIdentifier)
74    {
75  2 return this.keyIdentifierQuery.getCertificate(keyIdentifier);
76    }
77   
 
78  2 toggle @Override
79    public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial)
80    {
81  2 return this.issuerAndSerialQuery.getCertificate(issuer, serial);
82    }
83   
 
84  0 toggle @Override
85    public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial, byte[] keyIdentifier)
86    {
87  0 CertifiedPublicKey certificate = getCertificate(keyIdentifier);
88  0 if (certificate == null) {
89  0 certificate = getCertificate(issuer, serial);
90    }
91  0 return certificate;
92    }
93   
 
94  2 toggle @Override
95    public Collection<CertifiedPublicKey> getCertificate(PrincipalIndentifier subject)
96    {
97  2 return this.subjectQuery.getCertificates(subject);
98    }
99    }