JaasHelper.java
2.32 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.jaas.LoginModuleFactory
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceRegistration
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.auth.sso.impl;
import com.adobe.granite.auth.sso.impl.SSOLoginModule;
import com.adobe.granite.auth.sso.impl.SSOLoginModuleFactory;
import java.util.Dictionary;
import java.util.Properties;
import org.apache.felix.jaas.LoginModuleFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class JaasHelper {
private static final Logger log = LoggerFactory.getLogger(JaasHelper.class);
private ServiceRegistration factoryRegistration;
JaasHelper() {
}
public void open(BundleContext ctx, Dictionary properties) {
if (JaasHelper.hasSSOLoginModule()) {
try {
Properties props = new Properties();
props.put("jaas.ranking", properties.get("jaas.ranking"));
props.put("jaas.controlFlag", properties.get("jaas.controlFlag"));
props.put("jaas.realmName", properties.get("jaas.realmName"));
this.factoryRegistration = ctx.registerService(LoginModuleFactory.class.getName(), (Object)new SSOLoginModuleFactory(), (Dictionary)props);
}
catch (Throwable e) {
log.error("unable to create an register the SSO login module factory", e);
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void close() {
if (this.factoryRegistration != null) {
try {
this.factoryRegistration.unregister();
}
finally {
this.factoryRegistration = null;
}
}
}
public boolean enabled() {
return this.factoryRegistration != null;
}
private static boolean hasSSOLoginModule() {
try {
Class.forName(SSOLoginModule.class.getName());
log.debug("SSOLoginModule available.");
return true;
}
catch (Throwable e) {
log.debug("no SSOLoginModule available.");
return false;
}
}
}