mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-06 06:29:58 +08:00
feat: add organization's PasswordObfuscator to obfuscate login API's password (#3260)
* feat: add PasswordObfuscator to the login API * fix: change key error message * fix: remove unnecessary change * fix: fix one * fix: fix two * fix: fix three * fix: fix five * fix: disable organization update when key is invalid * fix: fix six * fix: use Form.Item to control key * fix: update obfuscator.js * Update obfuscator.go * Update obfuscator.go * Update auth.go * fix: remove real-time key monitoring --------- Co-authored-by: Yang Luo <hsluoyz@qq.com>
This commit is contained in:
@ -19,6 +19,7 @@ import * as ApplicationBackend from "./backend/ApplicationBackend";
|
||||
import * as LdapBackend from "./backend/LdapBackend";
|
||||
import * as Setting from "./Setting";
|
||||
import * as Conf from "./Conf";
|
||||
import * as Obfuscator from "./auth/Obfuscator";
|
||||
import i18next from "i18next";
|
||||
import {LinkOutlined} from "@ant-design/icons";
|
||||
import LdapTable from "./table/LdapTable";
|
||||
@ -112,6 +113,22 @@ class OrganizationEditPage extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
updatePasswordObfuscator(key, value) {
|
||||
const organization = this.state.organization;
|
||||
if (organization.passwordObfuscatorType === "") {
|
||||
organization.passwordObfuscatorType = "Plain";
|
||||
}
|
||||
if (key === "type") {
|
||||
organization.passwordObfuscatorType = value;
|
||||
organization.passwordObfuscatorKey = Obfuscator.getRandomKeyForObfuscator(value);
|
||||
} else if (key === "key") {
|
||||
organization.passwordObfuscatorKey = value;
|
||||
}
|
||||
this.setState({
|
||||
organization: organization,
|
||||
});
|
||||
}
|
||||
|
||||
renderOrganization() {
|
||||
return (
|
||||
<Card size="small" title={
|
||||
@ -294,6 +311,34 @@ class OrganizationEditPage extends React.Component {
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("general:Password obfuscator"), i18next.t("general:Password obfuscator - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<Select virtual={false} style={{width: "100%"}}
|
||||
value={this.state.organization.passwordObfuscatorType}
|
||||
onChange={(value => {this.updatePasswordObfuscator("type", value);})}>
|
||||
{
|
||||
[
|
||||
{id: "Plain", name: "Plain"},
|
||||
{id: "AES", name: "AES"},
|
||||
{id: "DES", name: "DES"},
|
||||
].map((obfuscatorType, index) => <Option key={index} value={obfuscatorType.id}>{obfuscatorType.name}</Option>)
|
||||
}
|
||||
</Select>
|
||||
</Col>
|
||||
</Row>
|
||||
{
|
||||
(this.state.organization.passwordObfuscatorType === "Plain" || this.state.organization.passwordObfuscatorType === "") ? null : (<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("general:Password obf key"), i18next.t("general:Password obf key - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<Input value={this.state.organization.passwordObfuscatorKey} onChange={(e) => {this.updatePasswordObfuscator("key", e.target.value);}} />
|
||||
</Col>
|
||||
</Row>)
|
||||
}
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("general:Supported country codes"), i18next.t("general:Supported country codes - Tooltip"))} :
|
||||
@ -528,6 +573,12 @@ class OrganizationEditPage extends React.Component {
|
||||
const organization = Setting.deepCopy(this.state.organization);
|
||||
organization.accountItems = organization.accountItems?.filter(accountItem => accountItem.name !== "Please select an account item");
|
||||
|
||||
const passwordObfuscatorErrorMessage = Obfuscator.checkPasswordObfuscator(organization.passwordObfuscatorType, organization.passwordObfuscatorKey);
|
||||
if (passwordObfuscatorErrorMessage.length > 0) {
|
||||
Setting.showMessage("error", passwordObfuscatorErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization)
|
||||
.then((res) => {
|
||||
if (res.status === "ok") {
|
||||
|
Reference in New Issue
Block a user