그들은 명시 적으로 LDAP에 바인드 풀링 (또는 Spring의 경우 authenticate
에서) 제거 : 사용자에 대한
https://github.com/spring-projects/spring-ldap/issues/216
ldapTemplate.authenticate
검색 및 LDAP 바인드를 수행 할 contextSource.getContext
를 호출합니다.
private AuthenticationStatus authenticate(Name base,
String filter,
String password,
SearchControls searchControls,
final AuthenticatedLdapEntryContextCallback callback,
final AuthenticationErrorCallback errorCallback) {
List<LdapEntryIdentification> result = search(base, filter, searchControls, new LdapEntryIdentificationContextMapper());
if (result.size() == 0) {
String msg = "No results found for search, base: '" + base + "'; filter: '" + filter + "'.";
LOG.info(msg);
return AuthenticationStatus.EMPTYRESULT;
} else if (result.size() > 1) {
String msg = "base: '" + base + "'; filter: '" + filter + "'.";
throw new IncorrectResultSizeDataAccessException(msg, 1, result.size());
}
final LdapEntryIdentification entryIdentification = result.get(0);
try {
DirContext ctx = contextSource.getContext(entryIdentification.getAbsoluteName().toString(), password);
executeWithContext(new ContextExecutor<Object>() {
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException {
callback.executeWithContext(ctx, entryIdentification);
return null;
}
}, ctx);
return AuthenticationStatus.SUCCESS;
}
catch (Exception e) {
LOG.debug("Authentication failed for entry with DN '" + entryIdentification.getAbsoluteName() + "'", e);
errorCallback.execute(e);
return AuthenticationStatus.UNDEFINED_FAILURE;
}
}
기본적으로 컨텍스트 원본은 풀링을 사용하지 않습니다. AbstractContextSource.java
에서 (어떤 것과 LdapContextSource
상속) :
public abstract class AbstractContextSource implements BaseLdapPathContextSource, InitializingBean {
...
public DirContext getContext(String principal, String credentials) {
// This method is typically called for authentication purposes, which means that we
// should explicitly disable pooling in case passwords are changed (LDAP-183).
return doGetContext(principal, credentials, EXPLICITLY_DISABLE_POOLING);
}
private DirContext doGetContext(String principal, String credentials, boolean explicitlyDisablePooling) {
Hashtable<String, Object> env = getAuthenticatedEnv(principal, credentials);
if(explicitlyDisablePooling) {
env.remove(SUN_LDAP_POOLING_FLAG);
}
DirContext ctx = createContext(env);
try {
authenticationStrategy.processContextAfterCreation(ctx, principal, credentials);
return ctx;
}
catch (NamingException e) {
closeContext(ctx);
throw LdapUtils.convertLdapException(e);
}
}
...
}
그리고 당신이 PoolingContextSource
를 사용하려고하면 getContext
호출하려고 authenticate
때, 당신은 UnsupportedOperationException
을 얻을 것이다 :이 코드는
public class PoolingContextSource
extends DelegatingBaseLdapPathContextSourceSupport
implements ContextSource, DisposableBean {
...
@Override
public DirContext getContext(String principal, String credentials) {
throw new UnsupportedOperationException("Not supported for this implementation");
}
}
입니다 spring-ldap-core 2.3.1.RELEASE
인공물에서.
PoolingContextSource
을 사용하여 여전히 LDAP 검색을위한 연결 풀링을 수행 할 수 있지만 인증을위한 연결 풀링은 작동하지 않습니다.
이 경우 관리자 DN과 암호가 지정된 이유는 무엇입니까? 나의 이해에 따라 클라이언트는 manger dn과 비밀번호를 사용하여 LDAP 서버에 연결하고 나중에 인증에 사용되는 사용자 dn과 비밀번호가있는 바인드 요청을 보냅니다. 그래서 manger DN과 비밀번호를 사용하여 생성 된 초기 연결은 풀링되지 않았습니까? – rpawar
위와 같이 웹 애플리케이션에서 BIND 작업을 통한 LDAP 기반 인증을 사용하는 경우 로그인하는 모든 사용자는 자체 LDAP 연결을 만듭니다. 이것은 많은 LDAP 연결로 이어질 것입니다. 풀을 만들고 연결을 다시 사용할 수있는 방법이 있습니까? 최소한이 연결에 대한 유휴 상태 또는 시간 초과를 어떻게 설정합니까? – rpawar
개별 사용자마다 생성 된 연결은 Spring LDAP 인프라 스트럭처에 의해 자동으로 닫혀 야하므로 걱정할 필요가 없습니다. 이 외에도 관리자 LDAP 연결이 생성되어 인증 전에 사용자를 검색하는 데 사용됩니다. 이 연결은 자동으로 닫히게되고 이론 상으로는 풀링이 가능해야하지만 LDAP 서버 XML은이를 지원하지 않습니다. ldap-server 요소는 ContextSource 인스턴스 만 생성하는 것으로 보이므로 대신를 생성하여 사용하십시오. –
marthursson