HandlerBridgeManager.java
3.68 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceRegistration
*/
package com.day.cq.compat.commonsauth.impl;
import com.day.cq.compat.commonsauth.impl.AuthenticationHandlerBridge;
import com.day.cq.compat.commonsauth.impl.AuthenticationInfoPostProcessorBridge;
import com.day.cq.compat.commonsauth.impl.Bridge;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import org.apache.sling.commons.auth.spi.AuthenticationHandler;
import org.apache.sling.commons.auth.spi.AuthenticationInfoPostProcessor;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class HandlerBridgeManager {
private final HashMap<Bridge, Object> bridgeServices = new HashMap();
private BundleContext bundleContext;
private synchronized void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext;
for (Map.Entry<Bridge, Object> entry : this.bridgeServices.entrySet()) {
if (!(entry.getValue() instanceof Map)) continue;
entry.setValue((Object)this.registerService(entry.getKey(), (Map)entry.getValue()));
}
}
private synchronized void deactivate() {
this.bundleContext = null;
}
private synchronized void bindAuthenticationHandler(AuthenticationHandler handler, Map<String, Object> properties) {
AuthenticationHandlerBridge bridge = new AuthenticationHandlerBridge(handler);
this.serviceAdded(bridge, properties);
}
private synchronized void unbindAuthenticationHandler(AuthenticationHandler handler) {
AuthenticationHandlerBridge bridge = new AuthenticationHandlerBridge(handler);
this.serviceRemoved(bridge);
}
private synchronized void bindAuthenticationInfoPostProcessor(AuthenticationInfoPostProcessor processor, Map<String, Object> properties) {
AuthenticationInfoPostProcessorBridge bridge = new AuthenticationInfoPostProcessorBridge(processor);
this.serviceAdded(bridge, properties);
}
private synchronized void unbindAuthenticationInfoPostProcessor(AuthenticationInfoPostProcessor processor) {
AuthenticationInfoPostProcessorBridge bridge = new AuthenticationInfoPostProcessorBridge(processor);
this.serviceRemoved(bridge);
}
private void serviceAdded(Bridge service, Map<String, Object> properties) {
if (this.bundleContext != null) {
this.bridgeServices.put(service, (Object)this.registerService(service, properties));
} else {
this.bridgeServices.put(service, properties);
}
}
private void serviceRemoved(Object service) {
Object registered = this.bridgeServices.remove(service);
if (registered instanceof ServiceRegistration) {
try {
((ServiceRegistration)registered).unregister();
}
catch (IllegalStateException ise) {
// empty catch block
}
}
}
private ServiceRegistration registerService(Bridge service, Map<String, Object> properties) {
Hashtable<String, Object> props = new Hashtable<String, Object>(properties);
props.remove("service.id");
props.remove("service.pid");
props.remove("objectClass");
props.remove("component.name");
props.remove("component.id");
props.put("service.description", service.toString());
return this.bundleContext.registerService(service.getServiceName(), (Object)service, props);
}
}