feat(系统设置): 认证登陆调试

This commit is contained in:
guoyuqi 2024-07-08 20:40:54 +08:00 committed by Craftsman
parent e17389c271
commit 7e3111385b
10 changed files with 69 additions and 26 deletions

View File

@ -11,6 +11,7 @@ public class FilterChainUtils {
filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/ldap/login", "anon");
filterChainDefinitionMap.put("/authentication/get-list", "anon");
filterChainDefinitionMap.put("/authentication//get/by/type/**", "anon");
filterChainDefinitionMap.put("/we_com/info", "anon");
filterChainDefinitionMap.put("/ding_talk/info", "anon");
filterChainDefinitionMap.put("/lark/info", "anon");

View File

@ -837,7 +837,7 @@
<select id="getMinderCaseReviewList" resultType="io.metersphere.functional.dto.FunctionalCaseMindDTO">
SELECT
crfc.id as id,
history.`status` as reviewStatus,
IFNULL(history.`status`, fc.review_status) as reviewStatus,
fc.module_id as moduleId,
fc.name as name,
fc.id as caseId,

View File

@ -2,6 +2,7 @@ import MSR from '@/api/http/index';
import {
AddAuthUrl,
DeleteAuthUrl,
GetAuthDetailByTypeUrl,
GetAuthDetailUrl,
GetAuthListUrl,
GetBaseInfoUrl,
@ -86,6 +87,11 @@ export function getAuthDetail(id: string) {
return MSR.get<AuthItem>({ url: GetAuthDetailUrl, params: id });
}
// 获取认证源详情
export function getAuthDetailByType(type: string) {
return MSR.get<AuthItem>({ url: GetAuthDetailByTypeUrl, params: type });
}
// 添加认证源
export function addAuth(data: AuthParams) {
return MSR.post({ url: AddAuthUrl, data });

View File

@ -24,6 +24,8 @@ export const GetAuthListUrl = '/system/authsource/list';
export const AddAuthUrl = '/system/authsource/add';
// 获取认证源详情
export const GetAuthDetailUrl = '/system/authsource/get';
// 根据类型获取认证源详情
export const GetAuthDetailByTypeUrl = '/authentication/get/by/type';
// 删除认证源
export const DeleteAuthUrl = '/system/authsource/delete';
// 测试ldap连接

View File

@ -196,4 +196,5 @@ export default {
'common.collapseAllSubModule': 'Collapse all submodules',
'common.selectedCount': '{count} data selected',
'common.advancedSettings': 'Advanced settings',
'common.auth_redirect_tip': 'You will be redirected to the certification source page for certification',
};

View File

@ -195,4 +195,5 @@ export default {
'common.collapseAllSubModule': '收起全部子模块',
'common.selectedCount': '(已选 {count} 项数据)',
'common.advancedSettings': '高级设置',
'common.auth_redirect_tip': '即将跳转至认证源页面进行认证',
};

View File

@ -91,7 +91,7 @@ export interface PageConfig extends ThemeConfig, LoginConfig, PlatformConfig {}
export type PageConfigKeys = keyof PageConfig;
// 认证源类型
export type AuthType = 'CAS' | 'LDAP' | 'OAuth2' | 'OIDC';
export type AuthType = 'CAS' | 'LDAP' | 'OAUTH2' | 'OIDC';
// 认证源配置列表项对象
export interface AuthItem {

View File

@ -1,5 +1,5 @@
<template>
<div></div>
<a-spin class="w-full" />
</template>
<script lang="ts" setup>

View File

@ -105,7 +105,7 @@
<span class="type-text text-[7px]">OAUTH</span>
</div>
<div v-if="isShowCAS && userInfo.authenticate !== 'CAS'" class="loginType" @click="redirectAuth('CAS')">
<span class="type-text text-[7px]">CAS</span>
<span class="type-text text-[10px]">CAS</span>
</div>
</div>
<div v-if="props.isPreview" class="mask"></div>
@ -122,7 +122,7 @@
import TabQrCode from '@/views/login/components/tabQrCode.vue';
import { getProjectInfo } from '@/api/modules/project-management/basicInfo';
import { getAuthDetail } from '@/api/modules/setting/config';
import { getAuthDetail, getAuthDetailByType } from '@/api/modules/setting/config';
import { getPlatformParamUrl } from '@/api/modules/user';
import { GetLoginLogoUrl } from '@/api/requrls/setting/config';
import { useI18n } from '@/hooks/useI18n';
@ -132,11 +132,11 @@
import { useAppStore, useUserStore } from '@/store';
import useLicenseStore from '@/store/modules/setting/license';
import { encrypted } from '@/utils';
import { setLoginExpires } from '@/utils/auth';
import { setLoginExpires, setToken } from '@/utils/auth';
import { getFirstRouteNameByPermission, routerNameHasPermission } from '@/utils/permission';
import type { LoginData } from '@/models/user';
import { SettingRouteEnum } from '@/enums/routeEnum';
import { ProjectManagementRouteEnum, SettingRouteEnum } from '@/enums/routeEnum';
import { ValidatedError } from '@arco-design/web-vue/es/form/interface';
@ -303,11 +303,11 @@
}
}
function redirectAuth(authId: string) {
if (authId === 'LDAP' || authId === 'LOCAL') {
function redirectAuth(authType: string) {
if (authType === 'LDAP' || authType === 'LOCAL') {
return;
}
getAuthDetail(authId).then((res) => {
getAuthDetailByType(authType).then((res) => {
if (!res) {
return;
}
@ -315,38 +315,32 @@
Message.error(t('login.auth_not_enable'));
return;
}
// cas
if (userInfo.value.authenticate === 'CAS') {
const config = JSON.parse(res.configuration);
if (config.casServerUrl && !config.loginUrl) {
return;
}
}
const authId = res.id;
openModal({
type: 'warning',
title: t('commons.auth_redirect_tip'),
content: t('ms.minders.leaveUnsavedTip'),
type: 'info',
content: t('common.auth_redirect_tip'),
okText: t('common.confirm'),
cancelText: t('common.cancel'),
okButtonProps: {
status: 'normal',
},
closable: false,
onBeforeOk: async () => {
const config = JSON.parse(res.configuration);
// eslint-disable-next-line no-eval
const redirectUrl = eval(`\`${config.redirectUrl}\``);
let url;
if (userInfo.value.authenticate === 'CAS') {
if (authType === 'CAS') {
url = `${config.loginUrl}?service=${encodeURIComponent(redirectUrl)}`;
}
if (userInfo.value.authenticate === 'OIDC') {
if (authType === 'OIDC') {
url = `${config.authUrl}?client_id=${config.clientId}&redirect_uri=${redirectUrl}&response_type=code&scope=openid+profile+email&state=${authId}`;
//
if (config.loginUrl) {
localStorage.setItem('oidcLoginUrl', config.loginUrl);
}
}
if (userInfo.value.authenticate === 'OAUTH2') {
if (authType === 'OAUTH2') {
url =
`${config.authUrl}?client_id=${config.clientId}&response_type=code` +
`&redirect_uri=${redirectUrl}&state=${authId}`;
@ -363,9 +357,47 @@
});
}
function getQueryVariable(variable: string) {
const urlString = window.location.href;
const queryIndex = urlString.indexOf('?');
if (queryIndex !== -1) {
const query = urlString.substring(queryIndex + 1);
//
const params = query.split('&');
// _token
let variableValue;
params.forEach((param) => {
const pair = param.split('=');
if (pair[0] === variable) {
console.log(pair[1]);
// eslint-disable-next-line prefer-destructuring
variableValue = pair[1];
}
});
return variableValue;
}
}
async function checkAuthUrlParam() {
const TOKEN = getQueryVariable('_token');
const CSRF = getQueryVariable('_csrf');
const pId = getQueryVariable('_pId');
const orgId = getQueryVariable('orgId');
if (TOKEN !== null && TOKEN !== undefined && CSRF !== null && CSRF !== undefined) {
setToken(TOKEN, CSRF);
appStore.setCurrentOrgId(pId || '');
appStore.setCurrentProjectId(orgId || '');
await userStore.checkIsLogin(true);
}
}
onMounted(() => {
userStore.getAuthentication();
initPlatformInfo();
checkAuthUrlParam();
});
</script>

View File

@ -305,7 +305,7 @@
<MsFormItemSub :text="t('system.config.auth.loginUrlTip')" :show-fill-icon="false" />
</a-form-item>
</template>
<template v-else-if="activeAuthForm.type === 'OAuth2'">
<template v-else-if="activeAuthForm.type === 'OAUTH2'">
<a-form-item
:label="t('system.config.auth.authUrl')"
field="configuration.authUrl"
@ -899,7 +899,7 @@
},
]);
break;
case 'OAuth2':
case 'OAUTH2':
description = description.concat([
{
label: t('system.config.auth.authUrl'),
@ -1150,7 +1150,7 @@
loginUrl: configuration.loginUrl,
};
break;
case 'OAuth2':
case 'OAUTH2':
_configuration = {
authUrl: configuration.authUrl,
tokenUrl: configuration.tokenUrl,