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

File X509CertificateQuery.java

 

Coverage histogram

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

Code metrics

0
8
2
1
88
39
4
0.5
4
2
2

Classes

Class Line # Actions
X509CertificateQuery 40 8 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 2 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.util.ArrayList;
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.params.CertifiedPublicKey;
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 all certificates in a certificate store.
36    *
37    * @version $Id: 1ba8059fd6c70664c64470423bc126d254e1ba24 $
38    * @since 6.1M2
39    */
 
40    public class X509CertificateQuery extends AbstractX509StoreQuery
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 a given subject key identifier 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  2 toggle public X509CertificateQuery(EntityReference store, CertificateFactory factory, BinaryStringEncoder encoder,
61    QueryManager queryManager, EntityReferenceSerializer<String> serializer) throws CertificateStoreException
62    {
63  2 super(store, SELECT_STATEMENT, FROM_STATEMENT, "", encoder, queryManager, serializer);
64  2 this.factory = factory;
65    }
66   
67    /**
68    * Get all certificates.
69    *
70    * @return all certificates from the store, or an empty list if none were found.
71    */
 
72  2 toggle public Collection<CertifiedPublicKey> getCertificates()
73    {
74  2 Collection<CertifiedPublicKey> result = new ArrayList<CertifiedPublicKey>();
75  2 try {
76  2 for (String cert : this.<String>execute()) {
77  4 try {
78  4 result.add(this.factory.decode(getEncoder().decode(cert)));
79    } catch (Exception e) {
80    // Ignored
81    }
82    }
83    } catch (Exception e) {
84    // Ignored
85    }
86  2 return result;
87    }
88    }