ServiceUsersConfigurationManager.java
3.7 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.References
* org.apache.felix.scr.annotations.Service
*/
package com.adobe.granite.repository.impl;
import com.adobe.granite.repository.impl.ServiceUsersConfiguration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;
@Component(immediate=1)
@Service(value={ServiceUsersConfigurationManager.class})
@References(value={@Reference(name="serviceUserConfigurations", referenceInterface=ServiceUsersConfiguration.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC, updated="updateServiceUserConfigurations")})
public class ServiceUsersConfigurationManager {
private final Map<Long, ServiceUsersConfiguration> serviceUserConfigurations = new HashMap<Long, ServiceUsersConfiguration>();
private Set<String> activeServiceUserFastPathEnabled = Collections.emptySet();
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void bindServiceUserConfigurations(ServiceUsersConfiguration config, Map<String, Object> props) {
Long key = (Long)props.get("service.id");
Map<Long, ServiceUsersConfiguration> map = this.serviceUserConfigurations;
synchronized (map) {
this.serviceUserConfigurations.put(key, config);
this.updateMappings();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void unbindServiceUserConfigurations(ServiceUsersConfiguration config, Map<String, Object> props) {
Long key = (Long)props.get("service.id");
Map<Long, ServiceUsersConfiguration> map = this.serviceUserConfigurations;
synchronized (map) {
if (this.serviceUserConfigurations.remove(key) != null) {
this.updateMappings();
}
}
}
protected void updateServiceUserConfigurations(ServiceUsersConfiguration config, Map<String, Object> props) {
this.bindServiceUserConfigurations(config, props);
}
protected void updateMappings() {
ArrayList<ServiceUsersConfiguration> sortedMappings = new ArrayList<ServiceUsersConfiguration>();
for (ServiceUsersConfiguration config : this.serviceUserConfigurations.values()) {
sortedMappings.add(config);
}
Collections.sort(sortedMappings);
HashSet<String> serviceUsersFastPathEnabled = new HashSet<String>();
for (ServiceUsersConfiguration sc : sortedMappings) {
if (sc.getSimpleSubjectPopulation()) {
serviceUsersFastPathEnabled.addAll(Arrays.asList(sc.getServiceUsers()));
continue;
}
serviceUsersFastPathEnabled.removeAll(Arrays.asList(sc.getServiceUsers()));
}
this.activeServiceUserFastPathEnabled = Collections.unmodifiableSet(serviceUsersFastPathEnabled);
}
public boolean isServiceUserFastPathEnabled(String serviceUser) {
return this.activeServiceUserFastPathEnabled.contains(serviceUser);
}
}