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

File DefaultTestAccessRule.java

 

Coverage histogram

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

Code metrics

2
11
7
1
110
57
8
0.73
1.57
7
1.14

Classes

Class Line # Actions
DefaultTestAccessRule 38 11 0% 8 2
0.990%
 

Contributing tests

This file is covered by 12 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   
21    package org.xwiki.security.authorization.testwikis.internal.entities;
22   
23    import org.xwiki.model.EntityType;
24    import org.xwiki.model.reference.DocumentReference;
25    import org.xwiki.model.reference.EntityReference;
26    import org.xwiki.security.authorization.Right;
27    import org.xwiki.security.authorization.RuleState;
28    import org.xwiki.security.authorization.testwikis.SecureTestEntity;
29    import org.xwiki.security.authorization.testwikis.TestAccessRule;
30    import org.xwiki.security.authorization.testwikis.TestEntity;
31   
32    /**
33    * Entity for access rule definitions.
34    *
35    * @version $Id: 3be20b1de2f11f36bd35ceeae7b1ac162b3ef676 $
36    * @since 5.0M2
37    */
 
38    public class DefaultTestAccessRule extends AbstractTestEntity implements TestAccessRule
39    {
40    /** The type of reference used by this class. */
41    public static final EntityType TYPE = EntityType.OBJECT;
42   
43    /** The reference to the user/group concerned by this access rule entity. */
44    private final DocumentReference userReference;
45   
46    /** The right defined by this access rule entity. */
47    private final Right right;
48   
49    /** The state defined by this access rule entity. */
50    private final RuleState state;
51   
52    /** True for a user access rule, and false for a group access rule. */
53    private final boolean isUser;
54   
55    /**
56    * Create a new access rule entity.
57    * @param user serialized reference to the user/group concerned by this access rule entity.
58    * @param userReference reference to the user/group concerned by this access rule entity.
59    * @param right right defined by this rule.
60    * @param state state defined by this rule.
61    * @param parent parent entity of this entity.
62    */
 
63  869 toggle public DefaultTestAccessRule(String user, EntityReference userReference, Right right, boolean state,
64    boolean isUser, TestEntity parent) {
65  869 super(
66    new EntityReference(String.format("%s@@%s@@%b", user, right.getName(), state),
67    TYPE, parent.getReference()),
68    parent);
69   
70  869 this.userReference = new DocumentReference(userReference);
71  869 this.right = right;
72  869 this.state = state ? RuleState.ALLOW : RuleState.DENY;
73  869 this.isUser = isUser;
74    }
75   
 
76  869 toggle @Override
77    protected void addToParent(TestEntity parent) {
78  869 ((SecureTestEntity) parent).addSecurityRules(this);
79    }
80   
 
81  0 toggle @Override
82    public EntityType getType()
83    {
84  0 return TYPE;
85    }
86   
 
87  894 toggle @Override
88    public DocumentReference getUser()
89    {
90  894 return userReference;
91    }
92   
 
93  894 toggle @Override
94    public Right getRight()
95    {
96  894 return right;
97    }
98   
 
99  894 toggle @Override
100    public RuleState getState()
101    {
102  894 return state;
103    }
104   
 
105  853 toggle @Override
106    public boolean isUser()
107    {
108  853 return isUser;
109    }
110    }