Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): 支持按DB组件设置密码安全规则 #7031 #7124

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3539,5 +3539,17 @@
"请输入或选择主机": "请输入或选择主机",
"实例/IP重复": "实例/IP重复",
"同主机关联的其他集群,勾选后一同克隆": "同主机关联的其他集群,勾选后一同克隆",
"开启弱密码检测": "开启弱密码检测",
"开启后,不允许超过 x 位连续字符,如出现以下示例密码将无法通过检测": "开启后,不允许超过 {x} 位连续字符,如出现以下示例密码将无法通过检测",
"连续键盘序_如_xx": "连续键盘序,如:{0}",
"连续字母序_如_xx": "连续字母序,如:{0}",
"连续数字序_如_xx": "连续数字序,如:{0}",
"连续特殊符号序_如_xx": "连续特殊符号序,如:{0}",
"重复的字母_数字_特殊符号_如_aa_bb_cc": "重复的字母、数字、特殊符号,如:{0}、{1}、{2}",
"密码组成设置": "密码组成设置",
"特殊字符(非空格)": "特殊字符(非空格)",
"密码校验": "密码校验",
"包含上述任意": "包含上述任意",
"指定特殊字符": "指定特殊字符",
"这行勿动!新增翻译请在上一行添加!": ""
}
4 changes: 2 additions & 2 deletions dbm-ui/frontend/src/services/source/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ interface AdminPasswordResultItem {
/**
* 查询密码安全策略
*/
export const getPasswordPolicy = (params = {}, payload = {} as IRequestPayload) =>
http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/', params, payload);
export const getPasswordPolicy = (params: { name: string }) =>
http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/', params);

/**
* 更新密码安全策略
Expand Down
22 changes: 5 additions & 17 deletions dbm-ui/frontend/src/services/types/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ export interface PasswordPolicy {
id: number;
name: string;
rule: {
include_rule: PasswordPolicyIncludeRule;
exclude_continuous_rule: {
limit: number;
letters: boolean;
numbers: boolean;
repeats: boolean;
symbols: boolean;
keyboards: boolean;
};
repeats: number;
max_length: number;
min_length: number;
include_rule: PasswordPolicyIncludeRule;
weak_password: boolean;
number_of_types: number;
symbols_allowed: string;
};
creator?: string;
create_time?: string;
Expand All @@ -117,14 +113,6 @@ export interface PasswordPolicyIncludeRule {
uppercase: boolean;
}

// 密码策略 include_rule
export interface PasswordPolicyIncludeRule {
numbers: boolean;
symbols: boolean;
lowercase: boolean;
uppercase: boolean;
}

/**
* 新增账号规则
*/
Expand Down
218 changes: 12 additions & 206 deletions dbm-ui/frontend/src/views/password-manage/policy/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,220 +12,26 @@
-->

<template>
<BkLoading :loading="isLoading">
<DbForm
class="password-policy"
:label-width="260">
<DbCard :title="t('密码组成')">
<BkFormItem
:label="t('密码长度')"
required>
<BkInput
v-model="formData.min_length"
class="password-policy-number"
:max="formData.max_length"
:min="8"
type="number" />
<span class="password-policy-text">{{ t('至') }}</span>
<BkInput
v-model="formData.max_length"
class="password-policy-number"
:max="32"
:min="formData.min_length"
type="number" />
<span class="password-policy-text">{{ t('最小长度_8_最大长度_32') }}</span>
</BkFormItem>
<BkFormItem
:label="t('密码必须包含')"
required>
<BkCheckbox
v-model="formData.include_rule.lowercase"
:false-label="false">
{{ t('小写字母') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.uppercase"
:false-label="false">
{{ t('大写字母') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.numbers"
:false-label="false">
{{ t('数字') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.symbols"
:false-label="false">
{{ t('特殊字符_除空格外') }}
</BkCheckbox>
</BkFormItem>
<BkFormItem :label="t('密码不允许连续N位出现')">
<p class="mb-8">
<span
class="password-policy-text mr-8"
style="padding: 0">
N =
</span>
<BkInput
v-model="formData.exclude_continuous_rule.limit"
class="password-policy-number"
:min="3"
type="number" />
</p>
<BkCheckbox
v-model="formData.exclude_continuous_rule.keyboards"
:false-label="false">
{{ t('键盘序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.letters"
:false-label="false">
{{ t('字母序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.numbers"
:false-label="false">
{{ t('数字序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.symbols"
:false-label="false">
{{ t('连续特殊符号序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.repeats"
:false-label="false">
{{ t('重复字母_数字_特殊符号') }}
</BkCheckbox>
</BkFormItem>
</DbCard>
<BkFormItem class="password-policy-footer">
<AuthButton
action-id="password_policy_set"
class="mr-8"
:loading="isSubmitting"
theme="primary"
@click="handleSubmit()">
{{ t('保存') }}
</AuthButton>
<BkButton
:disabled="isSubmitting"
@click="handleReset">
{{ t('重置') }}
</BkButton>
</BkFormItem>
</DbForm>
</BkLoading>
<DbTab v-model:active="activeTab" />
<div class="password-policy-content">
<RenderContent :db-type="activeTab" />
</div>
</template>

<script setup lang="ts">
import { Message } from 'bkui-vue';
import InfoBox from 'bkui-vue/lib/info-box';
import { useI18n } from 'vue-i18n';
import type { DBTypes } from '@common/const';

import { getPasswordPolicy, updatePasswordPolicy } from '@services/source/permission';
import DbTab from '@components/db-tab/Index.vue';

const initData = () => ({
max_length: 32,
min_length: 8,
include_rule: {
lowercase: true,
numbers: true,
symbols: true,
uppercase: true,
},
exclude_continuous_rule: {
keyboards: false,
letters: false,
limit: 3,
numbers: false,
repeats: false,
symbols: false,
},
});
import RenderContent from './components/Content.vue';

const { t } = useI18n();
const route = useRoute();

const passwordPolicyData = {
id: 0,
name: '',
};

const isLoading = ref(false);
const isSubmitting = ref(false);
const formData = reactive(initData());

const fetchPasswordPolicy = () => {
isLoading.value = true;
getPasswordPolicy()
.then((passwordPolicy) => {
passwordPolicyData.id = passwordPolicy.id;
passwordPolicyData.name = passwordPolicy.name;
Object.assign(formData, passwordPolicy.rule);
})
.finally(() => {
isLoading.value = false;
});
};
fetchPasswordPolicy();

const handleReset = () => {
InfoBox({
title: t('确认重置'),
content: t('重置将会恢复默认设置的内容'),
cancelText: t('取消'),
onConfirm: () => {
Object.assign(formData, initData());
handleSubmit(t('重置成功'));
return true;
},
});
};

const handleSubmit = (message = t('保存成功')) => {
isSubmitting.value = true;
updatePasswordPolicy({
...passwordPolicyData,
rule: formData,
})
.then(() => {
Message({
theme: 'success',
message,
});
})
.finally(() => {
isSubmitting.value = false;
});
};
const activeTab = ref<DBTypes>(route.query.db_type as DBTypes);
</script>

<style lang="less" scoped>
.password-policy {
font-size: @font-size-mini;

.password-policy-number {
width: 68px;
}

.password-policy-text {
display: inline-block;
padding: 0 8px;
}

.bk-checkbox {
display: flex;
width: max-content;
padding: 8px 0;
margin-left: 0;
}

.password-policy-footer {
margin: 32px 0 0 24px;

.bk-button {
width: 88px;
}
}
<style lang="less">
.password-policy-content {
padding: 16px 20px;
}
</style>
Loading
Loading