正在显示
3 个修改的文件
包含
21 行增加
和
0 行删除
@@ -4,6 +4,7 @@ go 1.15 | @@ -4,6 +4,7 @@ go 1.15 | ||
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | 6 | github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 |
7 | + github.com/abbot/go-http-auth v0.4.0 | ||
7 | //github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | 8 | //github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 |
8 | github.com/astaxie/beego v1.12.2 | 9 | github.com/astaxie/beego v1.12.2 |
9 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 10 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
@@ -21,4 +21,6 @@ func init() { | @@ -21,4 +21,6 @@ func init() { | ||
21 | beego.InsertFilter("/v1/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) | 21 | beego.InsertFilter("/v1/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) |
22 | beego.InsertFilter("/v1/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) | 22 | beego.InsertFilter("/v1/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) |
23 | beego.InsertFilter("/v1/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*")) | 23 | beego.InsertFilter("/v1/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*")) |
24 | + | ||
25 | + beego.InsertFilter("/log", beego.BeforeStatic, middleware.BasicAuth()) | ||
24 | } | 26 | } |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "fmt" | 6 | "fmt" |
7 | "github.com/astaxie/beego/context" | 7 | "github.com/astaxie/beego/context" |
8 | //"github.com/opentracing/opentracing-go" | 8 | //"github.com/opentracing/opentracing-go" |
9 | + auth "github.com/abbot/go-http-auth" | ||
9 | "github.com/tiptok/gocomm/common" | 10 | "github.com/tiptok/gocomm/common" |
10 | "github.com/tiptok/gocomm/pkg/log" | 11 | "github.com/tiptok/gocomm/pkg/log" |
11 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex" | 12 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex" |
@@ -154,3 +155,20 @@ func AllowCors() func(ctx *context.Context) { | @@ -154,3 +155,20 @@ func AllowCors() func(ctx *context.Context) { | ||
154 | // } | 155 | // } |
155 | // defer sp.Finish() | 156 | // defer sp.Finish() |
156 | //} | 157 | //} |
158 | + | ||
159 | +func secret(user, pwd string) string { | ||
160 | + if user == "admin" { | ||
161 | + // password is "hello" | ||
162 | + return "$1$dlPL2MqE$oQmn16q49SqdmhenQuNgs1" | ||
163 | + } | ||
164 | + return "" | ||
165 | +} | ||
166 | + | ||
167 | +func BasicAuth() func(ctx *context.Context) { | ||
168 | + return func(ctx *context.Context) { | ||
169 | + a := auth.NewBasicAuthenticator("example.com", secret) | ||
170 | + if username := a.CheckAuth(ctx.Request); username == "" { | ||
171 | + a.RequireAuth(ctx.ResponseWriter, ctx.Request) | ||
172 | + } | ||
173 | + } | ||
174 | +} |
-
请 注册 或 登录 后发表评论