mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
AccountUtil is merged to LDAPUtil
This commit is contained in:
@@ -59,7 +59,7 @@ trait IndexControllerBase extends ControllerBase {
|
||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||
updateLastLoginDate(account.userName)
|
||||
|
||||
if(AccountUtil.hasLdapDummyMailAddress(account)) {
|
||||
if(LDAPUtil.hasLdapDummyMailAddress(account)) {
|
||||
redirect("/" + account.userName + "/_edit")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package util
|
||||
|
||||
import model.Account
|
||||
|
||||
/**
|
||||
* Utility for account model.
|
||||
*/
|
||||
object AccountUtil {
|
||||
private val LDAP_DUMMY_MAL = "@ldap-devnull"
|
||||
|
||||
def hasLdapDummyMailAddress(account: Account): Boolean = {
|
||||
account.mailAddress.endsWith(LDAP_DUMMY_MAL)
|
||||
}
|
||||
|
||||
def getLdapDummyMailAddress(userName: String): String = {
|
||||
userName + LDAP_DUMMY_MAL
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.security.Security
|
||||
import org.slf4j.LoggerFactory
|
||||
import service.SystemSettingsService.Ldap
|
||||
import scala.annotation.tailrec
|
||||
import model.Account
|
||||
|
||||
/**
|
||||
* Utility for LDAP authentication.
|
||||
@@ -16,6 +17,26 @@ object LDAPUtil {
|
||||
private val LDAP_VERSION: Int = LDAPConnection.LDAP_V3
|
||||
private val logger = LoggerFactory.getLogger(getClass().getName())
|
||||
|
||||
private val LDAP_DUMMY_MAL = "@ldap-devnull"
|
||||
|
||||
/**
|
||||
* Returns true if mail address ends with "@ldap-devnull"
|
||||
*/
|
||||
def hasLdapDummyMailAddress(account: Account): Boolean = {
|
||||
account.mailAddress.endsWith(LDAP_DUMMY_MAL)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates dummy address (userName@ldap-devnull) for LDAP login.
|
||||
*
|
||||
* If mail address is not managed in LDAP server, GitBucket stores this dummy address in first LDAP login.
|
||||
* GitBucket does not send any mails to this dummy address. And these users must input their mail address
|
||||
* at the first step after LDAP authentication.
|
||||
*/
|
||||
def getLdapDummyMailAddress(userName: String): String = {
|
||||
userName + LDAP_DUMMY_MAL
|
||||
}
|
||||
|
||||
/**
|
||||
* Try authentication by LDAP using given configuration.
|
||||
* Returns Right(LDAPUserInfo) if authentication is successful, otherwise Left(errorMessage).
|
||||
@@ -53,7 +74,7 @@ object LDAPUtil {
|
||||
fullName = ldapSettings.fullNameAttribute.flatMap { fullNameAttribute =>
|
||||
findFullName(conn, userDN, ldapSettings.userNameAttribute, userName, fullNameAttribute)
|
||||
}.getOrElse(userName),
|
||||
mailAddress = AccountUtil.getLdapDummyMailAddress(userName)))
|
||||
mailAddress = getLdapDummyMailAddress(userName)))
|
||||
} else {
|
||||
findMailAddress(conn, userDN, ldapSettings.userNameAttribute, userName, ldapSettings.mailAttribute.get) match {
|
||||
case Some(mailAddress) => Right(LDAPUserInfo(
|
||||
|
||||
@@ -28,7 +28,7 @@ trait Notifier extends RepositoryService with AccountService with IssuesService
|
||||
)
|
||||
.distinct
|
||||
.withFilter ( _ != context.loginAccount.get.userName ) // the operation in person is excluded
|
||||
.foreach ( getAccountByUserName(_) filterNot (_.isGroupAccount) filterNot (AccountUtil.hasLdapDummyMailAddress(_)) foreach (x => notify(x.mailAddress)) )
|
||||
.foreach ( getAccountByUserName(_) filterNot (_.isGroupAccount) filterNot (LDAPUtil.hasLdapDummyMailAddress(_)) foreach (x => notify(x.mailAddress)) )
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@(account: model.Account, info: Option[Any])(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
@import util.AccountUtil
|
||||
@import util.LDAPUtil
|
||||
@html.main("Edit your profile"){
|
||||
<div class="container">
|
||||
<div class="row-fluid">
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="span9">
|
||||
@helper.html.information(info)
|
||||
@if(AccountUtil.hasLdapDummyMailAddress(account)){<div class="alert alert-danger">Please register your mail address.</div>}
|
||||
@if(LDAPUtil.hasLdapDummyMailAddress(account)){<div class="alert alert-danger">Please register your mail address.</div>}
|
||||
<form action="@url(account.userName)/_edit" method="POST" validate="true">
|
||||
<div class="box">
|
||||
<div class="box-header">Profile</div>
|
||||
@@ -33,7 +33,7 @@
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="mailAddress" class="strong">Mail Address:</label>
|
||||
<input type="text" name="mailAddress" id="mailAddress" value="@if(!AccountUtil.hasLdapDummyMailAddress(account)){@account.mailAddress}"/>
|
||||
<input type="text" name="mailAddress" id="mailAddress" value="@if(!LDAPUtil.hasLdapDummyMailAddress(account)){@account.mailAddress}"/>
|
||||
<span id="error-mailAddress" class="error"></span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@@ -54,7 +54,7 @@
|
||||
<a href="@path/@account.userName/_delete" class="btn btn-danger" id="delete">Delete account</a>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="Save"/>
|
||||
@if(!AccountUtil.hasLdapDummyMailAddress(account)){<a href="@url(account.userName)" class="btn">Cancel</a>}
|
||||
@if(!LDAPUtil.hasLdapDummyMailAddress(account)){<a href="@url(account.userName)" class="btn">Cancel</a>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user