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

File X509CertificateReferenceKeyIdentifierQuery.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
5
2
1
75
30
3
0.6
2.5
2
1.5

Classes

Class Line # Actions
X509CertificateReferenceKeyIdentifierQuery 35 5 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 14 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.store.CertificateStoreException;
24    import org.xwiki.crypto.store.wiki.internal.X509CertificateWikiStore;
25    import org.xwiki.model.reference.EntityReference;
26    import org.xwiki.model.reference.EntityReferenceSerializer;
27    import org.xwiki.query.QueryManager;
28   
29    /**
30    * Query reference to object containing a certificate in a certificate store based on issuer and serial number.
31    *
32    * @version $Id: 9e473f04a04408f527d926970102782548c2b3f2 $
33    * @since 6.1M2
34    */
 
35    public class X509CertificateReferenceKeyIdentifierQuery extends AbstractX509KeyIdentifierQuery
36    {
37    private static final String SELECT_STATEMENT = "select doc.fullName, obj.number";
38   
39    private static final String FROM_STATEMENT = ", doc.object("
40    + X509CertificateWikiStore.CERTIFICATECLASS_FULLNAME + ") obj";
41   
42    /**
43    * Create a query selecting a certificate matching a given subject key identifier in a given store.
44    *
45    * @param store the reference of a document or a space where the certificate should be stored.
46    * @param encoder a string encoder/decoder used to convert byte arrays to/from String.
47    * @param queryManager the query manager used to build queries.
48    * @param serializer the entity reference serializer to serialize the store reference for query
49    * @throws CertificateStoreException on error creating required queries.
50    */
 
51  14 toggle public X509CertificateReferenceKeyIdentifierQuery(EntityReference store, BinaryStringEncoder encoder,
52    QueryManager queryManager, EntityReferenceSerializer<String> serializer) throws CertificateStoreException
53    {
54  14 super(store, SELECT_STATEMENT, FROM_STATEMENT, "", encoder, queryManager, serializer);
55    }
56   
57    /**
58    * Get reference to the object containing a matching certificate.
59    *
60    * @param keyIdentifier the subject key identifier to match.
61    * @return a matching certificate, or null if none were found.
62    */
 
63  14 toggle public CertificateObjectReference getReference(byte[] keyIdentifier)
64    {
65  14 try {
66  14 Object[] result = this.<Object[]>execute(keyIdentifier).get(0);
67  8 return new CertificateObjectReference(
68    (String) result[0],
69    (int) result[1]
70    );
71    } catch (Exception e) {
72  6 return null;
73    }
74    }
75    }