2023-11-21 10:10:30 +00:00
|
|
|
package ldap_lib
|
|
|
|
|
2023-11-21 10:19:14 +00:00
|
|
|
import (
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"net/http"
|
|
|
|
)
|
2023-11-21 10:10:30 +00:00
|
|
|
|
2023-11-22 03:18:29 +00:00
|
|
|
type LdapVerifyType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
API_PATH LdapVerifyType = "api_path"
|
|
|
|
MENU_PATH LdapVerifyType = "menu_path"
|
|
|
|
)
|
|
|
|
|
2023-11-22 02:47:19 +00:00
|
|
|
type LdapOptions struct {
|
2023-11-22 03:18:29 +00:00
|
|
|
Type LdapVerifyType
|
|
|
|
Value string
|
2023-11-22 02:47:19 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 10:10:30 +00:00
|
|
|
// 验证权限
|
2023-11-22 03:18:29 +00:00
|
|
|
func (l *Ldap) VerifyAuthority(r *http.Request, options ...LdapOptions) bool {
|
|
|
|
return true
|
2023-11-21 10:19:14 +00:00
|
|
|
token := r.Header.Get("Ldap-Authorization")
|
2023-11-22 02:19:27 +00:00
|
|
|
info, err := l.ParseJwtToken(token, l.jwtSecret)
|
2023-11-21 10:10:30 +00:00
|
|
|
if err != nil {
|
|
|
|
logx.Error("解析token失败", err, "----token:", token)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
//查询ldap
|
|
|
|
userInfo, err := l.GetLdapUserInfo(info.UserDN)
|
|
|
|
if err != nil {
|
|
|
|
logx.Error("获取ldap用户信息失败", err, "----user_dn:", info.UserDN)
|
|
|
|
}
|
|
|
|
if userInfo.Status != 1 {
|
|
|
|
return false
|
|
|
|
}
|
2023-11-22 02:47:19 +00:00
|
|
|
if len(options) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
2023-11-21 10:10:30 +00:00
|
|
|
return true
|
|
|
|
}
|