Skip to content

Commit

Permalink
Update Radius and LDAP pages
Browse files Browse the repository at this point in the history
Simplify the code, use enabled instead of enable variable from settings,
check if ldap and radius are enabled in gvm-libs and display text if
they are disabled because of missing support in gvm-libs.
  • Loading branch information
bjoernricks committed Jun 4, 2019
1 parent a07ee3c commit ac7454b
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 126 deletions.
157 changes: 80 additions & 77 deletions gsa/src/web/pages/ldap/ldappage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,43 @@ class LdapAuthentication extends React.Component {
super(...args);

this.state = {
authdn: '',
ldaphost: '',
enable: '',
certificateInfo: {},
loading: 'true',
hasLdapSupport: true,
loading: true,
initial: true,
dialogVisible: false,
};

this.getLdapAuth = this.getLdapAuth.bind(this);
this.handleSaveSettings = this.handleSaveSettings.bind(this);
this.handleValueChange = this.handleValueChange.bind(this);
this.closeDialog = this.closeDialog.bind(this);
this.openDialog = this.openDialog.bind(this);
}

componentDidMount() {
this.load();
this.loadLdapAuthSettings();
}

load() {
this.getLdapAuth().then(this.setState({loading: false}));
}

getLdapAuth() {
loadLdapAuthSettings() {
const {gmp} = this.props;
const authData = gmp.user.currentAuthSettings().then(response => {
const data = response.data.get('method:ldap_connect');
const {authdn, certificateInfo, enable, ldaphost} = data;

this.setState({loading: true});

return gmp.user.currentAuthSettings().then(response => {
const {data: settings} = response;
// ldap support is enabled in gvm-libs
const hasLdapSupport = settings.has('method:ldap_connect');
const {authdn, certificateInfo, enabled, ldaphost} = settings.get(
'method:ldap_connect',
);
this.setState({
hasLdapSupport,
authdn,
certificateInfo,
enable,
enabled,
ldaphost,
loading: false,
initial: false,
});
});
return authData;
}

handleInteraction() {
Expand All @@ -116,27 +117,22 @@ class LdapAuthentication extends React.Component {
}
}

handleSaveSettings(state) {
const {authdn, certificate, enable, ldaphost} = state;

const data = {
authdn,
certificate,
enable,
ldaphost,
};
handleSaveSettings({authdn, certificate, enable, ldaphost}) {
const {gmp} = this.props;

this.handleInteraction();

return gmp.auth.saveLdap(data).then(() => {
this.getLdapAuth();
this.setState({dialogVisible: false});
});
}

handleValueChange(value, name) {
this.setState({[name]: value});
return gmp.auth
.saveLdap({
authdn,
certificate,
enable,
ldaphost,
})
.then(() => {
this.loadLdapAuthSettings();
this.setState({dialogVisible: false});
});
}

openDialog() {
Expand All @@ -148,68 +144,75 @@ class LdapAuthentication extends React.Component {
}

render() {
const {loading} = this.state;
if (loading) {
const {loading, initial} = this.state;
if (loading && initial) {
return <Loading />;
}

const {
authdn,
certificateInfo = {},
dialogVisible,
enable,
enabled,
hasLdapSupport,
ldaphost,
} = this.state;

return (
<React.Fragment>
<Layout flex="column">
<ToolBarIcons onOpenDialogClick={this.openDialog} />
{hasLdapSupport && (
<ToolBarIcons onOpenDialogClick={this.openDialog} />
)}
<Section
img={<LdapIcon size="large" />}
title={_('LDAP per-User Authentication')}
/>
<Table>
<colgroup>
<Col width="10%" />
<Col width="90%" />
</colgroup>
<TableBody>
<TableRow>
<TableData>{_('Enabled')}</TableData>
<TableData>{renderYesNo(enable)}</TableData>
</TableRow>
<TableRow>
<TableData>{_('LDAP Host')}</TableData>
<TableData>{ldaphost}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Auth. DN')}</TableData>
<TableData>{authdn}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Activation')}</TableData>
<TableData>{certificateInfo.activation_time}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Expiration')}</TableData>
<TableData>{certificateInfo.expiration_time}</TableData>
</TableRow>
<TableRow>
<TableData>{_('MD5 Fingerprint')}</TableData>
<TableData>{certificateInfo.md5_fingerprint}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Issued by')}</TableData>
<TableData>{certificateInfo.issuer}</TableData>
</TableRow>
</TableBody>
</Table>
{hasLdapSupport ? (
<Table>
<colgroup>
<Col width="10%" />
<Col width="90%" />
</colgroup>
<TableBody>
<TableRow>
<TableData>{_('Enabled')}</TableData>
<TableData>{renderYesNo(enabled)}</TableData>
</TableRow>
<TableRow>
<TableData>{_('LDAP Host')}</TableData>
<TableData>{ldaphost}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Auth. DN')}</TableData>
<TableData>{authdn}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Activation')}</TableData>
<TableData>{certificateInfo.activation_time}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Expiration')}</TableData>
<TableData>{certificateInfo.expiration_time}</TableData>
</TableRow>
<TableRow>
<TableData>{_('MD5 Fingerprint')}</TableData>
<TableData>{certificateInfo.md5_fingerprint}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Issued by')}</TableData>
<TableData>{certificateInfo.issuer}</TableData>
</TableRow>
</TableBody>
</Table>
) : (
<p>{_('Support for LDAP is not available.')}</p>
)}
</Layout>

{dialogVisible && (
<LdapDialog
authdn={authdn}
enable={enable}
enable={enabled}
ldaphost={ldaphost}
onClose={this.closeDialog}
onSave={this.handleSaveSettings}
Expand Down
109 changes: 60 additions & 49 deletions gsa/src/web/pages/radius/radiuspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,37 @@ class RadiusAuthentication extends React.Component {
super(...args);

this.state = {
enable: '',
radiushost: '',
radiuskey: '',
hasRadiusSupport: true,
loading: true,
initial: true,
dialogVisible: false,
};

this.getRadiusAuth = this.getRadiusAuth.bind(this);
this.handleSaveSettings = this.handleSaveSettings.bind(this);
this.closeDialog = this.closeDialog.bind(this);
this.openDialog = this.openDialog.bind(this);
}

componentDidMount() {
this.load();
this.loadRadiusAuthSettings();
}

load() {
this.getRadiusAuth().then(this.setState({loading: false}));
}

getRadiusAuth() {
loadRadiusAuthSettings() {
const {gmp} = this.props;
const authData = gmp.user.currentAuthSettings().then(response => {
const data = response.data.get('method:radius_connect');
const {enable, radiushost, radiuskey} = data;
const {data: settings} = response;
// radius support is enabled in gvm-libs
const hasRadiusSupport = settings.has('method:radius_connect');
const {enabled, radiushost, radiuskey} = settings.get(
'method:radius_connect',
);
this.setState({
enable,
hasRadiusSupport,
enabled,
radiushost,
radiuskey,
loading: false,
initial: false,
});
});
return authData;
Expand All @@ -113,23 +114,21 @@ class RadiusAuthentication extends React.Component {
}
}

handleSaveSettings(state) {
const {enable, radiushost, radiuskey} = state;

const data = {
enable,
radiushost,
radiuskey,
};

handleSaveSettings({enable, radiushost, radiuskey}) {
const {gmp} = this.props;

this.handleInteraction();

return gmp.auth.saveRadius(data).then(() => {
this.getRadiusAuth();
this.setState({dialogVisible: false});
});
return gmp.auth
.saveRadius({
enable,
radiushost,
radiuskey,
})
.then(() => {
this.loadRadiusAuthSettings();
this.setState({dialogVisible: false});
});
}

openDialog() {
Expand All @@ -146,40 +145,52 @@ class RadiusAuthentication extends React.Component {
return <Loading />;
}

const {dialogVisible, enable, radiushost, radiuskey} = this.state;
const {
hasRadiusSupport,
dialogVisible,
enabled,
radiushost,
radiuskey,
} = this.state;

return (
<React.Fragment>
<Layout flex="column">
<ToolBarIcons onOpenDialogClick={this.openDialog} />
{hasRadiusSupport && (
<ToolBarIcons onOpenDialogClick={this.openDialog} />
)}
<Section
img={<RadiusIcon size="large" />}
title={_('RADIUS Authentication')}
/>
<Table>
<colgroup>
<Col width="10%" />
<Col width="90%" />
</colgroup>
<TableBody>
<TableRow>
<TableData>{_('Enabled')}</TableData>
<TableData>{renderYesNo(enable)}</TableData>
</TableRow>
<TableRow>
<TableData>{_('RADIUS Host')}</TableData>
<TableData>{radiushost}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Secret Key')}</TableData>
<TableData>********</TableData>
</TableRow>
</TableBody>
</Table>
{hasRadiusSupport ? (
<Table>
<colgroup>
<Col width="10%" />
<Col width="90%" />
</colgroup>
<TableBody>
<TableRow>
<TableData>{_('Enabled')}</TableData>
<TableData>{renderYesNo(enabled)}</TableData>
</TableRow>
<TableRow>
<TableData>{_('RADIUS Host')}</TableData>
<TableData>{radiushost}</TableData>
</TableRow>
<TableRow>
<TableData>{_('Secret Key')}</TableData>
<TableData>********</TableData>
</TableRow>
</TableBody>
</Table>
) : (
<p>{_('Support for Radius is not available.')}</p>
)}
</Layout>
{dialogVisible && (
<RadiusDialog
enable={enable}
enable={enabled}
radiushost={radiushost}
radiuskey={radiuskey}
onClose={this.closeDialog}
Expand Down

0 comments on commit ac7454b

Please sign in to comment.