FormsConditionRestrictionProvider.java
5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.oak.api.PropertyState
* org.apache.jackrabbit.oak.api.Tree
* org.apache.jackrabbit.oak.api.Type
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.AbstractRestrictionProvider
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern
* org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
*/
package com.adobe.aemfd.formsfoundation.oak.restrictions.impl;
import com.adobe.aemfd.formsfoundation.oak.restrictions.impl.FormsConditionRestrictionPattern;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.AbstractRestrictionProvider;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
@Component
@Service(value={RestrictionProvider.class})
public class FormsConditionRestrictionProvider
extends AbstractRestrictionProvider {
private static final String RESTRICTION_NAME = "fd:condition";
private static final String[] DEFAULT_ROOTS = new String[]{"/content/dam/formsanddocuments"};
@Property(value={"/content/dam/formsanddocuments"}, label="Valid Root Paths", description="Paths for which restriction is valid", cardinality=Integer.MAX_VALUE)
private static final String PROPERTY_ROOTS = "form.condition.restriction.roots";
private static String[] rootPaths = DEFAULT_ROOTS;
private static final Map<String, RestrictionDefinition> supportedRestrictions = FormsConditionRestrictionProvider.supportedRestrictions();
public FormsConditionRestrictionProvider() {
super(supportedRestrictions);
}
@Activate
public void activate(ComponentContext ctx) {
Dictionary props = ctx.getProperties();
rootPaths = PropertiesUtil.toStringArray(props.get("form.condition.restriction.roots"), (String[])DEFAULT_ROOTS);
}
private boolean isSupported(String oakPath) {
if (oakPath == null) {
return false;
}
for (String rootPath : rootPaths) {
if (rootPath == null || rootPath.trim().length() <= 0 || !oakPath.startsWith(rootPath + "/") && !oakPath.equals(rootPath)) continue;
return true;
}
return false;
}
public boolean isUnsupportedPath(String oakPath) {
return !this.isSupported(oakPath);
}
private static Map<String, RestrictionDefinition> supportedRestrictions() {
RestrictionDefinitionImpl restrictionDefinition = new RestrictionDefinitionImpl("fd:condition", Type.STRINGS, false);
HashMap<String, RestrictionDefinitionImpl> supportedRestriction = new HashMap<String, RestrictionDefinitionImpl>();
supportedRestriction.put(restrictionDefinition.getName(), restrictionDefinition);
return Collections.unmodifiableMap(supportedRestriction);
}
public RestrictionPattern getPattern(String oakPath, Tree tree) {
PropertyState values;
if (oakPath != null && (values = tree.getProperty("fd:condition")) != null) {
return new FormsConditionRestrictionPattern((Iterable)values.getValue(Type.STRINGS), oakPath);
}
return RestrictionPattern.EMPTY;
}
public RestrictionPattern getPattern(String oakPath, Set<Restriction> restrictions) {
if (oakPath != null && restrictions != null && !restrictions.isEmpty()) {
for (Restriction restriction : restrictions) {
Iterable values;
String name = restriction.getDefinition().getName();
if (!"fd:condition".equals(name) || (values = (Iterable)restriction.getProperty().getValue(Type.STRINGS)) == null) continue;
return new FormsConditionRestrictionPattern((Iterable)restriction.getProperty().getValue(Type.STRINGS), oakPath);
}
}
return RestrictionPattern.EMPTY;
}
}