import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.unboundid.ldap.sdk.Attribute;\r
+import com.unboundid.ldap.sdk.ExtendedResult;\r
import com.unboundid.ldap.sdk.LDAPConnection;\r
import com.unboundid.ldap.sdk.LDAPException;\r
import com.unboundid.ldap.sdk.LDAPSearchException;\r
+import com.unboundid.ldap.sdk.ResultCode;\r
import com.unboundid.ldap.sdk.SearchResult;\r
import com.unboundid.ldap.sdk.SearchResultEntry;\r
import com.unboundid.ldap.sdk.SearchScope;\r
+import com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest;\r
import com.unboundid.util.ssl.SSLUtil;\r
import com.unboundid.util.ssl.TrustAllTrustManager;\r
\r
if (ldapPort == -1) // Default Port\r
ldapPort = 389;\r
\r
- return new LDAPConnection(ldapUrl.getHost(), ldapPort, bindUserName, bindPassword);\r
+ LDAPConnection conn = new LDAPConnection(ldapUrl.getHost(), ldapPort, bindUserName, bindPassword);\r
+\r
+ if (ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) {\r
+ SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());\r
+\r
+ ExtendedResult extendedResult = conn.processExtendedOperation(\r
+ new StartTLSExtendedRequest(sslUtil.createSSLContext()));\r
+\r
+ if (extendedResult.getResultCode() != ResultCode.SUCCESS) {\r
+ throw new LDAPException(extendedResult.getResultCode());\r
+ }\r
+ }\r
+ return conn;\r
}\r
} catch (URISyntaxException e) {\r
- logger.error("Bad LDAP URL, should be in the form: ldap(s)://<server>:<port>", e);\r
+ logger.error("Bad LDAP URL, should be in the form: ldap(s|+tls)://<server>:<port>", e);\r
} catch (GeneralSecurityException e) {\r
logger.error("Unable to create SSL Connection", e);\r
} catch (LDAPException e) {\r