Ver código fonte

Bind LDAP connection after TLS initialization (issue-343)

tags/v1.4.0
Günter Dressel 10 anos atrás
pai
commit
237faead29
2 arquivos alterados com 29 adições e 30 exclusões
  1. 2
    0
      releases.moxie
  2. 27
    30
      src/main/java/com/gitblit/LdapUserService.java

+ 2
- 0
releases.moxie Ver arquivo

security: ~ security: ~
fixes: fixes:
- Fixed support for implied SSH urls in web.otherUrls (issue-311) - Fixed support for implied SSH urls in web.otherUrls (issue-311)
- Bind LDAP connection after establishing TLS initialization (issue-343)
- Fix potential NPE on removing uncached repository from cache - Fix potential NPE on removing uncached repository from cache
- Ignore the default contents of .git/description file - Ignore the default contents of .git/description file
- Fix error on generating activity page when there is no activity - Fix error on generating activity page when there is no activity
- Chad Horohoe - Chad Horohoe
- Domingo Oropeza - Domingo Oropeza
- Chris Graham - Chris Graham
- Guenter Dressel
} }


# #

+ 27
- 30
src/main/java/com/gitblit/LdapUserService.java Ver arquivo

import com.unboundid.ldap.sdk.SearchResult; import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry; import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope; import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.SimpleBindRequest;
import com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest; import com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest;
import com.unboundid.util.ssl.SSLUtil; import com.unboundid.util.ssl.SSLUtil;
import com.unboundid.util.ssl.TrustAllTrustManager; import com.unboundid.util.ssl.TrustAllTrustManager;
private LDAPConnection getLdapConnection() { private LDAPConnection getLdapConnection() {
try { try {
URI ldapUrl = new URI(settings.getRequiredString(Keys.realm.ldap.server)); URI ldapUrl = new URI(settings.getRequiredString(Keys.realm.ldap.server));
String ldapHost = ldapUrl.getHost();
int ldapPort = ldapUrl.getPort();
String bindUserName = settings.getString(Keys.realm.ldap.username, ""); String bindUserName = settings.getString(Keys.realm.ldap.username, "");
String bindPassword = settings.getString(Keys.realm.ldap.password, ""); String bindPassword = settings.getString(Keys.realm.ldap.password, "");
int ldapPort = ldapUrl.getPort();
LDAPConnection conn;
if (ldapUrl.getScheme().equalsIgnoreCase("ldaps")) { // SSL if (ldapUrl.getScheme().equalsIgnoreCase("ldaps")) { // SSL
if (ldapPort == -1) // Default Port
ldapPort = 636;
LDAPConnection conn;
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager()); SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
if (StringUtils.isEmpty(bindUserName) && StringUtils.isEmpty(bindPassword)) {
conn = new LDAPConnection(sslUtil.createSSLSocketFactory(), ldapUrl.getHost(), ldapPort);
} else {
conn = new LDAPConnection(sslUtil.createSSLSocketFactory(), ldapUrl.getHost(), ldapPort, bindUserName, bindPassword);
}
return conn;
conn = new LDAPConnection(sslUtil.createSSLSocketFactory());
} else if (ldapUrl.getScheme().equalsIgnoreCase("ldap") || ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) { // no encryption or StartTLS
conn = new LDAPConnection();
} else { } else {
if (ldapPort == -1) // Default Port
ldapPort = 389;
LDAPConnection conn;
if (StringUtils.isEmpty(bindUserName) && StringUtils.isEmpty(bindPassword)) {
conn = new LDAPConnection(ldapUrl.getHost(), ldapPort);
} else {
conn = new LDAPConnection(ldapUrl.getHost(), ldapPort, bindUserName, bindPassword);
}
if (ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) {
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
ExtendedResult extendedResult = conn.processExtendedOperation(
logger.error("Unsupported LDAP URL scheme: " + ldapUrl.getScheme());
return null;
}
conn.connect(ldapHost, ldapPort);
if (ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) {
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
ExtendedResult extendedResult = conn.processExtendedOperation(
new StartTLSExtendedRequest(sslUtil.createSSLContext())); new StartTLSExtendedRequest(sslUtil.createSSLContext()));
if (extendedResult.getResultCode() != ResultCode.SUCCESS) {
throw new LDAPException(extendedResult.getResultCode());
}
if (extendedResult.getResultCode() != ResultCode.SUCCESS) {
throw new LDAPException(extendedResult.getResultCode());
} }
return conn;
} }
if ( ! StringUtils.isEmpty(bindUserName) || ! StringUtils.isEmpty(bindPassword)) {
conn.bind(new SimpleBindRequest(bindUserName, bindPassword));
}
return conn;
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
logger.error("Bad LDAP URL, should be in the form: ldap(s|+tls)://<server>:<port>", e); logger.error("Bad LDAP URL, should be in the form: ldap(s|+tls)://<server>:<port>", e);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {

Carregando…
Cancelar
Salvar