1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.macro.script

File DefaultScriptMacroPermissionPolicy.java

 

Coverage histogram

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

Code metrics

0
6
1
1
68
33
2
0.33
6
1
2

Classes

Class Line # Actions
DefaultScriptMacroPermissionPolicy 45 6 0% 2 1
0.8571428785.7%
 

Contributing tests

This file is covered by 8 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.rendering.internal.macro.script;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.rendering.macro.script.AbstractScriptMacroPermissionPolicy;
30    import org.xwiki.rendering.macro.script.DefaultScriptMacroParameters;
31    import org.xwiki.rendering.macro.script.MacroPermissionPolicy;
32    import org.xwiki.rendering.macro.script.ScriptMacroParameters;
33    import org.xwiki.rendering.transformation.MacroTransformationContext;
34   
35    /**
36    * Default Script Macro Permission policy: delegate to specific Script Macro Permission Policy using the
37    * {@code language} parameter and if no Policy is found then allow only if the current document has Programming Rights.
38    *
39    * @version $Id: 896a015b9897daf04f8781f182af19f4e6b046e5 $
40    * @since 4.1M1
41    */
42    @Component
43    @Named("script")
44    @Singleton
 
45    public class DefaultScriptMacroPermissionPolicy extends AbstractScriptMacroPermissionPolicy
46    {
47    /**
48    * Used to get Macro Permission Policy implementations.
49    */
50    @Inject
51    private ComponentManager componentManager;
52   
 
53  13 toggle @Override
54    public boolean hasPermission(ScriptMacroParameters parameters, MacroTransformationContext context)
55    {
56  13 boolean hasPermission;
57  13 try {
58  13 MacroPermissionPolicy policy = this.componentManager.getInstance(MacroPermissionPolicy.class,
59    ((DefaultScriptMacroParameters) parameters).getLanguage());
60  0 hasPermission = policy.hasPermission(parameters, context);
61    } catch (ComponentLookupException e) {
62    // No policy for that Macro, use the default implementation which forbids execution if the doc doesn't
63    // have Programming Rights.
64  13 hasPermission = super.hasPermission(parameters, context);
65    }
66  13 return hasPermission;
67    }
68    }