diff --git a/gateway/core/auth.go b/gateway/core/auth.go index 57c6eb0..50b9fc3 100644 --- a/gateway/core/auth.go +++ b/gateway/core/auth.go @@ -4,7 +4,7 @@ import "time" type Permit struct { Expire time.Time `json:"expire"` - Whitelists []string `json:"whitelists"` - Username string `json:"username"` - Password string `json:"password"` + Whitelists *[]string `json:"whitelists"` + Username *string `json:"username"` + Password *string `json:"password"` } diff --git a/gateway/fwd/auth/auth.go b/gateway/fwd/auth/auth.go index 283f722..07a7bd2 100644 --- a/gateway/fwd/auth/auth.go +++ b/gateway/fwd/auth/auth.go @@ -47,9 +47,9 @@ func Protect(conn net.Conn, proto Protocol, username, password *string) (*core.A } // 检查 IP 是否可用 - if len(permit.Whitelists) > 0 { + if permit.Whitelists != nil && len(*permit.Whitelists) > 0 { var found = false - for _, allowedHost := range permit.Whitelists { + for _, allowedHost := range *permit.Whitelists { var allowed = net.ParseIP(allowedHost) var remote = net.ParseIP(remoteHost) if remote.Equal(allowed) { @@ -62,8 +62,8 @@ func Protect(conn net.Conn, proto Protocol, username, password *string) (*core.A } } - if username != nil && password != nil { - if *username != permit.Username || *password != permit.Password { + if permit.Username != nil || permit.Password != nil { + if *username != *permit.Username || *password != *permit.Password { return nil, errors.New("用户名或密码错误") } } diff --git a/gateway/web/handlers/auth.go b/gateway/web/handlers/auth.go index aa34e11..40bc04e 100644 --- a/gateway/web/handlers/auth.go +++ b/gateway/web/handlers/auth.go @@ -20,13 +20,15 @@ func Permit(ctx *fiber.Ctx) (err error) { } // 获取请求参数 - req, err := core.Decrypt[PermitReq](&sec, app.PlatformSecret) + req, err := core.Decrypt[[]PermitReq](&sec, app.PlatformSecret) if err != nil { return err } // 保存授权配置 - app.Permits.Store(req.Id, &req.Permit) + for _, permit := range *req { + app.Permits.Store(permit.Id, &permit.Permit) + } return nil }