(refs #78)LDAP port is optional.

This commit is contained in:
takezoe
2013-08-17 01:48:01 +09:00
parent cdfdff5c32
commit 7e26b4695d
3 changed files with 10 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
"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)))

View File

@@ -23,7 +23,7 @@ trait SystemSettingsService {
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 @@ trait SystemSettingsService {
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 @@ object SystemSettingsService {
case class Ldap(
host: String,
port: Int,
port: Option[Int],
baseDN: String,
userNameAttribute: String,
mailAttribute: String)
@@ -93,6 +93,8 @@ object SystemSettingsService {
password: Option[String],
ssl: Option[Boolean])
val DefaultLdapPort = 389
private val AllowAccountRegistration = "allow_account_registration"
private val Gravatar = "gravatar"
private val Notification = "notification"

View File

@@ -1,6 +1,7 @@
package util
import service.SystemSettingsService.Ldap
import service.SystemSettingsService
import com.novell.ldap.LDAPConnection
/**
@@ -16,7 +17,7 @@ object LDAPUtil extends App {
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){