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

File X509CertificateKeyIdentifierQuery.java

 

Coverage histogram

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

Code metrics

0
5
2
1
80
32
3
0.6
2.5
2
1.5

Classes

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