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

File CascadingVfsPermissionChecker.java

 

Coverage histogram

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

Code metrics

2
11
1
1
77
42
4
0.36
11
1
4

Classes

Class Line # Actions
CascadingVfsPermissionChecker 44 11 0% 4 1
0.928571492.9%
 

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.vfs.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.vfs.VfsException;
31    import org.xwiki.vfs.VfsPermissionChecker;
32    import org.xwiki.vfs.VfsResourceReference;
33   
34    /**
35    * Verify VFS permission by first looking for a Permission Checker specific to a VFS URI scheme and if not found,
36    * default to the generic Permission Checker.
37    *
38    * @version $Id: ce816bc390ed3517a506caaca0e5b9d5def3031f $
39    * @since 7.4M2
40    */
41    @Component
42    @Named(CascadingVfsPermissionChecker.HINT)
43    @Singleton
 
44    public class CascadingVfsPermissionChecker implements VfsPermissionChecker
45    {
46    static final String HINT = "cascading";
47   
48    @Inject
49    private Provider<ComponentManager> componentManagerProvider;
50   
 
51  9 toggle @Override
52    public void checkPermission(VfsResourceReference resourceReference) throws VfsException
53    {
54    // Prevent using a VFS scheme that correspond to the hint of this component
55  9 String scheme = resourceReference.getURI().getScheme();
56  9 if (HINT.equals(scheme)) {
57  1 throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT));
58    }
59   
60    // Look for a scheme-specific permission checker
61  8 VfsPermissionChecker resolvedChecker;
62  8 ComponentManager componentManager = this.componentManagerProvider.get();
63  8 try {
64  8 resolvedChecker =
65    componentManager.getInstance(VfsPermissionChecker.class, scheme);
66    } catch (ComponentLookupException e) {
67    // Use the Generic permission checker
68  2 try {
69  2 resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class);
70    } catch (ComponentLookupException ee) {
71  0 throw new VfsException(String.format("No VFS Permission Checked has been found in the system. "
72    + "Refusing access to VFS URI scheme [%s]", scheme), ee);
73    }
74    }
75  8 resolvedChecker.checkPermission(resourceReference);
76    }
77    }