2018-11-23 07:04:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import FieldSet from 'Components/FieldSet';
|
|
|
|
import FormGroup from 'Components/Form/FormGroup';
|
|
|
|
import FormInputButton from 'Components/Form/FormInputButton';
|
2020-07-28 18:47:25 +00:00
|
|
|
import FormInputGroup from 'Components/Form/FormInputGroup';
|
|
|
|
import FormLabel from 'Components/Form/FormLabel';
|
|
|
|
import Icon from 'Components/Icon';
|
|
|
|
import ClipboardButton from 'Components/Link/ClipboardButton';
|
2018-11-23 07:04:42 +00:00
|
|
|
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
2020-07-28 18:47:25 +00:00
|
|
|
import { icons, inputTypes, kinds } from 'Helpers/Props';
|
2020-07-08 14:40:53 +00:00
|
|
|
import translate from 'Utilities/String/translate';
|
2018-11-23 07:04:42 +00:00
|
|
|
|
2022-12-20 17:56:04 +00:00
|
|
|
export const authenticationMethodOptions = [
|
2023-07-24 06:35:15 +00:00
|
|
|
{
|
|
|
|
key: 'none',
|
|
|
|
get value() {
|
|
|
|
return translate('None');
|
2022-07-12 03:12:57 +00:00
|
|
|
},
|
|
|
|
isDisabled: true
|
2023-07-24 06:35:15 +00:00
|
|
|
},
|
2022-12-20 17:56:04 +00:00
|
|
|
{
|
|
|
|
key: 'external',
|
|
|
|
get value() {
|
|
|
|
return translate('External');
|
|
|
|
},
|
|
|
|
isHidden: true
|
|
|
|
},
|
2023-07-24 06:35:15 +00:00
|
|
|
{
|
|
|
|
key: 'basic',
|
|
|
|
get value() {
|
|
|
|
return translate('AuthBasic');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'forms',
|
|
|
|
get value() {
|
|
|
|
return translate('AuthForm');
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 03:25:58 +00:00
|
|
|
];
|
|
|
|
|
2022-07-12 03:12:57 +00:00
|
|
|
export const authenticationRequiredOptions = [
|
2022-12-20 17:56:04 +00:00
|
|
|
{
|
|
|
|
key: 'enabled',
|
|
|
|
get value() {
|
|
|
|
return translate('Enabled');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'disabledForLocalAddresses',
|
|
|
|
get value() {
|
|
|
|
return translate('DisabledForLocalAddresses');
|
|
|
|
}
|
|
|
|
}
|
2022-07-12 03:12:57 +00:00
|
|
|
];
|
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
const certificateValidationOptions = [
|
2023-07-24 06:35:15 +00:00
|
|
|
{
|
|
|
|
key: 'enabled',
|
|
|
|
get value() {
|
|
|
|
return translate('Enabled');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'disabledForLocalAddresses',
|
|
|
|
get value() {
|
2022-12-20 17:56:04 +00:00
|
|
|
return translate('DisabledForLocalAddresses');
|
2023-07-24 06:35:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'disabled',
|
|
|
|
get value() {
|
|
|
|
return translate('Disabled');
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 03:25:58 +00:00
|
|
|
];
|
|
|
|
|
2018-11-23 07:04:42 +00:00
|
|
|
class SecuritySettings extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isConfirmApiKeyResetModalOpen: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onApikeyFocus = (event) => {
|
|
|
|
event.target.select();
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
onResetApiKeyPress = () => {
|
|
|
|
this.setState({ isConfirmApiKeyResetModalOpen: true });
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
onConfirmResetApiKey = () => {
|
|
|
|
this.setState({ isConfirmApiKeyResetModalOpen: false });
|
|
|
|
this.props.onConfirmResetApiKey();
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
onCloseResetApiKeyModal = () => {
|
|
|
|
this.setState({ isConfirmApiKeyResetModalOpen: false });
|
2022-03-20 23:20:34 +00:00
|
|
|
};
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
settings,
|
|
|
|
isResettingApiKey,
|
|
|
|
onInputChange
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
authenticationMethod,
|
2022-07-12 03:12:57 +00:00
|
|
|
authenticationRequired,
|
2018-11-23 07:04:42 +00:00
|
|
|
username,
|
|
|
|
password,
|
2019-04-13 03:25:58 +00:00
|
|
|
apiKey,
|
|
|
|
certificateValidation
|
2018-11-23 07:04:42 +00:00
|
|
|
} = settings;
|
|
|
|
|
|
|
|
const authenticationEnabled = authenticationMethod && authenticationMethod.value !== 'none';
|
|
|
|
|
|
|
|
return (
|
2020-07-08 14:40:53 +00:00
|
|
|
<FieldSet legend={translate('Security')}>
|
2018-11-23 07:04:42 +00:00
|
|
|
<FormGroup>
|
2020-08-29 03:56:13 +00:00
|
|
|
<FormLabel>{translate('Authentication')}</FormLabel>
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.SELECT}
|
|
|
|
name="authenticationMethod"
|
|
|
|
values={authenticationMethodOptions}
|
2020-08-29 03:56:13 +00:00
|
|
|
helpText={translate('AuthenticationMethodHelpText')}
|
2022-12-20 17:56:04 +00:00
|
|
|
helpTextWarning={translate('AuthenticationRequiredWarning')}
|
2018-11-23 07:04:42 +00:00
|
|
|
onChange={onInputChange}
|
|
|
|
{...authenticationMethod}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
{
|
2022-07-12 03:12:57 +00:00
|
|
|
authenticationEnabled ?
|
|
|
|
<FormGroup>
|
2022-12-20 17:56:04 +00:00
|
|
|
<FormLabel>{translate('AuthenticationRequired')}</FormLabel>
|
2022-07-12 03:12:57 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.SELECT}
|
|
|
|
name="authenticationRequired"
|
|
|
|
values={authenticationRequiredOptions}
|
2022-12-20 17:56:04 +00:00
|
|
|
helpText={translate('AuthenticationRequiredHelpText')}
|
2022-07-12 03:12:57 +00:00
|
|
|
onChange={onInputChange}
|
|
|
|
{...authenticationRequired}
|
|
|
|
/>
|
|
|
|
</FormGroup> :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
authenticationEnabled ?
|
2019-12-07 02:38:58 +00:00
|
|
|
<FormGroup>
|
2020-08-29 03:56:13 +00:00
|
|
|
<FormLabel>{translate('Username')}</FormLabel>
|
2019-12-07 02:38:58 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.TEXT}
|
|
|
|
name="username"
|
|
|
|
onChange={onInputChange}
|
|
|
|
{...username}
|
|
|
|
/>
|
2022-07-12 03:12:57 +00:00
|
|
|
</FormGroup> :
|
|
|
|
null
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2022-07-12 03:12:57 +00:00
|
|
|
authenticationEnabled ?
|
2019-12-07 02:38:58 +00:00
|
|
|
<FormGroup>
|
2020-08-29 03:56:13 +00:00
|
|
|
<FormLabel>{translate('Password')}</FormLabel>
|
2019-12-07 02:38:58 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.PASSWORD}
|
|
|
|
name="password"
|
|
|
|
onChange={onInputChange}
|
|
|
|
{...password}
|
|
|
|
/>
|
2022-07-12 03:12:57 +00:00
|
|
|
</FormGroup> :
|
|
|
|
null
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
<FormGroup>
|
2020-08-29 03:56:13 +00:00
|
|
|
<FormLabel>{translate('ApiKey')}</FormLabel>
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.TEXT}
|
|
|
|
name="apiKey"
|
|
|
|
readOnly={true}
|
2020-08-29 03:56:13 +00:00
|
|
|
helpTextWarning={translate('RestartRequiredHelpTextWarning')}
|
2018-11-23 07:04:42 +00:00
|
|
|
buttons={[
|
|
|
|
<ClipboardButton
|
|
|
|
key="copy"
|
|
|
|
value={apiKey.value}
|
|
|
|
kind={kinds.DEFAULT}
|
|
|
|
/>,
|
|
|
|
|
|
|
|
<FormInputButton
|
|
|
|
key="reset"
|
|
|
|
kind={kinds.DANGER}
|
|
|
|
onPress={this.onResetApiKeyPress}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
name={icons.REFRESH}
|
|
|
|
isSpinning={isResettingApiKey}
|
|
|
|
/>
|
|
|
|
</FormInputButton>
|
|
|
|
]}
|
|
|
|
onChange={onInputChange}
|
|
|
|
onFocus={this.onApikeyFocus}
|
|
|
|
{...apiKey}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
<FormGroup>
|
2020-08-29 03:56:13 +00:00
|
|
|
<FormLabel>{translate('CertificateValidation')}</FormLabel>
|
2019-04-13 03:25:58 +00:00
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.SELECT}
|
|
|
|
name="certificateValidation"
|
|
|
|
values={certificateValidationOptions}
|
2020-08-29 03:56:13 +00:00
|
|
|
helpText={translate('CertificateValidationHelpText')}
|
2019-04-13 03:25:58 +00:00
|
|
|
onChange={onInputChange}
|
|
|
|
{...certificateValidation}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
2018-11-23 07:04:42 +00:00
|
|
|
<ConfirmModal
|
|
|
|
isOpen={this.state.isConfirmApiKeyResetModalOpen}
|
|
|
|
kind={kinds.DANGER}
|
2020-08-29 03:56:13 +00:00
|
|
|
title={translate('ResetAPIKey')}
|
2023-06-12 21:58:14 +00:00
|
|
|
message={translate('ResetAPIKeyMessageText')}
|
2020-08-29 03:56:13 +00:00
|
|
|
confirmLabel={translate('Reset')}
|
2018-11-23 07:04:42 +00:00
|
|
|
onConfirm={this.onConfirmResetApiKey}
|
|
|
|
onCancel={this.onCloseResetApiKeyModal}
|
|
|
|
/>
|
|
|
|
</FieldSet>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SecuritySettings.propTypes = {
|
|
|
|
settings: PropTypes.object.isRequired,
|
|
|
|
isResettingApiKey: PropTypes.bool.isRequired,
|
|
|
|
onInputChange: PropTypes.func.isRequired,
|
|
|
|
onConfirmResetApiKey: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SecuritySettings;
|