Ver código fonte

允许用户名中出现点号。
修改ldap登录的filter为可以配置。

gefire 8 anos atrás
pai
commit
3b4ac00943
3 arquivos alterados com 7 adições e 2 exclusões
  1. 2 0
      conf/app.conf.example
  2. 3 1
      conf/enumerate.go
  3. 2 1
      models/member.go

+ 2 - 0
conf/app.conf.example

@@ -94,6 +94,8 @@ ldap_user=CN=ldap helper,OU=example.com,DC=example,DC=com
 ldap_password=superSecret
 #自动注册用户角色:0 超级管理员 /1 管理员/ 2 普通用户 
 ldap_user_role=2
+#ldap搜索filter规则,AD服务器: objectClass=User, openldap服务器: objectClass=posixAccount ,也可以定义为其他属性,如: title=mindoc
+ldap_filter=objectClass=posixAccount
 
 
 

+ 3 - 1
conf/enumerate.go

@@ -14,7 +14,9 @@ const CaptchaSessionName = "__captcha__"
 
 const RegexpEmail = `^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$`
 
-const RegexpAccount = `^[a-zA-Z][a-zA-z0-9]{2,50}$`
+//允许用户名中出现点号
+
+const RegexpAccount = `^[a-zA-Z][a-zA-z0-9\.]{2,50}$`
 
 // PageSize 默认分页条数.
 const PageSize = 15

+ 2 - 1
models/member.go

@@ -107,7 +107,8 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
 	searchRequest := ldap.NewSearchRequest(
 		beego.AppConfig.String("ldap_base"),
 		ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
-		fmt.Sprintf("(&(objectClass=User)(%s=%s))", beego.AppConfig.String("ldap_attribute"), account),
+		//修改objectClass通过配置文件获取值
+		fmt.Sprintf("(&(%s)(%s=%s))",beego.AppConfig.String("ldap_filter"), beego.AppConfig.String("ldap_attribute"), account),
 		[]string{"dn", "mail"},
 		nil,
 	)