Lines 26-31
Link Here
|
26 |
import javax.naming.InitialContext; |
26 |
import javax.naming.InitialContext; |
27 |
import javax.naming.NamingException; |
27 |
import javax.naming.NamingException; |
28 |
|
28 |
|
|
|
29 |
import org.apache.commons.lang.StringUtils; |
29 |
import org.apache.jorphan.logging.LoggingManager; |
30 |
import org.apache.jorphan.logging.LoggingManager; |
30 |
import org.apache.log.Logger; |
31 |
import org.apache.log.Logger; |
31 |
|
32 |
|
Lines 52-58
Link Here
|
52 |
*/ |
53 |
*/ |
53 |
public static synchronized Context lookupContext(String initialContextFactory, |
54 |
public static synchronized Context lookupContext(String initialContextFactory, |
54 |
String providerUrl, boolean useAuth, String securityPrincipal, String securityCredentials) throws NamingException { |
55 |
String providerUrl, boolean useAuth, String securityPrincipal, String securityCredentials) throws NamingException { |
55 |
Context ctx = MAP.get(initialContextFactory + providerUrl); |
56 |
String cacheKey = createKey(initialContextFactory ,providerUrl, securityPrincipal, securityCredentials); |
|
|
57 |
Context ctx = MAP.get(cacheKey); |
56 |
if (ctx == null) { |
58 |
if (ctx == null) { |
57 |
Properties props = new Properties(); |
59 |
Properties props = new Properties(); |
58 |
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); |
60 |
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); |
Lines 70-81
Link Here
|
70 |
} catch (Exception e) { |
72 |
} catch (Exception e) { |
71 |
throw new NamingException(e.toString()); |
73 |
throw new NamingException(e.toString()); |
72 |
} |
74 |
} |
73 |
MAP.put(initialContextFactory + providerUrl, ctx); |
75 |
MAP.put(cacheKey, ctx); |
74 |
} |
76 |
} |
75 |
return ctx; |
77 |
return ctx; |
76 |
} |
78 |
} |
77 |
|
79 |
|
78 |
/** |
80 |
/** |
|
|
81 |
* Create cache key |
82 |
* @param initialContextFactory |
83 |
* @param providerUrl |
84 |
* @param securityPrincipal |
85 |
* @param securityCredentials |
86 |
* @return |
87 |
*/ |
88 |
private static String createKey(String initialContextFactory, |
89 |
String providerUrl, String securityPrincipal, |
90 |
String securityCredentials) { |
91 |
StringBuilder builder = new StringBuilder(); |
92 |
builder.append(initialContextFactory); |
93 |
builder.append("#"); |
94 |
builder.append(providerUrl); |
95 |
builder.append("#"); |
96 |
if(!StringUtils.isEmpty(securityPrincipal)) { |
97 |
builder.append(securityPrincipal); |
98 |
builder.append("#"); |
99 |
} |
100 |
if(!StringUtils.isEmpty(securityCredentials)) { |
101 |
builder.append(securityCredentials); |
102 |
} |
103 |
return builder.toString(); |
104 |
} |
105 |
|
106 |
/** |
79 |
* Initialize the JNDI initial context |
107 |
* Initialize the JNDI initial context |
80 |
* |
108 |
* |
81 |
* @param useProps if true, create a new InitialContext; otherwise use the other parameters to call |
109 |
* @param useProps if true, create a new InitialContext; otherwise use the other parameters to call |