1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.user.api

File XWikiRightService.java

 

Coverage histogram

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

Code metrics

0
2
2
1
176
38
2
1
1
2
1

Classes

Class Line # Actions
XWikiRightService 31 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 com.xpn.xwiki.user.api;
21   
22    import java.util.List;
23   
24    import org.apache.commons.lang3.StringUtils;
25    import org.xwiki.model.reference.EntityReference;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.XWikiException;
29    import com.xpn.xwiki.doc.XWikiDocument;
30   
 
31    public interface XWikiRightService
32    {
33    /**
34    * The Superadmin username.
35    */
36    String SUPERADMIN_USER = "superadmin";
37   
38    /**
39    * The Superadmin full name.
40    */
41    String SUPERADMIN_USER_FULLNAME = "XWiki." + SUPERADMIN_USER;
42   
43    /**
44    * The Guest username.
45    */
46    String GUEST_USER = "XWikiGuest";
47   
48    /**
49    * The Guest full name.
50    */
51    String GUEST_USER_FULLNAME = "XWiki." + GUEST_USER;
52   
53    /**
54    * The AllGroup username.
55    */
56    String ALLGROUP_GROUP = "XWikiAllGroup";
57   
58    /**
59    * The AllGroup full name.
60    */
61    String ALLGROUP_GROUP_FULLNAME = "XWiki." + ALLGROUP_GROUP;
62   
63    /**
64    * @param userReference the user reference
65    * @return true if the passed reference belong to superadmin
66    * @since 9.2RC1
67    */
 
68  0 toggle static boolean isSuperAdmin(EntityReference userReference)
69    {
70  0 return userReference != null
71    && StringUtils.equalsIgnoreCase(userReference.getName(), XWikiRightService.SUPERADMIN_USER);
72    }
73   
74    /**
75    * @param userReference the user reference
76    * @return true if the passed reference belong to superadmin
77    * @since 9.2RC1
78    */
 
79  0 toggle static boolean isGuest(EntityReference userReference)
80    {
81  0 return userReference == null
82    || StringUtils.equalsIgnoreCase(userReference.getName(), XWikiRightService.GUEST_USER);
83    }
84   
85    /**
86    * Checks if the wiki current user has the right to execute (@code action} on the document {@code doc}, along with
87    * redirecting to the login if it's not the case and there is no logged in user (the user is the guest user).
88    *
89    * @param action the action to be executed on the document
90    * @param doc the document to perform action on
91    * @param context the xwiki context in which to perform the verification (from which to get the user, for example)
92    * @return {@code true} if the user has right to execute {@code action} on {@code doc}, {@code false} otherwise
93    * <strong> and requests the login from the authentication service (redirecting to the login page in the
94    * case of a form authenticator, for example) when no user is logged in. </strong>
95    * @throws XWikiException if something goes wrong during the rights checking process
96    */
97    boolean checkAccess(String action, XWikiDocument doc, XWikiContext context) throws XWikiException;
98   
99    /**
100    * Verifies if the user identified by {@code username} has the access level identified by {@code right} on the
101    * document with the name {@code docname}.
102    *
103    * @param right the access level to check (for example, 'view' or 'edit' or 'comment').
104    * @param username the name of the user to check the right for
105    * @param docname the document on which to check the right
106    * @param context the xwiki context in which to perform the verification
107    * @return {@code true} if the user has the specified right on the document, {@code false} otherwise
108    * @throws XWikiException if something goes wrong during the rights checking process
109    * @deprecated since 4.0M2, use
110    * {@link org.xwiki.security.authorization.AuthorizationManager#hasAccess(org.xwiki.security.authorization.Right, org.xwiki.model.reference.DocumentReference, org.xwiki.model.reference.EntityReference)}
111    * instead
112    */
113    @Deprecated
114    boolean hasAccessLevel(String right, String username, String docname, XWikiContext context) throws XWikiException;
115   
116    /**
117    * Checks if the author of the context document (last editor of the content of the document) has programming rights
118    * (used to determine if the protected calls in the script contained in the document should be executed or not).
119    *
120    * @param context the xwiki context of this request
121    * @return {@code true} if the author of the context document has programming rights, {@code false} otherwise.
122    * @deprecated since 6.1RC1, use
123    * {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right)}
124    * instead
125    */
126    @Deprecated
127    boolean hasProgrammingRights(XWikiContext context);
128   
129    /**
130    * Checks if the author of the passed document (last editor of the content of the document) has programming rights
131    * (used to determine if the protected calls in the script contained in the document should be executed or not).
132    *
133    * @param doc the document to check programming rights for
134    * @param context the xwiki context of this request
135    * @return {@code true} if the author of {@code doc} has programming rights, {@code false} otherwise.
136    * @deprecated since 6.1RC1, use
137    * {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right, org.xwiki.model.reference.EntityReference)}
138    * instead
139    */
140    @Deprecated
141    boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context);
142   
143    /**
144    * Checks that the current user in the context (the currently authenticated user) has administration rights either
145    * on the current wiki or on the current space.
146    *
147    * @param context the xwiki context of this request
148    * @return {@code true} if the current user in the context has the {@code admin} right, {@code false} otherwise
149    * @deprecated since 6.1RC1, use
150    * {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right)}
151    * instead
152    */
153    @Deprecated
154    boolean hasAdminRights(XWikiContext context);
155   
156    /**
157    * Checks that the current user in the context (the currently authenticated user) has administration rights on the
158    * current wiki, regardless of any space admin rights that might also be available.
159    *
160    * @param context the xwiki context of this request
161    * @return {@code true} if the current user in the context has the {@code admin} right, {@code false} otherwise
162    * @since 3.2M3
163    * @deprecated since 6.1RC1, use
164    * {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right, org.xwiki.model.reference.EntityReference)}
165    * instead
166    */
167    @Deprecated
168    boolean hasWikiAdminRights(XWikiContext context);
169   
170    /**
171    * @param context the xwiki context of this request
172    * @return the list of all the known access levels
173    * @throws XWikiException if something goes wrong during the rights checking process
174    */
175    List<String> listAllLevels(XWikiContext context) throws XWikiException;
176    }