From a6a08d13e9a7bff6e8b84c50aa1569e597b356da Mon Sep 17 00:00:00 2001 From: takezoe Date: Thu, 3 Apr 2014 06:54:56 +0900 Subject: [PATCH] (refs #335)Use string before '@' of mail address if user name is mail address in LDAP authentication. --- src/main/scala/util/LDAPUtil.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/scala/util/LDAPUtil.scala b/src/main/scala/util/LDAPUtil.scala index 05a717167..cf6ffe7ad 100644 --- a/src/main/scala/util/LDAPUtil.scala +++ b/src/main/scala/util/LDAPUtil.scala @@ -49,7 +49,7 @@ object LDAPUtil { ){ conn => findMailAddress(conn, userDN, ldapSettings.mailAttribute) match { case Some(mailAddress) => Right(LDAPUserInfo( - userName = userName, + userName = getUserNameFromMailAddress(userName), fullName = ldapSettings.fullNameAttribute.flatMap { fullNameAttribute => findFullName(conn, userDN, fullNameAttribute) }.getOrElse(userName), @@ -59,6 +59,13 @@ object LDAPUtil { } } + private def getUserNameFromMailAddress(userName: String): String = { + (userName.indexOf('@') match { + case i if i < 0 => userName.substring(0, i) + case i => userName + }).replaceAll("[^a-zA-Z0-9\\-_.]", "").replaceAll("^[_\\-]", "") + } + private def bind[A](host: String, port: Int, dn: String, password: String, tls: Boolean, keystore: String, error: String) (f: LDAPConnection => Either[String, A]): Either[String, A] = { if (tls) {