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

File X509CertificateReferenceIssuerAndSerialQuery.java

 

Coverage histogram

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

Code metrics

0
5
2
1
79
32
3
0.6
2.5
2
1.5

Classes

Class Line # Actions
X509CertificateReferenceIssuerAndSerialQuery 38 5 0% 3 0
1.0100%
 

Contributing tests

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