asab_webui_shell 25.1.11 → 25.1.13
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.
- package/dist/components/locationReplace.js +4 -16
- package/dist/config/ConfigReducer.js +1 -1
- package/dist/config/ConfigService.js +116 -137
- package/dist/containers/AdvancedMode/reducer.js +2 -2
- package/dist/containers/Alerts/index.js +18 -30
- package/dist/containers/Alerts/reducer.js +5 -6
- package/dist/containers/Application.js +531 -663
- package/dist/containers/AttentionRequired/reducer.js +2 -2
- package/dist/containers/FullscreenMode/reducer.js +2 -2
- package/dist/containers/Header/ApplicationScreenTitle/ApplicationScreenTitle.js +15 -16
- package/dist/containers/Header/ApplicationScreenTitle/index.js +6 -6
- package/dist/containers/Header/Help/HelpButton.js +17 -27
- package/dist/containers/Header/Help/HelpService.js +13 -24
- package/dist/containers/Header/Preview/PreviewFlag.js +6 -5
- package/dist/containers/Header/Preview/PreviewService.js +13 -24
- package/dist/containers/Header/index.js +15 -17
- package/dist/containers/Header/reducer.js +4 -4
- package/dist/containers/Navigation/index.js +35 -55
- package/dist/containers/Navigation/reducer.js +7 -13
- package/dist/containers/RouteErrorHandler/ErrorContainer.js +17 -19
- package/dist/containers/RouteErrorHandler/index.js +28 -44
- package/dist/containers/Router/ApplicationRouter.js +14 -16
- package/dist/containers/Router/index.js +26 -42
- package/dist/containers/Router/reducer.js +3 -3
- package/dist/containers/Sidebar/NavbarBrand.js +14 -23
- package/dist/containers/Sidebar/SidebarBottomItem.js +16 -15
- package/dist/containers/Sidebar/SidebarIcon.js +9 -7
- package/dist/containers/Sidebar/SidebarItem.js +70 -85
- package/dist/containers/Sidebar/SidebarItemRenderer.js +20 -20
- package/dist/containers/Sidebar/index.js +20 -36
- package/dist/containers/Sidebar/reducer.js +3 -3
- package/dist/containers/Sidepanel/Sidepanel.js +18 -26
- package/dist/containers/Toast/ToastComponent.js +12 -12
- package/dist/containers/Toast/ToastContainer.js +19 -30
- package/dist/containers/Toast/reducer.js +3 -6
- package/dist/index.js +5 -5
- package/dist/modules/about/AboutScreen.js +30 -38
- package/dist/modules/about/index.js +8 -26
- package/dist/modules/auth/api.js +110 -156
- package/dist/modules/auth/components/SessionExpirationAlert.js +10 -9
- package/dist/modules/auth/header.js +25 -23
- package/dist/modules/auth/index.js +440 -692
- package/dist/modules/auth/reducer.js +2 -2
- package/dist/modules/auth/screens/AccessControlScreen.js +24 -25
- package/dist/modules/auth/screens/InvitationScreen.js +89 -128
- package/dist/modules/i18n/dropdown.js +24 -23
- package/dist/modules/i18n/index.js +20 -33
- package/dist/modules/i18n/reducer.js +2 -2
- package/dist/modules/i18n/service.js +48 -102
- package/dist/modules/tenant/TenantDropdown.js +28 -27
- package/dist/modules/tenant/access/AccessDeniedCard.js +28 -54
- package/dist/modules/tenant/index.js +16 -29
- package/dist/modules/tenant/reducer.js +1 -1
- package/dist/modules/tenant/service.js +123 -207
- package/dist/screens/InvalidRouteScreen.js +10 -9
- package/dist/screens/SuspenseScreen.js +11 -20
- package/dist/screens/UnauthorizedAccessScreen.js +18 -21
- package/dist/services/AttentionRequiredService.js +117 -142
- package/dist/services/BrandingService.js +63 -80
- package/dist/services/HeaderService.js +47 -66
- package/dist/services/ReduxService.js +11 -17
- package/dist/services/TitleService.js +13 -24
- package/dist/theme/ThemeButton.js +13 -10
- package/dist/theme/ThemeReducer.js +1 -1
- package/dist/theme/ThemeService.js +25 -38
- package/package.json +1 -1
|
@@ -4,16 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
|
+
exports.default = void 0;
|
|
11
8
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
15
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
18
10
|
var _asab_webui_components = require("asab_webui_components");
|
|
19
11
|
var _header = require("./header");
|
|
@@ -23,36 +15,23 @@ var _actions2 = require("../../actions");
|
|
|
23
15
|
var _api = require("./api");
|
|
24
16
|
var _locationReplace = require("../../components/locationReplace");
|
|
25
17
|
var _SessionExpirationAlert = require("./components/SessionExpirationAlert");
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var AuthModule = exports["default"] = /*#__PURE__*/function (_Module) {
|
|
41
|
-
function AuthModule(app, name) {
|
|
42
|
-
var _this;
|
|
43
|
-
(0, _classCallCheck2["default"])(this, AuthModule);
|
|
44
|
-
_this = _callSuper(this, AuthModule, [app, "AuthModule"]);
|
|
45
|
-
_this.OAuthToken = JSON.parse(sessionStorage.getItem('SeaCatOAuth2Token'));
|
|
46
|
-
_this.UserInfo = null;
|
|
47
|
-
_this.Api = new _api.SeaCatAuthApi(app);
|
|
48
|
-
_this.RedirectURL = window.location.href;
|
|
49
|
-
_this.MustAuthenticate = true; // Setting this to false means, that we can operate without authenticated user
|
|
50
|
-
app.ReduxService.addReducer("auth", _reducer["default"]);
|
|
51
|
-
_this.App.addSplashScreenRequestor(_this);
|
|
52
|
-
_this.Authorization = _this.App.Config.get("authorization"); // Get authorization settings from configuration
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } // TODO: Use SessionExpirationAlert only after proper fix of the component
|
|
19
|
+
var AccessControlScreen = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require("./screens/AccessControlScreen"))));
|
|
20
|
+
var InvitationScreen = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require("./screens/InvitationScreen"))));
|
|
21
|
+
class AuthModule extends _asab_webui_components.Module {
|
|
22
|
+
constructor(app, name) {
|
|
23
|
+
super(app, "AuthModule");
|
|
24
|
+
this.OAuthToken = JSON.parse(sessionStorage.getItem('SeaCatOAuth2Token'));
|
|
25
|
+
this.UserInfo = null;
|
|
26
|
+
this.Api = new _api.SeaCatAuthApi(app);
|
|
27
|
+
this.RedirectURL = window.location.href;
|
|
28
|
+
this.MustAuthenticate = true; // Setting this to false means, that we can operate without authenticated user
|
|
29
|
+
app.ReduxService.addReducer("auth", _reducer.default);
|
|
30
|
+
this.App.addSplashScreenRequestor(this);
|
|
31
|
+
this.Authorization = this.App.Config.get("authorization"); // Get authorization settings from configuration
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
this.SessionExpiration = null; // Session expiration as defined in user info
|
|
34
|
+
this.sessionValidationInterval = null; // Initialize session validation interval
|
|
56
35
|
|
|
57
36
|
// Access control screen
|
|
58
37
|
app.Router.addRoute({
|
|
@@ -71,691 +50,460 @@ var AuthModule = exports["default"] = /*#__PURE__*/function (_Module) {
|
|
|
71
50
|
component: InvitationScreen,
|
|
72
51
|
resource: "seacat:tenant:assign"
|
|
73
52
|
});
|
|
74
|
-
return _this;
|
|
75
53
|
}
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
_context.next = 6;
|
|
105
|
-
return this.simulateUserinfo(MOCK_USERINFO);
|
|
106
|
-
case 6:
|
|
107
|
-
_context.next = 63;
|
|
108
|
-
break;
|
|
109
|
-
case 8:
|
|
110
|
-
// Check the query string for 'code'
|
|
111
|
-
qs = new URLSearchParams(window.location.search);
|
|
112
|
-
authorization_code = qs.get('code'); // Checking error type in params
|
|
113
|
-
errorType = qs.get('error');
|
|
114
|
-
if (!(errorType != undefined && errorType != 'tenant_access_denied')) {
|
|
115
|
-
_context.next = 13;
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
return _context.abrupt("return");
|
|
119
|
-
case 13:
|
|
120
|
-
if (!(authorization_code !== null)) {
|
|
121
|
-
_context.next = 25;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
_context.next = 16;
|
|
125
|
-
return this._updateToken(authorization_code);
|
|
126
|
-
case 16:
|
|
127
|
-
// Remove 'code' from a query string
|
|
128
|
-
qs["delete"]('code');
|
|
129
|
-
stateIndex = qs.get("state");
|
|
130
|
-
state = ""; // Check if stateIndex is present, eventually return empty state string
|
|
131
|
-
if (stateIndex != undefined) {
|
|
132
|
-
// Check if oauth2_state_ is present, eventually return empty string
|
|
133
|
-
if (localStorage.getItem("oauth2_state_".concat(stateIndex)) != undefined) {
|
|
134
|
-
state = localStorage.getItem("oauth2_state_".concat(stateIndex));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
localStorage.removeItem("oauth2_state_".concat(stateIndex));
|
|
54
|
+
initialize() {
|
|
55
|
+
var _this = this;
|
|
56
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
57
|
+
var headerService = _this.App.locateService("HeaderService");
|
|
58
|
+
headerService.addComponent({
|
|
59
|
+
component: _header.AuthHeaderInvitation,
|
|
60
|
+
componentProps: {
|
|
61
|
+
AuthModule: _this
|
|
62
|
+
},
|
|
63
|
+
order: 200
|
|
64
|
+
});
|
|
65
|
+
headerService.addComponent({
|
|
66
|
+
component: _header.AuthHeaderDropdown,
|
|
67
|
+
componentProps: {
|
|
68
|
+
AuthModule: _this
|
|
69
|
+
},
|
|
70
|
+
order: 700
|
|
71
|
+
});
|
|
72
|
+
if (typeof MOCK_USERINFO !== 'undefined') {
|
|
73
|
+
/* This section is only for DEV purposes! */
|
|
74
|
+
yield _this.simulateUserinfo(MOCK_USERINFO);
|
|
75
|
+
/* End of DEV section */
|
|
76
|
+
} else {
|
|
77
|
+
// Check the query string for 'code'
|
|
78
|
+
var qs = new URLSearchParams(window.location.search);
|
|
79
|
+
var authorization_code = qs.get('code');
|
|
138
80
|
|
|
139
|
-
|
|
140
|
-
|
|
81
|
+
// Checking error type in params
|
|
82
|
+
var errorType = qs.get('error');
|
|
83
|
+
if (errorType != undefined && errorType != 'tenant_access_denied') {
|
|
84
|
+
/*
|
|
85
|
+
If error appears in the URL search params and is NOT
|
|
86
|
+
tenant_access_denied, user will stay in splashscreen
|
|
87
|
+
with Access denied card
|
|
88
|
+
*/
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (authorization_code !== null) {
|
|
92
|
+
yield _this._updateToken(authorization_code);
|
|
93
|
+
// Remove 'code' from a query string
|
|
94
|
+
qs.delete('code');
|
|
95
|
+
var stateIndex = qs.get("state");
|
|
96
|
+
var state = "";
|
|
97
|
+
// Check if stateIndex is present, eventually return empty state string
|
|
98
|
+
if (stateIndex != undefined) {
|
|
99
|
+
// Check if oauth2_state_ is present, eventually return empty string
|
|
100
|
+
if (localStorage.getItem("oauth2_state_".concat(stateIndex)) != undefined) {
|
|
101
|
+
state = localStorage.getItem("oauth2_state_".concat(stateIndex));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
localStorage.removeItem("oauth2_state_".concat(stateIndex));
|
|
141
105
|
|
|
142
|
-
|
|
143
|
-
|
|
106
|
+
// Remove 'state' from a query string
|
|
107
|
+
qs.delete("state");
|
|
144
108
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
109
|
+
// Construct the new URL without `code` in the query string
|
|
110
|
+
// For this case, condition on empty qs string is sufficient and tested
|
|
111
|
+
var reloadUrl;
|
|
112
|
+
if (qs.toString() == '') {
|
|
113
|
+
// Remove `?` part from URL completely, if empty
|
|
114
|
+
reloadUrl = window.location.pathname + state; // part form localstorage instead of hash
|
|
115
|
+
} else {
|
|
116
|
+
reloadUrl = window.location.pathname + '?' + qs.toString() + state; // part form localstorage instead of hash
|
|
117
|
+
}
|
|
151
118
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
case 25:
|
|
156
|
-
if (!(this.OAuthToken != null)) {
|
|
157
|
-
_context.next = 58;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
_context.next = 28;
|
|
161
|
-
return this.updateUserInfo();
|
|
162
|
-
case 28:
|
|
163
|
-
result = _context.sent;
|
|
164
|
-
if (result) {
|
|
165
|
-
_context.next = 35;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
// User info not found - go to login
|
|
169
|
-
sessionStorage.removeItem('SeaCatOAuth2Token');
|
|
170
|
-
force_login_prompt = true;
|
|
171
|
-
_context.next = 34;
|
|
172
|
-
return this.Api.login(this.RedirectURL, force_login_prompt);
|
|
173
|
-
case 34:
|
|
174
|
-
return _context.abrupt("return");
|
|
175
|
-
case 35:
|
|
176
|
-
// Add interceptor with Bearer token in the Header into axios calls
|
|
177
|
-
this.App.addAxiosInterceptor(this.authInterceptor());
|
|
178
|
-
// Add webSocket interceptor with Bearer token into websocket calls
|
|
179
|
-
this.App.addWebSocketInterceptor(this.webSocketAuthInterceptor());
|
|
119
|
+
// Reload the app with `code` removed
|
|
120
|
+
yield (0, _locationReplace.locationReplace)(reloadUrl);
|
|
121
|
+
}
|
|
180
122
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
123
|
+
// Do we have an oauth token (we are authorized to use the app)
|
|
124
|
+
if (_this.OAuthToken != null) {
|
|
125
|
+
// Update the user info
|
|
126
|
+
var result = yield _this.updateUserInfo();
|
|
127
|
+
if (!result) {
|
|
128
|
+
// User info not found - go to login
|
|
129
|
+
sessionStorage.removeItem('SeaCatOAuth2Token');
|
|
130
|
+
var force_login_prompt = true;
|
|
131
|
+
yield _this.Api.login(_this.RedirectURL, force_login_prompt);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Add interceptor with Bearer token in the Header into axios calls
|
|
136
|
+
_this.App.addAxiosInterceptor(_this.authInterceptor());
|
|
137
|
+
// Add webSocket interceptor with Bearer token into websocket calls
|
|
138
|
+
_this.App.addWebSocketInterceptor(_this.webSocketAuthInterceptor());
|
|
139
|
+
|
|
140
|
+
// Authorization of the user based on tenant access
|
|
141
|
+
if (_this.App.Config.get("authorization") !== "disabled" && _this.App.Services.TenantService) {
|
|
142
|
+
// Tenant access validation
|
|
143
|
+
var tenantAuthorized = _this.validateTenant();
|
|
144
|
+
if (!tenantAuthorized) {
|
|
192
145
|
// If tenant not authorized, redirect to Access denied card
|
|
193
|
-
_force_login_prompt = false;
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
return _context.abrupt("return");
|
|
198
|
-
case 44:
|
|
199
|
-
if (!(this.App.Store && this.App.Services.TenantService && this.UserInfo !== null)) {
|
|
200
|
-
_context.next = 55;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
currentTenant = this.App.Services.TenantService.getCurrentTenant();
|
|
204
|
-
resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
|
|
205
|
-
/*
|
|
206
|
-
When switching between tenants,
|
|
207
|
-
we need to force authorization to obtain
|
|
208
|
-
correct data (resources) for particular
|
|
209
|
-
tenant (this is unavailable until auth token is updated)
|
|
210
|
-
*/
|
|
211
|
-
if (!(resources == undefined)) {
|
|
212
|
-
_context.next = 52;
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
_force_login_prompt2 = false;
|
|
216
|
-
_context.next = 51;
|
|
217
|
-
return this.Api.login(this.RedirectURL, _force_login_prompt2);
|
|
218
|
-
case 51:
|
|
219
|
-
return _context.abrupt("return");
|
|
220
|
-
case 52:
|
|
221
|
-
if (this.App.Store != null) {
|
|
222
|
-
this.App.Store.dispatch({
|
|
223
|
-
type: _actions.types.AUTH_RESOURCES,
|
|
224
|
-
resources: resources
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
_context.next = 55;
|
|
228
|
-
return this.validateNavigation();
|
|
229
|
-
case 55:
|
|
230
|
-
if (!(this.UserInfo != null)) {
|
|
231
|
-
_context.next = 58;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
_context.next = 58;
|
|
235
|
-
return this._startSessionExpirationValidation();
|
|
236
|
-
case 58:
|
|
237
|
-
if (!(this.UserInfo == null && this.MustAuthenticate)) {
|
|
238
|
-
_context.next = 63;
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
// TODO: force_login_prompt = true to break authentication failure loop
|
|
242
|
-
_force_login_prompt3 = false;
|
|
243
|
-
_context.next = 62;
|
|
244
|
-
return this.Api.login(this.RedirectURL, _force_login_prompt3);
|
|
245
|
-
case 62:
|
|
246
|
-
return _context.abrupt("return");
|
|
247
|
-
case 63:
|
|
248
|
-
this.App.removeSplashScreenRequestor(this);
|
|
249
|
-
case 64:
|
|
250
|
-
case "end":
|
|
251
|
-
return _context.stop();
|
|
146
|
+
var _force_login_prompt = false;
|
|
147
|
+
yield _this.Api.login(_this.RedirectURL, _force_login_prompt);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
252
150
|
}
|
|
253
|
-
}, _callee, this);
|
|
254
|
-
}));
|
|
255
|
-
function initialize() {
|
|
256
|
-
return _initialize.apply(this, arguments);
|
|
257
|
-
}
|
|
258
|
-
return initialize;
|
|
259
|
-
}()
|
|
260
|
-
}, {
|
|
261
|
-
key: "authInterceptor",
|
|
262
|
-
value: function authInterceptor() {
|
|
263
|
-
var _this2 = this;
|
|
264
|
-
var interceptor = function interceptor(config) {
|
|
265
|
-
config.headers['Authorization'] = 'Bearer ' + _this2.OAuthToken['access_token'];
|
|
266
|
-
return config;
|
|
267
|
-
};
|
|
268
|
-
return interceptor;
|
|
269
|
-
}
|
|
270
|
-
}, {
|
|
271
|
-
key: "webSocketAuthInterceptor",
|
|
272
|
-
value: function webSocketAuthInterceptor() {
|
|
273
|
-
return "access_token_".concat(this.OAuthToken['access_token']);
|
|
274
|
-
}
|
|
275
|
-
}, {
|
|
276
|
-
key: "simulateUserinfo",
|
|
277
|
-
value: function () {
|
|
278
|
-
var _simulateUserinfo = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(mock_userinfo) {
|
|
279
|
-
var mockParams, availableTenants;
|
|
280
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
281
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
282
|
-
case 0:
|
|
283
|
-
/*
|
|
284
|
-
This method takes parameters from wepack.dev.js settings
|
|
285
|
-
plugins: [
|
|
286
|
-
...
|
|
287
|
-
new webpack.DefinePlugin({
|
|
288
|
-
'MOCK_USERINFO': JSON.stringify({ // Inject mocked UserInfo object, this means the application will NOT require user authorization
|
|
289
|
-
"username": "johndev",
|
|
290
|
-
"email": "dev@dev.de",
|
|
291
|
-
"phone": "123456789",
|
|
292
|
-
"resources": ["authz:superuser"],
|
|
293
|
-
"roles": ["default/Admin"],
|
|
294
|
-
"sub": "devdb:dev:1abc2def3456",
|
|
295
|
-
"tenants": ["default"]
|
|
296
|
-
})
|
|
297
|
-
}),
|
|
298
|
-
...
|
|
299
|
-
],
|
|
300
|
-
*/
|
|
301
|
-
this.App.addAlert("warning", "ASABAuthModule|You are using MOCK_USERINFO!", 1, true);
|
|
302
|
-
mockParams = mock_userinfo;
|
|
303
|
-
if (mockParams.resources) {
|
|
304
|
-
mockParams["resources"] = Object.values(mockParams.resources);
|
|
305
|
-
}
|
|
306
|
-
if (mockParams.roles) {
|
|
307
|
-
mockParams["roles"] = Object.values(mockParams.roles);
|
|
308
|
-
}
|
|
309
|
-
if (mockParams.tenants) {
|
|
310
|
-
mockParams["tenants"] = Object.values(mockParams.tenants);
|
|
311
|
-
}
|
|
312
|
-
if (this.App.Store != null) {
|
|
313
|
-
this.App.Store.dispatch({
|
|
314
|
-
type: _actions.types.AUTH_USERINFO,
|
|
315
|
-
payload: mockParams
|
|
316
|
-
});
|
|
317
|
-
this.App.Store.dispatch({
|
|
318
|
-
type: _actions.types.AUTH_RESOURCES,
|
|
319
|
-
resources: mockParams["resources"]
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
151
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
152
|
+
// Validate resources of items and children in navigation (resource validation depends on tenant)
|
|
153
|
+
if (_this.App.Store && _this.App.Services.TenantService && _this.UserInfo !== null) {
|
|
154
|
+
var currentTenant = _this.App.Services.TenantService.getCurrentTenant();
|
|
155
|
+
var resources = _this.UserInfo.resources ? _this.UserInfo.resources[currentTenant] : [];
|
|
156
|
+
/*
|
|
157
|
+
When switching between tenants,
|
|
158
|
+
we need to force authorization to obtain
|
|
159
|
+
correct data (resources) for particular
|
|
160
|
+
tenant (this is unavailable until auth token is updated)
|
|
161
|
+
*/
|
|
162
|
+
if (resources == undefined) {
|
|
163
|
+
var _force_login_prompt2 = false;
|
|
164
|
+
yield _this.Api.login(_this.RedirectURL, _force_login_prompt2);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (_this.App.Store != null) {
|
|
168
|
+
_this.App.Store.dispatch({
|
|
169
|
+
type: _actions.types.AUTH_RESOURCES,
|
|
170
|
+
resources: resources
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
yield _this.validateNavigation();
|
|
174
|
+
}
|
|
175
|
+
if (_this.UserInfo != null) {
|
|
176
|
+
yield _this._startSessionExpirationValidation(); // Start session validation
|
|
334
177
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
178
|
+
}
|
|
179
|
+
if (_this.UserInfo == null && _this.MustAuthenticate) {
|
|
180
|
+
// TODO: force_login_prompt = true to break authentication failure loop
|
|
181
|
+
var _force_login_prompt3 = false;
|
|
182
|
+
yield _this.Api.login(_this.RedirectURL, _force_login_prompt3);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
_this.App.removeSplashScreenRequestor(_this);
|
|
187
|
+
})();
|
|
188
|
+
}
|
|
189
|
+
authInterceptor() {
|
|
190
|
+
var interceptor = config => {
|
|
191
|
+
config.headers['Authorization'] = 'Bearer ' + this.OAuthToken['access_token'];
|
|
192
|
+
return config;
|
|
193
|
+
};
|
|
194
|
+
return interceptor;
|
|
195
|
+
}
|
|
196
|
+
webSocketAuthInterceptor() {
|
|
197
|
+
return "access_token_".concat(this.OAuthToken['access_token']);
|
|
198
|
+
}
|
|
199
|
+
simulateUserinfo(mock_userinfo) {
|
|
200
|
+
var _this2 = this;
|
|
201
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
202
|
+
/*
|
|
203
|
+
This method takes parameters from wepack.dev.js settings
|
|
204
|
+
plugins: [
|
|
205
|
+
...
|
|
206
|
+
new webpack.DefinePlugin({
|
|
207
|
+
'MOCK_USERINFO': JSON.stringify({ // Inject mocked UserInfo object, this means the application will NOT require user authorization
|
|
208
|
+
"username": "johndev",
|
|
209
|
+
"email": "dev@dev.de",
|
|
210
|
+
"phone": "123456789",
|
|
211
|
+
"resources": ["authz:superuser"],
|
|
212
|
+
"roles": ["default/Admin"],
|
|
213
|
+
"sub": "devdb:dev:1abc2def3456",
|
|
214
|
+
"tenants": ["default"]
|
|
215
|
+
})
|
|
216
|
+
}),
|
|
217
|
+
...
|
|
218
|
+
],
|
|
219
|
+
*/
|
|
220
|
+
_this2.App.addAlert("warning", "ASABAuthModule|You are using MOCK_USERINFO!", 1, true);
|
|
221
|
+
var mockParams = mock_userinfo;
|
|
222
|
+
if (mockParams.resources) {
|
|
223
|
+
mockParams["resources"] = Object.values(mockParams.resources);
|
|
224
|
+
}
|
|
225
|
+
if (mockParams.roles) {
|
|
226
|
+
mockParams["roles"] = Object.values(mockParams.roles);
|
|
227
|
+
}
|
|
228
|
+
if (mockParams.tenants) {
|
|
229
|
+
mockParams["tenants"] = Object.values(mockParams.tenants);
|
|
230
|
+
}
|
|
231
|
+
if (_this2.App.Store != null) {
|
|
232
|
+
_this2.App.Store.dispatch({
|
|
233
|
+
type: _actions.types.AUTH_USERINFO,
|
|
234
|
+
payload: mockParams
|
|
235
|
+
});
|
|
236
|
+
_this2.App.Store.dispatch({
|
|
237
|
+
type: _actions.types.AUTH_RESOURCES,
|
|
238
|
+
resources: mockParams["resources"]
|
|
239
|
+
});
|
|
339
240
|
}
|
|
340
|
-
return simulateUserinfo;
|
|
341
|
-
}()
|
|
342
|
-
}, {
|
|
343
|
-
key: "logout",
|
|
344
|
-
value: function logout() {
|
|
345
|
-
this.App.addSplashScreenRequestor(this);
|
|
346
|
-
this._stopSessionExpirationValidation(); // Stop session validation and clear the timeout
|
|
347
241
|
|
|
348
|
-
|
|
349
|
-
var
|
|
350
|
-
if (
|
|
351
|
-
|
|
242
|
+
/** Check for TenantService and pass tenants list obtained from userinfo */
|
|
243
|
+
var availableTenants = mockParams.tenants;
|
|
244
|
+
if (_this2.App.Services.TenantService) {
|
|
245
|
+
yield _this2.App.Services.TenantService.setTenants(availableTenants, _this2._getAuthorizedTenant(mockParams));
|
|
352
246
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
247
|
+
})();
|
|
248
|
+
}
|
|
249
|
+
logout() {
|
|
250
|
+
this.App.addSplashScreenRequestor(this);
|
|
251
|
+
this._stopSessionExpirationValidation(); // Stop session validation and clear the timeout
|
|
252
|
+
|
|
253
|
+
sessionStorage.removeItem('SeaCatOAuth2Token');
|
|
254
|
+
var promise = this.Api.logout(this.OAuthToken['access_token']);
|
|
255
|
+
if (promise == null) {
|
|
256
|
+
window.location.reload();
|
|
358
257
|
}
|
|
258
|
+
promise.then(response => {
|
|
259
|
+
window.location.reload();
|
|
260
|
+
}).catch(error => {
|
|
261
|
+
window.location.reload();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
359
264
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
var
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
_context4.next = 8;
|
|
379
|
-
break;
|
|
265
|
+
// TODO: reconsider removing async/await with promise
|
|
266
|
+
validateNavigation() {
|
|
267
|
+
var _this3 = this;
|
|
268
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
269
|
+
var _state$navigation, _state$auth;
|
|
270
|
+
var state = _this3.App.Store.getState();
|
|
271
|
+
var navItems = (_state$navigation = state.navigation) === null || _state$navigation === void 0 ? void 0 : _state$navigation.navItems;
|
|
272
|
+
var resources = (_state$auth = state.auth) === null || _state$auth === void 0 ? void 0 : _state$auth.resources;
|
|
273
|
+
var authorizedNavItems = [];
|
|
274
|
+
navItems && (yield Promise.all(navItems.map(/*#__PURE__*/function () {
|
|
275
|
+
var _ref = (0, _asyncToGenerator2.default)(function* (itm, idx) {
|
|
276
|
+
if (resources.indexOf('authz:superuser') !== -1) {
|
|
277
|
+
// If user is superuser, validate every navigation item
|
|
278
|
+
authorizedNavItems.push(itm);
|
|
279
|
+
} else {
|
|
280
|
+
if (itm.resource) {
|
|
281
|
+
if (itm.children) {
|
|
282
|
+
itm.children = yield _this3._validateChildrenNav(itm, resources);
|
|
380
283
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
_context3.next = 18;
|
|
395
|
-
break;
|
|
396
|
-
case 4:
|
|
397
|
-
if (!itm.resource) {
|
|
398
|
-
_context3.next = 13;
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
if (!itm.children) {
|
|
402
|
-
_context3.next = 9;
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
_context3.next = 8;
|
|
406
|
-
return _this3._validateChildrenNav(itm, resources);
|
|
407
|
-
case 8:
|
|
408
|
-
itm.children = _context3.sent;
|
|
409
|
-
case 9:
|
|
410
|
-
// Item validation
|
|
411
|
-
access_auth = _this3._validateItemNav(itm.resource, resources);
|
|
412
|
-
if (access_auth == true) {
|
|
413
|
-
authorizedNavItems.push(itm);
|
|
414
|
-
}
|
|
415
|
-
_context3.next = 18;
|
|
416
|
-
break;
|
|
417
|
-
case 13:
|
|
418
|
-
if (!itm.children) {
|
|
419
|
-
_context3.next = 18;
|
|
420
|
-
break;
|
|
421
|
-
}
|
|
422
|
-
_context3.next = 16;
|
|
423
|
-
return _this3._validateChildrenNav(itm, resources);
|
|
424
|
-
case 16:
|
|
425
|
-
itm.children = _context3.sent;
|
|
426
|
-
if (itm.children.length > 0) {
|
|
427
|
-
authorizedNavItems.push(itm);
|
|
428
|
-
}
|
|
429
|
-
case 18:
|
|
430
|
-
case "end":
|
|
431
|
-
return _context3.stop();
|
|
432
|
-
}
|
|
433
|
-
}, _callee3);
|
|
434
|
-
}));
|
|
435
|
-
return function (_x2, _x3) {
|
|
436
|
-
return _ref.apply(this, arguments);
|
|
437
|
-
};
|
|
438
|
-
}()));
|
|
439
|
-
case 8:
|
|
440
|
-
this.App.Store.dispatch({
|
|
441
|
-
type: _actions2.SET_NAVIGATION_ITEMS,
|
|
442
|
-
navItems: authorizedNavItems
|
|
443
|
-
});
|
|
444
|
-
case 9:
|
|
445
|
-
case "end":
|
|
446
|
-
return _context4.stop();
|
|
284
|
+
// Item validation
|
|
285
|
+
var access_auth = _this3._validateItemNav(itm.resource, resources);
|
|
286
|
+
if (access_auth == true) {
|
|
287
|
+
authorizedNavItems.push(itm);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
if (itm.children) {
|
|
291
|
+
itm.children = yield _this3._validateChildrenNav(itm, resources);
|
|
292
|
+
if (itm.children.length > 0) {
|
|
293
|
+
authorizedNavItems.push(itm);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
447
297
|
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (child.resource) {
|
|
474
|
-
access_auth = _this4._validateItemNav(child.resource, resources);
|
|
475
|
-
if (access_auth == true) {
|
|
476
|
-
authorizedNavChildren.push(child);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
case 1:
|
|
480
|
-
case "end":
|
|
481
|
-
return _context5.stop();
|
|
482
|
-
}
|
|
483
|
-
}, _callee5);
|
|
484
|
-
}));
|
|
485
|
-
return function (_x6, _x7) {
|
|
486
|
-
return _ref2.apply(this, arguments);
|
|
487
|
-
};
|
|
488
|
-
}()));
|
|
489
|
-
case 3:
|
|
490
|
-
return _context6.abrupt("return", authorizedNavChildren);
|
|
491
|
-
case 4:
|
|
492
|
-
case "end":
|
|
493
|
-
return _context6.stop();
|
|
298
|
+
});
|
|
299
|
+
return function (_x, _x2) {
|
|
300
|
+
return _ref.apply(this, arguments);
|
|
301
|
+
};
|
|
302
|
+
}())));
|
|
303
|
+
_this3.App.Store.dispatch({
|
|
304
|
+
type: _actions2.SET_NAVIGATION_ITEMS,
|
|
305
|
+
navItems: authorizedNavItems
|
|
306
|
+
});
|
|
307
|
+
})();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Validate sidebar's item children
|
|
311
|
+
_validateChildrenNav(itm, resources) {
|
|
312
|
+
var _this4 = this;
|
|
313
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
314
|
+
// Item's children validation
|
|
315
|
+
var authorizedNavChildren = [];
|
|
316
|
+
yield Promise.all(itm.children.map(/*#__PURE__*/function () {
|
|
317
|
+
var _ref2 = (0, _asyncToGenerator2.default)(function* (child, id) {
|
|
318
|
+
if (child.resource) {
|
|
319
|
+
var access_auth = _this4._validateItemNav(child.resource, resources);
|
|
320
|
+
if (access_auth == true) {
|
|
321
|
+
authorizedNavChildren.push(child);
|
|
322
|
+
}
|
|
494
323
|
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
return
|
|
501
|
-
}()
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return valid;
|
|
324
|
+
});
|
|
325
|
+
return function (_x3, _x4) {
|
|
326
|
+
return _ref2.apply(this, arguments);
|
|
327
|
+
};
|
|
328
|
+
}()));
|
|
329
|
+
return authorizedNavChildren;
|
|
330
|
+
})();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Validate sidebar items
|
|
334
|
+
_validateItemNav(resource, resources) {
|
|
335
|
+
var valid = resources ? resources.indexOf(resource) !== -1 : false;
|
|
336
|
+
// If user is superuser, then item is enabled
|
|
337
|
+
if (resources.indexOf('authz:superuser') !== -1) {
|
|
338
|
+
valid = true;
|
|
511
339
|
}
|
|
340
|
+
return valid;
|
|
341
|
+
}
|
|
512
342
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
343
|
+
// Validate tenant access
|
|
344
|
+
validateTenant() {
|
|
345
|
+
var resources = [];
|
|
346
|
+
var tenants = [];
|
|
347
|
+
var currentTenant = this.App.Services.TenantService.getCurrentTenant();
|
|
348
|
+
if (this.UserInfo !== null) {
|
|
349
|
+
resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
|
|
350
|
+
tenants = this.UserInfo.tenants ? this.UserInfo.tenants : [];
|
|
351
|
+
}
|
|
352
|
+
var valid = tenants ? tenants.indexOf(currentTenant) !== -1 : false;
|
|
353
|
+
// If user is superuser, then tenant access is granted
|
|
354
|
+
if (resources && resources.indexOf('authz:superuser') !== -1) {
|
|
355
|
+
valid = true;
|
|
356
|
+
}
|
|
357
|
+
return valid;
|
|
358
|
+
}
|
|
359
|
+
updateUserInfo() {
|
|
360
|
+
var _this5 = this;
|
|
361
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
362
|
+
var _response$data;
|
|
363
|
+
var response;
|
|
364
|
+
try {
|
|
365
|
+
response = yield _this5.Api.userinfo(_this5.OAuthToken.access_token);
|
|
366
|
+
} catch (err) {
|
|
367
|
+
console.error("Failed to update user info", err);
|
|
368
|
+
_this5.UserInfo = null;
|
|
369
|
+
if (_this5.App.Store != null) {
|
|
370
|
+
_this5.App.Store.dispatch({
|
|
371
|
+
type: _actions.types.AUTH_USERINFO,
|
|
372
|
+
payload: _this5.UserInfo
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
523
376
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
|
|
377
|
+
_this5.UserInfo = response.data;
|
|
378
|
+
_this5.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
|
|
379
|
+
if (_this5.App.Store != null) {
|
|
380
|
+
_this5.App.Store.dispatch({
|
|
381
|
+
type: _actions.types.AUTH_USERINFO,
|
|
382
|
+
payload: _this5.UserInfo
|
|
383
|
+
});
|
|
528
384
|
}
|
|
529
|
-
return valid;
|
|
530
|
-
}
|
|
531
|
-
}, {
|
|
532
|
-
key: "updateUserInfo",
|
|
533
|
-
value: function () {
|
|
534
|
-
var _updateUserInfo = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
535
|
-
var _response$data;
|
|
536
|
-
var response, availableTenants;
|
|
537
|
-
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
538
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
539
|
-
case 0:
|
|
540
|
-
_context7.prev = 0;
|
|
541
|
-
_context7.next = 3;
|
|
542
|
-
return this.Api.userinfo(this.OAuthToken.access_token);
|
|
543
|
-
case 3:
|
|
544
|
-
response = _context7.sent;
|
|
545
|
-
_context7.next = 12;
|
|
546
|
-
break;
|
|
547
|
-
case 6:
|
|
548
|
-
_context7.prev = 6;
|
|
549
|
-
_context7.t0 = _context7["catch"](0);
|
|
550
|
-
console.error("Failed to update user info", _context7.t0);
|
|
551
|
-
this.UserInfo = null;
|
|
552
|
-
if (this.App.Store != null) {
|
|
553
|
-
this.App.Store.dispatch({
|
|
554
|
-
type: _actions.types.AUTH_USERINFO,
|
|
555
|
-
payload: this.UserInfo
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
return _context7.abrupt("return", false);
|
|
559
|
-
case 12:
|
|
560
|
-
this.UserInfo = response.data;
|
|
561
|
-
this.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
|
|
562
|
-
if (this.App.Store != null) {
|
|
563
|
-
this.App.Store.dispatch({
|
|
564
|
-
type: _actions.types.AUTH_USERINFO,
|
|
565
|
-
payload: this.UserInfo
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
385
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
_context7.next = 19;
|
|
576
|
-
return this.App.Services.TenantService.setTenants(availableTenants, this._getAuthorizedTenant(this.UserInfo));
|
|
577
|
-
case 19:
|
|
578
|
-
return _context7.abrupt("return", true);
|
|
579
|
-
case 20:
|
|
580
|
-
case "end":
|
|
581
|
-
return _context7.stop();
|
|
582
|
-
}
|
|
583
|
-
}, _callee7, this, [[0, 6]]);
|
|
584
|
-
}));
|
|
585
|
-
function updateUserInfo() {
|
|
586
|
-
return _updateUserInfo.apply(this, arguments);
|
|
386
|
+
/** Check for TenantService and pass tenants list obtained from userinfo */
|
|
387
|
+
var availableTenants = _this5.UserInfo.tenants;
|
|
388
|
+
if (_this5.App.Services.TenantService) {
|
|
389
|
+
yield _this5.App.Services.TenantService.setTenants(availableTenants, _this5._getAuthorizedTenant(_this5.UserInfo));
|
|
587
390
|
}
|
|
588
|
-
return
|
|
589
|
-
}()
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return this.Api.token_authorization_code(authorization_code, this.RedirectURL);
|
|
601
|
-
case 3:
|
|
602
|
-
response = _context8.sent;
|
|
603
|
-
_context8.next = 10;
|
|
604
|
-
break;
|
|
605
|
-
case 6:
|
|
606
|
-
_context8.prev = 6;
|
|
607
|
-
_context8.t0 = _context8["catch"](0);
|
|
608
|
-
console.error("Failed to update token", _context8.t0);
|
|
609
|
-
return _context8.abrupt("return", false);
|
|
610
|
-
case 10:
|
|
611
|
-
this.OAuthToken = response.data;
|
|
612
|
-
sessionStorage.setItem('SeaCatOAuth2Token', JSON.stringify(response.data));
|
|
613
|
-
return _context8.abrupt("return", true);
|
|
614
|
-
case 13:
|
|
615
|
-
case "end":
|
|
616
|
-
return _context8.stop();
|
|
617
|
-
}
|
|
618
|
-
}, _callee8, this, [[0, 6]]);
|
|
619
|
-
}));
|
|
620
|
-
function _updateToken(_x8) {
|
|
621
|
-
return _updateToken2.apply(this, arguments);
|
|
391
|
+
return true;
|
|
392
|
+
})();
|
|
393
|
+
}
|
|
394
|
+
_updateToken(authorization_code) {
|
|
395
|
+
var _this6 = this;
|
|
396
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
397
|
+
var response;
|
|
398
|
+
try {
|
|
399
|
+
response = yield _this6.Api.token_authorization_code(authorization_code, _this6.RedirectURL);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
console.error("Failed to update token", err);
|
|
402
|
+
return false;
|
|
622
403
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
404
|
+
_this6.OAuthToken = response.data;
|
|
405
|
+
sessionStorage.setItem('SeaCatOAuth2Token', JSON.stringify(response.data));
|
|
406
|
+
return true;
|
|
407
|
+
})();
|
|
408
|
+
}
|
|
409
|
+
_getAuthorizedTenant(userInfo) {
|
|
410
|
+
/*
|
|
411
|
+
Return the authorized tenant ID from userinfo.
|
|
412
|
+
Pick the first one if there are multiple tenants.
|
|
413
|
+
*/
|
|
414
|
+
if (userInfo !== null && userInfo !== void 0 && userInfo.resources) {
|
|
415
|
+
for (var tenantId in userInfo.resources) {
|
|
416
|
+
if (tenantId != '*' && userInfo.resources.hasOwnProperty(tenantId)) {
|
|
417
|
+
return tenantId;
|
|
637
418
|
}
|
|
638
|
-
} else {
|
|
639
|
-
return undefined;
|
|
640
419
|
}
|
|
420
|
+
} else {
|
|
421
|
+
return undefined;
|
|
641
422
|
}
|
|
423
|
+
}
|
|
642
424
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9() {
|
|
663
|
-
var currentTime, timeRemaining, isUserInfoUpdated;
|
|
664
|
-
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
665
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
666
|
-
case 0:
|
|
667
|
-
currentTime = Date.now() / 1000; // Convert milliseconds to seconds
|
|
668
|
-
timeRemaining = _this5.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
|
|
669
|
-
// Prevent glitches on very large time remaining values
|
|
670
|
-
if (timeRemaining >= Math.pow(2, 31)) {
|
|
671
|
-
// Set timeout to maximum allowed value
|
|
672
|
-
timeRemaining = Math.pow(2, 31) - 1;
|
|
673
|
-
}
|
|
425
|
+
// Loop validating session expiration
|
|
426
|
+
_startSessionExpirationValidation() {
|
|
427
|
+
var _this7 = this;
|
|
428
|
+
return (0, _asyncToGenerator2.default)(function* () {
|
|
429
|
+
if (!_this7.SessionExpiration) {
|
|
430
|
+
console.warn("Session expiration is not set.");
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
var warningDisplayed = false; // Tracks if the "about to expire" warning has been shown
|
|
434
|
+
|
|
435
|
+
var _validateSession = /*#__PURE__*/function () {
|
|
436
|
+
var _ref3 = (0, _asyncToGenerator2.default)(function* () {
|
|
437
|
+
var currentTime = Date.now() / 1000; // Convert milliseconds to seconds
|
|
438
|
+
var timeRemaining = _this7.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
|
|
439
|
+
// Prevent glitches on very large time remaining values
|
|
440
|
+
if (timeRemaining >= Math.pow(2, 31)) {
|
|
441
|
+
// Set timeout to maximum allowed value
|
|
442
|
+
timeRemaining = Math.pow(2, 31) - 1;
|
|
443
|
+
}
|
|
674
444
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
_this5.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, function (alert, store) {
|
|
703
|
-
return /*#__PURE__*/_react["default"].createElement(_SessionExpirationAlert.SessionExpirationAlert, {
|
|
704
|
-
alert: alert,
|
|
705
|
-
store: store
|
|
706
|
-
});
|
|
707
|
-
});
|
|
708
|
-
// Disable UI elements
|
|
709
|
-
if (_this5.App.Store) {
|
|
710
|
-
_this5.App.Store.dispatch({
|
|
711
|
-
type: _actions.types.AUTH_SESSION_EXPIRATION,
|
|
712
|
-
sessionExpired: true
|
|
713
|
-
});
|
|
445
|
+
// If remaining time is between 1 and 60s, repetitivelly ask for userInfo and trigger "about to expire" warning
|
|
446
|
+
if (timeRemaining <= 60 && timeRemaining > 0) {
|
|
447
|
+
if (!warningDisplayed) {
|
|
448
|
+
_this7.App.addAlert("info", "General|Your session will expire soon", 30, true);
|
|
449
|
+
warningDisplayed = true; // Mark the warning as displayed
|
|
450
|
+
}
|
|
451
|
+
yield _this7.updateUserInfo(); // Continue updating user info
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Validation on expired session
|
|
455
|
+
if (_this7.SessionExpiration <= currentTime) {
|
|
456
|
+
// Handle session expiration
|
|
457
|
+
var isUserInfoUpdated = yield _this7.updateUserInfo();
|
|
458
|
+
if (!isUserInfoUpdated) {
|
|
459
|
+
// Stop further checks
|
|
460
|
+
clearTimeout(_this7.sessionValidationInterval);
|
|
461
|
+
_this7.sessionValidationInterval = null;
|
|
462
|
+
_this7.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, (alert, store) => /*#__PURE__*/_react.default.createElement(_SessionExpirationAlert.SessionExpirationAlert, {
|
|
463
|
+
alert: alert,
|
|
464
|
+
store: store
|
|
465
|
+
}));
|
|
466
|
+
// Disable UI elements
|
|
467
|
+
if (_this7.App.Store) {
|
|
468
|
+
_this7.App.Store.dispatch({
|
|
469
|
+
type: _actions.types.AUTH_SESSION_EXPIRATION,
|
|
470
|
+
sessionExpired: true
|
|
471
|
+
});
|
|
714
472
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
473
|
+
// Disable UI elements
|
|
474
|
+
[...document.querySelectorAll('#app-sidebar .nav-link, [class^="btn"]:not(.alert-button), [class*=" btn"]:not(.alert-button), .btn-group a, .page-item, input, select')].forEach(i => {
|
|
475
|
+
i.classList.add("disabled");
|
|
476
|
+
i.setAttribute("disabled", "");
|
|
477
|
+
});
|
|
720
478
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
// Re-trigger validation after 10 seconds
|
|
729
|
-
_this5.sessionValidationInterval = setTimeout(_validateSession, 10000);
|
|
730
|
-
case 18:
|
|
731
|
-
case "end":
|
|
732
|
-
return _context9.stop();
|
|
733
|
-
}
|
|
734
|
-
}, _callee9);
|
|
735
|
-
}));
|
|
736
|
-
return function validateSession() {
|
|
737
|
-
return _ref3.apply(this, arguments);
|
|
738
|
-
};
|
|
739
|
-
}(); // Start the first validation cycle
|
|
740
|
-
_validateSession();
|
|
741
|
-
case 6:
|
|
742
|
-
case "end":
|
|
743
|
-
return _context10.stop();
|
|
479
|
+
// Reload on navigation actions
|
|
480
|
+
window.addEventListener("popstate", () => {
|
|
481
|
+
window.location.reload();
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
744
486
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
487
|
+
|
|
488
|
+
// Re-trigger validation after 10 seconds
|
|
489
|
+
_this7.sessionValidationInterval = setTimeout(_validateSession, 10000);
|
|
490
|
+
});
|
|
491
|
+
return function validateSession() {
|
|
492
|
+
return _ref3.apply(this, arguments);
|
|
493
|
+
};
|
|
494
|
+
}();
|
|
495
|
+
|
|
496
|
+
// Start the first validation cycle
|
|
497
|
+
_validateSession();
|
|
498
|
+
})();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Stop looping on session expiration validation
|
|
502
|
+
_stopSessionExpirationValidation() {
|
|
503
|
+
if (this.sessionValidationInterval) {
|
|
504
|
+
clearInterval(this.sessionValidationInterval);
|
|
505
|
+
this.sessionValidationInterval = null;
|
|
759
506
|
}
|
|
760
|
-
}
|
|
761
|
-
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
exports.default = AuthModule;
|