Revision 8460
Added by Jing Tao almost 11 years ago
src/edu/ucsb/nceas/metacat/AuthLdap.java | ||
---|---|---|
304 | 304 |
return authenticated; |
305 | 305 |
} |
306 | 306 |
|
307 |
|
|
307 | 308 |
/* |
309 |
* Get the aliased dn through a TLS connection |
|
310 |
*/ |
|
311 |
private String getAliasedDnTLS(String alias, Hashtable<String, String> env) throws NamingException, IOException { |
|
312 |
boolean useTLS = true; |
|
313 |
return getAliasedDn(alias, env, useTLS); |
|
314 |
} |
|
315 |
|
|
316 |
/* |
|
317 |
* Get the aliased dn through a non-TLS connection |
|
318 |
*/ |
|
319 |
private String getAliasedDnNonTLS(String alias, Hashtable<String, String> env) throws NamingException, IOException { |
|
320 |
boolean useTLS = false; |
|
321 |
return getAliasedDn(alias, env, useTLS); |
|
322 |
} |
|
323 |
|
|
324 |
/* |
|
308 | 325 |
* Get the aliasedDN (the real DN) for a specified an alias name |
309 | 326 |
*/ |
310 |
public String getAliasedDn(String alias, Hashtable<String, String> env) throws NamingException {
|
|
327 |
public String getAliasedDn(String alias, Hashtable<String, String> env, boolean useTLS) throws NamingException, IOException {
|
|
311 | 328 |
String aliasedDn = null; |
312 |
DirContext sctx = new InitialDirContext(env); |
|
329 |
LdapContext sctx = new InitialLdapContext(env, null); |
|
330 |
StartTlsResponse tls = null; |
|
331 |
if(useTLS) { |
|
332 |
tls = (StartTlsResponse) sctx.extendedOperation(new StartTlsRequest()); |
|
333 |
// Open a TLS connection (over the existing LDAP association) and get details |
|
334 |
// of the negotiated TLS session: cipher suite, peer certificate, etc. |
|
335 |
SSLSession session = tls.negotiate(); |
|
336 |
} |
|
313 | 337 |
SearchControls ctls = new SearchControls(); |
314 | 338 |
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); |
315 | 339 |
String filter = "(objectClass=*)"; |
... | ... | |
322 | 346 |
break; |
323 | 347 |
} |
324 | 348 |
} |
349 |
if(useTLS && tls != null) { |
|
350 |
tls.close(); |
|
351 |
} |
|
352 |
sctx.close(); |
|
325 | 353 |
return aliasedDn; |
326 | 354 |
|
327 | 355 |
} |
356 |
|
|
328 | 357 |
private boolean authenticateTLS(Hashtable<String, String> env, String userDN, String password) |
329 | 358 |
throws AuthTLSException{ |
330 | 359 |
logMetacat.info("AuthLdap.authenticateTLS - Trying to authenticate with TLS"); |
Also available in: Unified diff
Add the methods to get the aliased dn through non-tls or tls.