1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.security.authorization

File AuthorExecutor.java

 

Coverage histogram

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

Code metrics

0
2
2
1
119
25
2
1
1
2
1

Classes

Class Line # Actions
AuthorExecutor 35 2 0% 2 4
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.security.authorization;
21   
22    import java.util.concurrent.Callable;
23   
24    import org.xwiki.component.annotation.Role;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.stability.Unstable;
27   
28    /**
29    * Allow executing some code with the right of a provided user.
30    *
31    * @version $Id: c6d190f0c75c327429b7cd920a393fd2d50c4946 $
32    * @since 8.3RC1
33    */
34    @Role
 
35    public interface AuthorExecutor
36    {
37    /**
38    * Execute the passed {@link Callable} with the rights of the passed user.
39    *
40    * @param callable the task to execute
41    * @param authorReference the user to check rights on
42    * @return computed result
43    * @throws Exception if unable to compute a result
44    * @param <V> the result type of method <tt>call</tt>
45    * @deprecated since 10.11RC1, use {@link #call(Callable, DocumentReference, DocumentReference)} instead
46    */
47    @Deprecated
48    <V> V call(Callable<V> callable, DocumentReference authorReference) throws Exception;
49   
50    /**
51    * Execute the passed {@link Callable} with the rights of the passed user.
52    *
53    * @param callable the task to execute
54    * @param authorReference the user to check rights on
55    * @param sourceReference the reference of the document associated with the {@link Callable} (which will be used to
56    * test the author right)
57    * @return computed result
58    * @throws Exception if unable to compute a result
59    * @param <V> the result type of method <tt>call</tt>
60    * @since 10.11RC1
61    */
 
62  0 toggle @Unstable
63    default <V> V call(Callable<V> callable, DocumentReference authorReference, DocumentReference sourceReference)
64    throws Exception
65    {
66  0 return call(callable, authorReference);
67    }
68   
69    /**
70    * Setup the context so that following code is executed with provided user rights.
71    *
72    * <pre>
73    * {@code
74    * try (AutoCloseable context = this.executor.before(author)) {
75    * ...
76    * }
77    * }
78    * </pre>
79    *
80    * @param authorReference the user to check rights on
81    * @return the context to restore
82    * @see #after(AutoCloseable)
83    * @deprecated since 10.11RC1, use {@link #before(DocumentReference, DocumentReference)} instead
84    */
85    @Deprecated
86    AutoCloseable before(DocumentReference authorReference);
87   
88    /**
89    * Setup the context so that following code is executed with provided user rights.
90    *
91    * <pre>
92    * {@code
93    * try (AutoCloseable context = this.executor.before(author, sourceDocument)) {
94    * ...
95    * }
96    * }
97    * </pre>
98    *
99    * @param authorReference the user to check rights on
100    * @param sourceReference the reference of the document associated with the {@link Callable} (which will be used to
101    * test the author right)
102    * @return the context to restore
103    * @see #after(AutoCloseable)
104    * @since 10.11RC1
105    */
 
106  0 toggle @Unstable
107    default AutoCloseable before(DocumentReference authorReference, DocumentReference sourceReference)
108    {
109  0 return before(authorReference);
110    }
111   
112    /**
113    * Restore the context to it's previous state as defined by the provided {@link AutoCloseable}.
114    *
115    * @param context the context to restore
116    * @see #before(DocumentReference)
117    */
118    void after(AutoCloseable context);
119    }