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

File AuthorizationException.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

8
9
9
1
146
59
13
1.44
1
9
1.44

Classes

Class Line # Actions
AuthorizationException 31 9 0% 13 17
0.3461538634.6%
 

Contributing tests

This file is covered by 39 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.security.authorization;
21   
22    import org.xwiki.model.reference.DocumentReference;
23    import org.xwiki.model.reference.EntityReference;
24   
25    /**
26    * This is the base exception raised for various reasons by the authorization module.
27    *
28    * @version $Id: 7d34ac7e24fc20476cac5f5a6bf065f337192a8d $
29    * @since 4.0M2
30    */
 
31    public class AuthorizationException extends Exception
32    {
33    /** Constant value displayed for null entityReference. */
34    static final String NULL_ENTITY = "Main Wiki";
35   
36    /** Constant value displayed for null userReference. */
37    static final String NULL_USER = "Public";
38   
39    /** Serialization identifier. */
40    private static final long serialVersionUID = 1L;
41   
42    /**
43    * @param message Message.
44    */
 
45  0 toggle public AuthorizationException(String message)
46    {
47  0 super(message);
48    }
49   
50    /**
51    * @param message Message.
52    * @param cause Original cause.
53    */
 
54  0 toggle public AuthorizationException(String message, Throwable cause)
55    {
56  0 super(message, cause);
57    }
58   
59    /**
60    * @param userReference The user, for which the query was attempted.
61    * @param entityReference The entity, on which the query was attempted.
62    */
 
63  0 toggle public AuthorizationException(DocumentReference userReference, EntityReference entityReference)
64    {
65  0 this(userReference, entityReference, null, null);
66    }
67   
68    /**
69    * @param userReference The user, for which the query was attempted.
70    * @param entityReference The entity, on which the query was attempted.
71    * @param message Message.
72    */
 
73  1 toggle public AuthorizationException(DocumentReference userReference, EntityReference entityReference, String message)
74    {
75  1 this(null, userReference, entityReference, message, null);
76    }
77   
78    /**
79    * @param right The right being checked.
80    * @param userReference The user, for which the query was attempted.
81    * @param entityReference The entity, on which the query was attempted.
82    * @param message Message.
83    */
 
84  0 toggle public AuthorizationException(Right right, DocumentReference userReference, EntityReference entityReference,
85    String message)
86    {
87  0 this(right, userReference, entityReference, message, null);
88    }
89   
90    /**
91    * @param userReference The user, for which the query was attempted.
92    * @param entityReference The entity, on which the query was attempted.
93    * @param message Message.
94    * @param cause Original cause.
95    */
 
96  0 toggle public AuthorizationException(DocumentReference userReference, EntityReference entityReference, String message,
97    Throwable cause)
98    {
99  0 this(null, userReference, entityReference, message, cause);
100    }
101   
102    /**
103    * @param right The right being checked.
104    * @param userReference The user, for which the query was attempted.
105    * @param entityReference The entity, on which the query was attempted.
106    * @param message Message.
107    * @param cause Original cause.
108    */
 
109  41 toggle public AuthorizationException(Right right,
110    DocumentReference userReference,
111    EntityReference entityReference,
112    String message,
113    Throwable cause)
114    {
115  41 super(String.format("%s when checking %s access to [%s] for user [%s]",
116    message,
117  41 (right == null) ? "" : "[" + right.getName() + "]",
118  41 (entityReference == null) ? NULL_ENTITY : entityReference,
119  41 (userReference == null) ? NULL_USER : userReference), cause);
120    }
121   
122    /**
123    * @param entityReference The entity, on which the query was attempted.
124    * @param message Message.
125    * @param cause Original cause.
126    */
 
127  0 toggle public AuthorizationException(EntityReference entityReference,
128    String message,
129    Throwable cause)
130    {
131  0 super(String.format("%s when checking access to [%s]",
132    message,
133  0 (entityReference == null) ? NULL_ENTITY : entityReference), cause);
134    }
135   
136    /**
137    * @param userReference The user, for which the query was attempted.
138    * @param entityReference The entity, on which the query was attempted.
139    * @param cause Original cause.
140    */
 
141  0 toggle public AuthorizationException(DocumentReference userReference, EntityReference entityReference, Throwable cause)
142    {
143  0 this(userReference, entityReference, null, cause);
144    }
145   
146    }