2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-07-17 14:13:00 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
import React from "react";
|
2023-03-15 11:12:31 +08:00
|
|
|
import {Button, Card, Col, Input, InputNumber, Row, Select, Switch} from "antd";
|
2021-07-17 14:13:00 +08:00
|
|
|
import {EyeInvisibleOutlined, EyeTwoTone} from "@ant-design/icons";
|
|
|
|
import * as LddpBackend from "./backend/LdapBackend";
|
|
|
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
|
|
|
import * as Setting from "./Setting";
|
|
|
|
import i18next from "i18next";
|
|
|
|
|
|
|
|
const {Option} = Select;
|
|
|
|
|
|
|
|
class LdapEditPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
ldapId: props.match.params.ldapId,
|
2023-03-08 21:31:55 +08:00
|
|
|
organizationName: props.match.params.organizationName,
|
2021-07-17 14:13:00 +08:00
|
|
|
ldap: null,
|
|
|
|
organizations: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
UNSAFE_componentWillMount() {
|
|
|
|
this.getLdap();
|
|
|
|
this.getOrganizations();
|
|
|
|
}
|
|
|
|
|
|
|
|
getLdap() {
|
2023-03-08 21:31:55 +08:00
|
|
|
LddpBackend.getLdap(this.state.organizationName, this.state.ldapId)
|
2021-07-17 14:13:00 +08:00
|
|
|
.then((res) => {
|
|
|
|
if (res.status === "ok") {
|
|
|
|
this.setState({
|
2022-08-06 23:54:56 +08:00
|
|
|
ldap: res.data,
|
2022-07-10 15:45:55 +08:00
|
|
|
});
|
2021-07-17 14:13:00 +08:00
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", res.msg);
|
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
});
|
2021-07-17 14:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getOrganizations() {
|
|
|
|
OrganizationBackend.getOrganizations("admin")
|
|
|
|
.then((res) => {
|
|
|
|
this.setState({
|
2023-07-23 09:49:16 +08:00
|
|
|
organizations: res.data || [],
|
2021-07-17 14:13:00 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLdapField(key, value) {
|
|
|
|
this.setState((prevState) => {
|
|
|
|
prevState.ldap[key] = value;
|
|
|
|
return prevState;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAutoSyncWarn() {
|
|
|
|
if (this.state.ldap.autoSync > 0) {
|
|
|
|
return (
|
|
|
|
<span style={{
|
|
|
|
color: "#faad14",
|
2022-08-06 23:54:56 +08:00
|
|
|
marginLeft: "20px",
|
2021-07-17 14:13:00 +08:00
|
|
|
}}>{i18next.t("ldap:The Auto Sync option will sync all users to specify organization")}</span>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-07-17 14:13:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLdap() {
|
|
|
|
return (
|
|
|
|
<Card size="small" title={
|
|
|
|
<div>
|
|
|
|
{i18next.t("ldap:Edit LDAP")}
|
2023-03-12 11:12:51 +08:00
|
|
|
<Button onClick={() => this.submitLdapEdit()}>{i18next.t("general:Save")}</Button>
|
|
|
|
<Button style={{marginLeft: "20px"}} type="primary" onClick={() => this.submitLdapEdit(true)}>{i18next.t("general:Save & Exit")}</Button>
|
|
|
|
<Button style={{marginLeft: "20px"}}
|
|
|
|
onClick={() => Setting.goToLink(`/ldap/sync/${this.state.organizationName}/${this.state.ldapId}`)}>
|
2023-03-19 01:01:39 +08:00
|
|
|
{i18next.t("general:Sync")} LDAP
|
2023-03-12 11:12:51 +08:00
|
|
|
</Button>
|
2021-07-17 14:13:00 +08:00
|
|
|
</div>
|
|
|
|
} style={{marginLeft: "5px"}} type="inner">
|
|
|
|
<Row style={{marginTop: "10px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Select virtual={false} style={{width: "100%"}} disabled={!Setting.isAdminUser(this.props.account)}
|
2022-07-10 15:45:55 +08:00
|
|
|
value={this.state.ldap.owner} onChange={(value => {
|
|
|
|
this.updateLdapField("owner", value);
|
|
|
|
})}>
|
2021-07-17 14:13:00 +08:00
|
|
|
{
|
|
|
|
this.state.organizations.map((organization, index) => <Option key={index}
|
2022-07-10 15:45:55 +08:00
|
|
|
value={organization.name}>{organization.name}</Option>)
|
2021-07-17 14:13:00 +08:00
|
|
|
}
|
|
|
|
</Select>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
2023-03-19 01:01:39 +08:00
|
|
|
{Setting.getLabel(i18next.t("general:ID"), i18next.t("general:ID - Tooltip"))} :
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
2022-07-10 15:45:55 +08:00
|
|
|
<Input value={this.state.ldap.id} disabled={true} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
2023-03-18 10:16:35 +08:00
|
|
|
{Setting.getLabel(i18next.t("ldap:Server name"), i18next.t("ldap:Server name - Tooltip"))} :
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Input value={this.state.ldap.serverName} onChange={e => {
|
|
|
|
this.updateLdapField("serverName", e.target.value);
|
2022-07-10 15:45:55 +08:00
|
|
|
}} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
2023-03-18 10:16:35 +08:00
|
|
|
{Setting.getLabel(i18next.t("ldap:Server host"), i18next.t("ldap:Server host - Tooltip"))} :
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Input value={this.state.ldap.host} onChange={e => {
|
|
|
|
this.updateLdapField("host", e.target.value);
|
2022-07-10 15:45:55 +08:00
|
|
|
}} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
2023-03-18 10:16:35 +08:00
|
|
|
{Setting.getLabel(i18next.t("ldap:Server port"), i18next.t("ldap:Server port - Tooltip"))} :
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<InputNumber min={0} max={65535} formatter={value => value.replace(/\$\s?|(,*)/g, "")}
|
2022-07-10 15:45:55 +08:00
|
|
|
value={this.state.ldap.port} onChange={value => {
|
|
|
|
this.updateLdapField("port", value);
|
|
|
|
}} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2023-03-15 11:12:31 +08:00
|
|
|
<Row style={{marginTop: "20px"}} >
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Enable SSL"), i18next.t("ldap:Enable SSL - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21} >
|
|
|
|
<Switch checked={this.state.ldap.enableSsl} onChange={checked => {
|
|
|
|
this.updateLdapField("enableSsl", checked);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-07-17 14:13:00 +08:00
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Base DN"), i18next.t("ldap:Base DN - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Input value={this.state.ldap.baseDn} onChange={e => {
|
|
|
|
this.updateLdapField("baseDn", e.target.value);
|
2022-07-10 15:45:55 +08:00
|
|
|
}} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2023-04-13 14:12:31 +08:00
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Search Filter"), i18next.t("ldap:Search Filter - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Input value={this.state.ldap.filter} onChange={e => {
|
|
|
|
this.updateLdapField("filter", e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Filter fields"), i18next.t("ldap:Filter fields - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Select value={this.state.ldap.filterFields ?? []} style={{width: "100%"}} mode={"multiple"} options={[
|
|
|
|
{value: "uid", label: "uid"},
|
|
|
|
{value: "mail", label: "Email"},
|
|
|
|
{value: "mobile", label: "mobile"},
|
2023-05-19 21:16:59 +08:00
|
|
|
{value: "sAMAccountName", label: "sAMAccountName"},
|
2023-04-13 14:12:31 +08:00
|
|
|
].map((item) => Setting.getOption(item.label, item.value))} onChange={value => {
|
|
|
|
this.updateLdapField("filterFields", value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-07-17 14:13:00 +08:00
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Admin"), i18next.t("ldap:Admin - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
2023-04-13 14:12:31 +08:00
|
|
|
<Input value={this.state.ldap.username} onChange={e => {
|
|
|
|
this.updateLdapField("username", e.target.value);
|
2022-07-10 15:45:55 +08:00
|
|
|
}} />
|
2021-07-17 14:13:00 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Admin Password"), i18next.t("ldap:Admin Password - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
|
|
|
<Input.Password
|
2023-04-13 14:12:31 +08:00
|
|
|
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)} value={this.state.ldap.password}
|
2021-07-17 14:13:00 +08:00
|
|
|
onChange={e => {
|
2023-04-13 14:12:31 +08:00
|
|
|
this.updateLdapField("password", e.target.value);
|
2021-07-17 14:13:00 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: "20px"}}>
|
|
|
|
<Col style={{lineHeight: "32px", textAlign: "right", paddingRight: "25px"}} span={3}>
|
|
|
|
{Setting.getLabel(i18next.t("ldap:Auto Sync"), i18next.t("ldap:Auto Sync - Tooltip"))} :
|
|
|
|
</Col>
|
|
|
|
<Col span={21}>
|
2021-12-15 17:45:11 +08:00
|
|
|
<InputNumber min={0} formatter={value => value.replace(/\$\s?|(,*)/g, "")} disabled={false}
|
2022-07-10 15:45:55 +08:00
|
|
|
value={this.state.ldap.autoSync} onChange={value => {
|
|
|
|
this.updateLdapField("autoSync", value);
|
|
|
|
}} /><span> mins</span>
|
2021-07-17 14:13:00 +08:00
|
|
|
{this.renderAutoSyncWarn()}
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Card>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2021-07-17 14:13:00 +08:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:47:38 +08:00
|
|
|
submitLdapEdit(exitAfterSave) {
|
2021-07-17 14:13:00 +08:00
|
|
|
LddpBackend.updateLdap(this.state.ldap)
|
|
|
|
.then((res) => {
|
|
|
|
if (res.status === "ok") {
|
2022-07-10 15:45:55 +08:00
|
|
|
Setting.showMessage("success", "Update LDAP server success");
|
2023-03-12 11:12:51 +08:00
|
|
|
this.setState({
|
|
|
|
organizationName: this.state.ldap.owner,
|
2022-07-10 15:45:55 +08:00
|
|
|
});
|
2023-03-12 11:12:51 +08:00
|
|
|
|
2023-10-10 21:47:38 +08:00
|
|
|
if (exitAfterSave) {
|
2023-03-12 11:12:51 +08:00
|
|
|
this.props.history.push(`/organizations/${this.state.organizationName}`);
|
|
|
|
}
|
2021-07-17 14:13:00 +08:00
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", res.msg);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
Setting.showMessage("error", `Update LDAP server failed: ${error}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2023-03-12 11:12:51 +08:00
|
|
|
{
|
|
|
|
this.state.ldap !== null ? this.renderLdap() : null
|
|
|
|
}
|
|
|
|
<div style={{marginTop: "20px", marginLeft: "40px"}}>
|
|
|
|
<Button size="large" onClick={() => this.submitLdapEdit()}>{i18next.t("general:Save")}</Button>
|
|
|
|
<Button style={{marginLeft: "20px"}} type="primary" size="large" onClick={() => this.submitLdapEdit(true)}>{i18next.t("general:Save & Exit")}</Button>
|
|
|
|
</div>
|
2021-07-17 14:13:00 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LdapEditPage;
|