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

File X509CertificateIssuerAndSerialQuery.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
5
2
1
83
34
3
0.6
2.5
2
1.5

Classes

Class Line # Actions
X509CertificateIssuerAndSerialQuery 40 5 0% 3 1
0.8571428785.7%
 

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.query;
21   
22    import java.math.BigInteger;
23   
24    import org.xwiki.crypto.BinaryStringEncoder;
25    import org.xwiki.crypto.pkix.CertificateFactory;
26    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
27    import org.xwiki.crypto.pkix.params.PrincipalIndentifier;
28    import org.xwiki.crypto.store.CertificateStoreException;
29    import org.xwiki.crypto.store.wiki.internal.X509CertificateWikiStore;
30    import org.xwiki.model.reference.EntityReference;
31    import org.xwiki.model.reference.EntityReferenceSerializer;
32    import org.xwiki.query.QueryManager;
33   
34    /**
35    * Query certificates in a certificate store based on issuer and serial number.
36    *
37    * @version $Id: 678ee781e196fa0cc3cbcfd84ad14d75007ef33f $
38    * @since 6.1M2
39    */
 
40    public class X509CertificateIssuerAndSerialQuery extends AbstractX509IssuerAndSerialQuery
41    {
42    private static final String SELECT_STATEMENT =
43    "select obj." + X509CertificateWikiStore.CERTIFICATECLASS_PROP_CERTIFICATE;
44   
45    private static final String FROM_STATEMENT = ", doc.object("
46    + X509CertificateWikiStore.CERTIFICATECLASS_FULLNAME + ") obj";
47   
48    private final CertificateFactory factory;
49   
50    /**
51    * Create a query selecting a certificate matching the given issuer and serial number in a given store.
52    *
53    * @param store the reference of a document or a space where the certificate should be stored.
54    * @param factory a certificate factory used to convert byte arrays to certificate.
55    * @param encoder a string encoder/decoder used to convert byte arrays to/from String.
56    * @param queryManager the query manager used to build queries.
57    * @param serializer the entity reference serializer to serialize the store reference for query
58    * @throws CertificateStoreException on error creating required queries.
59    */
 
60  6 toggle public X509CertificateIssuerAndSerialQuery(EntityReference store, CertificateFactory factory,
61    BinaryStringEncoder encoder, QueryManager queryManager, EntityReferenceSerializer<String> serializer)
62    throws CertificateStoreException
63    {
64  6 super(store, SELECT_STATEMENT, FROM_STATEMENT, "", encoder, queryManager, serializer);
65  6 this.factory = factory;
66    }
67   
68    /**
69    * Get matching certificate.
70    *
71    * @param issuer the issuer to match.
72    * @param serial the serial number to match.
73    * @return a matching certificate, or null if none were found.
74    */
 
75  2 toggle public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial)
76    {
77  2 try {
78  2 return this.factory.decode(getEncoder().decode(this.<String>execute(issuer, serial).get(0)));
79    } catch (Exception e) {
80  0 return null;
81    }
82    }
83    }