| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
|
| 38 |
|
|
| 39 |
|
@version |
| 40 |
|
@since |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 7 |
Complexity Density: 0.41 |
|
| 42 |
|
public class TestAccessRuleFactory extends AbstractEntityFactory<TestAccessRule> |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@param |
| 47 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 48 |
268 |
TestAccessRuleFactory(TestEntity parent)... |
| 49 |
|
{ |
| 50 |
268 |
setParent(parent); |
| 51 |
|
} |
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
268 |
@Override... |
| 54 |
|
public List<String> getTagNames() |
| 55 |
|
{ |
| 56 |
268 |
return Arrays.asList("allowUser", "denyUser", "allowGroup", "denyGroup"); |
| 57 |
|
} |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 59 |
218 |
@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 |
|
|
| 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 |
|
} |