1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.script

File StoreScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
11
7
1
164
78
8
0.73
1.57
7
1.14

Classes

Class Line # Actions
StoreScriptService 51 11 0% 8 20
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.script;
21   
22    import java.io.File;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.crypto.store.CertificateStore;
30    import org.xwiki.crypto.store.FileStoreReference;
31    import org.xwiki.crypto.store.KeyStore;
32    import org.xwiki.crypto.store.StoreReference;
33    import org.xwiki.crypto.store.WikiStoreReference;
34    import org.xwiki.environment.Environment;
35    import org.xwiki.model.reference.DocumentReference;
36    import org.xwiki.model.reference.SpaceReference;
37    import org.xwiki.script.service.ScriptService;
38    import org.xwiki.security.authorization.ContextualAuthorizationManager;
39    import org.xwiki.stability.Unstable;
40   
41    /**
42    * Script service allowing a user to create keys pairs and issue certificates.
43    *
44    * @version $Id: c5cd63e2d430060baaa0a5d2c71e1358c00a4a7f $
45    * @since 8.4RC1
46    */
47    @Component
48    @Named(CryptoScriptService.ROLEHINT + '.' + StoreScriptService.ROLEHINT)
49    @Singleton
50    @Unstable
 
51    public class StoreScriptService implements ScriptService
52    {
53    /**
54    * The role hint of this component.
55    */
56    public static final String ROLEHINT = "store";
57   
58    /**
59    * Used to get permanent directory.
60    */
61    @Inject
62    private Environment environment;
63   
64    @Inject
65    @Named("X509file")
66    private KeyStore x509FileKeyStore;
67   
68    @Inject
69    @Named("X509wiki")
70    private KeyStore x509WikiKeyStore;
71   
72    @Inject
73    @Named("X509wiki")
74    private CertificateStore x509WikiCertificateStore;
75   
76    @Inject
77    private ContextualAuthorizationManager contextualAuthorizationManager;
78   
 
79  0 toggle private StoreReference getFileStoreReference(String filename, boolean multi)
80    {
81  0 File file;
82   
83  0 if (!filename.startsWith("/")) {
84  0 file = new File(environment.getPermanentDirectory(), filename);
85    } else {
86  0 file = new File(filename);
87    }
88  0 return new FileStoreReference(file, multi);
89    }
90   
91    /**
92    * Returns a X509 key store based on a folder of files. This store allows storage of multiple keys.
93    *
94    * @param filename the name of the folder. If it does not starts with "/", it will be located
95    * in the permanent directory.
96    * @return a multi-key keystore.
97    */
 
98  0 toggle public ScriptingKeyStore getX509FileKeyStore(String filename)
99    {
100  0 return new ScriptingKeyStore(x509FileKeyStore, getFileStoreReference(filename, true),
101    contextualAuthorizationManager);
102    }
103   
104    /**
105    * Returns a X509 key store based on a single file. This store allows storage of a single key.
106    *
107    * @param filename the name of the file. If it does not starts with "/", it will be located
108    * in the permanent directory.
109    * @return a single key store.
110    */
 
111  0 toggle public ScriptingKeyStore getX509FileSingleKeyStore(String filename)
112    {
113  0 return new ScriptingKeyStore(x509FileKeyStore, getFileStoreReference(filename, false),
114    contextualAuthorizationManager);
115    }
116   
117    /**
118    * Returns a X509 key store based on a wiki space. This store allows storage of multiple keys.
119    *
120    * @param reference the space reference.
121    * @return a multi-key store.
122    */
 
123  0 toggle public ScriptingKeyStore getX509SpaceKeyStore(SpaceReference reference)
124    {
125  0 return new ScriptingKeyStore(x509WikiKeyStore, new WikiStoreReference(reference),
126    contextualAuthorizationManager);
127    }
128   
129    /**
130    * Returns a X509 key store based on a wiki document. This store allows storage of a single key.
131    *
132    * @param reference the document reference.
133    * @return a single key store.
134    */
 
135  0 toggle public ScriptingKeyStore getX509DocumentKeyStore(DocumentReference reference)
136    {
137  0 return new ScriptingKeyStore(x509WikiKeyStore, new WikiStoreReference(reference),
138    contextualAuthorizationManager);
139    }
140   
141    /**
142    * Returns a X509 certificate store based on a wiki space. This store allows storage of multiple certificates.
143    *
144    * @param reference the space reference.
145    * @return a multi-certificate store.
146    */
 
147  0 toggle public ScriptingCertificateStore getX509SpaceCertificateStore(SpaceReference reference)
148    {
149  0 return new ScriptingCertificateStore(x509WikiCertificateStore, new WikiStoreReference(reference),
150    contextualAuthorizationManager);
151    }
152   
153    /**
154    * Returns a X509 certificate store based on a wiki document. This store allows storage of a single certificate.
155    *
156    * @param reference the document reference.
157    * @return a single key store.
158    */
 
159  0 toggle public ScriptingCertificateStore getX509DocumentCertificateStore(DocumentReference reference)
160    {
161  0 return new ScriptingCertificateStore(x509WikiCertificateStore, new WikiStoreReference(reference),
162    contextualAuthorizationManager);
163    }
164    }