本文整理汇总了Java中org.springframework.ldap.support.LdapUtils.closeContext方法的典型用法代码示例。如果您正苦于以下问题:Java LdapUtils.closeContext方法的具体用法?Java LdapUtils.closeContext怎么用?Java LdapUtils.closeContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.ldap.support.LdapUtils
的用法示例。
在下文中一共展示了LdapUtils.closeContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAuthentication
import org.springframework.ldap.support.LdapUtils; //导入方法依赖的package包/类
@Override
protected DirContextOperations doAuthentication(
UsernamePasswordAuthenticationToken auth) {
String username = auth.getName();
String password = (String) auth.getCredentials();
DirContext ctx = bindAsUser(username, password);
try {
return searchForUser(ctx, username);
}
catch (NamingException e) {
logger.error("Failed to locate directory entry for authenticated user: "
+ username, e);
throw badCredentials(e);
}
finally {
LdapUtils.closeContext(ctx);
}
}
示例2: verifyAuthenticate
import org.springframework.ldap.support.LdapUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
@Category(NoAdTest.class)
public void verifyAuthenticate() {
EqualsFilter filter = new EqualsFilter("cn", "Some Person2");
List<String> results = ldapTemplate.search("", filter.toString(), new DnContextMapper());
if (results.size() != 1) {
throw new IncorrectResultSizeDataAccessException(1, results.size());
}
DirContext ctx = null;
try {
ctx = tested.getContext(results.get(0), "password");
assertThat(true).isTrue();
}
catch (Exception e) {
fail("Authentication failed");
}
finally {
LdapUtils.closeContext(ctx);
}
}
示例3: processContextAfterCreation
import org.springframework.ldap.support.LdapUtils; //导入方法依赖的package包/类
public final DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
throws NamingException {
if (ctx instanceof LdapContext) {
final LdapContext ldapCtx = (LdapContext) ctx;
final StartTlsResponse tlsResponse = (StartTlsResponse) ldapCtx.extendedOperation(new StartTlsRequest());
try {
if (hostnameVerifier != null) {
tlsResponse.setHostnameVerifier(hostnameVerifier);
}
tlsResponse.negotiate(sslSocketFactory); // If null, the default SSL socket factory is used
applyAuthentication(ldapCtx, userDn, password);
if (shutdownTlsGracefully) {
// Wrap the target context in a proxy to intercept any calls
// to 'close', so that we can shut down the TLS connection
// gracefully first.
return (DirContext) Proxy.newProxyInstance(DirContextProxy.class.getClassLoader(), new Class<?>[] {
LdapContext.class, DirContextProxy.class }, new TlsAwareDirContextProxy(ldapCtx,
tlsResponse));
}
else {
return ctx;
}
}
catch (IOException e) {
LdapUtils.closeContext(ctx);
throw new UncategorizedLdapException("Failed to negotiate TLS session", e);
}
}
else {
throw new IllegalArgumentException(
"Processed Context must be an LDAPv3 context, i.e. an LdapContext implementation");
}
}
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:37,代码来源:AbstractTlsDirContextAuthenticationStrategy.java
示例4: testCloseContext
import org.springframework.ldap.support.LdapUtils; //导入方法依赖的package包/类
@Test
public void testCloseContext() throws NamingException {
LdapUtils.closeContext(dirContextMock);
verify(dirContextMock).close();
}
示例5: testCloseContext_NullContext
import org.springframework.ldap.support.LdapUtils; //导入方法依赖的package包/类
@Test
public void testCloseContext_NullContext() throws NamingException {
LdapUtils.closeContext(null);
}