本文整理匯總了Java中javax.naming.ldap.LdapContext.reconnect方法的典型用法代碼示例。如果您正苦於以下問題:Java LdapContext.reconnect方法的具體用法?Java LdapContext.reconnect怎麽用?Java LdapContext.reconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.ldap.LdapContext
的用法示例。
在下文中一共展示了LdapContext.reconnect方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyPassword
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
/**
* Verifies that the password supplied is actually the user's password, by
* attempting to rebind to a copy of the LDAP server context using the user's
* username and the supplied password.
*
* @param password
* The password to validate.
* @return <code>True</code> if a connection can successfully be established
* to the LDAP host using the user's id and the supplied password,
* and <code>False</code> otherwise.
*/
public boolean verifyPassword(String password) {
boolean result = false;
LdapContext ldapContext = null;
try {
ldapContext = _ldapContext.newInstance(null);
ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION,
LdapConstants.SECURITY_AUTHENTICATION_SIMPLE);
ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, _userDN);
ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
ldapContext.reconnect(null);
result = true;
} catch (NamingException exception) {
// no-op
} finally {
if (null != ldapContext) {
try {
ldapContext.close();
} catch (NamingException ex) {
// no-op
}
}
}
return result;
}
示例2: ldapApiCheck
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
private boolean ldapApiCheck(String loginId, String password) {
boolean result = false;
String action = "login";
try {
initLdapContext(action);
LdapContext ldapCtx = ldapContexts.get(action);
ldapCtx.addToEnvironment(Context.SECURITY_PRINCIPAL, loginId);
ldapCtx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
// 密碼驗證,不報錯則為驗證成功
ldapCtx.reconnect(null);
result = true;
loggerInfo("LDAP信息", "校驗", "成功", loginId);
}
catch (AuthenticationException e) {
// 此異常為用戶驗證失敗,因此不做ldapContext清除
loggerError("LDAP信息校驗", loginId + " (業務意義為驗證失敗,異常信息可以忽略)", e);
}
catch (Exception e1) {
loggerError("LDAP信息校驗", loginId, e1);
clearLdapContext(action);
}
return result;
}
示例3: testReconnect_share_connection
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public void testReconnect_share_connection() throws Exception {
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
LdapContext context = new InitialLdapContext(env, null);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
// doesn't create new connection
context.reconnect(null);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_SEARCH_RESULT_DONE,
new EncodableLdapResult(), null) });
// another and context share the same connection now
LdapContext another = (LdapContext) context.lookup("");
MockLdapServer one = new MockLdapServer(server);
one.start();
one.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
// create new connection
context.reconnect(null);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
// use original connection
another.reconnect(null);
}
示例4: applyAuthentication
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
// Force reconnect with user credentials
ctx.reconnect(null);
}
示例5: testReconnect
import javax.naming.ldap.LdapContext; //導入方法依賴的package包/類
public void testReconnect() throws Exception {
Control[] expected = new Control[] { new PagedResultsControl(10,
Control.NONCRITICAL) };
env.put("java.naming.ldap.control.connect", expected);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
LdapContext context = new InitialLdapContext(env, null);
Control[] controls = context.getConnectControls();
assertNotNull(controls);
assertNotSame(expected, controls);
Control c = controls[0];
assertTrue(c instanceof PagedResultsControl);
assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c)
.isCritical());
assertEquals(expected[0], c);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
expected = new Control[] { new SortControl("", Control.NONCRITICAL) };
context.reconnect(expected);
controls = context.getConnectControls();
assertNotNull(controls);
assertEquals(1, controls.length);
c = controls[0];
assertTrue(c instanceof SortControl);
assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
assertNotSame(expected, controls);
assertEquals(expected[0], c);
expected[0] = new PagedResultsControl(10, Control.NONCRITICAL);
controls = context.getConnectControls();
assertNotNull(controls);
assertEquals(1, controls.length);
c = controls[0];
assertTrue(c instanceof SortControl);
assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
context.reconnect(null);
assertNull(context.getConnectControls());
}