Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
15ab288
add authentication layer
ChamseddineBhd Mar 25, 2020
2f89244
remove unused dependency
ChamseddineBhd Mar 25, 2020
ceaaeb7
cosmetic changes
ChamseddineBhd Mar 25, 2020
0bb964f
remove logs
ChamseddineBhd Mar 25, 2020
5fc16af
Merge branch 'master' into authetication
ChamseddineBhd Mar 25, 2020
804961f
delete callback html files, save user in store
ChamseddineBhd Mar 25, 2020
043463a
Merge branch 'authetication' of https://github.com/powsybl/powsybl-st…
ChamseddineBhd Mar 25, 2020
fdd9791
authentication not required in dev
ChamseddineBhd Mar 26, 2020
7f4ebf6
mock the user manager
ChamseddineBhd Mar 26, 2020
ad65768
resolve conflicts with master
ChamseddineBhd Mar 26, 2020
db6a32a
resolve conflicts with master
ChamseddineBhd Mar 26, 2020
c227a87
rename class, remove unused function
ChamseddineBhd Mar 27, 2020
bb04476
update AuthService
ChamseddineBhd Mar 27, 2020
6dbed48
update UserManagerMock
ChamseddineBhd Mar 30, 2020
7e34b39
add new login compnent
ChamseddineBhd Mar 30, 2020
30a3f77
remove unused dependency
ChamseddineBhd Mar 30, 2020
b7bcb02
resolve conflicts with master
ChamseddineBhd Mar 30, 2020
9e09994
move authentication folder
ChamseddineBhd Mar 30, 2020
f718cbf
update AuthService.js
ChamseddineBhd Mar 30, 2020
f589f73
secure paramater & studPane pages
ChamseddineBhd Mar 30, 2020
b2a328b
cosmetic changes
ChamseddineBhd Mar 30, 2020
abb8a38
cosmetic changes
ChamseddineBhd Mar 30, 2020
fe4d460
remove log message
ChamseddineBhd Mar 30, 2020
9a054b6
remove unused function call
ChamseddineBhd Mar 31, 2020
7218b1f
resolve conflict with master
ChamseddineBhd Mar 31, 2020
9e26374
remove debug idp values
ChamseddineBhd Mar 31, 2020
993589e
save previous route when logging in
ChamseddineBhd Mar 31, 2020
2e2952a
save previous query params
ChamseddineBhd Mar 31, 2020
ddf91cc
cosmetic changes
ChamseddineBhd Mar 31, 2020
c69c367
cosmetic changes
ChamseddineBhd Mar 31, 2020
1d78ce4
remove silent redirect param
ChamseddineBhd Mar 31, 2020
89714e7
add idp settings object
ChamseddineBhd Apr 1, 2020
ce45795
copyright
ChamseddineBhd Apr 1, 2020
d014058
Merge branch 'master' into authetication
ChamseddineBhd Apr 1, 2020
c6615bc
add scope from idp settings
ChamseddineBhd Apr 2, 2020
8aaf9ca
remove client secret param
ChamseddineBhd Apr 2, 2020
a05235c
update AuthService
ChamseddineBhd Apr 2, 2020
d89465f
add .env.development
ChamseddineBhd Apr 2, 2020
5232d3d
empty idpSettings
ChamseddineBhd Apr 2, 2020
b8d8b27
update SiginCallback
ChamseddineBhd Apr 2, 2020
bd16ecb
cosmetic changes
ChamseddineBhd Apr 3, 2020
b2d1a32
cosmetic changes
ChamseddineBhd Apr 3, 2020
2e37c8a
cosmetic changes
ChamseddineBhd Apr 3, 2020
0085f16
cosmetic changes
ChamseddineBhd Apr 3, 2020
f1ae026
cosmetic changes'
ChamseddineBhd Apr 3, 2020
7285161
close menu after click
ChamseddineBhd Apr 3, 2020
a5f8473
change show parameters behaviour
ChamseddineBhd Apr 3, 2020
23fa250
move authentication functions to AuthService
ChamseddineBhd Apr 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
REACT_APP_API_STUDY_SERVER=api/study-server
REACT_APP_API_CASE_SERVER=api/case-server

REACT_APP_USE_AUTHENTICATION=true
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_USE_AUTHENTICATION=false
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-window": "^1.8.5",
"redux": "^4.0.5",
"typeface-roboto": "0.0.75",
"oidc-client": "^1.10.1",
"react-virtualized": "^9.21.2"
},
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions public/idpSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"authority" : "#",
"client_id" : "#",
"redirect_uri": "#",
"post_logout_redirect_uri" : "#",
"scope" : "#"
}
85 changes: 63 additions & 22 deletions src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React from 'react';
import React, {useEffect, useState} from 'react';

import {useSelector} from 'react-redux'
import {useDispatch, useSelector} from 'react-redux'

import {Route, Switch, useHistory, useLocation} from 'react-router-dom';

Expand All @@ -18,6 +18,8 @@ import StudyManager from './study-manager';
import TopBar from './top-bar';
import {LIGHT_THEME} from '../redux/actions'
import Parameters from "./parameters";
import {userManagerPromise, login, logout, handleSigninCallback} from '../utils/authentication/AuthService';
import Authentication from "./authentication";

const lightTheme = createMuiTheme({
palette: {
Expand All @@ -41,23 +43,50 @@ const getMuiTheme = (theme) => {
}
};

const App = () => {
const SignInCallback = (props) => {
useEffect(() => {
if (props.userManager.instance !== null) {
props.handleSigninCallback();
}
}, [props.userManager]);

return (
<h1> </h1>
)
};

const noUserManager = {instance: null, error: null};

const App = () => {
const theme = useSelector(state => state.theme);

const user = useSelector(state => state.user);

const [userManager, setUserManager] = useState(noUserManager);

const history = useHistory();

const dispatch = useDispatch();

const location = useLocation();

useEffect(() => {
userManagerPromise
.then(userManager => {
setUserManager({instance : userManager, error : null });
})
.catch(function(error) {
setUserManager({instance : null, error : error.message});
console.debug("error when importing the idp settings")
});
}, []);

function studyClickHandler(studyName) {
history.push("/studies/" + studyName);
}

function showParameters() {
if (location.pathname === "/parameters") {
// if already at parameters go back to study
history.goBack();
} else {
if (location.pathname !== "/parameters") {
history.push("/parameters");
}
}
Expand All @@ -66,21 +95,33 @@ const App = () => {
<ThemeProvider theme={getMuiTheme(theme)}>
<React.Fragment>
<CssBaseline />
<TopBar onParametersClick={ () => showParameters() }/>
<Switch>
<Route exact path="/">
<StudyManager onStudyClick={ name => studyClickHandler(name) }/>
</Route>
<Route exact path="/studies/:studyName">
<StudyPane/>
</Route>
<Route exact path="/parameters">
<Parameters/>
</Route>
<Route>
<h1>Error: bad URL; No matched Route.</h1>
</Route>
</Switch>
<TopBar onParametersClick={() => showParameters()} onLogoutClick={() => logout(dispatch, userManager.instance)}/>
{ user !== null ? (
<Switch>
<Route exact path="/">
<StudyManager onStudyClick={name => studyClickHandler(name)}/>)
</Route>
<Route exact path="/studies/:studyName">
<StudyPane/>
</Route>
<Route exact path="/parameters">
<Parameters/>
</Route>
<Route>
<h1>Error: bad URL; No matched Route.</h1>
</Route>
</Switch>)
: (
<Switch>
<Route exact path="/sign-in-callback">
<SignInCallback userManager={userManager} handleSigninCallback={() => handleSigninCallback(dispatch, history, userManager.instance)}/>
</Route>
<Route>
{userManager.error !== null && (<h1>Error : Getting userManager; {userManager.error}</h1>)}
{userManager.error === null && (<Authentication disabled={userManager.instance === null} onLoginClick={() => login(location, userManager.instance)}/>)}
</Route>
</Switch>
)}
</React.Fragment>
</ThemeProvider>
)
Expand Down
87 changes: 87 additions & 0 deletions src/components/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, {useEffect} from 'react';
import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';
import CssBaseline from '@material-ui/core/CssBaseline';
import Link from '@material-ui/core/Link';
import Box from '@material-ui/core/Box';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import Container from '@material-ui/core/Container';
import {FormattedMessage} from "react-intl";

const useStyles = makeStyles((theme) => ({
paper: {
marginTop: theme.spacing(8),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
avatar: {
margin: theme.spacing(1),
backgroundColor: theme.palette.secondary.main,
},
submit: {
margin: theme.spacing(3, 0, 2),
borderRadius: '30px'
},
logo: {
width: 64,
height: 64,
},
}));


const Authentication = (props) => {
const classes = useStyles();

function Copyright() {
return (
<Typography variant="body2" color="textSecondary" align="center">
{'Copyright © '}
<Link color="inherit" href="#">
Grid Suite
</Link>{' '}
{new Date().getFullYear()}
{'.'}
</Typography>
);
}

return (
<Container component="main" maxWidth="xs">
<CssBaseline />
<div className={classes.paper}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
<FormattedMessage id="login"/> ?
</Typography>

<Button
disabled={props.disabled}
fullWidth
variant="contained"
color="primary"
className={classes.submit}
onClick={props.onLoginClick}
>
<FormattedMessage id="connection"/>
</Button>
</div>
<Box mt={2}>
<Copyright />
</Box>
</Container>
);
};

export default Authentication;
6 changes: 3 additions & 3 deletions src/components/study-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {ReactComponent as IeeeLogo} from '../images/ieee_logo.svg';
import {loadStudiesSuccess} from '../redux/actions';
import {fetchStudies, deleteStudy} from '../utils/rest-api';
import CreateStudyForm from "./create-study-form";

import {CardHeader} from "@material-ui/core";
import IconButton from "@material-ui/core/IconButton";
import MoreVertIcon from '@material-ui/icons/MoreVert';
Expand Down Expand Up @@ -248,7 +249,6 @@ const StudyCard = ({study, onClick}) => {
};

const StudyManager = ({onStudyClick}) => {

const dispatch = useDispatch();

useEffect(() => {
Expand All @@ -265,12 +265,12 @@ const StudyManager = ({onStudyClick}) => {

return (
<Container maxWidth="lg">
<CreateStudyForm />
<CreateStudyForm/>
<Grid container spacing={2} className={classes.grid}>
{
studies.map(study =>
<Grid item xs={12} sm={6} md={3} key={study.studyName}>
<StudyCard study={study} onClick={() => onStudyClick(study.studyName)} />
<StudyCard study={study} onClick={() => onStudyClick(study.studyName)}/>
</Grid>
)
}
Expand Down
Loading