import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { createSubscribedElement } from '../../UnstatedUtils'; import { toastSuccess, toastError } from '../../../util/apiNotification'; import AppContainer from '../../../services/AppContainer'; import AdminGeneralSecurityContainer from '../../../services/AdminGeneralSecurityContainer'; import AdminLdapSecurityContainer from '../../../services/AdminLdapSecurityContainer'; import LdapAuthTestModal from './LdapAuthTestModal'; class LdapSecuritySetting extends React.Component { constructor(props) { super(props); this.state = { isRetrieving: true, isLdapAuthTestModalShown: false, }; this.onClickSubmit = this.onClickSubmit.bind(this); this.openLdapAuthTestModal = this.openLdapAuthTestModal.bind(this); this.closeLdapAuthTestModal = this.closeLdapAuthTestModal.bind(this); } async componentDidMount() { const { adminLdapSecurityContainer } = this.props; try { await adminLdapSecurityContainer.retrieveSecurityData(); } catch (err) { toastError(err); } this.setState({ isRetrieving: false }); } async onClickSubmit() { const { t, adminLdapSecurityContainer, adminGeneralSecurityContainer } = this.props; try { await adminLdapSecurityContainer.updateLdapSetting(); await adminGeneralSecurityContainer.retrieveSetupStratedies(); toastSuccess(t('security_setting.ldap.updated_ldap')); } catch (err) { toastError(err); } } openLdapAuthTestModal() { this.setState({ isLdapAuthTestModalShown: true }); } closeLdapAuthTestModal() { this.setState({ isLdapAuthTestModalShown: false }); } render() { const { t, adminGeneralSecurityContainer, adminLdapSecurityContainer } = this.props; const { isLdapEnabled } = adminGeneralSecurityContainer.state; if (this.state.isRetrieving) { return null; } return (

LDAP

{ adminGeneralSecurityContainer.switchIsLdapEnabled() }} />
{(!adminGeneralSecurityContainer.state.setupStrategies.includes('ldap') && isLdapEnabled) &&
{t('security_setting.setup_is_not_yet_complete')}
}
{isLdapEnabled && (

{t('security_setting.configuration')}

adminLdapSecurityContainer.changeServerUrl(e.target.value)} />

{t('security_setting.example')}: ldaps://ldap.company.com/ou=people,dc=company,dc=com

{t('security_setting.ldap.bind_mode')}
Bind DN
adminLdapSecurityContainer.changeBindDN(e.target.value)} /> {(adminLdapSecurityContainer.state.isUserBind === true) ? (

{t('security_setting.ldap.bind_DN_user_detail1')}
{/* eslint-disable-next-line react/no-danger */}
{t('security_setting.example')}1: uid={'{{ username }}'},dc=domain,dc=com
{t('security_setting.example')}2: {'{{ username }}'}@domain.com

) : (

{t('security_setting.ldap.bind_DN_manager_detail')}
{t('security_setting.example')}1: uid=admin,dc=domain,dc=com
{t('security_setting.example')}2: admin@domain.com

)}
{t('security_setting.ldap.bind_DN_password')}
{(adminLdapSecurityContainer.state.isUserBind) ? (

{t('security_setting.ldap.bind_DN_password_user_detail')}

) : ( <>

{t('security_setting.ldap.bind_DN_password_manager_detail')}

adminLdapSecurityContainer.changeBindDNPassword(e.target.value)} /> )}
{t('security_setting.ldap.search_filter')}
adminLdapSecurityContainer.changeSearchFilter(e.target.value)} />

{t('security_setting.ldap.search_filter_detail1')}
{/* eslint-disable-next-line react/no-danger */}
{/* eslint-disable-next-line react/no-danger */}

{t('security_setting.example')}1 - {t('security_setting.ldap.search_filter_example1')}: (|(uid={'{{ username }}'})(mail={'{{ username }}'}))
{t('security_setting.example')}2 - {t('security_setting.ldap.search_filter_example2')}: (sAMAccountName={'{{ username }}'})

Attribute Mapping ({t('security_setting.optional')})

{t('username')}
adminLdapSecurityContainer.changeAttrMapUsername(e.target.value)} />

{/* eslint-disable-next-line react/no-danger */}

{ adminLdapSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }} />

{/* eslint-disable-next-line react/no-danger */}

{t('Email')}
adminLdapSecurityContainer.changeAttrMapMail(e.target.value)} />

{t('security_setting.ldap.mail_detail')}

{t('Name')}
adminLdapSecurityContainer.changeAttrMapName(e.target.value)} />

{t('security_setting.ldap.name_detail')}

{t('security_setting.ldap.group_search_filter')} ({t('security_setting.optional')})

{t('security_setting.ldap.group_search_base_DN')}
adminLdapSecurityContainer.changeGroupSearchBase(e.target.value)} />

{/* eslint-disable-next-line react/no-danger */}
{t('security_setting.example')}: ou=groups,dc=domain,dc=com

{t('security_setting.ldap.group_search_filter')}
adminLdapSecurityContainer.changeGroupSearchFilter(e.target.value)} />

{/* eslint-disable react/no-danger */}

{/* eslint-enable react/no-danger */}

{t('security_setting.example')}: {/* eslint-disable-next-line react/no-danger */}

{t('security_setting.ldap.group_search_user_DN_property')}
adminLdapSecurityContainer.changeGroupDnProperty(e.target.value)} />

{/* eslint-disable-next-line react/no-danger */}

)}
); } } LdapSecuritySetting.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired, adminLdapSecurityContainer: PropTypes.instanceOf(AdminLdapSecurityContainer).isRequired, }; const LdapSecuritySettingWrapper = (props) => { return createSubscribedElement(LdapSecuritySetting, props, [AppContainer, AdminGeneralSecurityContainer, AdminLdapSecurityContainer]); }; export default withTranslation()(LdapSecuritySettingWrapper);