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

File TestAccessRuleFactory.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
17
3
1
90
49
7
0.41
5.67
3
2.33

Classes

Class Line # Actions
TestAccessRuleFactory 42 17 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 15 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.parser;
22   
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.xml.sax.Attributes;
27    import org.xwiki.model.EntityType;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.security.authorization.Right;
30    import org.xwiki.security.authorization.testwikis.TestAccessRule;
31    import org.xwiki.security.authorization.testwikis.TestEntity;
32    import org.xwiki.security.authorization.testwikis.TestWiki;
33    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestAccessRule;
34    import org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestDocument;
35   
36    /**
37    * Test access rule factory.
38    *
39    * @version $Id: 5488ca2f485e77d2176c6dad3c1b79ae1d94d354 $
40    * @since 5.0M2
41    */
 
42    public class TestAccessRuleFactory extends AbstractEntityFactory<TestAccessRule>
43    {
44    /**
45    * Create a new factory for access rules of the given parent.
46    * @param parent parent entity to used by this factory.
47    */
 
48  268 toggle TestAccessRuleFactory(TestEntity parent)
49    {
50  268 setParent(parent);
51    }
52   
 
53  268 toggle @Override
54    public List<String> getTagNames()
55    {
56  268 return Arrays.asList("allowUser", "denyUser", "allowGroup", "denyGroup");
57    }
58   
 
59  218 toggle @Override
60    TestAccessRule getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes)
61    {
62  218 EntityReference userRef = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestDocument.TYPE,
63    new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, parent.getReference().getRoot()));
64   
65  218 Boolean allow = name.startsWith("allow");
66   
67  218 String type = attributes.getValue("type");
68   
69  218 String user = parser.getSerializer().serialize(userRef);
70   
71  218 Boolean isUser = name.endsWith("User");
72   
73  218 if (type != null) {
74  99 Right right = Right.toRight(type);
75  99 new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
76    } else {
77  119 EntityType parentType = parent.getType();
78  119 if (parentType == EntityType.WIKI && ((TestWiki) parent).isMainWiki()) {
79    // Null here means root (or farm)
80  12 parentType = null;
81    }
82  119 for (Right right : Right.getEnabledRights(parentType)) {
83  834 if (right != Right.CREATOR) {
84  770 new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
85    }
86    }
87    }
88  218 return null;
89    }
90    }