mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
Introducing "Enable SSL" option on LDAP settings
This commit is contained in:
@@ -41,6 +41,7 @@ trait SystemSettingsControllerBase extends ControllerBase {
|
|||||||
"fullNameAttribute" -> trim(label("Full name attribute", optional(text()))),
|
"fullNameAttribute" -> trim(label("Full name attribute", optional(text()))),
|
||||||
"mailAttribute" -> trim(label("Mail address attribute", optional(text()))),
|
"mailAttribute" -> trim(label("Mail address attribute", optional(text()))),
|
||||||
"tls" -> trim(label("Enable TLS", optional(boolean()))),
|
"tls" -> trim(label("Enable TLS", optional(boolean()))),
|
||||||
|
"ssl" -> trim(label("Enable SSL", optional(boolean()))),
|
||||||
"keystore" -> trim(label("Keystore", optional(text())))
|
"keystore" -> trim(label("Keystore", optional(text())))
|
||||||
)(Ldap.apply))
|
)(Ldap.apply))
|
||||||
)(SystemSettings.apply).verifying { settings =>
|
)(SystemSettings.apply).verifying { settings =>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ trait SystemSettingsService {
|
|||||||
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
||||||
ldap.mailAttribute.foreach(x => props.setProperty(LdapMailAddressAttribute, x))
|
ldap.mailAttribute.foreach(x => props.setProperty(LdapMailAddressAttribute, x))
|
||||||
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
||||||
|
ldap.ssl.foreach(x => props.setProperty(LdapSsl, x.toString))
|
||||||
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +93,7 @@ trait SystemSettingsService {
|
|||||||
getOptionValue(props, LdapFullNameAttribute, None),
|
getOptionValue(props, LdapFullNameAttribute, None),
|
||||||
getOptionValue(props, LdapMailAddressAttribute, None),
|
getOptionValue(props, LdapMailAddressAttribute, None),
|
||||||
getOptionValue[Boolean](props, LdapTls, None),
|
getOptionValue[Boolean](props, LdapTls, None),
|
||||||
|
getOptionValue[Boolean](props, LdapSsl, None),
|
||||||
getOptionValue(props, LdapKeystore, None)))
|
getOptionValue(props, LdapKeystore, None)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -134,6 +136,7 @@ object SystemSettingsService {
|
|||||||
fullNameAttribute: Option[String],
|
fullNameAttribute: Option[String],
|
||||||
mailAttribute: Option[String],
|
mailAttribute: Option[String],
|
||||||
tls: Option[Boolean],
|
tls: Option[Boolean],
|
||||||
|
ssl: Option[Boolean],
|
||||||
keystore: Option[String])
|
keystore: Option[String])
|
||||||
|
|
||||||
case class Smtp(
|
case class Smtp(
|
||||||
@@ -174,6 +177,7 @@ object SystemSettingsService {
|
|||||||
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
||||||
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
||||||
private val LdapTls = "ldap.tls"
|
private val LdapTls = "ldap.tls"
|
||||||
|
private val LdapSsl = "ldap.ssl"
|
||||||
private val LdapKeystore = "ldap.keystore"
|
private val LdapKeystore = "ldap.keystore"
|
||||||
|
|
||||||
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ object LDAPUtil {
|
|||||||
dn = ldapSettings.bindDN.getOrElse(""),
|
dn = ldapSettings.bindDN.getOrElse(""),
|
||||||
password = ldapSettings.bindPassword.getOrElse(""),
|
password = ldapSettings.bindPassword.getOrElse(""),
|
||||||
tls = ldapSettings.tls.getOrElse(false),
|
tls = ldapSettings.tls.getOrElse(false),
|
||||||
|
ssl = ldapSettings.ssl.getOrElse(false),
|
||||||
keystore = ldapSettings.keystore.getOrElse(""),
|
keystore = ldapSettings.keystore.getOrElse(""),
|
||||||
error = "System LDAP authentication failed."
|
error = "System LDAP authentication failed."
|
||||||
){ conn =>
|
){ conn =>
|
||||||
@@ -65,6 +66,7 @@ object LDAPUtil {
|
|||||||
dn = userDN,
|
dn = userDN,
|
||||||
password = password,
|
password = password,
|
||||||
tls = ldapSettings.tls.getOrElse(false),
|
tls = ldapSettings.tls.getOrElse(false),
|
||||||
|
ssl = ldapSettings.ssl.getOrElse(false),
|
||||||
keystore = ldapSettings.keystore.getOrElse(""),
|
keystore = ldapSettings.keystore.getOrElse(""),
|
||||||
error = "User LDAP Authentication Failed."
|
error = "User LDAP Authentication Failed."
|
||||||
){ conn =>
|
){ conn =>
|
||||||
@@ -96,7 +98,7 @@ object LDAPUtil {
|
|||||||
}).replaceAll("[^a-zA-Z0-9\\-_.]", "").replaceAll("^[_\\-]", "")
|
}).replaceAll("[^a-zA-Z0-9\\-_.]", "").replaceAll("^[_\\-]", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private def bind[A](host: String, port: Int, dn: String, password: String, tls: Boolean, keystore: String, error: String)
|
private def bind[A](host: String, port: Int, dn: String, password: String, tls: Boolean, ssl: Boolean, keystore: String, error: String)
|
||||||
(f: LDAPConnection => Either[String, A]): Either[String, A] = {
|
(f: LDAPConnection => Either[String, A]): Either[String, A] = {
|
||||||
if (tls) {
|
if (tls) {
|
||||||
// Dynamically set Sun as the security provider
|
// Dynamically set Sun as the security provider
|
||||||
@@ -109,7 +111,13 @@ object LDAPUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val conn: LDAPConnection = new LDAPConnection(new LDAPJSSEStartTLSFactory())
|
val conn: LDAPConnection =
|
||||||
|
if(ssl) {
|
||||||
|
new LDAPConnection(new LDAPJSSESecureSocketFactory())
|
||||||
|
}else {
|
||||||
|
new LDAPConnection(new LDAPJSSEStartTLSFactory())
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
conn.connect(host, port)
|
conn.connect(host, port)
|
||||||
|
|||||||
@@ -169,6 +169,13 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" name="ldap.ssl"@if(settings.ldap.flatMap(_.ssl).getOrElse(false)){ checked}/> Enable SSL
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="ldapBindDN">Keystore</label>
|
<label class="control-label" for="ldapBindDN">Keystore</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|||||||
Reference in New Issue
Block a user