Skip to content

Commit b402882

Browse files
committed
adding authentication
1 parent f46c1f6 commit b402882

File tree

7 files changed

+168
-47
lines changed

7 files changed

+168
-47
lines changed

web-server/components/SlycatRemoteControls.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class SlycatRemoteControls extends Component {
2424
remote_hosts: [],
2525
hostname: display.hostname ? display.hostname : null,
2626
username: display.username ? display.username : null,
27-
session_exists: null,
27+
session_exists: this.props.sessionExists ? this.props.sessionExists : false,
2828
password: "",
2929
hostnames: [],
3030
loadingData: this.props.loadingData,

web-server/plugins/slycat-cca/js/components/CCANavItems.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,35 @@
44
import * as React from "react";
55
import { CCANavItem } from "./CCANavItem";
66
import { useAppSelector } from "./wizard-store/hooks";
7-
import { selectTab, TabNames } from "./wizard-store/reducers/cCAWizardSlice";
7+
import { selectDataLocation, selectTab, TabNames } from "./wizard-store/reducers/cCAWizardSlice";
88

99
export const CCAWizardNavItems = () => {
1010
const tabName = useAppSelector(selectTab);
11+
const dataLocation = useAppSelector(selectDataLocation);
1112
return (
1213
<ul className="nav nav-pills">
1314
<CCANavItem
1415
key={"Locate Data"}
1516
name={"Locate Data"}
1617
active={tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB}
1718
/>
19+
<CCANavItem
20+
key={"Authentication"}
21+
name={"Authentication"}
22+
active={tabName === TabNames.CCA_AUTHENTICATION_TAB}
23+
hidden={tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB || dataLocation !== "remote"}
24+
/>
1825
<CCANavItem
1926
key={"Upload Table"}
2027
name={"Upload Table"}
2128
active={
22-
tabName === TabNames.CCA_LOCAL_BROWSER_TAB || tabName === TabNames.CCA_REMOTE_BROWSER_TAB
29+
tabName === TabNames.CCA_LOCAL_BROWSER_TAB ||
30+
tabName === TabNames.CCA_REMOTE_BROWSER_TAB
31+
}
32+
hidden={
33+
tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB ||
34+
tabName === TabNames.CCA_AUTHENTICATION_TAB
2335
}
24-
hidden={tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB}
2536
/>
2637
<CCANavItem
2738
key={"Select Columns"}

web-server/plugins/slycat-cca/js/components/CCAWizardSteps.tsx

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CCALocalBrowserTab } from "./wizard-tabs/CCALocalBrowserTab";
1010
import { CCATableIngestion } from "./wizard-tabs/CCATableIngestion";
1111
import { CCAModelCreation } from "./wizard-tabs/CCAModelCreation";
1212
import { CCARemoteBrowserTab } from "./wizard-tabs/CCARemoteBrowser";
13+
import { CCAAuthenticationTab } from "./wizard-tabs/CCAAuthenticationTab";
1314

1415
export const CCAWizardSteps = () => {
1516
// The `state` arg is correctly typed as `RootState` already
@@ -20,45 +21,10 @@ export const CCAWizardSteps = () => {
2021
<div className="tab-content">
2122
<CCAWizardDataSelectionTab hidden={!(tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB)} />
2223
<CCALocalBrowserTab hidden={!(tabName === TabNames.CCA_LOCAL_BROWSER_TAB)} />
24+
<CCAAuthenticationTab hidden={!(tabName === TabNames.CCA_AUTHENTICATION_TAB)} />
2325
<CCARemoteBrowserTab hidden={!(tabName === TabNames.CCA_REMOTE_BROWSER_TAB)} />
2426
<CCATableIngestion hidden={!(tabName === TabNames.CCA_TABLE_INGESTION)} />
2527
<CCAModelCreation hidden={!(tabName === TabNames.CCA_FINISH_MODEL)}/>
26-
<div hidden={true}>
27-
<form role="form">
28-
{/* <slycat-remote-controls
29-
params="
30-
hostname:remote.hostname,
31-
username:remote.username,
32-
password:remote.password,
33-
status:remote.status,
34-
status_type:remote.status_type,
35-
enable:remote.enable,
36-
focus:remote.focus,
37-
activate:connect,
38-
session_exists:remote.session_exists"
39-
></slycat-remote-controls> */}
40-
</form>
41-
</div>
42-
43-
<div hidden={true} style={{ height: "400px" }}>
44-
<div className="slycat-remote-browser-flex-layout">
45-
{/* <slycat-remote-browser
46-
params="
47-
type:'remote',
48-
sid:remote.sid,
49-
hostname:remote.hostname,
50-
selection:browser.selection,
51-
path:browser.path,
52-
open_file_callback:load_table,
53-
session_exists:remote.session_exists,
54-
persistence_id:'cca-table-file',
55-
progress:remote.progress,
56-
progress_status:remote.progress_status,
57-
reauth:reauth,"
58-
></slycat-remote-browser>
59-
<slycat-parser-controls params="parser:parser,category:'table'"></slycat-parser-controls> */}
60-
</div>
61-
</div>
6228
</div>
6329
</div>
6430
);

web-server/plugins/slycat-cca/js/components/CCAWizardUtils.tsx

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Attribute,
1010
resetCCAWizard,
1111
selectAttributes,
12+
selectAuthInfo,
1213
selectDataLocation,
1314
selectDescription,
1415
selectFileUploaded,
@@ -19,6 +20,7 @@ import {
1920
selectScaleInputs,
2021
selectTab,
2122
setAttributes,
23+
setAuthInfo,
2224
setFileUploaded,
2325
setMid,
2426
setPid,
@@ -28,6 +30,7 @@ import {
2830
import client from "js/slycat-web-client";
2931
import fileUploader from "js/slycat-file-uploader-factory";
3032
import * as dialog from "js/slycat-dialog";
33+
import { REMOTE_AUTH_LABELS } from "../../../../utils/ui-labels";
3134

3235
/**
3336
* A hook for controlling how the back and continue buttons work based on the current redux state
@@ -39,6 +42,7 @@ export const useCCAWizardFooter = () => {
3942
const fileUploaded = useAppSelector(selectFileUploaded);
4043
const dispatch = useAppDispatch();
4144
const uploadSelection = useUploadSelection();
45+
const handleAuthentication = useHandleAuthentication();
4246
const finishModel = useFinishModel();
4347

4448
/**
@@ -51,7 +55,12 @@ export const useCCAWizardFooter = () => {
5155
}
5256
if (tabName === TabNames.CCA_DATA_WIZARD_SELECTION_TAB && dataLocation === "remote") {
5357
console.log(dataLocation);
54-
dispatch(setTabName(TabNames.CCA_REMOTE_BROWSER_TAB));
58+
dispatch(setTabName(TabNames.CCA_AUTHENTICATION_TAB));
59+
}
60+
if (tabName === TabNames.CCA_AUTHENTICATION_TAB) {
61+
console.log(dataLocation);
62+
handleAuthentication();
63+
// dispatch(setTabName(TabNames.CCA_REMOTE_BROWSER_TAB));
5564
}
5665
if (tabName === TabNames.CCA_LOCAL_BROWSER_TAB && fileUploaded) {
5766
dispatch(setTabName(TabNames.CCA_TABLE_INGESTION));
@@ -62,7 +71,15 @@ export const useCCAWizardFooter = () => {
6271
if (tabName === TabNames.CCA_FINISH_MODEL) {
6372
finishModel();
6473
}
65-
}, [dispatch, uploadSelection, fileUploaded, setTabName, tabName, dataLocation]);
74+
}, [
75+
dispatch,
76+
uploadSelection,
77+
handleAuthentication,
78+
fileUploaded,
79+
setTabName,
80+
tabName,
81+
dataLocation,
82+
]);
6683

6784
/**
6885
* handle back operation
@@ -233,7 +250,6 @@ export const useHandleLocalFileSubmit = (): [
233250
] => {
234251
const mid = useAppSelector(selectMid);
235252
const pid = useAppSelector(selectPid);
236-
const dispatch = useAppDispatch();
237253
const fileUploadSuccess = useFileUploadSuccess();
238254
const [progress, setProgress] = React.useState<number>(0);
239255
const [progressStatus, setProgressStatus] = React.useState("");
@@ -372,6 +388,50 @@ export const useFinishModel = () => {
372388
}, [mid, name, description, marking, server_root]);
373389
};
374390

391+
export const useHandleAuthentication = () => {
392+
const authInfo = useAppSelector(selectAuthInfo);
393+
const dispatch = useAppDispatch();
394+
return React.useCallback(async () => {
395+
// this.setState({ loadingData: true });
396+
// this.props.callBack(this.state.sessionExists, true);
397+
console.log(authInfo);
398+
if (!authInfo.password) {
399+
alert(`password is empty`);
400+
return;
401+
}
402+
client
403+
.post_remotes_fetch({
404+
parameters: {
405+
hostname: authInfo.hostname,
406+
username: authInfo.username,
407+
password: atob(authInfo.password),
408+
},
409+
})
410+
.then(async () => {
411+
return await client.get_remotes_fetch(authInfo.hostname).then((json: any) => {
412+
if (json.status === false) {
413+
alert(`connection could not be established`);
414+
} else {
415+
console.log("dispatching", { ...authInfo, sessionExists: true })
416+
dispatch(setAuthInfo({ ...authInfo, sessionExists: true }));
417+
}
418+
});
419+
})
420+
.catch((errorResponse: any) => {
421+
if (errorResponse.status == 403) {
422+
alert(`${errorResponse.statusText} \n\n-${REMOTE_AUTH_LABELS.authErrorForbiddenDescription}
423+
\n-${REMOTE_AUTH_LABELS.authErrorForbiddenNote}`);
424+
} else if (errorResponse.status == 401) {
425+
alert(
426+
`${errorResponse.statusText} \n\n-${REMOTE_AUTH_LABELS.authErrorUnauthorizedDescription}`,
427+
);
428+
} else {
429+
alert(`${errorResponse.statusText}`);
430+
}
431+
});
432+
}, [authInfo]);
433+
};
434+
375435
/**
376436
* Hook for dealing with submission to the server of the inputs, outputs, and scale inputs to the server.
377437
* @returns a function for updating inputs and outputs

web-server/plugins/slycat-cca/js/components/wizard-store/reducers/cCAWizardSlice.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ import { RootState } from "../store";
66

77
export enum TabNames {
88
CCA_DATA_WIZARD_SELECTION_TAB = "CCADataWizardSelectionTab",
9-
CCA_LOCAL_BROWSER_TAB = "CCSLocalBrowserTab",
10-
CCA_REMOTE_BROWSER_TAB = "CCSRemoteBrowserTab",
9+
CCA_LOCAL_BROWSER_TAB = "CCALocalBrowserTab",
10+
CCA_AUTHENTICATION_TAB= "CCAAuthenticationTab",
11+
CCA_REMOTE_BROWSER_TAB = "CCARemoteBrowserTab",
1112
CCA_TABLE_INGESTION = "CCATableIngestion",
1213
CCA_FINISH_MODEL = "CCAFinishModel",
1314
}
1415
export enum dataLocationType {
1516
LOCAL = "local",
1617
REMOTE = "remote",
1718
}
19+
export interface AuthenticationInformation {
20+
username: string | undefined;
21+
password: string | undefined;
22+
hostname: string | undefined;
23+
sessionExists: boolean;
24+
}
1825
export interface Attribute {
1926
index: number;
2027
"Axis Type": string;
@@ -38,6 +45,7 @@ export interface CCAWizardState {
3845
marking: string | undefined;
3946
description: string | undefined;
4047
name: string | undefined;
48+
authInfo: AuthenticationInformation;
4149
}
4250
const initialState: CCAWizardState = {
4351
tab: TabNames.CCA_DATA_WIZARD_SELECTION_TAB,
@@ -50,6 +58,12 @@ const initialState: CCAWizardState = {
5058
marking: undefined,
5159
description: undefined,
5260
name: undefined,
61+
authInfo: {
62+
username: undefined,
63+
password: undefined,
64+
hostname: undefined,
65+
sessionExists: false,
66+
},
5367
};
5468
export const cCAWizardSlice = createSlice({
5569
name: "cCAWizard",
@@ -85,6 +99,10 @@ export const cCAWizardSlice = createSlice({
8599
setName: (state, action: PayloadAction<string>) => {
86100
state.name = action.payload;
87101
},
102+
setAuthInfo: (state, action: PayloadAction<AuthenticationInformation>) => {
103+
console.log(action.payload);
104+
state.authInfo = action.payload;
105+
},
88106
resetCCAWizard: () => initialState,
89107
},
90108
});
@@ -102,6 +120,7 @@ export const {
102120
setMarking,
103121
setDescription,
104122
setName,
123+
setAuthInfo
105124
} = cCAWizardSlice.actions;
106125
// Other code such as selectors can use the imported `RootState` type
107126
export const selectTab = (state: RootState) => state.cCAWizard.tab;
@@ -114,5 +133,6 @@ export const selectScaleInputs = (state: RootState) => state.cCAWizard.scaleInpu
114133
export const selectMarking = (state: RootState) => state.cCAWizard.marking;
115134
export const selectDescription = (state: RootState) => state.cCAWizard.marking;
116135
export const selectName = (state: RootState) => state.cCAWizard.marking;
136+
export const selectAuthInfo = (state: RootState) => state.cCAWizard.authInfo;
117137

118138
export default cCAWizardSlice.reducer;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Copyright (c) 2013, 2018 National Technology and Engineering Solutions of Sandia, LLC . Under the terms of Contract
2+
DE-NA0003525 with National Technology and Engineering Solutions of Sandia, LLC, the U.S. Government
3+
retains certain rights in this software. */
4+
import * as React from "react";
5+
import SlycatRemoteControls from "components/SlycatRemoteControls";
6+
import { useAppDispatch, useAppSelector } from "../wizard-store/hooks";
7+
import {
8+
AuthenticationInformation,
9+
selectAuthInfo,
10+
setAuthInfo,
11+
} from "../wizard-store/reducers/cCAWizardSlice";
12+
export const CCAAuthenticationTab = (props: { hidden?: boolean }) => {
13+
const { hidden = false } = props;
14+
const dispatch = useAppDispatch();
15+
const authInfo = useAppSelector(selectAuthInfo);
16+
const callBack = (
17+
hostname: string,
18+
username: string,
19+
password: string,
20+
session_exists: boolean,
21+
) => {
22+
const authInfo: AuthenticationInformation = {
23+
username,
24+
password: btoa(password),
25+
// decode with atob
26+
hostname,
27+
sessionExists: session_exists,
28+
};
29+
dispatch(setAuthInfo(authInfo));
30+
};
31+
return (
32+
<div hidden={hidden}>
33+
<SlycatRemoteControls
34+
sessionExists={authInfo.sessionExists}
35+
loadingData={false}
36+
callBack={callBack}
37+
showConnectButton={false}
38+
/>
39+
</div>
40+
);
41+
};

web-server/plugins/slycat-cca/js/components/wizard-tabs/CCARemoteBrowser.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33
retains certain rights in this software. */
44
import * as React from "react";
55
import { useSetUploadStatus } from "../CCAWizardUtils";
6-
6+
import RemoteFileBrowser from "components/RemoteFileBrowser";
7+
import { useAppDispatch } from "../wizard-store/hooks";
78
export const CCARemoteBrowserTab = (props: { hidden?: boolean }) => {
89
const { hidden = false } = props;
910
const setUploadStatus = useSetUploadStatus();
10-
return <div hidden={hidden}>REMOTE</div>;
11+
const dispatch = useAppDispatch();
12+
const onSelectTableFile = (newPath: any, type: any, file: any) => {
13+
console.log(newPath, type, file);
14+
};
15+
const onSelectParserCallBack = (parser: string) => {
16+
console.log('parser',parser);
17+
};
18+
const onReauth = () => {
19+
console.log("onReauth");
20+
};
21+
// TODO: add remote browser
22+
return (
23+
<div hidden={hidden}>
24+
<RemoteFileBrowser
25+
onSelectFileCallBack={onSelectTableFile}
26+
onSelectParserCallBack={onSelectParserCallBack}
27+
onReauthCallBack={onReauth}
28+
hostname={"hostname"}
29+
useSMB={false}
30+
showSelector={false}
31+
/>
32+
</div>
33+
);
1134
};

0 commit comments

Comments
 (0)