fusenapi/utils/ldap_lib/auth.go

36 lines
726 B
Go
Raw Normal View History

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 02:47:19 +00:00
type LdapOptions struct {
}
2023-11-21 10:10:30 +00:00
// 验证权限
2023-11-22 02:47:19 +00:00
func (l *Ldap) VerifyAuthority(r *http.Request, options ...string) bool {
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
}
// todo 获取分组信息
/*for _, option := range options {
}*/
2023-11-21 10:10:30 +00:00
return true
}