(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())), "ldapAuthentication" -> trim(label("LDAP", boolean())),
"ldap" -> optionalIfNotChecked("ldapAuthentication", mapping( "ldap" -> optionalIfNotChecked("ldapAuthentication", mapping(
"host" -> trim(label("LDAP host", text(required))), "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))), "baseDN" -> trim(label("BaseDN", text(required))),
"userNameAttribute" -> trim(label("User name attribute", text(required))), "userNameAttribute" -> trim(label("User name attribute", text(required))),
"mailAttribute" -> trim(label("Mail address attribute", text(required))) "mailAttribute" -> trim(label("Mail address attribute", text(required)))

View File

@@ -23,7 +23,7 @@ trait SystemSettingsService {
if(settings.ldapAuthentication){ if(settings.ldapAuthentication){
settings.ldap.map { ldap => settings.ldap.map { ldap =>
props.setProperty(LdapHost, ldap.host) 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(LdapBaseDN, ldap.baseDN)
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute) props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute) props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute)
@@ -56,10 +56,10 @@ trait SystemSettingsService {
if(getValue(props, LdapAuthentication, false)){ if(getValue(props, LdapAuthentication, false)){
Some(Ldap( Some(Ldap(
getValue(props, LdapHost, ""), getValue(props, LdapHost, ""),
getValue(props, LdapPort, 389), getOptionValue(props, LdapPort, Some(DefaultLdapPort)),
getValue(props, LdapBaseDN, ""), getValue(props, LdapBaseDN, ""),
getValue(props, LdapUserNameAttribute, "uid"), getValue(props, LdapUserNameAttribute, ""),
getValue(props, LdapMailAddressAttribute, "mail"))) getValue(props, LdapMailAddressAttribute, "")))
} else { } else {
None None
} }
@@ -81,7 +81,7 @@ object SystemSettingsService {
case class Ldap( case class Ldap(
host: String, host: String,
port: Int, port: Option[Int],
baseDN: String, baseDN: String,
userNameAttribute: String, userNameAttribute: String,
mailAttribute: String) mailAttribute: String)
@@ -93,6 +93,8 @@ object SystemSettingsService {
password: Option[String], password: Option[String],
ssl: Option[Boolean]) ssl: Option[Boolean])
val DefaultLdapPort = 389
private val AllowAccountRegistration = "allow_account_registration" private val AllowAccountRegistration = "allow_account_registration"
private val Gravatar = "gravatar" private val Gravatar = "gravatar"
private val Notification = "notification" private val Notification = "notification"

View File

@@ -1,6 +1,7 @@
package util package util
import service.SystemSettingsService.Ldap import service.SystemSettingsService.Ldap
import service.SystemSettingsService
import com.novell.ldap.LDAPConnection import com.novell.ldap.LDAPConnection
/** /**
@@ -16,7 +17,7 @@ object LDAPUtil extends App {
var conn: LDAPConnection = null var conn: LDAPConnection = null
try { try {
conn = new LDAPConnection() 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 val userDN = ldapSettings.userNameAttribute + "=" + userName + ",ou=Users," + ldapSettings.baseDN
conn.bind(3, userDN, password.getBytes) conn.bind(3, userDN, password.getBytes)
if(conn.isBound){ if(conn.isBound){