Unverified Commit 445f81b1 authored by gaoyan's avatar gaoyan Committed by GitHub

[wip]Perfect ldap test login and test connection function with front end pages (#2057)

* Perfect ldap test login and test connection function with front end pages * Perfect ldap test login and test connection function with front end pages * fix style
parent 9f0d4a9d
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
package org.dinky.controller; package org.dinky.controller;
import org.dinky.data.dto.LoginDTO;
import org.dinky.data.dto.UserDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.exception.AuthException;
import org.dinky.data.model.SystemConfiguration; import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.User; import org.dinky.data.model.User;
import org.dinky.data.result.ProTableResult; import org.dinky.data.result.ProTableResult;
...@@ -28,8 +31,12 @@ import org.dinky.service.LdapService; ...@@ -28,8 +31,12 @@ import org.dinky.service.LdapService;
import java.util.List; import java.util.List;
import javax.naming.NamingException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -69,4 +76,21 @@ public class LdapController { ...@@ -69,4 +76,21 @@ public class LdapController {
.total((long) users.size()) .total((long) users.size())
.build(); .build();
} }
/**
* ldap test login
*
* @param loginDTO basic information for user login
* @return {@link Result}{@link UserDTO} obtain the user's UserDTO
*/
@PostMapping("/testLogin")
public Result<User> login(@RequestBody LoginDTO loginDTO) {
try {
return Result.succeed(ldapService.authenticate(loginDTO));
} catch (AuthException e) {
return Result.failed(e.getStatus());
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
} }
...@@ -135,9 +135,6 @@ public class SystemConfiguration { ...@@ -135,9 +135,6 @@ public class SystemConfiguration {
.defaultValue("Dinky") .defaultValue("Dinky")
.note("The project name specified in DolphinScheduler, case insensitive"); .note("The project name specified in DolphinScheduler, case insensitive");
private final Configuration<Boolean> ldapEnable =
key("ldap.settings.enable").booleanType().defaultValue(false).note("LDAP ON-OFF");
private final Configuration<String> ldapUrl = private final Configuration<String> ldapUrl =
key("ldap.settings.url").stringType().defaultValue("").note("ldap server address"); key("ldap.settings.url").stringType().defaultValue("").note("ldap server address");
...@@ -187,6 +184,9 @@ public class SystemConfiguration { ...@@ -187,6 +184,9 @@ public class SystemConfiguration {
private final Configuration<String> ldapCastNickname = private final Configuration<String> ldapCastNickname =
key("ldap.settings.castNickname").stringType().defaultValue("sn").note(""); key("ldap.settings.castNickname").stringType().defaultValue("sn").note("");
private final Configuration<Boolean> ldapEnable =
key("ldap.settings.enable").booleanType().defaultValue(false).note("LDAP ON-OFF");
/** Initialize after spring bean startup */ /** Initialize after spring bean startup */
public void initAfterBeanStarted() { public void initAfterBeanStarted() {
if (StrUtil.isBlank(dinkyAddr.getDefaultValue())) { if (StrUtil.isBlank(dinkyAddr.getDefaultValue())) {
......
...@@ -575,6 +575,11 @@ export default { ...@@ -575,6 +575,11 @@ export default {
'sys.ldap.settings.defaultTeant': 'The LDAP imports the default tenant code', 'sys.ldap.settings.defaultTeant': 'The LDAP imports the default tenant code',
'sys.ldap.settings.defaultTeant.note': 'After opening the automatic import of users, the new user login needs a default tenant code, otherwise it cannot log in', 'sys.ldap.settings.defaultTeant.note': 'After opening the automatic import of users, the new user login needs a default tenant code, otherwise it cannot log in',
'sys.ldap.settings.testConnect': 'Test Connect',
'sys.ldap.settings.testConnect.success': 'Test Connect Successful, {count} users were obtained',
'sys.ldap.settings.testLogin': 'Test Login',
'sys.ldap.settings.loadUser': 'Load User',
// process // process
'sys.process.id': 'Process ID', 'sys.process.id': 'Process ID',
'sys.process.name': 'Process Name', 'sys.process.name': 'Process Name',
......
...@@ -577,6 +577,11 @@ export default { ...@@ -577,6 +577,11 @@ export default {
'sys.ldap.settings.defaultTeant': 'LDAP导入默认租户编码', 'sys.ldap.settings.defaultTeant': 'LDAP导入默认租户编码',
'sys.ldap.settings.defaultTeant.note': '开启自动导入用户后,新用户登录需要一个默认的租户编码,否则无法登录', 'sys.ldap.settings.defaultTeant.note': '开启自动导入用户后,新用户登录需要一个默认的租户编码,否则无法登录',
'sys.ldap.settings.testConnect': '测试连接',
'sys.ldap.settings.testConnect.success': '测试连接成功,获取到了{count}个用户',
'sys.ldap.settings.testLogin': '测试登录',
'sys.ldap.settings.loadUser': '导入用户',
// process // process
'sys.process.id': '进程ID', 'sys.process.id': '进程ID',
......
...@@ -34,11 +34,18 @@ type GeneralConfigProps = { ...@@ -34,11 +34,18 @@ type GeneralConfigProps = {
tag: React.ReactNode; tag: React.ReactNode;
onSave: (data: BaseConfigProperties) => void; onSave: (data: BaseConfigProperties) => void;
loading: boolean; loading: boolean;
toolBarRender?: any;
} }
const GeneralConfig: React.FC<GeneralConfigProps> = (props) => { const GeneralConfig: React.FC<GeneralConfigProps> = (props) => {
const {data, tag, onSave: handleSubmit, loading} = props; const {
data,
tag,
onSave: handleSubmit,
loading,
toolBarRender
} = props;
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
...@@ -119,6 +126,7 @@ const GeneralConfig: React.FC<GeneralConfigProps> = (props) => { ...@@ -119,6 +126,7 @@ const GeneralConfig: React.FC<GeneralConfigProps> = (props) => {
* rest props for ProList * rest props for ProList
*/ */
const restProps: ProListProps = { const restProps: ProListProps = {
toolBarRender:toolBarRender,
rowKey: 'key', rowKey: 'key',
style: {margin: 0}, style: {margin: 0},
loading: loading, loading: loading,
......
...@@ -17,11 +17,19 @@ ...@@ -17,11 +17,19 @@
import {BaseConfigProperties} from '@/types/SettingCenter/data'; import {BaseConfigProperties} from '@/types/SettingCenter/data';
import {ProCard} from '@ant-design/pro-components'; import {ModalForm, ProCard, ProFormText} from '@ant-design/pro-components';
import GeneralConfig from '@/pages/SettingCenter/GlobalSetting/SettingOverView/GeneralConfig'; import GeneralConfig from '@/pages/SettingCenter/GlobalSetting/SettingOverView/GeneralConfig';
import {l} from '@/utils/intl'; import {l} from '@/utils/intl';
import {Button, Space, Tag} from 'antd'; import {Space, Tag} from 'antd';
import React from 'react'; import React from 'react';
import {
ApiFilled,
LoginOutlined,
UserSwitchOutlined,
} from "@ant-design/icons";
import {handleOption, queryDataByParams} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
import {SuccessMessage} from "@/utils/messages";
interface LdapConfigProps { interface LdapConfigProps {
data: BaseConfigProperties[]; data: BaseConfigProperties[];
...@@ -32,6 +40,22 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => { ...@@ -32,6 +40,22 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => {
const [loading, setLoading] = React.useState(false); const [loading, setLoading] = React.useState(false);
const testConnection = async () => {
setLoading(true);
const datas = await queryDataByParams(API_CONSTANTS.LDAP_TEST_CONNECT);
if (datas) {
SuccessMessage(l("sys.ldap.settings.testConnect.success","",{count:datas}))
}
setLoading(false);
}
const testLogin = async (value: any) => {
setLoading(true);
await handleOption(API_CONSTANTS.LDAP_TEST_LOGIN, l("sys.ldap.settings.testLogin"), value);
setLoading(false);
}
const onSaveHandler = (data: BaseConfigProperties) => { const onSaveHandler = (data: BaseConfigProperties) => {
setLoading(true); setLoading(true);
onSave(data); onSave(data);
...@@ -39,6 +63,39 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => { ...@@ -39,6 +63,39 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => {
setLoading(false); setLoading(false);
}, 1000); }, 1000);
}; };
/**
* render ldap test login form
*/
const renderTestLoginForm = () => {
return (
<ModalForm
width={400} onFinish={testLogin}
trigger={<Tag icon={<LoginOutlined/>} color="#108ee9">{l("sys.ldap.settings.testLogin")}</Tag>}
>
<ProFormText name="username" label={l("login.username.placeholder")}/>
<ProFormText name="password" label={l("login.password.placeholder")}/>
</ModalForm>
)
}
/**
* render ldap test case toolbar
*/
const renderToolBar = () => {
return [
<Space key={"ldapToolBar"}>
<Tag icon={<ApiFilled/>} color="#87d068" onClick={() => testConnection()}>
{l("sys.ldap.settings.testConnect")}
</Tag>
{renderTestLoginForm()}
<Tag icon={<UserSwitchOutlined/>} color="#f50" onClick={() => {}}>
{l("sys.ldap.settings.loadUser")}
</Tag>
</Space>
];
};
return <> return <>
<ProCard <ProCard
title={l('sys.setting.ldap')} title={l('sys.setting.ldap')}
...@@ -52,6 +109,7 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => { ...@@ -52,6 +109,7 @@ export const LdapConfig = ({data, onSave}: LdapConfigProps) => {
onSave={onSaveHandler} onSave={onSaveHandler}
tag={<><Tag color={'default'}>{l('sys.setting.tag.integration')}</Tag></>} tag={<><Tag color={'default'}>{l('sys.setting.tag.integration')}</Tag></>}
data={data} data={data}
toolBarRender={renderToolBar}
/> />
</ProCard> </ProCard>
</>; </>;
......
...@@ -185,6 +185,9 @@ export const API_CONSTANTS = { ...@@ -185,6 +185,9 @@ export const API_CONSTANTS = {
// -- LDAP // -- LDAP
GET_LDAP_ENABLE: "/api/ldap/ldapEnableStatus", GET_LDAP_ENABLE: "/api/ldap/ldapEnableStatus",
LDAP_TEST_CONNECT: "/api/ldap/testConnection",
LDAP_TEST_LOGIN: "/api/ldap/testLogin",
LDAP_LIST_USER: "/api/ldap/listUser",
// -- home // -- home
GET_STATUS_COUNT: "api/jobInstance/getStatusCount", GET_STATUS_COUNT: "api/jobInstance/getStatusCount",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment