访问控制支持基本认证和子请求认证

This commit is contained in:
GoEdgeLab
2021-06-19 21:35:38 +08:00
parent 68538170ed
commit 75c18751dd
17 changed files with 728 additions and 34 deletions

View File

@@ -1,33 +1,80 @@
{$layout "layout_popup"}
<h3>创建认证</h3>
<h3>创建认证方式</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<table class="ui table definitions selectable">
<table class="ui table definition selectable">
<tr>
<td class="title">名称 *</td>
<td>
<input type="text" name="name" maxlength="50"/>
<input type="text" name="name" maxlength="50" ref="focus"/>
</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 v-for="authType in authTypes" :value="authType.code">{{authType.name}}</option>
</select>
<p class="comment" v-html="authDescription"></p>
</td>
</tr>
<!-- BasicAuth -->
<tbody>
<tbody v-show="type == 'basicAuth'">
<tr>
<td></td>
<td>用户 *</td>
<td>
<http-auth-basic-auth-user-box></http-auth-basic-auth-user-box>
</td>
</tr>
<tr>
<td colspan="2">
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
<td>认证领域名<em>Realm</em></td>
<td>
<input type="text" name="basicAuthRealm" value="" maxlength="100"/>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
<td>字符集</td>
<td>
<input type="text" name="basicAuthCharset" style="width: 6em" maxlength="50"/>
<p class="comment">类似于<code-label>UTF-8</code-label></p>
</td>
</tr>
</tbody>
<!-- SubRequest -->
<tbody>
<tbody v-show="type == 'subRequest'">
<tr>
<td>子请求URL *</td>
<td>
<input type="text" name="subRequestURL" maxlength="1024"/>
<p class="comment">可以是一个完整的URL也可以是一个路径。</p>
</td>
</tr>
<tr>
<td>请求方法</td>
<td>
<radio name="subRequestFollowRequest" :v-value="1" v-model="subRequestFollowRequest">同当前请求一致</radio> &nbsp; &nbsp;
<radio name="subRequestFollowRequest" :v-value="0" v-model="subRequestFollowRequest">自定义</radio>
<div style="margin-top: 0.8em" v-show="subRequestFollowRequest == 0">
<div class="ui divider"></div>
<select class="ui dropdown auto-width" name="subRequestMethod">
<option value="POST">POST</option>
<option value="GET">GET</option>
<option value="PUT">PUT</option>
<option value="HEAD">HEAD</option>
</select>
</div>
</td>
</tr>
</tbody>
</table>

View File

@@ -1,3 +1,32 @@
Tea.context(function () {
this.success = NotifyPopup
this.type = ""
this.authDescription = ""
this.changeType = function () {
let that = this
let authType = this.authTypes.$find(function (k, v) {
return v.code == that.type
})
if (authType != null) {
this.authDescription = authType.description
} else {
this.authDescription = ""
}
}
/**
* 基本认证
*/
this.moreBasicAuthOptionsVisible = false
this.showMoreBasicAuthOptions = function () {
this.moreBasicAuthOptionsVisible = !this.moreBasicAuthOptionsVisible
}
/**
* 子请求
*/
this.subRequestFollowRequest = 1
})

View File

@@ -4,6 +4,8 @@
<div class="right-box">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<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>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -0,0 +1,85 @@
{$layout "layout_popup"}
<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"/>
<table class="ui table definition selectable">
<tr>
<td class="title">名称 *</td>
<td>
<input type="text" name="name" maxlength="50" ref="focus" v-model="policy.name"/>
</td>
</tr>
<tr>
<td>认证类型 *</td>
<td>
{{policy.typeName}}
<p class="comment" v-html="authDescription"></p>
</td>
</tr>
<!-- BasicAuth -->
<tbody v-show="type == 'basicAuth'">
<tr>
<td>用户 *</td>
<td>
<http-auth-basic-auth-user-box :v-users="policy.params.users"></http-auth-basic-auth-user-box>
</td>
</tr>
<tr>
<td colspan="2">
<a href="" @click.prevent="showMoreBasicAuthOptions()">更多选项<i class="ui icon angle" :class="{up: moreBasicAuthOptionsVisible, down: !moreBasicAuthOptionsVisible}"></i></a>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
<td>认证领域名<em>Realm</em></td>
<td>
<input type="text" name="basicAuthRealm" value="" maxlength="100" v-model="policy.params.realm"/>
</td>
</tr>
<tr v-show="moreBasicAuthOptionsVisible">
<td>字符集</td>
<td>
<input type="text" name="basicAuthCharset" style="width: 6em" v-model="policy.params.charset" maxlength="50"/>
<p class="comment">类似于<code-label>utf-8</code-label></p>
</td>
</tr>
</tbody>
<!-- SubRequest -->
<tbody v-show="type == 'subRequest'">
<tr>
<td>子请求URL *</td>
<td>
<input type="text" name="subRequestURL" maxlength="1024" v-model="policy.params.url"/>
<p class="comment">可以是一个完整的URL也可以是一个路径。</p>
</td>
</tr>
<tr>
<td>请求方法</td>
<td>
<radio name="subRequestFollowRequest" :v-value="1" v-model="subRequestFollowRequest">同当前请求一致</radio> &nbsp; &nbsp;
<radio name="subRequestFollowRequest" :v-value="0" v-model="subRequestFollowRequest">自定义</radio>
<div style="margin-top: 0.8em" v-show="subRequestFollowRequest == 0">
<div class="ui divider"></div>
<select class="ui dropdown auto-width" name="subRequestMethod" v-model="policy.params.method">
<option value="">[请选择]</option>
<option value="POST">POST</option>
<option value="GET">GET</option>
<option value="PUT">PUT</option>
<option value="HEAD">HEAD</option>
</select>
</div>
</td>
</tr>
</tbody>
<tr>
<td>是否启用</td>
<td><checkbox name="isOn" value="1" v-model="policy.isOn"></checkbox></td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,37 @@
Tea.context(function () {
this.success = NotifyPopup
this.type = this.policy.type
this.authDescription = ""
this.$delay(function () {
this.changeType()
})
this.changeType = function () {
let that = this
let authType = this.authTypes.$find(function (k, v) {
return v.code == that.type
})
if (authType != null) {
this.policy.typeName = authType.name
this.authDescription = authType.description
} else {
this.authDescription = ""
}
}
/**
* 基本认证
*/
this.moreBasicAuthOptionsVisible = false
this.showMoreBasicAuthOptions = function () {
this.moreBasicAuthOptionsVisible = !this.moreBasicAuthOptionsVisible
}
/**
* 子请求
*/
this.subRequestFollowRequest = (this.policy.params.method != null && this.policy.params.method.length > 0) ? 0 : 1
})