1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.crypto.store.wiki.internal

File X509CertificateWikiStore.java

 

Coverage histogram

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

Code metrics

0
6
3
1
136
52
4
0.67
2
3
1.33

Classes

Class Line # Actions
X509CertificateWikiStore 48 6 0% 4 1
0.888888988.9%
 

Contributing tests

This file is covered by 16 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;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.crypto.pkix.CertificateProvider;
29    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
30    import org.xwiki.crypto.store.CertificateStore;
31    import org.xwiki.crypto.store.CertificateStoreException;
32    import org.xwiki.crypto.store.StoreReference;
33    import org.xwiki.crypto.store.wiki.internal.query.X509CertificateQuery;
34    import org.xwiki.model.reference.LocalDocumentReference;
35   
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.XWikiException;
38   
39    /**
40    * X509 implementation of {@link org.xwiki.crypto.store.CertificateStore} for a wiki store.
41    *
42    * @version $Id: 02fc0a899e5265abff2a3d50021f519cb6861d03 $
43    * @since 6.1M2
44    */
45    @Component
46    @Named("X509wiki")
47    @Singleton
 
48    public class X509CertificateWikiStore extends AbstractX509WikiStore implements CertificateStore
49    {
50    /**
51    * Space where the certificate class is stored.
52    */
53    public static final String CERTIFICATECLASS_SPACE = "Crypto";
54   
55    /**
56    * Document name of the certificate class.
57    */
58    public static final String CERTIFICATECLASS_NAME = "CertificateClass";
59   
60    /**
61    * Full name of the certificate class.
62    */
63    public static final String CERTIFICATECLASS_FULLNAME = CERTIFICATECLASS_SPACE + "." + CERTIFICATECLASS_NAME;
64   
65    /**
66    * Reference to the signature class.
67    */
68    public static final LocalDocumentReference CERTIFICATECLASS =
69    new LocalDocumentReference(CERTIFICATECLASS_SPACE, CERTIFICATECLASS_NAME);
70   
71    /**
72    * Name of the issuer field.
73    */
74    public static final String CERTIFICATECLASS_PROP_ISSUER = "issuer";
75   
76    /**
77    * Name of the serial field.
78    */
79    public static final String CERTIFICATECLASS_PROP_SERIAL = "serial";
80   
81    /**
82    * Name of the subject field.
83    */
84    public static final String CERTIFICATECLASS_PROP_SUBJECT = "subject";
85   
86    /**
87    * Name of the key identifier field.
88    */
89    public static final String CERTIFICATECLASS_PROP_KEYID = "keyid";
90   
91    /**
92    * Name of the certificate field.
93    */
94    public static final String CERTIFICATECLASS_PROP_CERTIFICATE = "certificate";
95   
96    /**
97    * {@inheritDoc}
98    *
99    * @param store an {@link org.xwiki.crypto.store.WikiStoreReference} to a document reference or a space reference.
100    */
 
101  8 toggle @Override
102    public void store(StoreReference store, CertifiedPublicKey certificate) throws CertificateStoreException
103    {
104  8 XWikiContext context = getXWikiContext();
105   
106  8 try {
107  8 context.getWiki().saveDocument(storeCertificate(store, certificate, context), context);
108    } catch (XWikiException e) {
109  0 throw new CertificateStoreException("Error while saving certificate to store [" + store + "]", e);
110    }
111    }
112   
113    /**
114    * {@inheritDoc}
115    *
116    * @param store an {@link org.xwiki.crypto.store.WikiStoreReference} to a document reference or a space reference.
117    */
 
118  6 toggle @Override
119    public CertificateProvider getCertificateProvider(StoreReference store) throws CertificateStoreException
120    {
121  6 return new X509CertificateProvider(resolveStore(store), getCertificateFactory(), getEncoder(),
122    getQueryManager(), getSerializer());
123    }
124   
125    /**
126    * {@inheritDoc}
127    *
128    * @param store an {@link org.xwiki.crypto.store.WikiStoreReference} to a document reference or a space reference.
129    */
 
130  2 toggle @Override
131    public Collection<CertifiedPublicKey> getAllCertificates(StoreReference store) throws CertificateStoreException
132    {
133  2 return new X509CertificateQuery(resolveStore(store), getCertificateFactory(), getEncoder(), getQueryManager(),
134    getSerializer()).getCertificates();
135    }
136    }