"lodash.mergewith": "4.6.2",
"lodash.template": "4.5.0",
"mem": "4.0.0",
+ "parse-duration": "0.4.4",
"prop-types": "15.7.2",
"query-string": "6.9.0",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-dropzone": "5.1.1",
"react-highlight-words": "0.14.0",
+ "react-idle-timer": "4.3.6",
"react-redux": "5.0.7",
"react-router": "4.3.1",
"react-router-dom": "4.3.1",
SSHHelpPageHTML: string;
SSHHelpHostSuffix: string;
SiteName: string;
+ IdleTimeout: string;
};
Login: {
LoginCluster: string;
SSHHelpPageHTML: "",
SSHHelpHostSuffix: "",
SiteName: "",
+ IdleTimeout: "0s",
},
Login: {
LoginCluster: "",
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { connect } from "react-redux";
+import { useIdleTimer } from "react-idle-timer";
+import { Dispatch } from "redux";
+
+import { RootState } from "~/store/store";
+import { SnackbarKind, snackbarActions } from "~/store/snackbar/snackbar-actions";
+import { logout } from "~/store/auth/auth-action";
+import parse from "parse-duration";
+import * as React from "react";
+import { min } from "lodash";
+
+interface AutoLogoutDataProps {
+ sessionIdleTimeout: number;
+ lastWarningDuration: number;
+}
+
+interface AutoLogoutActionProps {
+ doLogout: () => void;
+ doWarn: (message: string, duration: number) => void;
+ doCloseWarn: () => void;
+}
+
+const mapStateToProps = (state: RootState, ownProps: any): AutoLogoutDataProps => {
+ return {
+ sessionIdleTimeout: parse(state.auth.config.clusterConfig.Workbench.IdleTimeout, 's') || 0,
+ lastWarningDuration: ownProps.lastWarningDuration || 60,
+ };
+};
+
+const mapDispatchToProps = (dispatch: Dispatch): AutoLogoutActionProps => ({
+ doLogout: () => dispatch<any>(logout(true)),
+ doWarn: (message: string, duration: number) =>
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message, hideDuration: duration, kind: SnackbarKind.WARNING })),
+ doCloseWarn: () => dispatch(snackbarActions.CLOSE_SNACKBAR()),
+});
+
+type AutoLogoutProps = AutoLogoutDataProps & AutoLogoutActionProps;
+
+export const AutoLogout = connect(mapStateToProps, mapDispatchToProps)(
+ (props: AutoLogoutProps) => {
+ let logoutTimer: NodeJS.Timer;
+ const lastWarningDuration = min([props.lastWarningDuration, props.sessionIdleTimeout])! * 1000 ;
+
+ const handleOnIdle = () => {
+ logoutTimer = setTimeout(
+ () => props.doLogout(), lastWarningDuration);
+ props.doWarn(
+ "Your session is about to be closed due to inactivity",
+ lastWarningDuration);
+ };
+
+ const handleOnActive = () => {
+ clearTimeout(logoutTimer);
+ props.doCloseWarn();
+ };
+
+ useIdleTimer({
+ timeout: (props.lastWarningDuration < props.sessionIdleTimeout)
+ ? 1000 * (props.sessionIdleTimeout - props.lastWarningDuration)
+ : 1,
+ onIdle: handleOnIdle,
+ onActive: handleOnActive,
+ debounce: 500
+ });
+
+ return <span />;
+ });
isNotLinking: boolean;
isLinkingPath: boolean;
siteBanner: string;
+ sessionIdleTimeout: number;
}
type MainPanelRootProps = MainPanelRootDataProps & WithStyles<CssRules>;
export const MainPanelRoot = withStyles(styles)(
({ classes, loading, working, user, buildInfo, uuidPrefix,
- isNotLinking, isLinkingPath, siteBanner }: MainPanelRootProps) =>
+ isNotLinking, isLinkingPath, siteBanner, sessionIdleTimeout }: MainPanelRootProps) =>
loading
? <WorkbenchLoadingScreen />
: <>
<Grid container direction="column" className={classes.root}>
{user
? (user.isActive || (!user.isActive && isLinkingPath)
- ? <WorkbenchPanel isNotLinking={isNotLinking} isUserActive={user.isActive} />
+ ? <WorkbenchPanel isNotLinking={isNotLinking} isUserActive={user.isActive} sessionIdleTimeout={sessionIdleTimeout} />
: <InactivePanel />)
: <LoginPanel />}
</Grid>
import { RootState } from '~/store/store';
import { connect } from 'react-redux';
+import parse from 'parse-duration';
import { MainPanelRoot, MainPanelRootDataProps } from '~/views/main-panel/main-panel-root';
import { isSystemWorking } from '~/store/progress-indicator/progress-indicator-reducer';
import { isWorkbenchLoading } from '~/store/workbench/workbench-actions';
uuidPrefix: state.auth.localCluster,
isNotLinking: state.linkAccountPanel.status === LinkAccountPanelStatus.NONE || state.linkAccountPanel.status === LinkAccountPanelStatus.INITIAL,
isLinkingPath: state.router.location ? matchLinkAccountRoute(state.router.location.pathname) !== null : false,
- siteBanner: state.auth.config.clusterConfig.Workbench.SiteName
+ siteBanner: state.auth.config.clusterConfig.Workbench.SiteName,
+ sessionIdleTimeout: parse(state.auth.config.clusterConfig.Workbench.IdleTimeout, 's') || 0
};
};
import { CollectionsContentAddressPanel } from '~/views/collection-content-address-panel/collection-content-address-panel';
import { AllProcessesPanel } from '../all-processes-panel/all-processes-panel';
import { NotFoundPanel } from '../not-found-panel/not-found-panel';
+import { AutoLogout } from '~/views-components/auto-logout/auto-logout';
type CssRules = 'root' | 'container' | 'splitter' | 'asidePanel' | 'contentWrapper' | 'content';
interface WorkbenchDataProps {
isUserActive: boolean;
isNotLinking: boolean;
+ sessionIdleTimeout: number;
}
type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
export const WorkbenchPanel =
withStyles(styles)((props: WorkbenchPanelProps) =>
<Grid container item xs className={props.classes.root}>
+ { props.sessionIdleTimeout > 0 && <AutoLogout />}
<Grid container item xs className={props.classes.container}>
<SplitterLayout customClassName={props.classes.splitter} percentage={true}
primaryIndex={0} primaryMinSize={10}
pbkdf2 "^3.0.3"
safe-buffer "^5.1.1"
+parse-duration@0.4.4:
+ version "0.4.4"
+ resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-0.4.4.tgz#11c0f51a689e97d06c57bd772f7fda7dc013243c"
+ integrity sha512-KbAJuYGUhZkB9gotDiKLnZ7Z3VTacK3fgwmDdB6ZVDtJbMBT6MfLga0WJaYpPDu0mzqT0NgHtHDt5PY4l0nidg==
+
parse-glob@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c"
memoize-one "^4.0.0"
prop-types "^15.5.8"
+react-idle-timer@4.3.6:
+ version "4.3.6"
+ resolved "https://registry.yarnpkg.com/react-idle-timer/-/react-idle-timer-4.3.6.tgz#bdf56cee6ccc8c144ece18d152b3e304e13f3fa2"
+ integrity sha512-sJS4w123E4HkuM/l3j8FTVl0St6ghGA22Ich/Nz/luJSM4MEA6PvSwEBaAXLx3uCLB1fK7CACjvB4ozW3uWuCA==
+
react-is@^16.4.2, react-is@^16.6.3, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6, react-is@^16.9.0:
version "16.11.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.11.0.tgz#b85dfecd48ad1ce469ff558a882ca8e8313928fa"