mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-10 10:10:27 +08:00
访问控制支持基本认证和子请求认证
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
package serverconfigs
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -13,23 +11,17 @@ import (
|
||||
type HTTPAuthBasicMethodUser struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Encoder string `json:"encoding"`
|
||||
}
|
||||
|
||||
func (this *HTTPAuthBasicMethodUser) Validate(password string) (bool, error) {
|
||||
switch this.Encoder {
|
||||
case "md5":
|
||||
return this.Password == stringutil.Md5(password), nil
|
||||
case "base64":
|
||||
return this.Password == base64.StdEncoding.EncodeToString([]byte(password)), nil
|
||||
default:
|
||||
return this.Password == password, nil
|
||||
}
|
||||
return this.Password == password, nil
|
||||
}
|
||||
|
||||
// HTTPAuthBasicMethod BasicAuth方法定义
|
||||
type HTTPAuthBasicMethod struct {
|
||||
Users []*HTTPAuthBasicMethodUser `json:"users"`
|
||||
Users []*HTTPAuthBasicMethodUser `json:"users"`
|
||||
Realm string `json:"realm"`
|
||||
Charset string `json:"charset"`
|
||||
|
||||
userMap map[string]*HTTPAuthBasicMethodUser // username => *User
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user