@beinformed/ui 1.18.3 → 1.18.4
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/CHANGELOG.md +6 -0
- package/esm/constants/Constants.js +1 -0
- package/esm/constants/Constants.js.map +1 -1
- package/esm/constants/Settings.js +10 -3
- package/esm/constants/Settings.js.map +1 -1
- package/esm/models/form/FormModel.js +3 -1
- package/esm/models/form/FormModel.js.map +1 -1
- package/esm/modularui/Authenticate.js +98 -20
- package/esm/modularui/Authenticate.js.map +1 -1
- package/esm/redux/actions/Preferences.js +2 -2
- package/esm/redux/actions/Preferences.js.map +1 -1
- package/lib/constants/Constants.js +3 -1
- package/lib/constants/Constants.js.flow +1 -0
- package/lib/constants/Constants.js.map +1 -1
- package/lib/constants/Settings.js +13 -3
- package/lib/constants/Settings.js.flow +8 -3
- package/lib/constants/Settings.js.map +1 -1
- package/lib/models/form/FormModel.js +3 -1
- package/lib/models/form/FormModel.js.flow +1 -1
- package/lib/models/form/FormModel.js.map +1 -1
- package/lib/modularui/Authenticate.js +99 -20
- package/lib/modularui/Authenticate.js.flow +72 -18
- package/lib/modularui/Authenticate.js.map +1 -1
- package/lib/react-server/__tests__/serverUtil.spec.js.flow +6 -4
- package/lib/redux/actions/Preferences.js +1 -1
- package/lib/redux/actions/Preferences.js.flow +7 -3
- package/lib/redux/actions/Preferences.js.map +1 -1
- package/package.json +6 -6
- package/src/constants/Constants.js +1 -0
- package/src/constants/Settings.js +8 -3
- package/src/models/form/FormModel.js +1 -1
- package/src/modularui/Authenticate.js +72 -18
- package/src/react-server/__tests__/serverUtil.spec.js +6 -4
- package/src/redux/actions/Preferences.js +7 -3
|
@@ -112,10 +112,11 @@ describe("serverUtil", () => {
|
|
|
112
112
|
{
|
|
113
113
|
type: "SET_PREFERENCES",
|
|
114
114
|
payload: {
|
|
115
|
-
"FormClient.login_url": "/
|
|
116
|
-
"FormClient.logout_url": "/
|
|
115
|
+
"FormClient.login_url": "/j_security_check",
|
|
116
|
+
"FormClient.logout_url": "/Logoff",
|
|
117
117
|
"FormClient.password_field_name": "j_password",
|
|
118
118
|
"FormClient.username_field_name": "j_username",
|
|
119
|
+
"security.clients": null,
|
|
119
120
|
},
|
|
120
121
|
},
|
|
121
122
|
]);
|
|
@@ -158,10 +159,11 @@ describe("serverUtil", () => {
|
|
|
158
159
|
{
|
|
159
160
|
type: "SET_PREFERENCES",
|
|
160
161
|
payload: {
|
|
161
|
-
"FormClient.login_url": "/
|
|
162
|
-
"FormClient.logout_url": "/
|
|
162
|
+
"FormClient.login_url": "/j_security_check",
|
|
163
|
+
"FormClient.logout_url": "/Logoff",
|
|
163
164
|
"FormClient.password_field_name": "j_password",
|
|
164
165
|
"FormClient.username_field_name": "j_username",
|
|
166
|
+
"security.clients": null,
|
|
165
167
|
},
|
|
166
168
|
},
|
|
167
169
|
]);
|
|
@@ -147,7 +147,7 @@ exports.setAllContentInDataSetting = setAllContentInDataSetting;
|
|
|
147
147
|
var setLoginPreferences = function setLoginPreferences(state) {
|
|
148
148
|
var _state$preferences$LO, _state$preferences$LO2, _state$preferences$LO3, _state$preferences$LO4, _loginSettings;
|
|
149
149
|
|
|
150
|
-
var loginSettings = (_loginSettings = {}, (0, _defineProperty2.default)(_loginSettings, _constants.LOGIN_PATH_SETTING, getServerPreferenceValue(_constants.LOGIN_PATH_SETTING, (_state$preferences$LO = state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGIN_PATH_SETTING]) !== null && _state$preferences$LO !== void 0 ? _state$preferences$LO : "
|
|
150
|
+
var loginSettings = (_loginSettings = {}, (0, _defineProperty2.default)(_loginSettings, _constants.LOGIN_TYPE, getServerPreferenceValue(_constants.LOGIN_TYPE, state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGIN_TYPE])), (0, _defineProperty2.default)(_loginSettings, _constants.LOGIN_PATH_SETTING, getServerPreferenceValue(_constants.LOGIN_PATH_SETTING, (_state$preferences$LO = state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGIN_PATH_SETTING]) !== null && _state$preferences$LO !== void 0 ? _state$preferences$LO : "/j_security_check")), (0, _defineProperty2.default)(_loginSettings, _constants.LOGIN_USERNAME_SETTING, getServerPreferenceValue(_constants.LOGIN_USERNAME_SETTING, (_state$preferences$LO2 = state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGIN_USERNAME_SETTING]) !== null && _state$preferences$LO2 !== void 0 ? _state$preferences$LO2 : "j_username")), (0, _defineProperty2.default)(_loginSettings, _constants.LOGIN_PASSWORD_SETTING, getServerPreferenceValue(_constants.LOGIN_PASSWORD_SETTING, (_state$preferences$LO3 = state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGIN_PASSWORD_SETTING]) !== null && _state$preferences$LO3 !== void 0 ? _state$preferences$LO3 : "j_password")), (0, _defineProperty2.default)(_loginSettings, _constants.LOGOUT_PATH_SETTING, getServerPreferenceValue(_constants.LOGOUT_PATH_SETTING, (_state$preferences$LO4 = state === null || state === void 0 ? void 0 : state.preferences[_constants.LOGOUT_PATH_SETTING]) !== null && _state$preferences$LO4 !== void 0 ? _state$preferences$LO4 : "/Logoff")), _loginSettings);
|
|
151
151
|
(0, _Settings.setSettings)(loginSettings);
|
|
152
152
|
return setPreferences(loginSettings);
|
|
153
153
|
};
|
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
} from "../types";
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
-
BASE,
|
|
16
15
|
ALL_CONTENT_IN_DATA_SETTING,
|
|
16
|
+
LOGIN_TYPE,
|
|
17
17
|
LOGIN_PASSWORD_SETTING,
|
|
18
18
|
LOGIN_PATH_SETTING,
|
|
19
19
|
LOGIN_USERNAME_SETTING,
|
|
@@ -123,9 +123,13 @@ export const setLoginPreferences = (
|
|
|
123
123
|
state?: ReduxState
|
|
124
124
|
): SetPreferencesAction => {
|
|
125
125
|
const loginSettings = {
|
|
126
|
+
[LOGIN_TYPE]: getServerPreferenceValue(
|
|
127
|
+
LOGIN_TYPE,
|
|
128
|
+
state?.preferences[LOGIN_TYPE]
|
|
129
|
+
),
|
|
126
130
|
[LOGIN_PATH_SETTING]: getServerPreferenceValue(
|
|
127
131
|
LOGIN_PATH_SETTING,
|
|
128
|
-
state?.preferences[LOGIN_PATH_SETTING] ??
|
|
132
|
+
state?.preferences[LOGIN_PATH_SETTING] ?? `/j_security_check`
|
|
129
133
|
),
|
|
130
134
|
[LOGIN_USERNAME_SETTING]: getServerPreferenceValue(
|
|
131
135
|
LOGIN_USERNAME_SETTING,
|
|
@@ -137,7 +141,7 @@ export const setLoginPreferences = (
|
|
|
137
141
|
),
|
|
138
142
|
[LOGOUT_PATH_SETTING]: getServerPreferenceValue(
|
|
139
143
|
LOGOUT_PATH_SETTING,
|
|
140
|
-
state?.preferences[LOGOUT_PATH_SETTING] ??
|
|
144
|
+
state?.preferences[LOGOUT_PATH_SETTING] ?? `/Logoff`
|
|
141
145
|
),
|
|
142
146
|
};
|
|
143
147
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Preferences.js","names":["getServerPreferenceValue","preferenceName","defaultValue","type","value","preferencesProvider","getPreferenceByName","split","val","setServerPreference","propertyName","setPreference","propertyValue","payload","setPreferences","preferences","setThemePreference","configTheme","themeData","JSON","parse","error","JsonParseException","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","ALL_CONTENT_IN_DATA_SETTING","setLoginPreferences","loginSettings","
|
|
1
|
+
{"version":3,"file":"Preferences.js","names":["getServerPreferenceValue","preferenceName","defaultValue","type","value","preferencesProvider","getPreferenceByName","split","val","setServerPreference","propertyName","setPreference","propertyValue","payload","setPreferences","preferences","setThemePreference","configTheme","themeData","JSON","parse","error","JsonParseException","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","ALL_CONTENT_IN_DATA_SETTING","setLoginPreferences","loginSettings","LOGIN_TYPE","LOGIN_PATH_SETTING","LOGIN_USERNAME_SETTING","LOGIN_PASSWORD_SETTING","LOGOUT_PATH_SETTING"],"sources":["../../../src/redux/actions/Preferences.js"],"sourcesContent":["// @flow\nimport { isPlainObject } from \"../../utils/helpers/objects\";\n\nimport { JsonParseException } from \"../../exceptions\";\nimport { setSetting, setSettings } from \"../../constants/Settings\";\n\nimport type {\n PreferenceValue,\n ReduxState,\n SetPreferenceAction,\n SetPreferencesAction,\n} from \"../types\";\n\nimport {\n ALL_CONTENT_IN_DATA_SETTING,\n LOGIN_TYPE,\n LOGIN_PASSWORD_SETTING,\n LOGIN_PATH_SETTING,\n LOGIN_USERNAME_SETTING,\n LOGOUT_PATH_SETTING,\n} from \"../../constants\";\n\n/**\n */\nconst getServerPreferenceValue = (\n preferenceName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n) => {\n let value = null;\n if (typeof preferencesProvider !== \"undefined\") {\n value = preferencesProvider.getPreferenceByName(preferenceName);\n }\n\n if (value == null) {\n value = defaultValue;\n }\n\n if (typeof value === \"string\" && type !== \"string\" && value.includes(\",\")) {\n value = value.split(\",\").map((val) => val.trim());\n }\n\n return value;\n};\n\n/**\n */\nexport const setServerPreference = (\n propertyName: string,\n defaultValue: PreferenceValue = null,\n type?: string\n): SetPreferenceAction => {\n const value = getServerPreferenceValue(propertyName, defaultValue, type);\n return setPreference(propertyName, value);\n};\n\n/**\n */\nexport const setPreference = (\n propertyName: string,\n propertyValue: PreferenceValue = null\n): SetPreferenceAction => ({\n type: \"SET_PREFERENCE\",\n payload: {\n [propertyName]: propertyValue,\n },\n});\n\n/**\n */\nexport const setPreferences = (preferences: Object): SetPreferencesAction => ({\n type: \"SET_PREFERENCES\",\n payload: {\n ...preferences,\n },\n});\n\n/**\n */\nexport const setThemePreference = (\n configTheme: string\n): SetPreferenceAction => {\n let themeData = {};\n\n try {\n themeData = configTheme ? JSON.parse(configTheme) : null;\n } catch (error) {\n throw new JsonParseException(`Theme file contains invalid JSON: ${error}`);\n }\n\n if (themeData && isPlainObject(themeData)) {\n setSettings(themeData.settings);\n }\n\n return setPreference(\"theme\", themeData);\n};\n\n/**\n * Make modular-ui-content-in-data preference available client side\n */\nexport const setAllContentInDataSetting = (\n state?: ReduxState\n): SetPreferenceAction => {\n let allContentInDataSetting = false;\n\n if (\n typeof preferencesProvider !== \"undefined\" &&\n typeof preferencesProvider.getModularUIContentInData !== \"undefined\"\n ) {\n allContentInDataSetting = preferencesProvider.getModularUIContentInData();\n } else if (typeof state !== \"undefined\") {\n allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];\n }\n\n setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);\n return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);\n};\n\n/**\n * Retrieves login settings from runtime preferences and sets them as setting in the preference reducer\n */\nexport const setLoginPreferences = (\n state?: ReduxState\n): SetPreferencesAction => {\n const loginSettings = {\n [LOGIN_TYPE]: getServerPreferenceValue(\n LOGIN_TYPE,\n state?.preferences[LOGIN_TYPE]\n ),\n [LOGIN_PATH_SETTING]: getServerPreferenceValue(\n LOGIN_PATH_SETTING,\n state?.preferences[LOGIN_PATH_SETTING] ?? `/j_security_check`\n ),\n [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(\n LOGIN_USERNAME_SETTING,\n state?.preferences[LOGIN_USERNAME_SETTING] ?? \"j_username\"\n ),\n [LOGIN_PASSWORD_SETTING]: getServerPreferenceValue(\n LOGIN_PASSWORD_SETTING,\n state?.preferences[LOGIN_PASSWORD_SETTING] ?? \"j_password\"\n ),\n [LOGOUT_PATH_SETTING]: getServerPreferenceValue(\n LOGOUT_PATH_SETTING,\n state?.preferences[LOGOUT_PATH_SETTING] ?? `/Logoff`\n ),\n };\n\n setSettings(loginSettings);\n return setPreferences(loginSettings);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AACA;;AASA;;;;;;AASA;AACA;AACA,IAAMA,wBAAwB,GAAG,SAA3BA,wBAA2B,CAC/BC,cAD+B,EAI5B;EAAA,IAFHC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,EAKKhC,wBAAwB,CAC5CgC,6BAD4C,2BAE5CP,KAF4C,aAE5CA,KAF4C,uBAE5CA,KAAK,CAAEV,WAAP,CAAmBiB,6BAAnB,CAF4C,6FAL7B,iDAShBC,iCATgB,EASSjC,wBAAwB,CAChDiC,iCADgD,4BAEhDR,KAFgD,aAEhDA,KAFgD,uBAEhDA,KAAK,CAAEV,WAAP,CAAmBkB,iCAAnB,CAFgD,2EAEF,YAFE,CATjC,iDAahBC,iCAbgB,EAaSlC,wBAAwB,CAChDkC,iCADgD,4BAEhDT,KAFgD,aAEhDA,KAFgD,uBAEhDA,KAAK,CAAEV,WAAP,CAAmBmB,iCAAnB,CAFgD,2EAEF,YAFE,CAbjC,iDAiBhBC,8BAjBgB,EAiBMnC,wBAAwB,CAC7CmC,8BAD6C,4BAE7CV,KAF6C,aAE7CA,KAF6C,uBAE7CA,KAAK,CAAEV,WAAP,CAAmBoB,8BAAnB,CAF6C,qFAjB9B,kBAAnB;EAuBA,2BAAYL,aAAZ;EACA,OAAOhB,cAAc,CAACgB,aAAD,CAArB;AACD,CA5BM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.4",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -109,12 +109,12 @@
|
|
|
109
109
|
"@commitlint/config-conventional": "^16.2.4",
|
|
110
110
|
"@testing-library/react-hooks": "^8.0.0",
|
|
111
111
|
"auditjs": "^4.0.37",
|
|
112
|
-
"babel-jest": "^28.0
|
|
112
|
+
"babel-jest": "^28.1.0",
|
|
113
113
|
"babel-plugin-styled-components": "^2.0.7",
|
|
114
114
|
"cherry-pick": "^0.5.0",
|
|
115
115
|
"cross-env": "^7.0.3",
|
|
116
116
|
"documentation": "^13.2.5",
|
|
117
|
-
"eslint": "^8.
|
|
117
|
+
"eslint": "^8.15.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",
|
|
@@ -123,14 +123,14 @@
|
|
|
123
123
|
"eslint-plugin-jsdoc": "^39.2.9",
|
|
124
124
|
"eslint-plugin-react": "^7.28.0",
|
|
125
125
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
126
|
-
"flow-bin": "^0.
|
|
126
|
+
"flow-bin": "^0.178.0",
|
|
127
127
|
"flow-copy-source": "^2.0.9",
|
|
128
128
|
"flow-typed": "^3.6.1",
|
|
129
129
|
"glob": "^8.0.1",
|
|
130
130
|
"history": "^4.0.0",
|
|
131
131
|
"husky": "^7.0.4",
|
|
132
|
-
"jest": "^28.0
|
|
133
|
-
"jest-environment-jsdom": "^28.0
|
|
132
|
+
"jest": "^28.1.0",
|
|
133
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
134
134
|
"jest-junit": "^13.2.0",
|
|
135
135
|
"jest-sonar-reporter": "^2.0.0",
|
|
136
136
|
"jscodeshift": "^0.13.1",
|
|
@@ -198,6 +198,7 @@ export const ATTRIBUTE_WIDTH = {
|
|
|
198
198
|
|
|
199
199
|
export const ALL_CONTENT_IN_DATA_SETTING = "hasAllContentInData";
|
|
200
200
|
|
|
201
|
+
export const LOGIN_TYPE = "security.clients";
|
|
201
202
|
export const LOGIN_PATH_SETTING = "FormClient.login_url";
|
|
202
203
|
export const LOGIN_USERNAME_SETTING = "FormClient.username_field_name";
|
|
203
204
|
export const LOGIN_PASSWORD_SETTING = "FormClient.password_field_name";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { isPlainObject, has } from "../utils/helpers/objects";
|
|
3
3
|
import {
|
|
4
|
-
BASE,
|
|
5
4
|
ALL_CONTENT_IN_DATA_SETTING,
|
|
5
|
+
LOGIN_TYPE,
|
|
6
6
|
LOGIN_PATH_SETTING,
|
|
7
7
|
LOGIN_USERNAME_SETTING,
|
|
8
8
|
LOGIN_PASSWORD_SETTING,
|
|
@@ -123,10 +123,15 @@ export const allSettings = (): { [name: string]: Setting } => settings;
|
|
|
123
123
|
export const hasAllContentInData = (): boolean =>
|
|
124
124
|
getSetting(ALL_CONTENT_IN_DATA_SETTING, true);
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Login type, only available when pac4j is configured
|
|
128
|
+
*/
|
|
129
|
+
export const loginType = (): string => getSetting(LOGIN_TYPE, "JAAS");
|
|
130
|
+
|
|
126
131
|
/**
|
|
127
132
|
*/
|
|
128
133
|
export const loginPath = (): string =>
|
|
129
|
-
getSetting(LOGIN_PATH_SETTING,
|
|
134
|
+
getSetting(LOGIN_PATH_SETTING, "/j_security_check");
|
|
130
135
|
/**
|
|
131
136
|
*/
|
|
132
137
|
export const loginUsernameField = (): string =>
|
|
@@ -138,4 +143,4 @@ export const loginPasswordField = (): string =>
|
|
|
138
143
|
/**
|
|
139
144
|
*/
|
|
140
145
|
export const logoutPath = (): string =>
|
|
141
|
-
getSetting(LOGOUT_PATH_SETTING,
|
|
146
|
+
getSetting(LOGOUT_PATH_SETTING, "/Logoff");
|
|
@@ -5,10 +5,10 @@ import universalFetch from "../utils/fetch/universalFetch";
|
|
|
5
5
|
import Cache from "../utils/browser/Cache";
|
|
6
6
|
|
|
7
7
|
import { UnauthorizedException } from "../exceptions";
|
|
8
|
-
import type { RequestOptions } from "../utils/fetch/types";
|
|
9
8
|
import {
|
|
10
|
-
|
|
9
|
+
loginType,
|
|
11
10
|
loginPath,
|
|
11
|
+
loginPasswordField,
|
|
12
12
|
loginUsernameField,
|
|
13
13
|
logoutPath,
|
|
14
14
|
} from "../constants";
|
|
@@ -24,10 +24,27 @@ class Authenticate {
|
|
|
24
24
|
this._isBasic = false;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
*/
|
|
29
|
+
get authenticationType(): "JAAS" | "PAC4J_FORM" | "PAC4J_BASIC" {
|
|
30
|
+
const type = loginType();
|
|
31
|
+
|
|
32
|
+
if (!type || type === "JAAS") {
|
|
33
|
+
return "JAAS";
|
|
34
|
+
}
|
|
35
|
+
if (type.includes("FormClient")) {
|
|
36
|
+
return "PAC4J_FORM";
|
|
37
|
+
} else if (type.includes("BasicClient")) {
|
|
38
|
+
return "PAC4J_BASIC";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error(`Unsupported login type found: ${type}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
27
44
|
/**
|
|
28
45
|
*/
|
|
29
46
|
get isBasicAuthentication(): boolean {
|
|
30
|
-
return this._isBasic;
|
|
47
|
+
return this._isBasic || this.authenticationType === "PAC4J_BASIC";
|
|
31
48
|
}
|
|
32
49
|
|
|
33
50
|
/**
|
|
@@ -64,36 +81,73 @@ class Authenticate {
|
|
|
64
81
|
|
|
65
82
|
/**
|
|
66
83
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
login(username: string, password: string): Promise<any> {
|
|
85
|
+
switch (this.authenticationType) {
|
|
86
|
+
case "PAC4J_FORM":
|
|
87
|
+
return this.doFormLogin(username, password);
|
|
88
|
+
case "PAC4J_BASIC":
|
|
89
|
+
return this.doBasicAuthentication(username, password);
|
|
90
|
+
default:
|
|
91
|
+
return this.doJaasAuthentication(username, password);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*/
|
|
97
|
+
getFormLoginUrl(): string {
|
|
98
|
+
switch (this.authenticationType) {
|
|
99
|
+
case "PAC4J_BASIC":
|
|
100
|
+
case "PAC4J_FORM":
|
|
101
|
+
return `${BASE}${loginPath()}`;
|
|
102
|
+
default:
|
|
103
|
+
return `${BASE}/j_security_check`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
71
106
|
|
|
107
|
+
/**
|
|
108
|
+
*/
|
|
109
|
+
getFormLoginData(username: string, password: string): string {
|
|
72
110
|
const encodedUsername = encodeURIComponent(username);
|
|
73
111
|
const encodedPassword = encodeURIComponent(password);
|
|
74
112
|
|
|
75
|
-
|
|
76
|
-
|
|
113
|
+
switch (this.authenticationType) {
|
|
114
|
+
case "PAC4J_BASIC":
|
|
115
|
+
case "PAC4J_FORM":
|
|
116
|
+
return `${loginUsernameField()}=${encodedUsername}&${loginPasswordField()}=${encodedPassword}`;
|
|
117
|
+
default:
|
|
118
|
+
return `j_username=${encodedUsername}&j_password=${encodedPassword}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
*/
|
|
124
|
+
doFormLogin(username: string, password: string): Promise<any> {
|
|
125
|
+
return universalFetch({
|
|
126
|
+
url: this.getFormLoginUrl(),
|
|
77
127
|
method: HTTP_METHODS.POST,
|
|
78
128
|
headers: {
|
|
79
129
|
Accept: "application/json",
|
|
80
130
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
81
131
|
},
|
|
82
|
-
data:
|
|
83
|
-
};
|
|
132
|
+
data: this.getFormLoginData(username, password),
|
|
133
|
+
});
|
|
84
134
|
}
|
|
85
135
|
|
|
86
136
|
/**
|
|
87
137
|
*/
|
|
88
|
-
|
|
138
|
+
doBasicAuthentication(username: string, password: string): Promise<any> {
|
|
139
|
+
Cache.addItem("basic", btoa(`${username}:${password}`));
|
|
140
|
+
return Promise.resolve();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
*/
|
|
145
|
+
doJaasAuthentication(username: string, password: string): Promise<any> {
|
|
89
146
|
return this.initLogin(true).then(() => {
|
|
90
147
|
if (this.isBasicAuthentication) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return Promise.resolve();
|
|
148
|
+
return this.doBasicAuthentication(username, password);
|
|
94
149
|
}
|
|
95
|
-
|
|
96
|
-
return universalFetch(this.createLogin(username, password));
|
|
150
|
+
return this.doFormLogin(username, password);
|
|
97
151
|
});
|
|
98
152
|
}
|
|
99
153
|
|
|
@@ -101,7 +155,7 @@ class Authenticate {
|
|
|
101
155
|
*/
|
|
102
156
|
logout(): Promise<void> {
|
|
103
157
|
return universalFetch({
|
|
104
|
-
url: logoutPath()
|
|
158
|
+
url: `${BASE}${logoutPath()}`,
|
|
105
159
|
}).then(() => {
|
|
106
160
|
// clear cache because of cached contributions
|
|
107
161
|
Cache.clear();
|
|
@@ -112,10 +112,11 @@ describe("serverUtil", () => {
|
|
|
112
112
|
{
|
|
113
113
|
type: "SET_PREFERENCES",
|
|
114
114
|
payload: {
|
|
115
|
-
"FormClient.login_url": "/
|
|
116
|
-
"FormClient.logout_url": "/
|
|
115
|
+
"FormClient.login_url": "/j_security_check",
|
|
116
|
+
"FormClient.logout_url": "/Logoff",
|
|
117
117
|
"FormClient.password_field_name": "j_password",
|
|
118
118
|
"FormClient.username_field_name": "j_username",
|
|
119
|
+
"security.clients": null,
|
|
119
120
|
},
|
|
120
121
|
},
|
|
121
122
|
]);
|
|
@@ -158,10 +159,11 @@ describe("serverUtil", () => {
|
|
|
158
159
|
{
|
|
159
160
|
type: "SET_PREFERENCES",
|
|
160
161
|
payload: {
|
|
161
|
-
"FormClient.login_url": "/
|
|
162
|
-
"FormClient.logout_url": "/
|
|
162
|
+
"FormClient.login_url": "/j_security_check",
|
|
163
|
+
"FormClient.logout_url": "/Logoff",
|
|
163
164
|
"FormClient.password_field_name": "j_password",
|
|
164
165
|
"FormClient.username_field_name": "j_username",
|
|
166
|
+
"security.clients": null,
|
|
165
167
|
},
|
|
166
168
|
},
|
|
167
169
|
]);
|
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
} from "../types";
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
-
BASE,
|
|
16
15
|
ALL_CONTENT_IN_DATA_SETTING,
|
|
16
|
+
LOGIN_TYPE,
|
|
17
17
|
LOGIN_PASSWORD_SETTING,
|
|
18
18
|
LOGIN_PATH_SETTING,
|
|
19
19
|
LOGIN_USERNAME_SETTING,
|
|
@@ -123,9 +123,13 @@ export const setLoginPreferences = (
|
|
|
123
123
|
state?: ReduxState
|
|
124
124
|
): SetPreferencesAction => {
|
|
125
125
|
const loginSettings = {
|
|
126
|
+
[LOGIN_TYPE]: getServerPreferenceValue(
|
|
127
|
+
LOGIN_TYPE,
|
|
128
|
+
state?.preferences[LOGIN_TYPE]
|
|
129
|
+
),
|
|
126
130
|
[LOGIN_PATH_SETTING]: getServerPreferenceValue(
|
|
127
131
|
LOGIN_PATH_SETTING,
|
|
128
|
-
state?.preferences[LOGIN_PATH_SETTING] ??
|
|
132
|
+
state?.preferences[LOGIN_PATH_SETTING] ?? `/j_security_check`
|
|
129
133
|
),
|
|
130
134
|
[LOGIN_USERNAME_SETTING]: getServerPreferenceValue(
|
|
131
135
|
LOGIN_USERNAME_SETTING,
|
|
@@ -137,7 +141,7 @@ export const setLoginPreferences = (
|
|
|
137
141
|
),
|
|
138
142
|
[LOGOUT_PATH_SETTING]: getServerPreferenceValue(
|
|
139
143
|
LOGOUT_PATH_SETTING,
|
|
140
|
-
state?.preferences[LOGOUT_PATH_SETTING] ??
|
|
144
|
+
state?.preferences[LOGOUT_PATH_SETTING] ?? `/Logoff`
|
|
141
145
|
),
|
|
142
146
|
};
|
|
143
147
|
|