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

File X509CertificateSubjectQuery.java

 

Coverage histogram

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

Code metrics

0
8
2
1
90
40
4
0.5
4
2
2

Classes

Class Line # Actions
X509CertificateSubjectQuery 41 8 0% 4 0
1.0100%
 

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.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.pkix.params.PrincipalIndentifier;
29    import org.xwiki.crypto.store.CertificateStoreException;
30    import org.xwiki.crypto.store.wiki.internal.X509CertificateWikiStore;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.model.reference.EntityReferenceSerializer;
33    import org.xwiki.query.QueryManager;
34   
35    /**
36    * Query certificates in a certificate store based on subject.
37    *
38    * @version $Id: 6e6d212c6d36ac43ee74533d00ccaaef731d1c6d $
39    * @since 6.1M2
40    */
 
41    public class X509CertificateSubjectQuery extends AbstractX509SubjectQuery
42    {
43    private static final String SELECT_STATEMENT =
44    "select obj." + X509CertificateWikiStore.CERTIFICATECLASS_PROP_CERTIFICATE;
45   
46    private static final String FROM_STATEMENT = ", doc.object("
47    + X509CertificateWikiStore.CERTIFICATECLASS_FULLNAME + ") obj";
48   
49    private final CertificateFactory factory;
50   
51    /**
52    * Create a query selecting certificates matching a given subject from a given store.
53    *
54    * @param store the reference of a document or a space where the certificate should be stored.
55    * @param factory a certificate factory used to convert byte arrays to certificate.
56    * @param encoder a string encoder/decoder used to convert byte arrays to/from String.
57    * @param queryManager the query manager used to build queries.
58    * @param serializer the entity reference serializer to serialize the store reference for query
59    * @throws CertificateStoreException on error creating required queries.
60    */
 
61  6 toggle public X509CertificateSubjectQuery(EntityReference store, CertificateFactory factory, BinaryStringEncoder encoder,
62    QueryManager queryManager, EntityReferenceSerializer<String> serializer) 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 certificates.
70    *
71    * @param subject the subject to match.
72    * @return matching certificates, or an empty list if none were found.
73    */
 
74  2 toggle public Collection<CertifiedPublicKey> getCertificates(PrincipalIndentifier subject)
75    {
76  2 Collection<CertifiedPublicKey> result = new ArrayList<CertifiedPublicKey>();
77  2 try {
78  2 for (String cert : this.<String>execute(subject)) {
79  4 try {
80  4 result.add(this.factory.decode(getEncoder().decode(cert)));
81    } catch (Exception e) {
82    // Ignored
83    }
84    }
85    } catch (Exception e) {
86    // Ignored
87    }
88  2 return result;
89    }
90    }