summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/middleware
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-03-12 18:00:21 +0100
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-03-12 18:01:06 +0100
commit2d4424c28ac35763ef44c42ae2f01664d42b268c (patch)
tree4e6ebdc2e57c1c8f2c91d3ec094b340c89dfe5c5 /sdnr/wt/odlux/framework/src/middleware
parentcaf781999351fc6a3e2acb5b2fe47fe04a291d2d (diff)
Security provider for UX-Client-Login
Use ODL provided oauth2/token for UX clients Change-Id: I9f9ae931fc5e74dc13076bd23551d163c0685606 Issue-ID: SDNC-648 Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/odlux/framework/src/middleware')
-rw-r--r--sdnr/wt/odlux/framework/src/middleware/navigation.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/sdnr/wt/odlux/framework/src/middleware/navigation.ts b/sdnr/wt/odlux/framework/src/middleware/navigation.ts
index 758b51845..8db01b18c 100644
--- a/sdnr/wt/odlux/framework/src/middleware/navigation.ts
+++ b/sdnr/wt/odlux/framework/src/middleware/navigation.ts
@@ -6,14 +6,14 @@ import { Dispatch } from '../flux/store';
import { LocationChanged, NavigateToApplication } from "../actions/navigationActions";
import { PushAction, ReplaceAction, GoAction, GoBackAction, GoForwardeAction } from '../actions/navigationActions';
-import applicationManager from "../services/applicationManager";
+import { applicationManager } from "../services/applicationManager";
const routerMiddlewareCreator = (history: History) => () => (next: Dispatch): Dispatch => (action) => {
-
+
if (action instanceof NavigateToApplication) {
const application = applicationManager.applications && applicationManager.applications[action.applicationName];
if (application) {
- const href = `/${ application.path || application.name }${ action.href ? '/' + action.href : '' }`.replace(/\/{2,}/i, '/');
+ const href = `/${application.path || application.name}${action.href ? '/' + action.href : ''}`.replace(/\/{2,}/i, '/');
if (action.replace) {
history.replace(href, action.state);
} else {
@@ -30,6 +30,13 @@ const routerMiddlewareCreator = (history: History) => () => (next: Dispatch): Di
history.goBack();
} else if (action instanceof GoForwardeAction) {
history.goForward();
+ } else if (action instanceof LocationChanged) {
+ // ensure user is logged in and token is valid
+ if (!action.pathname.startsWith("/login") && applicationStore && (!applicationStore.state.framework.authenticationState.user || !applicationStore.state.framework.authenticationState.user.isValid)) {
+ history.replace(`/login?returnTo=${action.pathname}`);
+ } else {
+ return next(action);
+ }
} else {
return next(action);
}
@@ -44,8 +51,10 @@ function startListener(history: History, store: ApplicationStore) {
}
const history = createHashHistory();
+let applicationStore: ApplicationStore | null = null;
export function startHistoryListener(store: ApplicationStore) {
+ applicationStore = store;
startListener(history, store);
}