diff --git a/src/main/scala/app/SystemSettingsController.scala b/src/main/scala/app/SystemSettingsController.scala index 03df403..b688d12 100644 --- a/src/main/scala/app/SystemSettingsController.scala +++ b/src/main/scala/app/SystemSettingsController.scala @@ -26,7 +26,7 @@ "ldapAuthentication" -> trim(label("LDAP", boolean())), "ldap" -> optionalIfNotChecked("ldapAuthentication", mapping( "host" -> trim(label("LDAP host", text(required))), - "port" -> trim(label("LDAP port", number(required))), + "port" -> trim(label("LDAP port", optional(number()))), "baseDN" -> trim(label("BaseDN", text(required))), "userNameAttribute" -> trim(label("User name attribute", text(required))), "mailAttribute" -> trim(label("Mail address attribute", text(required))) diff --git a/src/main/scala/service/SystemSettingsService.scala b/src/main/scala/service/SystemSettingsService.scala index ee83a12..a36e62b 100644 --- a/src/main/scala/service/SystemSettingsService.scala +++ b/src/main/scala/service/SystemSettingsService.scala @@ -23,7 +23,7 @@ if(settings.ldapAuthentication){ settings.ldap.map { ldap => props.setProperty(LdapHost, ldap.host) - props.setProperty(LdapPort, ldap.port.toString) + ldap.port.foreach(x => props.setProperty(LdapPort, x.toString)) props.setProperty(LdapBaseDN, ldap.baseDN) props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute) props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute) @@ -56,10 +56,10 @@ if(getValue(props, LdapAuthentication, false)){ Some(Ldap( getValue(props, LdapHost, ""), - getValue(props, LdapPort, 389), + getOptionValue(props, LdapPort, Some(DefaultLdapPort)), getValue(props, LdapBaseDN, ""), - getValue(props, LdapUserNameAttribute, "uid"), - getValue(props, LdapMailAddressAttribute, "mail"))) + getValue(props, LdapUserNameAttribute, ""), + getValue(props, LdapMailAddressAttribute, ""))) } else { None } @@ -81,7 +81,7 @@ case class Ldap( host: String, - port: Int, + port: Option[Int], baseDN: String, userNameAttribute: String, mailAttribute: String) @@ -93,6 +93,8 @@ password: Option[String], ssl: Option[Boolean]) + val DefaultLdapPort = 389 + private val AllowAccountRegistration = "allow_account_registration" private val Gravatar = "gravatar" private val Notification = "notification" diff --git a/src/main/scala/util/LDAPUtil.scala b/src/main/scala/util/LDAPUtil.scala index 21454ef..edd75fe 100644 --- a/src/main/scala/util/LDAPUtil.scala +++ b/src/main/scala/util/LDAPUtil.scala @@ -1,6 +1,7 @@ package util import service.SystemSettingsService.Ldap +import service.SystemSettingsService import com.novell.ldap.LDAPConnection /** @@ -16,7 +17,7 @@ var conn: LDAPConnection = null try { conn = new LDAPConnection() - conn.connect(ldapSettings.host, ldapSettings.port) + conn.connect(ldapSettings.host, ldapSettings.port.getOrElse(SystemSettingsService.DefaultLdapPort)) val userDN = ldapSettings.userNameAttribute + "=" + userName + ",ou=Users," + ldapSettings.baseDN conn.bind(3, userDN, password.getBytes) if(conn.isBound){