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-21 10:19:14 +00:00
|
|
|
func (l *Ldap) VerifyAuthority(r *http.Request, jwtSecret string) bool {
|
|
|
|
token := r.Header.Get("Ldap-Authorization")
|
2023-11-21 10:10:30 +00:00
|
|
|
info, err := l.ParseJwtToken(token, jwtSecret)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
// TODO 查询权限组相关信息
|
|
|
|
return true
|
|
|
|
}
|