优化访问控制,将“认证”两字改为“鉴权”

This commit is contained in:
刘祥超
2022-08-30 11:22:54 +08:00
parent 6df6809ab3
commit 316e793b1e
22 changed files with 756 additions and 77 deletions

View File

@@ -5,7 +5,7 @@ import (
"strings"
)
// format address
// FormatAddress format address
func FormatAddress(addr string) string {
if strings.HasSuffix(addr, "unix:") {
return addr
@@ -17,7 +17,7 @@ func FormatAddress(addr string) string {
return addr
}
// 分割数字
// SplitNumbers 分割数字
func SplitNumbers(numbers string) (result []int64) {
if len(numbers) == 0 {
return

View File

@@ -0,0 +1,67 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package utils
import (
"github.com/iwind/TeaGo/lists"
"strings"
)
func FilterNotEmpty(item string) bool {
return len(item) > 0
}
func MapAddPrefixFunc(prefix string) func(item string) string {
return func(item string) string {
if !strings.HasPrefix(item, prefix) {
return prefix + item
}
return item
}
}
type StringsStream struct {
s []string
}
func NewStringsStream(s []string) *StringsStream {
return &StringsStream{s: s}
}
func (this *StringsStream) Map(f ...func(item string) string) *StringsStream {
for index, item := range this.s {
for _, f1 := range f {
item = f1(item)
}
this.s[index] = item
}
return this
}
func (this *StringsStream) Filter(f ...func(item string) bool) *StringsStream {
for _, f1 := range f {
var newStrings = []string{}
for _, item := range this.s {
if f1(item) {
newStrings = append(newStrings, item)
}
}
this.s = newStrings
}
return this
}
func (this *StringsStream) Unique() *StringsStream {
var newStrings = []string{}
for _, item := range this.s {
if !lists.ContainsString(newStrings, item) {
newStrings = append(newStrings, item)
}
}
this.s = newStrings
return this
}
func (this *StringsStream) Result() []string {
return this.s
}

View File

@@ -0,0 +1,25 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package utils_test
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"strings"
"testing"
)
func TestStringsStream_Filter(t *testing.T) {
var stream = utils.NewStringsStream([]string{"a", "b", "1", "2", "", "png", "a"})
stream.Filter(func(item string) bool {
return len(item) > 0
})
t.Log(stream.Result())
stream.Map(func(item string) string {
return "." + item
})
t.Log(stream.Result())
stream.Unique()
t.Log(stream.Result())
stream.Map(strings.ToUpper, strings.ToLower)
t.Log(stream.Result())
}

View File

@@ -1,13 +1,16 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build !plus
package access
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"strings"
)
type CreatePopupAction struct {
@@ -37,6 +40,9 @@ func (this *CreatePopupAction) RunPost(params struct {
SubRequestMethod string
SubRequestFollowRequest bool
Exts []string
DomainsJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
@@ -44,14 +50,42 @@ func (this *CreatePopupAction) RunPost(params struct {
Field("name", params.Name).
Require("请输入名称").
Field("type", params.Type).
Require("请输入认证类型")
Require("请输入鉴权类型")
var ref = &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
var paramsJSON []byte
// 扩展名
var exts = utils.NewStringsStream(params.Exts).
Map(strings.TrimSpace, strings.ToLower).
Filter(utils.FilterNotEmpty).
Map(utils.MapAddPrefixFunc(".")).
Unique().
Result()
// 域名
var domains = []string{}
if len(params.DomainsJSON) > 0 {
var rawDomains = []string{}
err := json.Unmarshal(params.DomainsJSON, &rawDomains)
if err != nil {
this.ErrorPage(err)
return
}
// TODO 如果用户填写了一个网址,应该分析域名并填入
domains = utils.NewStringsStream(rawDomains).
Map(strings.TrimSpace, strings.ToLower).
Filter(utils.FilterNotEmpty).
Unique().
Result()
}
var method serverconfigs.HTTPAuthMethodInterface
switch params.Type {
case serverconfigs.HTTPAuthTypeBasicAuth:
users := []*serverconfigs.HTTPAuthBasicMethodUser{}
var users = []*serverconfigs.HTTPAuthBasicMethodUser{}
err := json.Unmarshal(params.HttpAuthBasicAuthUsersJSON, &users)
if err != nil {
this.ErrorPage(err)
@@ -60,40 +94,39 @@ func (this *CreatePopupAction) RunPost(params struct {
if len(users) == 0 {
this.Fail("请添加至少一个用户")
}
method := &serverconfigs.HTTPAuthBasicMethod{
method = &serverconfigs.HTTPAuthBasicMethod{
Users: users,
Realm: params.BasicAuthRealm,
Charset: params.BasicAuthCharset,
}
methodJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
paramsJSON = methodJSON
case serverconfigs.HTTPAuthTypeSubRequest:
params.Must.Field("subRequestURL", params.SubRequestURL).
Require("请输入子请求URL")
if params.SubRequestFollowRequest {
params.SubRequestMethod = ""
}
method := &serverconfigs.HTTPAuthSubRequestMethod{
method = &serverconfigs.HTTPAuthSubRequestMethod{
URL: params.SubRequestURL,
Method: params.SubRequestMethod,
}
methodJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
paramsJSON = methodJSON
default:
this.Fail("不支持的认证类型'" + params.Type + "'")
this.Fail("不支持的鉴权类型'" + params.Type + "'")
}
if method == nil {
this.Fail("无法找到对应的鉴权方式")
}
method.SetExts(exts)
method.SetDomains(domains)
paramsJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
var paramsMap map[string]interface{}
err := json.Unmarshal(paramsJSON, &paramsMap)
err = json.Unmarshal(paramsJSON, &paramsMap)
if err != nil {
this.ErrorPage(err)
return
@@ -108,7 +141,7 @@ func (this *CreatePopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
defer this.CreateLogInfo("创建HTTP认证 %d", createResp.HttpAuthPolicyId)
defer this.CreateLogInfo("创建HTTP鉴权 %d", createResp.HttpAuthPolicyId)
ref.AuthPolicyId = createResp.HttpAuthPolicyId
ref.AuthPolicy = &serverconfigs.HTTPAuthPolicy{
Id: createResp.HttpAuthPolicyId,

View File

@@ -7,6 +7,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
)
type IndexAction struct {
@@ -28,6 +29,26 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["webId"] = webConfig.Id
// 移除不存在的鉴权方法
var allTypes = []string{}
for _, def := range serverconfigs.FindAllHTTPAuthTypes() {
allTypes = append(allTypes, def.Code)
}
var refs = webConfig.Auth.PolicyRefs
var realRefs = []*serverconfigs.HTTPAuthPolicyRef{}
for _, ref := range refs {
if ref.AuthPolicy == nil {
continue
}
if !lists.ContainsString(allTypes, ref.AuthPolicy.Type) {
continue
}
realRefs = append(realRefs, ref)
}
webConfig.Auth.PolicyRefs = realRefs
this.Data["authConfig"] = webConfig.Auth
this.Show()
@@ -40,7 +61,7 @@ func (this *IndexAction) RunPost(params struct {
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo("修改Web %d 的认证设置", params.WebId)
defer this.CreateLogInfo("修改Web %d 的鉴权设置", params.WebId)
var authConfig = &serverconfigs.HTTPAuthConfig{}
err := json.Unmarshal(params.AuthJSON, authConfig)
@@ -53,7 +74,7 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("配置校验失败:" + err.Error())
}
// 保存之前删除多的配置信息
// 保存之前删除多的配置信息
for _, ref := range authConfig.PolicyRefs {
ref.AuthPolicy = nil
}

View File

@@ -16,6 +16,7 @@ func init() {
GetPost("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).
GetPost("/updatePopup", new(UpdatePopupAction)).
Post("/random", new(RandomAction)).
EndAll()
})
}

View File

@@ -0,0 +1,18 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package access
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/rands"
)
type RandomAction struct {
actionutils.ParentAction
}
func (this *RandomAction) RunPost(params struct{}) {
this.Data["random"] = rands.HexString(32)
this.Success()
}

View File

@@ -1,14 +1,17 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build !plus
package access
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"strings"
)
type UpdatePopupAction struct {
@@ -70,17 +73,20 @@ func (this *UpdatePopupAction) RunPost(params struct {
SubRequestMethod string
SubRequestFollowRequest bool
Exts []string
DomainsJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo("修改HTTP认证 %d", params.PolicyId)
defer this.CreateLogInfo("修改HTTP鉴权 %d", params.PolicyId)
policyResp, err := this.RPC().HTTPAuthPolicyRPC().FindEnabledHTTPAuthPolicy(this.AdminContext(), &pb.FindEnabledHTTPAuthPolicyRequest{HttpAuthPolicyId: params.PolicyId})
if err != nil {
this.ErrorPage(err)
return
}
policy := policyResp.HttpAuthPolicy
var policy = policyResp.HttpAuthPolicy
if policy == nil {
this.NotFound("httpAuthPolicy", params.PolicyId)
return
@@ -91,12 +97,40 @@ func (this *UpdatePopupAction) RunPost(params struct {
Field("name", params.Name).
Require("请输入名称")
// 扩展名
var exts = utils.NewStringsStream(params.Exts).
Map(strings.TrimSpace, strings.ToLower).
Filter(utils.FilterNotEmpty).
Map(utils.MapAddPrefixFunc(".")).
Unique().
Result()
// 域名
var domains = []string{}
if len(params.DomainsJSON) > 0 {
var rawDomains = []string{}
err := json.Unmarshal(params.DomainsJSON, &rawDomains)
if err != nil {
this.ErrorPage(err)
return
}
// TODO 如果用户填写了一个网址,应该分析域名并填入
domains = utils.NewStringsStream(rawDomains).
Map(strings.TrimSpace, strings.ToLower).
Filter(utils.FilterNotEmpty).
Unique().
Result()
}
var ref = &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
var paramsJSON []byte
var method serverconfigs.HTTPAuthMethodInterface
switch policyType {
case serverconfigs.HTTPAuthTypeBasicAuth:
users := []*serverconfigs.HTTPAuthBasicMethodUser{}
var users = []*serverconfigs.HTTPAuthBasicMethodUser{}
err := json.Unmarshal(params.HttpAuthBasicAuthUsersJSON, &users)
if err != nil {
this.ErrorPage(err)
@@ -105,36 +139,35 @@ func (this *UpdatePopupAction) RunPost(params struct {
if len(users) == 0 {
this.Fail("请添加至少一个用户")
}
method := &serverconfigs.HTTPAuthBasicMethod{
method = &serverconfigs.HTTPAuthBasicMethod{
Users: users,
Realm: params.BasicAuthRealm,
Charset: params.BasicAuthCharset,
}
methodJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
paramsJSON = methodJSON
case serverconfigs.HTTPAuthTypeSubRequest:
params.Must.Field("subRequestURL", params.SubRequestURL).
Require("请输入子请求URL")
if params.SubRequestFollowRequest {
params.SubRequestMethod = ""
}
method := &serverconfigs.HTTPAuthSubRequestMethod{
method = &serverconfigs.HTTPAuthSubRequestMethod{
URL: params.SubRequestURL,
Method: params.SubRequestMethod,
}
methodJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
paramsJSON = methodJSON
default:
this.Fail("不支持的认证类型'" + policyType + "'")
this.Fail("不支持的鉴权类型'" + policyType + "'")
}
if method == nil {
this.Fail("无法找到对应的鉴权方式")
}
method.SetExts(exts)
method.SetDomains(domains)
paramsJSON, err := json.Marshal(method)
if err != nil {
this.ErrorPage(err)
return
}
var paramsMap map[string]interface{}

View File

@@ -2485,13 +2485,13 @@ Vue.component("traffic-map-box",{props:["v-stats","v-is-attack"],mounted:functio
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
</div>
<p class="comment">系统总是会先执行记录日志、标签等不会修改请求的动作,再执行阻止、验证码等可能改变请求的动作。</p>
</div>`}),Vue.component("http-auth-config-box",{props:["v-auth-config","v-is-location"],data:function(){let e=this.vAuthConfig;return null==(e=null==e?{isPrior:!1,isOn:!1}:e).policyRefs&&(e.policyRefs=[]),{authConfig:e}},methods:{isOn:function(){return(!this.vIsLocation||this.authConfig.isPrior)&&this.authConfig.isOn},add:function(){let t=this;teaweb.popup("/servers/server/settings/access/createPopup",{callback:function(e){t.authConfig.policyRefs.push(e.data.policyRef)},height:"28em"})},update:function(e,t){teaweb.popup("/servers/server/settings/access/updatePopup?policyId="+t,{callback:function(e){teaweb.success("保存成功",function(){teaweb.reload()})},height:"28em"})},remove:function(e){this.authConfig.policyRefs.$remove(e)},methodName:function(e){switch(e){case"basicAuth":return"BasicAuth";case"subRequest":return"子请求"}return""}},template:`<div>
</div>`}),Vue.component("http-auth-config-box",{props:["v-auth-config","v-is-location"],data:function(){let e=this.vAuthConfig;return null==(e=null==e?{isPrior:!1,isOn:!1}:e).policyRefs&&(e.policyRefs=[]),{authConfig:e}},methods:{isOn:function(){return(!this.vIsLocation||this.authConfig.isPrior)&&this.authConfig.isOn},add:function(){let t=this;teaweb.popup("/servers/server/settings/access/createPopup",{callback:function(e){t.authConfig.policyRefs.push(e.data.policyRef),t.change()},height:"28em"})},update:function(e,t){teaweb.popup("/servers/server/settings/access/updatePopup?policyId="+t,{callback:function(e){teaweb.success("保存成功",function(){teaweb.reload()})},height:"28em"})},remove:function(e){this.authConfig.policyRefs.$remove(e),this.change()},methodName:function(e){switch(e){case"basicAuth":return"BasicAuth";case"subRequest":return"子请求";case"typeA":return"URL鉴权A";case"typeB":return"URL鉴权B";case"typeC":return"URL鉴权C";case"typeD":return"URL鉴权D"}return""},change:function(){let e=this;setTimeout(function(){e.$emit("change",this.authConfig)},100)}},template:`<div>
<input type="hidden" name="authJSON" :value="JSON.stringify(authConfig)"/>
<table class="ui table selectable definition">
<prior-checkbox :v-config="authConfig" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || authConfig.isPrior">
<tr>
<td class="title">启用认证</td>
<td class="title">启用鉴权</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="authConfig.isOn"/>
@@ -2502,14 +2502,14 @@ Vue.component("traffic-map-box",{props:["v-stats","v-is-attack"],mounted:functio
</tbody>
</table>
<div class="margin"></div>
<!-- 认证方式 -->
<!-- 鉴权方式 -->
<div v-show="isOn()">
<h4>认证方式</h4>
<h4>鉴权方式</h4>
<table class="ui table selectable celled" v-show="authConfig.policyRefs.length > 0">
<thead>
<tr>
<th class="three wide">名称</th>
<th class="three wide">认证方法</th>
<th class="three wide">鉴权方法</th>
<th>参数</th>
<th class="two wide">状态</th>
<th class="two op">操作</th>
@@ -2527,6 +2527,15 @@ Vue.component("traffic-map-box",{props:["v-stats","v-is-attack"],mounted:functio
<span v-if="ref.authPolicy.params.method.length > 0" class="grey">[{{ref.authPolicy.params.method}}]</span>
{{ref.authPolicy.params.url}}
</span>
<span v-if="ref.authPolicy.type == 'typeA'">{{ref.authPolicy.params.signParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeB'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeC'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeD'">{{ref.authPolicy.params.signParamName}}/{{ref.authPolicy.params.timestampParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<div v-if="(ref.authPolicy.params.exts != null && ref.authPolicy.params.exts.length > 0) || (ref.authPolicy.params.domains != null && ref.authPolicy.params.domains.length > 0)">
<grey-label v-if="ref.authPolicy.params.exts != null" v-for="ext in ref.authPolicy.params.exts">扩展名:{{ext}}</grey-label>
<grey-label v-if="ref.authPolicy.params.domains != null" v-for="domain in ref.authPolicy.params.domains">域名:{{domain}}</grey-label>
</div>
</td>
<td>
<label-on :v-is-on="ref.authPolicy.isOn"></label-on>
@@ -2538,7 +2547,7 @@ Vue.component("traffic-map-box",{props:["v-stats","v-is-attack"],mounted:functio
</tr>
</tbody>
</table>
<button class="ui button small" type="button" @click.prevent="add">+添加认证方式</button>
<button class="ui button small" type="button" @click.prevent="add">+添加鉴权方式</button>
</div>
<div class="margin"></div>
</div>`}),Vue.component("user-selector",{props:["v-user-id","data-url"],data:function(){let e=this.vUserId,t=(null==e&&(e=0),this.dataUrl);return null!=t&&0!=t.length||(t="/servers/users/options"),{users:[],userId:e,dataURL:t}},methods:{change:function(e){null!=e?this.$emit("change",e.id):this.$emit("change",0)}},template:`<div>

View File

@@ -7457,6 +7457,7 @@ Vue.component("http-auth-config-box", {
teaweb.popup("/servers/server/settings/access/createPopup", {
callback: function (resp) {
that.authConfig.policyRefs.push(resp.data.policyRef)
that.change()
},
height: "28em"
})
@@ -7474,6 +7475,7 @@ Vue.component("http-auth-config-box", {
},
remove: function (index) {
this.authConfig.policyRefs.$remove(index)
this.change()
},
methodName: function (methodType) {
switch (methodType) {
@@ -7481,8 +7483,23 @@ Vue.component("http-auth-config-box", {
return "BasicAuth"
case "subRequest":
return "子请求"
case "typeA":
return "URL鉴权A"
case "typeB":
return "URL鉴权B"
case "typeC":
return "URL鉴权C"
case "typeD":
return "URL鉴权D"
}
return ""
},
change: function () {
let that = this
setTimeout(function () {
// 延时通知,是为了让表单有机会变更数据
that.$emit("change", this.authConfig)
}, 100)
}
},
template: `<div>
@@ -7491,7 +7508,7 @@ Vue.component("http-auth-config-box", {
<prior-checkbox :v-config="authConfig" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || authConfig.isPrior">
<tr>
<td class="title">启用认证</td>
<td class="title">启用鉴权</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="authConfig.isOn"/>
@@ -7502,14 +7519,14 @@ Vue.component("http-auth-config-box", {
</tbody>
</table>
<div class="margin"></div>
<!-- 认证方式 -->
<!-- 鉴权方式 -->
<div v-show="isOn()">
<h4>认证方式</h4>
<h4>鉴权方式</h4>
<table class="ui table selectable celled" v-show="authConfig.policyRefs.length > 0">
<thead>
<tr>
<th class="three wide">名称</th>
<th class="three wide">认证方法</th>
<th class="three wide">鉴权方法</th>
<th>参数</th>
<th class="two wide">状态</th>
<th class="two op">操作</th>
@@ -7527,6 +7544,15 @@ Vue.component("http-auth-config-box", {
<span v-if="ref.authPolicy.params.method.length > 0" class="grey">[{{ref.authPolicy.params.method}}]</span>
{{ref.authPolicy.params.url}}
</span>
<span v-if="ref.authPolicy.type == 'typeA'">{{ref.authPolicy.params.signParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeB'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeC'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeD'">{{ref.authPolicy.params.signParamName}}/{{ref.authPolicy.params.timestampParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<div v-if="(ref.authPolicy.params.exts != null && ref.authPolicy.params.exts.length > 0) || (ref.authPolicy.params.domains != null && ref.authPolicy.params.domains.length > 0)">
<grey-label v-if="ref.authPolicy.params.exts != null" v-for="ext in ref.authPolicy.params.exts">扩展名:{{ext}}</grey-label>
<grey-label v-if="ref.authPolicy.params.domains != null" v-for="domain in ref.authPolicy.params.domains">域名:{{domain}}</grey-label>
</div>
</td>
<td>
<label-on :v-is-on="ref.authPolicy.isOn"></label-on>
@@ -7538,7 +7564,7 @@ Vue.component("http-auth-config-box", {
</tr>
</tbody>
</table>
<button class="ui button small" type="button" @click.prevent="add">+添加认证方式</button>
<button class="ui button small" type="button" @click.prevent="add">+添加鉴权方式</button>
</div>
<div class="margin"></div>
</div>`

View File

@@ -25,6 +25,7 @@ Vue.component("http-auth-config-box", {
teaweb.popup("/servers/server/settings/access/createPopup", {
callback: function (resp) {
that.authConfig.policyRefs.push(resp.data.policyRef)
that.change()
},
height: "28em"
})
@@ -42,6 +43,7 @@ Vue.component("http-auth-config-box", {
},
remove: function (index) {
this.authConfig.policyRefs.$remove(index)
this.change()
},
methodName: function (methodType) {
switch (methodType) {
@@ -49,8 +51,23 @@ Vue.component("http-auth-config-box", {
return "BasicAuth"
case "subRequest":
return "子请求"
case "typeA":
return "URL鉴权A"
case "typeB":
return "URL鉴权B"
case "typeC":
return "URL鉴权C"
case "typeD":
return "URL鉴权D"
}
return ""
},
change: function () {
let that = this
setTimeout(function () {
// 延时通知,是为了让表单有机会变更数据
that.$emit("change", this.authConfig)
}, 100)
}
},
template: `<div>
@@ -59,7 +76,7 @@ Vue.component("http-auth-config-box", {
<prior-checkbox :v-config="authConfig" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || authConfig.isPrior">
<tr>
<td class="title">启用认证</td>
<td class="title">启用鉴权</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="authConfig.isOn"/>
@@ -70,14 +87,14 @@ Vue.component("http-auth-config-box", {
</tbody>
</table>
<div class="margin"></div>
<!-- 认证方式 -->
<!-- 鉴权方式 -->
<div v-show="isOn()">
<h4>认证方式</h4>
<h4>鉴权方式</h4>
<table class="ui table selectable celled" v-show="authConfig.policyRefs.length > 0">
<thead>
<tr>
<th class="three wide">名称</th>
<th class="three wide">认证方法</th>
<th class="three wide">鉴权方法</th>
<th>参数</th>
<th class="two wide">状态</th>
<th class="two op">操作</th>
@@ -95,6 +112,15 @@ Vue.component("http-auth-config-box", {
<span v-if="ref.authPolicy.params.method.length > 0" class="grey">[{{ref.authPolicy.params.method}}]</span>
{{ref.authPolicy.params.url}}
</span>
<span v-if="ref.authPolicy.type == 'typeA'">{{ref.authPolicy.params.signParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeB'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeC'">有效期{{ref.authPolicy.params.life}}秒</span>
<span v-if="ref.authPolicy.type == 'typeD'">{{ref.authPolicy.params.signParamName}}/{{ref.authPolicy.params.timestampParamName}}/有效期{{ref.authPolicy.params.life}}秒</span>
<div v-if="(ref.authPolicy.params.exts != null && ref.authPolicy.params.exts.length > 0) || (ref.authPolicy.params.domains != null && ref.authPolicy.params.domains.length > 0)">
<grey-label v-if="ref.authPolicy.params.exts != null" v-for="ext in ref.authPolicy.params.exts">扩展名:{{ext}}</grey-label>
<grey-label v-if="ref.authPolicy.params.domains != null" v-for="domain in ref.authPolicy.params.domains">域名:{{domain}}</grey-label>
</div>
</td>
<td>
<label-on :v-is-on="ref.authPolicy.isOn"></label-on>
@@ -106,7 +132,7 @@ Vue.component("http-auth-config-box", {
</tr>
</tbody>
</table>
<button class="ui button small" type="button" @click.prevent="add">+添加认证方式</button>
<button class="ui button small" type="button" @click.prevent="add">+添加鉴权方式</button>
</div>
<div class="margin"></div>
</div>`

View File

@@ -58,6 +58,7 @@ div.comment {
color: rgba(0, 0, 0, 0.4);
padding-top: 0.4em;
font-weight: normal;
word-break: break-all;
}
p.comment em,
div.comment em {

View File

@@ -1 +1 @@
{"version":3,"sources":["@layout_popup.less"],"names":[],"mappings":";AACA;EACC,WAAA;;AAGD;EACC,aAAA;;AAGD;EACC,qBAAA;;AAGD,CAAC;AAAW,CAAC,SAAS;AAAQ,CAAC,SAAS;AAAS,IAAI;EACpD,WAAA;;AAGD,CAAC;AAAU,IAAI;AAAU,IAAI;EAC5B,cAAA;;AAGD,IAAI;AAAO,KAAK;AAAO,CAAC;EACvB,sBAAA;;AAGD,CAAC;EACA,iBAAA;;AAGD,IAAI;AAAM,GAAG;EACZ,cAAA;;AAGD,IAAI;EACH,cAAA;;AAGD,GAAG,IAAI;EACN,mBAAmB,8CAAnB;;AAGD;EACC,uBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAM;EACL,sBAAA;;AAGD,MAAO;AAAI,MAAO;EACjB,gBAAA;;AAGD,CAAC;AAAU,GAAG;EACb,yBAAA;EACA,kBAAA;EACA,mBAAA;;AAGD,CAAC,QAAS;AAAI,GAAG,QAAS;EACzB,6BAAA;;AAGD;EACC,mBAAA;EACA,2BA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AAGD,cAAc;AAAQ,aAAa;AAAQ,YAAY;EACtD,sBAAA;;AAGD;AAAgB;AAAe;EAC9B,sBAAA;;AAGD;EACC,2BAAA;;AAID,KAAK;EACJ,yBAAA;;AAID,QAAQ;EACP,4BAA4B,wBAA5B;EACA,gBAAA;;AAID,UAAW;EACV,gBAAA;EACA,gBAAA;EACA,kBAAA;EACA,2CAAA;EACA,aAAA;EACA,YAAA;;AAGD,UAAW,MAAK;EACf,UAAA","file":"@layout_popup.css"}

View File

@@ -63,6 +63,7 @@ p.comment, div.comment {
color: rgba(0, 0, 0, 0.4);
padding-top: 0.4em;
font-weight: normal;
word-break: break-all;
}
p.comment em, div.comment em {

View File

@@ -1,6 +1,6 @@
{$layout "layout_popup"}
<h3>创建认证方式</h3>
<h3>创建鉴权方式</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
@@ -12,16 +12,118 @@
</td>
</tr>
<tr>
<td>认证类型 *</td>
<td>鉴权类型 *</td>
<td>
<select class="ui dropdown auto-width" name="type" v-model="type" @change="changeType">
<option value="">[认证类型]</option>
<option value="">[鉴权类型]</option>
<option v-for="authType in authTypes" :value="authType.code">{{authType.name}}</option>
</select>
<p class="comment" v-html="authDescription"></p>
</td>
</tr>
<!-- TypeA -->
<tbody v-show="type == 'typeA'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeASecret" v-model="typeASecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeASecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>签名参数 *</td>
<td>
<input type="text" maxlength="30" name="typeASignParamName" value="sign" v-model="typeASignParamName" @input="changeTypeASignParamName"/>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeALife" value="30" style="width: 7em"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeB -->
<tbody v-show="type == 'typeB'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeBSecret" v-model="typeBSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeBSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeBLife" value="30" style="width: 7em"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeC -->
<tbody v-show="type == 'typeC'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeCSecret" v-model="typeCSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeCSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeCLife" value="30" style="width: 7em"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeD -->
<tbody v-show="type == 'typeD'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeDSecret" v-model="typeDSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeDSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>签名参数 *</td>
<td>
<input type="text" maxlength="30" name="typeDSignParamName" value="sign" v-model="typeDSignParamName" @input="changeTypeDSignParamName"/>
</td>
</tr>
<tr>
<td>时间戳参数 *</td>
<td>
<input type="text" maxlength="30" name="typeDTimestampParamName" value="t" v-model="typeDTimestampParamName" @input="changeTypeDTimestampParamName"/>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeDLife" value="30" style="width: 7em"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- BasicAuth -->
<tbody v-show="type == 'basicAuth'">
<tr>
@@ -32,7 +134,7 @@
</tr>
<tr>
<td colspan="2">
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多基本认证选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
@@ -76,6 +178,25 @@
</td>
</tr>
</tbody>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>限定文件扩展名</td>
<td>
<values-box name="exts"></values-box>
<p class="comment">如果不为空,则表示只有这些扩展名的文件才需要鉴权;扩展名需要包含点符号(.),比如<code-label>.png</code-label></p>
</td>
</tr>
<tr>
<td>限定域名</td>
<td>
<domains-box></domains-box>
<p class="comment">如果不为空,则表示只有这些域名的文件才需要鉴权。</p>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>

View File

@@ -3,6 +3,7 @@ Tea.context(function () {
this.type = ""
this.authDescription = ""
this.rawDescription = ""
this.changeType = function () {
let that = this
@@ -11,11 +12,78 @@ Tea.context(function () {
})
if (authType != null) {
this.authDescription = authType.description
this.rawDescription = authType.description
} else {
this.authDescription = ""
this.rawDescription = ""
}
}
/**
* TypeA
*/
this.typeASecret = ""
this.typeASignParamName = "sign"
this.generateTypeASecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeASecret = resp.data.random
})
}
this.changeTypeASignParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeASignParamName + "=")
}
/**
* TypeB
*/
this.typeBSecret = ""
this.generateTypeBSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeBSecret = resp.data.random
})
}
/**
* TypeC
*/
this.typeCSecret = ""
this.generateTypeCSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeCSecret = resp.data.random
})
}
/**
* TypeD
*/
this.typeDSecret = ""
this.typeDSignParamName = "sign"
this.typeDTimestampParamName = "t"
this.generateTypeDSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeDSecret = resp.data.random
})
}
this.changeTypeDSignParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeDSignParamName + "=")
this.authDescription = this.authDescription.replace("t=", this.typeDTimestampParamName + "=")
}
this.changeTypeDTimestampParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeDSignParamName + "=")
this.authDescription = this.authDescription.replace("t=", this.typeDTimestampParamName + "=")
}
/**
* 基本认证
*/

View File

@@ -3,10 +3,10 @@
{$template "/left_menu_with_menu"}
<div class="right-box with-menu">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<form class="ui form" data-tea-action="$" data-tea-success="success" ref="authForm">
<csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId">
<http-auth-config-box :v-auth-config="authConfig"></http-auth-config-box>
<submit-btn></submit-btn>
<http-auth-config-box :v-auth-config="authConfig" @change="changeMethods"></http-auth-config-box>
<submit-btn @ref=""></submit-btn>
</form>
</div>

View File

@@ -1,3 +1,10 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
this.changeMethods = function (config) {
Tea.action("$")
.form(this.$refs.authForm)
.post()
teaweb.successRefresh("保存成功")
}
})

View File

@@ -1,6 +1,6 @@
{$layout "layout_popup"}
<h3>修改认证方式</h3>
<h3>修改鉴权方式</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="policyId" :value="policy.id"/>
@@ -13,13 +13,115 @@
</td>
</tr>
<tr>
<td>认证类型 *</td>
<td>鉴权类型 *</td>
<td>
{{policy.typeName}}
<p class="comment" v-html="authDescription"></p>
</td>
</tr>
<!-- TypeA -->
<tbody v-show="type == 'typeA'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeASecret" v-model="typeASecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeASecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>签名参数 *</td>
<td>
<input type="text" maxlength="30" name="typeASignParamName" value="sign" v-model="typeASignParamName" @input="changeTypeASignParamName"/>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeALife" value="30" style="width: 7em" v-model="policy.params.life"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeB -->
<tbody v-show="type == 'typeB'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeBSecret" v-model="typeBSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeBSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeBLife" value="30" style="width: 7em" v-model="policy.params.life"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeC -->
<tbody v-show="type == 'typeC'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeCSecret" v-model="typeCSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeCSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeCLife" value="30" style="width: 7em" v-model="policy.params.life"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- TypeD -->
<tbody v-show="type == 'typeD'">
<tr>
<td>鉴权密钥 *</td>
<td>
<input type="text" maxlength="40" name="typeDSecret" v-model="typeDSecret" autocomplete="off"/>
<p class="comment">只能包含字母、数字长度不超过40。<a href="" @click.prevent="generateTypeDSecret()">[随机生成]</a></p>
</td>
</tr>
<tr>
<td>签名参数 *</td>
<td>
<input type="text" maxlength="30" name="typeDSignParamName" value="sign" v-model="typeDSignParamName" @input="changeTypeDSignParamName"/>
</td>
</tr>
<tr>
<td>时间戳参数 *</td>
<td>
<input type="text" maxlength="30" name="typeDTimestampParamName" value="t" v-model="typeDTimestampParamName" @input="changeTypeDTimestampParamName"/>
</td>
</tr>
<tr>
<td>有效时间</td>
<td>
<div class="ui input right labeled">
<input type="text" maxlength="8" name="typeDLife" value="30" style="width: 7em" v-model="policy.params.life"/>
<span class="ui label"></span>
</div>
<p class="comment">链接有效时间。</p>
</td>
</tr>
</tbody>
<!-- BasicAuth -->
<tbody v-show="type == 'basicAuth'">
<tr>
@@ -30,7 +132,7 @@
</tr>
<tr>
<td colspan="2">
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多基本认证选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
@@ -76,9 +178,28 @@
</tr>
</tbody>
<tr>
<td>是否启用</td>
<td><checkbox name="isOn" value="1" v-model="policy.isOn"></checkbox></td>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>限定文件扩展名</td>
<td>
<values-box name="exts" :v-values="policy.params.exts"></values-box>
<p class="comment">如果不为空,则表示只有这些扩展名的文件才需要鉴权;扩展名需要包含点符号(.),比如<code-label>.png</code-label></p>
</td>
</tr>
<tr>
<td>限定域名</td>
<td>
<domains-box :v-domains="policy.params.domains"></domains-box>
<p class="comment">如果不为空,则表示只有这些域名的文件才需要鉴权。</p>
</td>
</tr>
<tr>
<td>是否启用</td>
<td><checkbox name="isOn" value="1" v-model="policy.isOn"></checkbox></td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>

View File

@@ -3,6 +3,7 @@ Tea.context(function () {
this.type = this.policy.type
this.authDescription = ""
this.rawDescription = ""
this.$delay(function () {
this.changeType()
@@ -16,13 +17,106 @@ Tea.context(function () {
if (authType != null) {
this.policy.typeName = authType.name
this.authDescription = authType.description
this.rawDescription = authType.description
} else {
this.authDescription = ""
this.rawDescription = ""
}
}
/**
* 基本认证
* TypeA
*/
this.typeASecret = ""
this.typeASignParamName = "sign"
if (this.policy.type == "typeA") {
this.typeASecret = this.policy.params.secret
this.typeASignParamName = this.policy.params.signParamName
this.$delay(function () {
this.changeTypeASignParamName()
})
}
this.generateTypeASecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeASecret = resp.data.random
})
}
this.changeTypeASignParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeASignParamName + "=")
}
/**
* TypeB
*/
this.typeBSecret = ""
if (this.policy.type == "typeB") {
this.typeBSecret = this.policy.params.secret
}
this.generateTypeBSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeBSecret = resp.data.random
})
}
/**
* TypeC
*/
this.typeCSecret = ""
if (this.policy.type == "typeC") {
this.typeCSecret = this.policy.params.secret
}
this.generateTypeCSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeCSecret = resp.data.random
})
}
/**
* TypeD
*/
this.typeDSecret = ""
this.typeDSignParamName = "sign"
this.typeDTimestampParamName = "t"
if (this.policy.type == "typeD") {
this.typeDSecret = this.policy.params.secret
this.typeDSignParamName = this.policy.params.signParamName
this.typeDTimestampParamName = this.policy.params.timestampParamName
this.$delay(function () {
this.changeTypeDSignParamName()
this.changeTypeDTimestampParamName()
})
}
this.generateTypeDSecret = function () {
this.$post(".random")
.success(function (resp) {
this.typeDSecret = resp.data.random
})
}
this.changeTypeDSignParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeDSignParamName + "=")
this.authDescription = this.authDescription.replace("t=", this.typeDTimestampParamName + "=")
}
this.changeTypeDTimestampParamName = function () {
this.authDescription = this.rawDescription.replace("sign=", this.typeDSignParamName + "=")
this.authDescription = this.authDescription.replace("t=", this.typeDTimestampParamName + "=")
}
/**
* 基本鉴权
*/
this.moreBasicAuthOptionsVisible = false

View File

@@ -6,10 +6,10 @@
{$template "../left_menu"}
<div class="right-box tiny">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<form class="ui form" data-tea-action="$" data-tea-success="success" ref="authForm">
<csrf-token></csrf-token>
<input type="hidden" name="webId" :value="webId">
<http-auth-config-box :v-auth-config="authConfig" :v-is-location="true"></http-auth-config-box>
<http-auth-config-box :v-auth-config="authConfig" :v-is-location="true" @change="changeMethods"></http-auth-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -1,3 +1,10 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
this.changeMethods = function (config) {
Tea.action("$")
.form(this.$refs.authForm)
.post()
teaweb.successRefresh("保存成功")
}
})