(refs #78)Fix for LDAP authentication.

This commit is contained in:
takezoe
2013-08-17 01:10:06 +09:00
parent 231fd268df
commit df5600f03f
4 changed files with 17 additions and 22 deletions

View File

@@ -27,9 +27,10 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
post("/signin", form){ form => post("/signin", form){ form =>
val settings = loadSystemSettings() val settings = loadSystemSettings()
settings.authType match { if(settings.ldapAuthentication){
case "LDAP" => ldapAuthentication(form, settings) ldapAuthentication(form, settings)
case _ => defaultAuthentication(form) } else {
defaultAuthentication(form)
} }
} }

View File

@@ -23,8 +23,8 @@ trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
"password" -> trim(label("SMTP Password", optional(text()))), "password" -> trim(label("SMTP Password", optional(text()))),
"ssl" -> trim(label("Enable SSL", optional(boolean()))) "ssl" -> trim(label("Enable SSL", optional(boolean())))
)(Smtp.apply)), )(Smtp.apply)),
"authType" -> trim(label("Auth Type", text(required))), "ldapAuthentication" -> trim(label("LDAP", boolean())),
"ldap" -> optional(_.get("authType") == Some("LDAP"), 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", number(required))),
"baseDN" -> trim(label("BaseDN", text(required))), "baseDN" -> trim(label("BaseDN", text(required))),

View File

@@ -19,7 +19,8 @@ trait SystemSettingsService {
smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString)) smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString))
} }
} }
if(settings.authType == "LDAP"){ props.setProperty(LdapAuthentication, settings.ldapAuthentication.toString)
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) props.setProperty(LdapPort, ldap.port.toString)
@@ -51,14 +52,14 @@ trait SystemSettingsService {
} else { } else {
None None
}, },
getValue(props, AuthType, ""), getValue(props, LdapAuthentication, false),
if(getValue(props, AuthType, "") == "LDAP"){ if(getValue(props, LdapAuthentication, false)){
Some(Ldap( Some(Ldap(
getValue(props, LdapHost, ""), getValue(props, LdapHost, ""),
getValue(props, LdapPort, 389), getValue(props, LdapPort, 389),
getValue(props, LdapBaseDN, ""), getValue(props, LdapBaseDN, ""),
getValue(props, LdapUserNameAttribute, "uid"), getValue(props, LdapUserNameAttribute, "uid"),
getValue(props, LdapUserNameAttribute, "mail"))) getValue(props, LdapMailAddressAttribute, "mail")))
} else { } else {
None None
} }
@@ -75,7 +76,7 @@ object SystemSettingsService {
gravatar: Boolean, gravatar: Boolean,
notification: Boolean, notification: Boolean,
smtp: Option[Smtp], smtp: Option[Smtp],
authType: String, ldapAuthentication: Boolean,
ldap: Option[Ldap]) ldap: Option[Ldap])
case class Ldap( case class Ldap(
@@ -94,13 +95,13 @@ object SystemSettingsService {
private val AllowAccountRegistration = "allow_account_registration" private val AllowAccountRegistration = "allow_account_registration"
private val Gravatar = "gravatar" private val Gravatar = "gravatar"
private val AuthType = "auth_type"
private val Notification = "notification" private val Notification = "notification"
private val SmtpHost = "smtp.host" private val SmtpHost = "smtp.host"
private val SmtpPort = "smtp.port" private val SmtpPort = "smtp.port"
private val SmtpUser = "smtp.user" private val SmtpUser = "smtp.user"
private val SmtpPassword = "smtp.password" private val SmtpPassword = "smtp.password"
private val SmtpSsl = "smtp.ssl" private val SmtpSsl = "smtp.ssl"
private val LdapAuthentication = "ldap_authentication"
private val LdapHost = "ldap.host" private val LdapHost = "ldap.host"
private val LdapPort = "ldap.port" private val LdapPort = "ldap.port"
private val LdapBaseDN = "ldap.baseDN" private val LdapBaseDN = "ldap.baseDN"

View File

@@ -40,13 +40,7 @@
<label><strong>Authentication</strong></label> <label><strong>Authentication</strong></label>
<fieldset> <fieldset>
<label> <label>
<input type="radio" id="authTypeDefault" name="authType" value="Default"@if(settings.authType != "LDAP"){ checked}/> <input type="checkbox" id="ldapAuthentication" name="ldapAuthentication"@if(settings.ldap){ checked}/>
Default
</label>
</fieldset>
<fieldset>
<label>
<input type="radio" id="authTypeLDAP" name="authType" value="LDAP"@if(settings.authType == "LDAP"){ checked}/>
LDAP LDAP
</label> </label>
</fieldset> </fieldset>
@@ -147,9 +141,8 @@ $(function(){
$('.notification input').prop('disabled', !$(this).prop('checked')); $('.notification input').prop('disabled', !$(this).prop('checked'));
}).change(); }).change();
$('input[name=authType]').click(function(){ $('#ldapAuthentication').change(function(){
$('.ldap input').prop('disabled', $('input[name=authType]:checked').val() != "LDAP"); $('.ldap input').prop('disabled', !$(this).prop('checked'));
}); }).change();
$('input[name=authType]:checked').click();
}); });
</script> </script>