@beinformed/ui 1.20.2 → 1.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/esm/constants/Constants.js +0 -15
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +6 -0
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/hooks/useAuthentication.js +40 -5
  7. package/esm/hooks/useAuthentication.js.map +1 -1
  8. package/esm/models/application/ApplicationModel.js +6 -1
  9. package/esm/models/application/ApplicationModel.js.map +1 -1
  10. package/esm/redux/actions/Authorization.js +2 -1
  11. package/esm/redux/actions/Authorization.js.map +1 -1
  12. package/esm/redux/actions/Error.js +3 -1
  13. package/esm/redux/actions/Error.js.map +1 -1
  14. package/lib/constants/Constants.js +2 -20
  15. package/lib/constants/Constants.js.flow +0 -15
  16. package/lib/constants/Constants.js.map +1 -1
  17. package/lib/constants/Settings.js +6 -0
  18. package/lib/constants/Settings.js.flow +9 -0
  19. package/lib/constants/Settings.js.map +1 -1
  20. package/lib/hooks/useAuthentication.js +47 -5
  21. package/lib/hooks/useAuthentication.js.flow +40 -3
  22. package/lib/hooks/useAuthentication.js.map +1 -1
  23. package/lib/models/application/ApplicationModel.js +7 -1
  24. package/lib/models/application/ApplicationModel.js.flow +7 -1
  25. package/lib/models/application/ApplicationModel.js.map +1 -1
  26. package/lib/redux/actions/Authorization.js +3 -2
  27. package/lib/redux/actions/Authorization.js.flow +2 -1
  28. package/lib/redux/actions/Authorization.js.map +1 -1
  29. package/lib/redux/actions/Error.js +4 -1
  30. package/lib/redux/actions/Error.js.flow +3 -1
  31. package/lib/redux/actions/Error.js.map +1 -1
  32. package/package.json +5 -5
  33. package/src/constants/Constants.js +0 -15
  34. package/src/constants/Settings.js +9 -0
  35. package/src/hooks/useAuthentication.js +40 -3
  36. package/src/models/application/ApplicationModel.js +7 -1
  37. package/src/redux/actions/Authorization.js +2 -1
  38. package/src/redux/actions/Error.js +3 -1
@@ -1,34 +1,62 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.useLogout = exports.useLogin = void 0;
7
9
 
10
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
11
+
8
12
  var _reactRedux = require("react-redux");
9
13
 
10
14
  var _selectors = require("../redux/_modularui/selectors");
11
15
 
12
16
  var _actions = require("../redux/actions");
13
17
 
18
+ var _Cache = _interopRequireDefault(require("../utils/browser/Cache"));
19
+
20
+ var _constants = require("../constants");
21
+
22
+ var _exceptions = require("../exceptions");
23
+
14
24
  /**
15
25
  */
16
26
  var useLogin = function useLogin() {
17
- var _application$isLogged;
27
+ var _application$isLogged, _application$authenti;
18
28
 
19
29
  var dispatch = (0, _reactRedux.useDispatch)();
20
30
  var application = (0, _reactRedux.useSelector)(_selectors.getApplication);
21
31
  var auth = (0, _reactRedux.useSelector)(function (state) {
22
32
  return state.auth;
23
33
  });
34
+ var isAuthenticated = (_application$isLogged = application === null || application === void 0 ? void 0 : application.isLoggedIn) !== null && _application$isLogged !== void 0 ? _application$isLogged : false;
24
35
  return {
25
- isAuthenticated: (_application$isLogged = application === null || application === void 0 ? void 0 : application.isLoggedIn) !== null && _application$isLogged !== void 0 ? _application$isLogged : false,
36
+ isAuthenticated: isAuthenticated,
37
+ authenticationTypes: (_application$authenti = application === null || application === void 0 ? void 0 : application.authenticationTypes) !== null && _application$authenti !== void 0 ? _application$authenti : [],
26
38
  errorMessage: auth.error,
27
39
  resetErrors: function resetErrors() {
28
40
  return dispatch((0, _actions.resetAuthErrors)());
29
41
  },
30
42
  login: function login(username, password) {
31
43
  return dispatch((0, _actions.login)(username, password));
44
+ },
45
+ redirectLogin: function redirectLogin(authenticationType) {
46
+ if (_Cache.default.getItem("isRedirectLogin")) {
47
+ var _context;
48
+
49
+ // prevent endless loop in redirects when authentication type can't be redirected
50
+ throw new _exceptions.IllegalStateException((0, _concat.default)(_context = "Could not redirect to '".concat(authenticationType.authentication, "' using url: '")).call(_context, authenticationType.redirectUri, "'"));
51
+ }
52
+
53
+ if (!isAuthenticated) {
54
+ var _context2;
55
+
56
+ _Cache.default.setItem("isRedirectLogin", true);
57
+
58
+ window.location.assign((0, _concat.default)(_context2 = "".concat(_constants.BASE)).call(_context2, authenticationType.redirectUri));
59
+ }
32
60
  }
33
61
  };
34
62
  };
@@ -39,14 +67,28 @@ var useLogin = function useLogin() {
39
67
  exports.useLogin = useLogin;
40
68
 
41
69
  var useLogout = function useLogout() {
42
- var _application$isLogged2;
70
+ var _application$isLogged2, _application$authenti2;
43
71
 
44
72
  var dispatch = (0, _reactRedux.useDispatch)();
45
73
  var application = (0, _reactRedux.useSelector)(_selectors.getApplication);
74
+ var LOGOUT_PATH = (0, _constants.getSetting)("LOGOUT_PATH", "/signout");
75
+ var isAuthenticated = (_application$isLogged2 = application === null || application === void 0 ? void 0 : application.isLoggedIn) !== null && _application$isLogged2 !== void 0 ? _application$isLogged2 : false;
46
76
  return {
47
- isAuthenticated: (_application$isLogged2 = application === null || application === void 0 ? void 0 : application.isLoggedIn) !== null && _application$isLogged2 !== void 0 ? _application$isLogged2 : false,
77
+ isAuthenticated: isAuthenticated,
78
+ authenticationTypes: (_application$authenti2 = application === null || application === void 0 ? void 0 : application.authenticationTypes) !== null && _application$authenti2 !== void 0 ? _application$authenti2 : [],
48
79
  logout: function logout() {
49
- return dispatch((0, _actions.logout)());
80
+ if (_Cache.default.getItem("isRedirectLogin")) {
81
+ var _context3, _context4, _context5, _context6;
82
+
83
+ var origin = window.location.origin;
84
+ var url = (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = (0, _concat.default)(_context5 = (0, _concat.default)(_context6 = "".concat(origin)).call(_context6, _constants.BASE, "/logout?url=")).call(_context5, origin)).call(_context4, _constants.BASE)).call(_context3, LOGOUT_PATH);
85
+
86
+ _Cache.default.setItem("isRedirectLogin", false);
87
+
88
+ window.location.assign(url);
89
+ } else {
90
+ return dispatch((0, _actions.logout)());
91
+ }
50
92
  }
51
93
  };
52
94
  };
@@ -4,15 +4,23 @@ import { useSelector, useDispatch } from "react-redux";
4
4
  import { getApplication } from "../redux/_modularui/selectors";
5
5
  import { login, logout, resetAuthErrors } from "../redux/actions";
6
6
 
7
+ import Cache from "../utils/browser/Cache";
8
+ import { BASE, getSetting } from "../constants";
9
+
7
10
  import type { ResetAuthErrorsAction } from "../redux/types";
11
+ import type { AuthenticationType } from "../models/types";
12
+ import { IllegalStateException } from "../exceptions";
8
13
  type LoginHook = {
9
14
  isAuthenticated: boolean,
15
+ authenticationTypes: Array<AuthenticationType>,
10
16
  errorMessage: ?string,
11
17
  resetErrors: () => ResetAuthErrorsAction,
12
18
  login: (username: string, password: string) => void,
19
+ redirectLogin: (authenticationType: AuthenticationType) => void,
13
20
  };
14
21
  type LogoutHook = {
15
22
  isAuthenticated: boolean,
23
+ authenticationTypes: Array<AuthenticationType>,
16
24
  logout: () => void,
17
25
  };
18
26
 
@@ -24,12 +32,28 @@ export const useLogin = (): LoginHook => {
24
32
  const application = useSelector(getApplication);
25
33
  const auth = useSelector((state) => state.auth);
26
34
 
35
+ const isAuthenticated = application?.isLoggedIn ?? false;
36
+
27
37
  return {
28
- isAuthenticated: application?.isLoggedIn ?? false,
38
+ isAuthenticated,
39
+ authenticationTypes: application?.authenticationTypes ?? [],
29
40
  errorMessage: auth.error,
30
41
  resetErrors: () => dispatch(resetAuthErrors()),
31
42
  login: (username: string, password: string) =>
32
43
  dispatch(login(username, password)),
44
+ redirectLogin: (authenticationType: AuthenticationType) => {
45
+ if (Cache.getItem("isRedirectLogin")) {
46
+ // prevent endless loop in redirects when authentication type can't be redirected
47
+ throw new IllegalStateException(
48
+ `Could not redirect to '${authenticationType.authentication}' using url: '${authenticationType.redirectUri}'`
49
+ );
50
+ }
51
+
52
+ if (!isAuthenticated) {
53
+ Cache.setItem("isRedirectLogin", true);
54
+ window.location.assign(`${BASE}${authenticationType.redirectUri}`);
55
+ }
56
+ },
33
57
  };
34
58
  };
35
59
 
@@ -39,8 +63,21 @@ export const useLogout = (): LogoutHook => {
39
63
  const dispatch = useDispatch();
40
64
  const application = useSelector(getApplication);
41
65
 
66
+ const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
67
+
68
+ const isAuthenticated = application?.isLoggedIn ?? false;
42
69
  return {
43
- isAuthenticated: application?.isLoggedIn ?? false,
44
- logout: () => dispatch(logout()),
70
+ isAuthenticated,
71
+ authenticationTypes: application?.authenticationTypes ?? [],
72
+ logout: () => {
73
+ if (Cache.getItem("isRedirectLogin")) {
74
+ const origin = window.location.origin;
75
+ const url = `${origin}${BASE}/logout?url=${origin}${BASE}${LOGOUT_PATH}`;
76
+ Cache.setItem("isRedirectLogin", false);
77
+ window.location.assign(url);
78
+ } else {
79
+ return dispatch(logout());
80
+ }
81
+ },
45
82
  };
46
83
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthentication.js","names":["useLogin","dispatch","useDispatch","application","useSelector","getApplication","auth","state","isAuthenticated","isLoggedIn","errorMessage","error","resetErrors","resetAuthErrors","login","username","password","useLogout","logout"],"sources":["../../src/hooks/useAuthentication.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { getApplication } from \"../redux/_modularui/selectors\";\nimport { login, logout, resetAuthErrors } from \"../redux/actions\";\n\nimport type { ResetAuthErrorsAction } from \"../redux/types\";\ntype LoginHook = {\n isAuthenticated: boolean,\n errorMessage: ?string,\n resetErrors: () => ResetAuthErrorsAction,\n login: (username: string, password: string) => void,\n};\ntype LogoutHook = {\n isAuthenticated: boolean,\n logout: () => void,\n};\n\n/**\n */\nexport const useLogin = (): LoginHook => {\n const dispatch = useDispatch();\n\n const application = useSelector(getApplication);\n const auth = useSelector((state) => state.auth);\n\n return {\n isAuthenticated: application?.isLoggedIn ?? false,\n errorMessage: auth.error,\n resetErrors: () => dispatch(resetAuthErrors()),\n login: (username: string, password: string) =>\n dispatch(login(username, password)),\n };\n};\n\n/**\n */\nexport const useLogout = (): LogoutHook => {\n const dispatch = useDispatch();\n const application = useSelector(getApplication);\n\n return {\n isAuthenticated: application?.isLoggedIn ?? false,\n logout: () => dispatch(logout()),\n };\n};\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AAcA;AACA;AACO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,GAAiB;EAAA;;EACvC,IAAMC,QAAQ,GAAG,IAAAC,uBAAA,GAAjB;EAEA,IAAMC,WAAW,GAAG,IAAAC,uBAAA,EAAYC,yBAAZ,CAApB;EACA,IAAMC,IAAI,GAAG,IAAAF,uBAAA,EAAY,UAACG,KAAD;IAAA,OAAWA,KAAK,CAACD,IAAjB;EAAA,CAAZ,CAAb;EAEA,OAAO;IACLE,eAAe,2BAAEL,WAAF,aAAEA,WAAF,uBAAEA,WAAW,CAAEM,UAAf,yEAA6B,KADvC;IAELC,YAAY,EAAEJ,IAAI,CAACK,KAFd;IAGLC,WAAW,EAAE;MAAA,OAAMX,QAAQ,CAAC,IAAAY,wBAAA,GAAD,CAAd;IAAA,CAHR;IAILC,KAAK,EAAE,eAACC,QAAD,EAAmBC,QAAnB;MAAA,OACLf,QAAQ,CAAC,IAAAa,cAAA,EAAMC,QAAN,EAAgBC,QAAhB,CAAD,CADH;IAAA;EAJF,CAAP;AAOD,CAbM;AAeP;AACA;;;;;AACO,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAkB;EAAA;;EACzC,IAAMhB,QAAQ,GAAG,IAAAC,uBAAA,GAAjB;EACA,IAAMC,WAAW,GAAG,IAAAC,uBAAA,EAAYC,yBAAZ,CAApB;EAEA,OAAO;IACLG,eAAe,4BAAEL,WAAF,aAAEA,WAAF,uBAAEA,WAAW,CAAEM,UAAf,2EAA6B,KADvC;IAELS,MAAM,EAAE;MAAA,OAAMjB,QAAQ,CAAC,IAAAiB,eAAA,GAAD,CAAd;IAAA;EAFH,CAAP;AAID,CARM"}
1
+ {"version":3,"file":"useAuthentication.js","names":["useLogin","dispatch","useDispatch","application","useSelector","getApplication","auth","state","isAuthenticated","isLoggedIn","authenticationTypes","errorMessage","error","resetErrors","resetAuthErrors","login","username","password","redirectLogin","authenticationType","Cache","getItem","IllegalStateException","authentication","redirectUri","setItem","window","location","assign","BASE","useLogout","LOGOUT_PATH","getSetting","logout","origin","url"],"sources":["../../src/hooks/useAuthentication.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { getApplication } from \"../redux/_modularui/selectors\";\nimport { login, logout, resetAuthErrors } from \"../redux/actions\";\n\nimport Cache from \"../utils/browser/Cache\";\nimport { BASE, getSetting } from \"../constants\";\n\nimport type { ResetAuthErrorsAction } from \"../redux/types\";\nimport type { AuthenticationType } from \"../models/types\";\nimport { IllegalStateException } from \"../exceptions\";\ntype LoginHook = {\n isAuthenticated: boolean,\n authenticationTypes: Array<AuthenticationType>,\n errorMessage: ?string,\n resetErrors: () => ResetAuthErrorsAction,\n login: (username: string, password: string) => void,\n redirectLogin: (authenticationType: AuthenticationType) => void,\n};\ntype LogoutHook = {\n isAuthenticated: boolean,\n authenticationTypes: Array<AuthenticationType>,\n logout: () => void,\n};\n\n/**\n */\nexport const useLogin = (): LoginHook => {\n const dispatch = useDispatch();\n\n const application = useSelector(getApplication);\n const auth = useSelector((state) => state.auth);\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n\n return {\n isAuthenticated,\n authenticationTypes: application?.authenticationTypes ?? [],\n errorMessage: auth.error,\n resetErrors: () => dispatch(resetAuthErrors()),\n login: (username: string, password: string) =>\n dispatch(login(username, password)),\n redirectLogin: (authenticationType: AuthenticationType) => {\n if (Cache.getItem(\"isRedirectLogin\")) {\n // prevent endless loop in redirects when authentication type can't be redirected\n throw new IllegalStateException(\n `Could not redirect to '${authenticationType.authentication}' using url: '${authenticationType.redirectUri}'`\n );\n }\n\n if (!isAuthenticated) {\n Cache.setItem(\"isRedirectLogin\", true);\n window.location.assign(`${BASE}${authenticationType.redirectUri}`);\n }\n },\n };\n};\n\n/**\n */\nexport const useLogout = (): LogoutHook => {\n const dispatch = useDispatch();\n const application = useSelector(getApplication);\n\n const LOGOUT_PATH = getSetting(\"LOGOUT_PATH\", \"/signout\");\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n return {\n isAuthenticated,\n authenticationTypes: application?.authenticationTypes ?? [],\n logout: () => {\n if (Cache.getItem(\"isRedirectLogin\")) {\n const origin = window.location.origin;\n const url = `${origin}${BASE}/logout?url=${origin}${BASE}${LOGOUT_PATH}`;\n Cache.setItem(\"isRedirectLogin\", false);\n window.location.assign(url);\n } else {\n return dispatch(logout());\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AAIA;;AAeA;AACA;AACO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,GAAiB;EAAA;;EACvC,IAAMC,QAAQ,GAAG,IAAAC,uBAAA,GAAjB;EAEA,IAAMC,WAAW,GAAG,IAAAC,uBAAA,EAAYC,yBAAZ,CAApB;EACA,IAAMC,IAAI,GAAG,IAAAF,uBAAA,EAAY,UAACG,KAAD;IAAA,OAAWA,KAAK,CAACD,IAAjB;EAAA,CAAZ,CAAb;EAEA,IAAME,eAAe,4BAAGL,WAAH,aAAGA,WAAH,uBAAGA,WAAW,CAAEM,UAAhB,yEAA8B,KAAnD;EAEA,OAAO;IACLD,eAAe,EAAfA,eADK;IAELE,mBAAmB,2BAAEP,WAAF,aAAEA,WAAF,uBAAEA,WAAW,CAAEO,mBAAf,yEAAsC,EAFpD;IAGLC,YAAY,EAAEL,IAAI,CAACM,KAHd;IAILC,WAAW,EAAE;MAAA,OAAMZ,QAAQ,CAAC,IAAAa,wBAAA,GAAD,CAAd;IAAA,CAJR;IAKLC,KAAK,EAAE,eAACC,QAAD,EAAmBC,QAAnB;MAAA,OAC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CAAT;;QACAX,cAAA,CAAMK,OAAN,CAAc,iBAAd,EAAiC,KAAjC;;QACAC,MAAM,CAACC,QAAP,CAAgBC,MAAhB,CAAuBO,GAAvB;MACD,CALD,MAKO;QACL,OAAOlC,QAAQ,CAAC,IAAAgC,eAAA,GAAD,CAAf;MACD;IACF;EAZI,CAAP;AAcD,CArBM"}
@@ -13,6 +13,8 @@ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
13
13
 
14
14
  var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
15
15
 
16
+ var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
17
+
16
18
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
17
19
 
18
20
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
@@ -119,7 +121,11 @@ var ApplicationModel = /*#__PURE__*/function (_ResourceModel) {
119
121
  }, {
120
122
  key: "authenticationTypes",
121
123
  get: function get() {
122
- return this.getContribution("security", []);
124
+ var authenticationTypes = this.getContribution("security", []); //put primary first
125
+
126
+ return authenticationTypes === null || authenticationTypes === void 0 ? void 0 : (0, _sort.default)(authenticationTypes).call(authenticationTypes, function (a, b) {
127
+ return a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1;
128
+ });
123
129
  }
124
130
  /**
125
131
  * Getting the tab links
@@ -68,7 +68,13 @@ export default class ApplicationModel extends ResourceModel {
68
68
  * Getting the authentication types of the application
69
69
  */
70
70
  get authenticationTypes(): Array<AuthenticationType> {
71
- return this.getContribution("security", []);
71
+ const authenticationTypes = this.getContribution("security", []);
72
+
73
+ //put primary first
74
+ return authenticationTypes?.sort(
75
+ (a: AuthenticationType, b: AuthenticationType) =>
76
+ a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1
77
+ );
72
78
  }
73
79
  /**
74
80
  * Getting the tab links
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationModel.js","names":["ApplicationModel","userService","links","getLinkByKey","href","path","NotAllowedUriException","models","userServiceModel","model","type","userServices","getContribution","getLinksByGroup","LinkModel","create","_userServices","UserServicesModel","isLoggedIn","userLink","data","contributions","resourcetype","ResourceModel"],"sources":["../../../src/models/application/ApplicationModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport UserServicesModel from \"../user/UserServicesModel\";\n\nimport { NotAllowedUriException } from \"../../exceptions\";\n\nimport type { ModularUIModel, AuthenticationType } from \"../types\";\nimport type { ModularUIResponse } from \"../../modularui\";\nimport type LinkCollection from \"../links/LinkCollection\";\nimport type Href from \"../href/Href\";\n\n/**\n * The Application model\n */\nexport default class ApplicationModel extends ResourceModel {\n _userServices: ?UserServicesModel;\n\n /**\n * Retrieve type of model\n */\n get type(): string {\n return \"Application\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"Application\"\n );\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const userService = this.links.getLinkByKey(\"UserServices\");\n if (userService && userService.href.path === \"/login\") {\n throw new NotAllowedUriException(\n \"The user service (Login panel) should not have the uri '/login', use a different URI because this uri matches the login service.\"\n );\n }\n\n return userService ? [userService] : [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const userServiceModel = models.find(\n (model) => model.type === \"UserServices\"\n );\n\n if (userServiceModel) {\n this.userServices = userServiceModel;\n }\n }\n\n /**\n * Getting the label of the application\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the authentication types of the application\n */\n get authenticationTypes(): Array<AuthenticationType> {\n return this.getContribution(\"security\", []);\n }\n /**\n * Getting the tab links\n */\n get tabs(): LinkCollection {\n return this.links.getLinksByGroup(\"tab\");\n }\n\n /**\n * Get modelcatalog link\n */\n get modelcatalog(): LinkModel {\n return LinkModel.create(\"modelcatalog\", \"/modelcatalog\", \"Model catalog\");\n }\n\n /**\n * Set the userservices for this application\n */\n set userServices(model: ?ModularUIModel) {\n this._userServices = model instanceof UserServicesModel ? model : null;\n }\n\n /**\n * returns the userservices configured for this application\n */\n get userServices(): ?UserServicesModel {\n return this._userServices ? this._userServices : null;\n }\n\n /**\n * Indicates if the user is logged in\n */\n get isLoggedIn(): boolean {\n return this.userServices?.isLoggedIn ?? false;\n }\n\n /**\n * Retrieve link to the user information,\n * only available when the user services are available\n */\n get userHref(): Href | null {\n if (this.userServices != null && this.userServices.userLink != null) {\n return this.userServices.userLink.href;\n }\n\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AAEA;;;;;;AAOA;AACA;AACA;IACqBA,gB;;;;;;;;;;;;;;;;;;;;;;;;IAGnB;AACF;AACA;IACE,eAAmB;MACjB,OAAO,aAAP;IACD;IAED;AACF;;;;;IAQE;AACF;IACE,qCAA8C;MAC5C,IAAMC,WAAW,GAAG,KAAKC,KAAL,CAAWC,YAAX,CAAwB,cAAxB,CAApB;;MACA,IAAIF,WAAW,IAAIA,WAAW,CAACG,IAAZ,CAAiBC,IAAjB,KAA0B,QAA7C,EAAuD;QACrD,MAAM,IAAIC,kCAAJ,CACJ,kIADI,CAAN;MAGD;;MAED,OAAOL,WAAW,GAAG,CAACA,WAAD,CAAH,GAAmB,EAArC;IACD;IAED;AACF;;;;WACE,wBAAeM,MAAf,EAA8C;MAC5C,IAAMC,gBAAgB,GAAG,mBAAAD,MAAM,MAAN,CAAAA,MAAM,EAC7B,UAACE,KAAD;QAAA,OAAWA,KAAK,CAACC,IAAN,KAAe,cAA1B;MAAA,CAD6B,CAA/B;;MAIA,IAAIF,gBAAJ,EAAsB;QACpB,KAAKG,YAAL,GAAoBH,gBAApB;MACD;IACF;IAED;AACF;AACA;;;;SACE,eAAoB;MAClB,OAAO,KAAKI,eAAL,CAAqB,OAArB,EAA8B,EAA9B,CAAP;IACD;IAED;AACF;AACA;;;;SACE,eAAqD;MACnD,OAAO,KAAKA,eAAL,CAAqB,UAArB,EAAiC,EAAjC,CAAP;IACD;IACD;AACF;AACA;;;;SACE,eAA2B;MACzB,OAAO,KAAKV,KAAL,CAAWW,eAAX,CAA2B,KAA3B,CAAP;IACD;IAED;AACF;AACA;;;;SACE,eAA8B;MAC5B,OAAOC,kBAAA,CAAUC,MAAV,CAAiB,cAAjB,EAAiC,eAAjC,EAAkD,eAAlD,CAAP;IACD;IAED;AACF;AACA;;;;;IAKE;AACF;AACA;IACE,eAAuC;MACrC,OAAO,KAAKC,aAAL,GAAqB,KAAKA,aAA1B,GAA0C,IAAjD;IACD;IAED;AACF;AACA;;SAbE,aAAiBP,KAAjB,EAAyC;MACvC,KAAKO,aAAL,GAAqBP,KAAK,YAAYQ,0BAAjB,GAAqCR,KAArC,GAA6C,IAAlE;IACD;;;SAYD,eAA0B;MAAA;;MACxB,sDAAO,KAAKE,YAAZ,uDAAO,mBAAmBO,UAA1B,yEAAwC,KAAxC;IACD;IAED;AACF;AACA;AACA;;;;SACE,eAA4B;MAC1B,IAAI,KAAKP,YAAL,IAAqB,IAArB,IAA6B,KAAKA,YAAL,CAAkBQ,QAAlB,IAA8B,IAA/D,EAAqE;QACnE,OAAO,KAAKR,YAAL,CAAkBQ,QAAlB,CAA2Bf,IAAlC;MACD;;MAED,OAAO,IAAP;IACD;;;WA1FD,2BAAyBgB,IAAzB,EAA2D;MACzD,OACEA,IAAI,CAACC,aAAL,CAAmBC,YAAnB,IACAF,IAAI,CAACC,aAAL,CAAmBC,YAAnB,KAAoC,aAFtC;IAID;;;EAjB2CC,uB"}
1
+ {"version":3,"file":"ApplicationModel.js","names":["ApplicationModel","userService","links","getLinkByKey","href","path","NotAllowedUriException","models","userServiceModel","model","type","userServices","getContribution","authenticationTypes","a","b","isPrimary","getLinksByGroup","LinkModel","create","_userServices","UserServicesModel","isLoggedIn","userLink","data","contributions","resourcetype","ResourceModel"],"sources":["../../../src/models/application/ApplicationModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport UserServicesModel from \"../user/UserServicesModel\";\n\nimport { NotAllowedUriException } from \"../../exceptions\";\n\nimport type { ModularUIModel, AuthenticationType } from \"../types\";\nimport type { ModularUIResponse } from \"../../modularui\";\nimport type LinkCollection from \"../links/LinkCollection\";\nimport type Href from \"../href/Href\";\n\n/**\n * The Application model\n */\nexport default class ApplicationModel extends ResourceModel {\n _userServices: ?UserServicesModel;\n\n /**\n * Retrieve type of model\n */\n get type(): string {\n return \"Application\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"Application\"\n );\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const userService = this.links.getLinkByKey(\"UserServices\");\n if (userService && userService.href.path === \"/login\") {\n throw new NotAllowedUriException(\n \"The user service (Login panel) should not have the uri '/login', use a different URI because this uri matches the login service.\"\n );\n }\n\n return userService ? [userService] : [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const userServiceModel = models.find(\n (model) => model.type === \"UserServices\"\n );\n\n if (userServiceModel) {\n this.userServices = userServiceModel;\n }\n }\n\n /**\n * Getting the label of the application\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the authentication types of the application\n */\n get authenticationTypes(): Array<AuthenticationType> {\n const authenticationTypes = this.getContribution(\"security\", []);\n\n //put primary first\n return authenticationTypes?.sort(\n (a: AuthenticationType, b: AuthenticationType) =>\n a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1\n );\n }\n /**\n * Getting the tab links\n */\n get tabs(): LinkCollection {\n return this.links.getLinksByGroup(\"tab\");\n }\n\n /**\n * Get modelcatalog link\n */\n get modelcatalog(): LinkModel {\n return LinkModel.create(\"modelcatalog\", \"/modelcatalog\", \"Model catalog\");\n }\n\n /**\n * Set the userservices for this application\n */\n set userServices(model: ?ModularUIModel) {\n this._userServices = model instanceof UserServicesModel ? model : null;\n }\n\n /**\n * returns the userservices configured for this application\n */\n get userServices(): ?UserServicesModel {\n return this._userServices ? this._userServices : null;\n }\n\n /**\n * Indicates if the user is logged in\n */\n get isLoggedIn(): boolean {\n return this.userServices?.isLoggedIn ?? false;\n }\n\n /**\n * Retrieve link to the user information,\n * only available when the user services are available\n */\n get userHref(): Href | null {\n if (this.userServices != null && this.userServices.userLink != null) {\n return this.userServices.userLink.href;\n }\n\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AAEA;;;;;;AAOA;AACA;AACA;IACqBA,gB;;;;;;;;;;;;;;;;;;;;;;;;IAGnB;AACF;AACA;IACE,eAAmB;MACjB,OAAO,aAAP;IACD;IAED;AACF;;;;;IAQE;AACF;IACE,qCAA8C;MAC5C,IAAMC,WAAW,GAAG,KAAKC,KAAL,CAAWC,YAAX,CAAwB,cAAxB,CAApB;;MACA,IAAIF,WAAW,IAAIA,WAAW,CAACG,IAAZ,CAAiBC,IAAjB,KAA0B,QAA7C,EAAuD;QACrD,MAAM,IAAIC,kCAAJ,CACJ,kIADI,CAAN;MAGD;;MAED,OAAOL,WAAW,GAAG,CAACA,WAAD,CAAH,GAAmB,EAArC;IACD;IAED;AACF;;;;WACE,wBAAeM,MAAf,EAA8C;MAC5C,IAAMC,gBAAgB,GAAG,mBAAAD,MAAM,MAAN,CAAAA,MAAM,EAC7B,UAACE,KAAD;QAAA,OAAWA,KAAK,CAACC,IAAN,KAAe,cAA1B;MAAA,CAD6B,CAA/B;;MAIA,IAAIF,gBAAJ,EAAsB;QACpB,KAAKG,YAAL,GAAoBH,gBAApB;MACD;IACF;IAED;AACF;AACA;;;;SACE,eAAoB;MAClB,OAAO,KAAKI,eAAL,CAAqB,OAArB,EAA8B,EAA9B,CAAP;IACD;IAED;A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ACAF,IAAI,CAACC,aAAL,CAAmBC,YAAnB,KAAoC,aAFtC;IAID;;;EAjB2CC,uB"}
@@ -64,12 +64,13 @@ var handleUnauthorized = function handleUnauthorized(errorResponse) {
64
64
 
65
65
 
66
66
  var location = getState().router.location;
67
+ var LOGIN_PATH = (0, _constants.getSetting)("LOGIN_PATH", "/signin");
67
68
 
68
- if ((location === null || location === void 0 ? void 0 : location.pathname) !== _Constants.LOGIN_PATH) {
69
+ if ((location === null || location === void 0 ? void 0 : location.pathname) !== LOGIN_PATH) {
69
70
  var _location$state;
70
71
 
71
72
  var locationFrom = location === null || location === void 0 ? void 0 : (_location$state = location.state) === null || _location$state === void 0 ? void 0 : _location$state.from;
72
- return dispatch((0, _actions.replace)(_Constants.LOGIN_PATH, {
73
+ return dispatch((0, _actions.replace)(LOGIN_PATH, {
73
74
  from: locationFrom ? locationFrom : getState().router.location,
74
75
  // cannot open login in a modal, because of previous locations that might be secure
75
76
  modal: false
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import { LOGIN_PATH, NOTIFICATION_TYPES } from "../../constants/Constants";
2
+ import { NOTIFICATION_TYPES } from "../../constants/Constants";
3
3
 
4
4
  import ErrorResponse from "../../models/error/ErrorResponse";
5
5
 
@@ -62,6 +62,7 @@ export const handleUnauthorized =
62
62
 
63
63
  // add current location as from location before redirect
64
64
  const location = getState().router.location;
65
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
65
66
  if (location?.pathname !== LOGIN_PATH) {
66
67
  const locationFrom = location?.state?.from;
67
68
  return dispatch(
@@ -1 +1 @@
1
- {"version":3,"file":"Authorization.js","names":["handleUnauthorized","errorResponse","dispatch","getState","connectKey","removeModelByKey","getSetting","response","error","window","location","reload","application","getApplication","Cache","getItem","isLoggedIn","reloadApplication","logoutSuccess","removeItem","isInvalidUsername","WARNING_TIMEOUT","showNotification","NOTIFICATION_TYPES","WARNING","id","defaultMessage","message","router","pathname","LOGIN_PATH","locationFrom","state","from","replace","modal","type"],"sources":["../../../src/redux/actions/Authorization.js"],"sourcesContent":["// @flow\nimport { LOGIN_PATH, NOTIFICATION_TYPES } from \"../../constants/Constants\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { replace } from \"../_router/actions\";\nimport { logoutSuccess } from \"./SignOut\";\nimport { showNotification } from \"./Notification\";\n\nimport Cache from \"../../utils/browser/Cache\";\n\nimport { removeModelByKey } from \"../_modularui/actions\";\nimport { getApplication } from \"../_modularui/selectors\";\nimport { reloadApplication } from \"./Application\";\n\nimport { getSetting } from \"../../constants\";\n\nimport type { ThunkAction } from \"../types\";\n\n/**\n */\nexport const handleUnauthorized =\n (errorResponse: ErrorResponse): ThunkAction =>\n (dispatch, getState) => {\n if (errorResponse.connectKey) {\n dispatch(removeModelByKey(errorResponse.connectKey));\n }\n\n if (\n getSetting(\"PAGE_RELOAD_ON_UNAUTHORIZED_ERROR\", false) &&\n errorResponse.response?.error\n ) {\n window.location.reload();\n return;\n }\n\n // reload application when flag auth is set or isLogged\n const application = getApplication(getState());\n if (Cache.getItem(\"auth\") || application?.isLoggedIn) {\n dispatch(reloadApplication());\n }\n\n // set logged auth\n dispatch(logoutSuccess());\n\n Cache.removeItem(\"auth\");\n\n if (errorResponse.isInvalidUsername) {\n const WARNING_TIMEOUT = 4000;\n dispatch(\n showNotification(\n NOTIFICATION_TYPES.WARNING,\n {\n id: errorResponse.id,\n defaultMessage: errorResponse.message,\n },\n null,\n WARNING_TIMEOUT\n )\n );\n }\n\n // add current location as from location before redirect\n const location = getState().router.location;\n if (location?.pathname !== LOGIN_PATH) {\n const locationFrom = location?.state?.from;\n return dispatch(\n replace(LOGIN_PATH, {\n from: locationFrom ? locationFrom : getState().router.location,\n // cannot open login in a modal, because of previous locations that might be secure\n modal: false,\n })\n );\n }\n\n return { type: \"NO_ACTION\" };\n };\n"],"mappings":";;;;;;;;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;AACA;A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AH,aAAGA,QAAH,0CAAGA,QAAQ,CAAEsB,KAAb,oDAAG,gBAAiBC,IAAtC;MACA,OAAO/B,QAAQ,CACb,IAAAgC,gBAAA,EAAQJ,qBAAR,EAAoB;QAClBG,IAAI,EAAEF,YAAY,GAAGA,YAAH,GAAkB5B,QAAQ,GAAGyB,MAAX,CAAkBlB,QADpC;QAElB;QACAyB,KAAK,EAAE;MAHW,CAApB,CADa,CAAf;IAOD;;IAED,OAAO;MAAEC,IAAI,EAAE;IAAR,CAAP;EACD,CAtDD;AAAA,CADK"}
1
+ {"version":3,"file":"Authorization.js","names":["handleUnauthorized","errorResponse","dispatch","getState","connectKey","removeModelByKey","getSetting","response","error","window","location","reload","application","getApplication","Cache","getItem","isLoggedIn","reloadApplication","logoutSuccess","removeItem","isInvalidUsername","WARNING_TIMEOUT","showNotification","NOTIFICATION_TYPES","WARNING","id","defaultMessage","message","router","LOGIN_PATH","pathname","locationFrom","state","from","replace","modal","type"],"sources":["../../../src/redux/actions/Authorization.js"],"sourcesContent":["// @flow\nimport { NOTIFICATION_TYPES } from \"../../constants/Constants\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { replace } from \"../_router/actions\";\nimport { logoutSuccess } from \"./SignOut\";\nimport { showNotification } from \"./Notification\";\n\nimport Cache from \"../../utils/browser/Cache\";\n\nimport { removeModelByKey } from \"../_modularui/actions\";\nimport { getApplication } from \"../_modularui/selectors\";\nimport { reloadApplication } from \"./Application\";\n\nimport { getSetting } from \"../../constants\";\n\nimport type { ThunkAction } from \"../types\";\n\n/**\n */\nexport const handleUnauthorized =\n (errorResponse: ErrorResponse): ThunkAction =>\n (dispatch, getState) => {\n if (errorResponse.connectKey) {\n dispatch(removeModelByKey(errorResponse.connectKey));\n }\n\n if (\n getSetting(\"PAGE_RELOAD_ON_UNAUTHORIZED_ERROR\", false) &&\n errorResponse.response?.error\n ) {\n window.location.reload();\n return;\n }\n\n // reload application when flag auth is set or isLogged\n const application = getApplication(getState());\n if (Cache.getItem(\"auth\") || application?.isLoggedIn) {\n dispatch(reloadApplication());\n }\n\n // set logged auth\n dispatch(logoutSuccess());\n\n Cache.removeItem(\"auth\");\n\n if (errorResponse.isInvalidUsername) {\n const WARNING_TIMEOUT = 4000;\n dispatch(\n showNotification(\n NOTIFICATION_TYPES.WARNING,\n {\n id: errorResponse.id,\n defaultMessage: errorResponse.message,\n },\n null,\n WARNING_TIMEOUT\n )\n );\n }\n\n // add current location as from location before redirect\n const location = getState().router.location;\n const LOGIN_PATH = getSetting(\"LOGIN_PATH\", \"/signin\");\n if (location?.pathname !== LOGIN_PATH) {\n const locationFrom = location?.state?.from;\n return dispatch(\n replace(LOGIN_PATH, {\n from: locationFrom ? locationFrom : getState().router.location,\n // cannot open login in a modal, because of previous locations that might be secure\n modal: false,\n })\n );\n }\n\n return { type: \"NO_ACTION\" };\n };\n"],"mappings":";;;;;;;;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAEA;;AAIA;AACA;AACO,IAAMA,kBAAkB,GAC7B,SADWA,kBACX,CAACC,aAAD;EAAA,OACA,UAACC,QAAD,EAAWC,QAAX,EAAwB;IAAA;;IACtB,IAAIF,aAAa,CAACG,UAAlB,EAA8B;MAC5BF,QAAQ,CAAC,IAAAG,0BAAA,EAAiBJ,aAAa,CAACG,UAA/B,CAAD,CAAR;IACD;;IAED,IACE,IAAAE,qBAAA,EAAW,mCAAX,EAAgD,KAAhD,8BACAL,aAAa,CAACM,QADd,kDACA,sBAAwBC,KAF1B,EAGE;MACAC,MAAM,CAACC,QAAP,CAAgBC,MAAhB;MACA;IACD,CAXqB,CAatB;;;IACA,IAAMC,WAAW,GAAG,IAAAC,yBAAA,EAAeV,QAAQ,EAAvB,CAApB;;IACA,IAAIW,cAAA,CAAMC,OAAN,CAAc,MAAd,KAAyBH,WAAzB,aAAyBA,WAAzB,eAAyBA,WAAW,CAAEI,UAA1C,EAAsD;MACpDd,QAAQ,CAAC,IAAAe,8BAAA,GAAD,CAAR;IACD,CAjBqB,CAmBtB;;;IACAf,QAAQ,CAAC,IAAAgB,sBAAA,GAAD,CAAR;;IAEAJ,cAAA,CAAMK,UAAN,CAAiB,MAAjB;;IAEA,IAAIlB,aAAa,CAACmB,iBAAlB,EAAqC;MACnC,IAAMC,eAAe,GAAG,IAAxB;MACAnB,QAAQ,CACN,IAAAoB,8BAAA,EACEC,6BAAA,CAAmBC,OADrB,EAEE;QACEC,EAAE,EAAExB,aAAa,CAACwB,EADpB;QAEEC,cAAc,EAAEzB,aAAa,CAAC0B;MAFhC,CAFF,EAME,IANF,EAOEN,eAPF,CADM,CAAR;IAWD,CArCqB,CAuCtB;;;IACA,IAAMX,QAAQ,GAAGP,QAAQ,GAAGyB,MAAX,CAAkBlB,QAAnC;IACA,IAAMmB,UAAU,GAAG,IAAAvB,qBAAA,EAAW,YAAX,EAAyB,SAAzB,CAAnB;;IACA,IAAI,CAAAI,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEoB,QAAV,MAAuBD,UAA3B,EAAuC;MAAA;;MACrC,IAAME,YAAY,GAAGrB,QAAH,aAAGA,QAAH,0CAAGA,QAAQ,CAAEsB,KAAb,oDAAG,gBAAiBC,IAAtC;MACA,OAAO/B,QAAQ,CACb,IAAAgC,gBAAA,EAAQL,UAAR,EAAoB;QAClBI,IAAI,EAAEF,YAAY,GAAGA,YAAH,GAAkB5B,QAAQ,GAAGyB,MAAX,CAAkBlB,QADpC;QAElB;QACAyB,KAAK,EAAE;MAHW,CAApB,CADa,CAAf;IAOD;;IAED,OAAO;MAAEC,IAAI,EAAE;IAAR,CAAP;EACD,CAvDD;AAAA,CADK"}
@@ -9,6 +9,8 @@ exports.setCustomErrorResponseHandler = exports.handleError = void 0;
9
9
 
10
10
  var _Constants = require("../../constants/Constants");
11
11
 
12
+ var _Settings = require("../../constants/Settings");
13
+
12
14
  var _ErrorResponse = _interopRequireDefault(require("../../models/error/ErrorResponse"));
13
15
 
14
16
  var _actions = require("../_router/actions");
@@ -46,7 +48,8 @@ var defaultErrorResponseHandler = function defaultErrorResponseHandler(error) {
46
48
  }
47
49
 
48
50
  if (error.isBlocked || error.isConcurrentUser) {
49
- dispatch((0, _actions.push)(_Constants.LOGOUT_PATH));
51
+ var LOGOUT_PATH = (0, _Settings.getSetting)("LOGOUT_PATH", "/signout");
52
+ dispatch((0, _actions.push)(LOGOUT_PATH));
50
53
  }
51
54
 
52
55
  if (error.isChangePassword) {
@@ -1,5 +1,6 @@
1
1
  // @flow
2
- import { LOGOUT_PATH, IS_SERVER } from "../../constants/Constants";
2
+ import { IS_SERVER } from "../../constants/Constants";
3
+ import { getSetting } from "../../constants/Settings";
3
4
 
4
5
  import ErrorResponse from "../../models/error/ErrorResponse";
5
6
 
@@ -39,6 +40,7 @@ const defaultErrorResponseHandler: DefaultErrorResponseHandler =
39
40
  }
40
41
 
41
42
  if (error.isBlocked || error.isConcurrentUser) {
43
+ const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
42
44
  dispatch(push(LOGOUT_PATH));
43
45
  }
44
46
 
@@ -1 +1 @@
1
- {"version":3,"file":"Error.js","names":["saveError","error","type","payload","defaultErrorResponseHandler","dispatch","isResourceNotFoundAfterReload","isRemoteServiceException","isUnauthorized","handleUnauthorized","isBlocked","isConcurrentUser","push","LOGOUT_PATH","isChangePassword","changePassword","IS_SERVER","setTimeout","showXHRErrorNotification","customErrorResponseHandler","errorResponse","defaultHandler","setCustomErrorResponseHandler","handler","handleError","resetProgress","ErrorResponse"],"sources":["../../../src/redux/actions/Error.js"],"sourcesContent":["// @flow\nimport { LOGOUT_PATH, IS_SERVER } from \"../../constants/Constants\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { push } from \"../_router/actions\";\nimport { showXHRErrorNotification } from \"./Notification\";\nimport { resetProgress } from \"./ProgressIndicator\";\nimport { changePassword } from \"./SignIn\";\nimport { handleUnauthorized } from \"./Authorization\";\n\nimport type { FetchException } from \"../../exceptions\";\nimport type { Dispatch, SaveErrorAction, ThunkAction } from \"../types\";\n\ntype DefaultErrorResponseHandler = (error: ErrorResponse) => ThunkAction;\ntype CustomErrorResponseHandler = (\n errorResponse: ErrorResponse,\n defaultHandler: DefaultErrorResponseHandler\n) => ThunkAction;\n\n/**\n */\nconst saveError = (error): SaveErrorAction => ({\n type: \"SAVE_ERROR\",\n payload: error,\n});\n\n/**\n */\nconst defaultErrorResponseHandler: DefaultErrorResponseHandler =\n (error: ErrorResponse): ThunkAction =>\n (dispatch: Dispatch) => {\n if (error.isResourceNotFoundAfterReload || error.isRemoteServiceException) {\n return dispatch({ type: \"NO_ACTION\" });\n }\n\n if (error.isUnauthorized) {\n return dispatch(handleUnauthorized(error));\n }\n\n if (error.isBlocked || error.isConcurrentUser) {\n dispatch(push(LOGOUT_PATH));\n }\n\n if (error.isChangePassword) {\n return dispatch(changePassword());\n }\n\n if (IS_SERVER) {\n return dispatch(saveError(error));\n }\n\n setTimeout(() => {\n throw error;\n });\n\n return dispatch(showXHRErrorNotification(error));\n };\n\n/**\n * Standard Custom error response, acts as a proxy and can be overwritten by {@link setCustomErrorResponseHandler}\n */\nlet customErrorResponseHandler: CustomErrorResponseHandler =\n (errorResponse, defaultHandler) => (dispatch: Dispatch) =>\n dispatch(defaultHandler(errorResponse));\n\n/**\n * Set a custom error response handler,\n * can be used when custom functionality is needed on certain (error) response\n * of the modular ui, for example when custom logic is needed when a user is unauthorized<br>\n * It receives an {@link ErrorResponse} and the {@link defaultErrorResponseHandler}\n */\nexport const setCustomErrorResponseHandler = (\n handler: CustomErrorResponseHandler\n) => {\n customErrorResponseHandler = handler;\n};\n\n/**\n * Handle errors by sending an error notification message\n */\nexport const handleError =\n (error: Error | FetchException): ThunkAction =>\n (dispatch: Dispatch) => {\n dispatch(resetProgress());\n\n const errorResponse = new ErrorResponse(error);\n\n return dispatch(\n customErrorResponseHandler(errorResponse, defaultErrorResponseHandler)\n );\n };\n"],"mappings":";;;;;;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A;;;AACO,IAAME,6BAA6B,GAAG,SAAhCA,6BAAgC,CAC3CC,OAD2C,EAExC;EACHJ,0BAA0B,GAAGI,OAA7B;AACD,CAJM;AAMP;AACA;AACA;;;;;AACO,IAAMC,WAAW,GACtB,SADWA,WACX,CAACvB,KAAD;EAAA,OACA,UAACI,QAAD,EAAwB;IACtBA,QAAQ,CAAC,IAAAoB,gCAAA,GAAD,CAAR;IAEA,IAAML,aAAa,GAAG,IAAIM,sBAAJ,CAAkBzB,KAAlB,CAAtB;IAEA,OAAOI,QAAQ,CACbc,0BAA0B,CAACC,aAAD,EAAgBhB,2BAAhB,CADb,CAAf;EAGD,CATD;AAAA,CADK"}
1
+ {"version":3,"file":"Error.js","names":["saveError","error","type","payload","defaultErrorResponseHandler","dispatch","isResourceNotFoundAfterReload","isRemoteServiceException","isUnauthorized","handleUnauthorized","isBlocked","isConcurrentUser","LOGOUT_PATH","getSetting","push","isChangePassword","changePassword","IS_SERVER","setTimeout","showXHRErrorNotification","customErrorResponseHandler","errorResponse","defaultHandler","setCustomErrorResponseHandler","handler","handleError","resetProgress","ErrorResponse"],"sources":["../../../src/redux/actions/Error.js"],"sourcesContent":["// @flow\nimport { IS_SERVER } from \"../../constants/Constants\";\nimport { getSetting } from \"../../constants/Settings\";\n\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\n\nimport { push } from \"../_router/actions\";\nimport { showXHRErrorNotification } from \"./Notification\";\nimport { resetProgress } from \"./ProgressIndicator\";\nimport { changePassword } from \"./SignIn\";\nimport { handleUnauthorized } from \"./Authorization\";\n\nimport type { FetchException } from \"../../exceptions\";\nimport type { Dispatch, SaveErrorAction, ThunkAction } from \"../types\";\n\ntype DefaultErrorResponseHandler = (error: ErrorResponse) => ThunkAction;\ntype CustomErrorResponseHandler = (\n errorResponse: ErrorResponse,\n defaultHandler: DefaultErrorResponseHandler\n) => ThunkAction;\n\n/**\n */\nconst saveError = (error): SaveErrorAction => ({\n type: \"SAVE_ERROR\",\n payload: error,\n});\n\n/**\n */\nconst defaultErrorResponseHandler: DefaultErrorResponseHandler =\n (error: ErrorResponse): ThunkAction =>\n (dispatch: Dispatch) => {\n if (error.isResourceNotFoundAfterReload || error.isRemoteServiceException) {\n return dispatch({ type: \"NO_ACTION\" });\n }\n\n if (error.isUnauthorized) {\n return dispatch(handleUnauthorized(error));\n }\n\n if (error.isBlocked || error.isConcurrentUser) {\n const LOGOUT_PATH = getSetting(\"LOGOUT_PATH\", \"/signout\");\n dispatch(push(LOGOUT_PATH));\n }\n\n if (error.isChangePassword) {\n return dispatch(changePassword());\n }\n\n if (IS_SERVER) {\n return dispatch(saveError(error));\n }\n\n setTimeout(() => {\n throw error;\n });\n\n return dispatch(showXHRErrorNotification(error));\n };\n\n/**\n * Standard Custom error response, acts as a proxy and can be overwritten by {@link setCustomErrorResponseHandler}\n */\nlet customErrorResponseHandler: CustomErrorResponseHandler =\n (errorResponse, defaultHandler) => (dispatch: Dispatch) =>\n dispatch(defaultHandler(errorResponse));\n\n/**\n * Set a custom error response handler,\n * can be used when custom functionality is needed on certain (error) response\n * of the modular ui, for example when custom logic is needed when a user is unauthorized<br>\n * It receives an {@link ErrorResponse} and the {@link defaultErrorResponseHandler}\n */\nexport const setCustomErrorResponseHandler = (\n handler: CustomErrorResponseHandler\n) => {\n customErrorResponseHandler = handler;\n};\n\n/**\n * Handle errors by sending an error notification message\n */\nexport const handleError =\n (error: Error | FetchException): ThunkAction =>\n (dispatch: Dispatch) => {\n dispatch(resetProgress());\n\n const errorResponse = new ErrorResponse(error);\n\n return dispatch(\n customErrorResponseHandler(errorResponse, defaultErrorResponseHandler)\n );\n };\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAWA;AACA;AACA,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,KAAD;EAAA,OAA6B;IAC7CC,IAAI,EAAE,YADuC;IAE7CC,OAAO,EAAEF;EAFoC,CAA7B;AAAA,CAAlB;AAKA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,IAAMC,WAAW,GACtB,SADWA,WACX,CAACxB,KAAD;EAAA,OACA,UAACI,QAAD,EAAwB;IACtBA,QAAQ,CAAC,IAAAqB,gCAAA,GAAD,CAAR;IAEA,IAAML,aAAa,GAAG,IAAIM,sBAAJ,CAAkB1B,KAAlB,CAAtB;IAEA,OAAOI,QAAQ,CACbe,0BAA0B,CAACC,aAAD,EAAgBjB,2BAAhB,CADb,CAAf;EAGD,CATD;AAAA,CADK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.20.2",
3
+ "version": "1.20.3",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -114,16 +114,16 @@
114
114
  "cherry-pick": "^0.5.0",
115
115
  "cross-env": "^7.0.3",
116
116
  "documentation": "^13.2.5",
117
- "eslint": "^8.17.0",
117
+ "eslint": "^8.18.0",
118
118
  "eslint-config-prettier": "^8.3.0",
119
119
  "eslint-plugin-babel": "^5.3.1",
120
120
  "eslint-plugin-ft-flow": "^2.0.1",
121
121
  "eslint-plugin-import": "^2.26.0",
122
122
  "eslint-plugin-jest": "^26.5.3",
123
- "eslint-plugin-jsdoc": "^39.3.2",
123
+ "eslint-plugin-jsdoc": "^39.3.3",
124
124
  "eslint-plugin-react": "^7.30.0",
125
125
  "eslint-plugin-react-hooks": "^4.5.0",
126
- "flow-bin": "^0.180.0",
126
+ "flow-bin": "^0.180.1",
127
127
  "flow-copy-source": "^2.0.9",
128
128
  "flow-typed": "^3.6.1",
129
129
  "glob": "^8.0.3",
@@ -134,7 +134,7 @@
134
134
  "jest-junit": "^13.2.0",
135
135
  "jest-sonar-reporter": "^2.0.0",
136
136
  "jscodeshift": "^0.13.1",
137
- "lint-staged": "^13.0.1",
137
+ "lint-staged": "^13.0.2",
138
138
  "polished": "^4.0.0",
139
139
  "prettier": "^2.7.1",
140
140
  "react": "^18.0.0",
@@ -51,21 +51,6 @@ export const UPLOAD_PATH = `${BASE}/uploadFile`;
51
51
  */
52
52
  export const CAPTCHA_PATH = `${BASE}/captchaServices`;
53
53
 
54
- /**
55
- * Path to login page / component
56
- */
57
- export const LOGIN_PATH = "/signin";
58
-
59
- /**
60
- * Path to administrator login page / component
61
- */
62
- export const ADMINISTRATOR_LOGIN_PATH = null;
63
-
64
- /**
65
- * Path to logout page / component
66
- */
67
- export const LOGOUT_PATH = "/signout";
68
-
69
54
  /**
70
55
  * Path to change password page / component
71
56
  */
@@ -51,6 +51,15 @@ const defaultSettings = {
51
51
  // Renders the login variants as option on the global logout page
52
52
  RENDER_MULTI_LOGIN_ON_GLOBAL_LOGOUT_PAGE: false,
53
53
 
54
+ // Path to login page / component
55
+ LOGIN_PATH: "/signin",
56
+
57
+ // Path to administrator login page / component
58
+ ADMINISTRATOR_LOGIN_PATH: "",
59
+
60
+ // Path to logout page / component
61
+ LOGOUT_PATH: "/signout",
62
+
54
63
  // Render forms in a modal
55
64
  RENDER_FORMS_IN_MODAL: true,
56
65
 
@@ -4,15 +4,23 @@ import { useSelector, useDispatch } from "react-redux";
4
4
  import { getApplication } from "../redux/_modularui/selectors";
5
5
  import { login, logout, resetAuthErrors } from "../redux/actions";
6
6
 
7
+ import Cache from "../utils/browser/Cache";
8
+ import { BASE, getSetting } from "../constants";
9
+
7
10
  import type { ResetAuthErrorsAction } from "../redux/types";
11
+ import type { AuthenticationType } from "../models/types";
12
+ import { IllegalStateException } from "../exceptions";
8
13
  type LoginHook = {
9
14
  isAuthenticated: boolean,
15
+ authenticationTypes: Array<AuthenticationType>,
10
16
  errorMessage: ?string,
11
17
  resetErrors: () => ResetAuthErrorsAction,
12
18
  login: (username: string, password: string) => void,
19
+ redirectLogin: (authenticationType: AuthenticationType) => void,
13
20
  };
14
21
  type LogoutHook = {
15
22
  isAuthenticated: boolean,
23
+ authenticationTypes: Array<AuthenticationType>,
16
24
  logout: () => void,
17
25
  };
18
26
 
@@ -24,12 +32,28 @@ export const useLogin = (): LoginHook => {
24
32
  const application = useSelector(getApplication);
25
33
  const auth = useSelector((state) => state.auth);
26
34
 
35
+ const isAuthenticated = application?.isLoggedIn ?? false;
36
+
27
37
  return {
28
- isAuthenticated: application?.isLoggedIn ?? false,
38
+ isAuthenticated,
39
+ authenticationTypes: application?.authenticationTypes ?? [],
29
40
  errorMessage: auth.error,
30
41
  resetErrors: () => dispatch(resetAuthErrors()),
31
42
  login: (username: string, password: string) =>
32
43
  dispatch(login(username, password)),
44
+ redirectLogin: (authenticationType: AuthenticationType) => {
45
+ if (Cache.getItem("isRedirectLogin")) {
46
+ // prevent endless loop in redirects when authentication type can't be redirected
47
+ throw new IllegalStateException(
48
+ `Could not redirect to '${authenticationType.authentication}' using url: '${authenticationType.redirectUri}'`
49
+ );
50
+ }
51
+
52
+ if (!isAuthenticated) {
53
+ Cache.setItem("isRedirectLogin", true);
54
+ window.location.assign(`${BASE}${authenticationType.redirectUri}`);
55
+ }
56
+ },
33
57
  };
34
58
  };
35
59
 
@@ -39,8 +63,21 @@ export const useLogout = (): LogoutHook => {
39
63
  const dispatch = useDispatch();
40
64
  const application = useSelector(getApplication);
41
65
 
66
+ const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
67
+
68
+ const isAuthenticated = application?.isLoggedIn ?? false;
42
69
  return {
43
- isAuthenticated: application?.isLoggedIn ?? false,
44
- logout: () => dispatch(logout()),
70
+ isAuthenticated,
71
+ authenticationTypes: application?.authenticationTypes ?? [],
72
+ logout: () => {
73
+ if (Cache.getItem("isRedirectLogin")) {
74
+ const origin = window.location.origin;
75
+ const url = `${origin}${BASE}/logout?url=${origin}${BASE}${LOGOUT_PATH}`;
76
+ Cache.setItem("isRedirectLogin", false);
77
+ window.location.assign(url);
78
+ } else {
79
+ return dispatch(logout());
80
+ }
81
+ },
45
82
  };
46
83
  };
@@ -68,7 +68,13 @@ export default class ApplicationModel extends ResourceModel {
68
68
  * Getting the authentication types of the application
69
69
  */
70
70
  get authenticationTypes(): Array<AuthenticationType> {
71
- return this.getContribution("security", []);
71
+ const authenticationTypes = this.getContribution("security", []);
72
+
73
+ //put primary first
74
+ return authenticationTypes?.sort(
75
+ (a: AuthenticationType, b: AuthenticationType) =>
76
+ a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1
77
+ );
72
78
  }
73
79
  /**
74
80
  * Getting the tab links
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import { LOGIN_PATH, NOTIFICATION_TYPES } from "../../constants/Constants";
2
+ import { NOTIFICATION_TYPES } from "../../constants/Constants";
3
3
 
4
4
  import ErrorResponse from "../../models/error/ErrorResponse";
5
5
 
@@ -62,6 +62,7 @@ export const handleUnauthorized =
62
62
 
63
63
  // add current location as from location before redirect
64
64
  const location = getState().router.location;
65
+ const LOGIN_PATH = getSetting("LOGIN_PATH", "/signin");
65
66
  if (location?.pathname !== LOGIN_PATH) {
66
67
  const locationFrom = location?.state?.from;
67
68
  return dispatch(
@@ -1,5 +1,6 @@
1
1
  // @flow
2
- import { LOGOUT_PATH, IS_SERVER } from "../../constants/Constants";
2
+ import { IS_SERVER } from "../../constants/Constants";
3
+ import { getSetting } from "../../constants/Settings";
3
4
 
4
5
  import ErrorResponse from "../../models/error/ErrorResponse";
5
6
 
@@ -39,6 +40,7 @@ const defaultErrorResponseHandler: DefaultErrorResponseHandler =
39
40
  }
40
41
 
41
42
  if (error.isBlocked || error.isConcurrentUser) {
43
+ const LOGOUT_PATH = getSetting("LOGOUT_PATH", "/signout");
42
44
  dispatch(push(LOGOUT_PATH));
43
45
  }
44
46