nodefony 7.0.0-beta.8 → 7.0.0
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 +375 -8505
- package/README.md +30 -27
- package/autoloader.es6 +46 -48
- package/builder.es6 +66 -76
- package/cli/builder/bundles/bundle.js +57 -63
- package/cli/builder/bundles/controller.js +34 -38
- package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
- package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
- package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +27 -38
- package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
- package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
- package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
- package/cli/builder/bundles/users-bundle/Resources/config/config.js +13 -6
- package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
- package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -77
- package/cli/builder/bundles/users-bundle/Resources/js/users.js +3 -0
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- package/cli/builder/bundles/users-bundle/Resources/scss/custom.scss +6 -4
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +12 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
- package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
- package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -35
- package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
- package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
- package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
- package/cli/builder/bundles/users-bundle/package.json +29 -27
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +103 -112
- package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
- package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
- package/cli/builder/bundles/users-bundle/tests/loginTest.js +122 -72
- package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
- package/cli/builder/microService/microService.js +139 -141
- package/cli/builder/microService/skeletons/package.json +23 -22
- package/cli/builder/project/project.js +228 -181
- package/cli/builder/project/skeletons/README.md +30 -27
- package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
- package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
- package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
- package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
- package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
- package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
- package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
- package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
- package/cli/builder/project/skeletons/package.json.twig +71 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +134 -136
- package/cli/builder/sandbox/skeletons/bootstrap/custom.scss +5 -3
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +37 -12
- package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
- package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
- package/cli/builder/skeletons/package.json.twig +57 -0
- package/cli/builder/skeletons/unittest/testFile.js +44 -45
- package/cli/builder/vue/skeletons/vue.config.js +84 -10
- package/cli/builder/vue/vueBuilder.js +116 -114
- package/cli/generate/generate.es6 +38 -39
- package/cli/install/install.js +45 -58
- package/cli/sequelize/sequelize.js +50 -39
- package/cli/start.js +353 -347
- package/cli/tools/pm2.es6 +55 -57
- package/cli/tools/tools.es6 +36 -37
- package/cli.es6 +270 -243
- package/container.es6 +51 -59
- package/error.es6 +25 -27
- package/fileClass.es6 +53 -55
- package/finder/file.es6 +5 -4
- package/finder/fileResult.es6 +23 -22
- package/finder/finder2.es6 +46 -54
- package/finder.es6 +88 -97
- package/kernel/annotations/annotations.es6 +44 -46
- package/kernel/api/api.es6 +6 -8
- package/kernel/api/graphqlApi.es6 +21 -21
- package/kernel/api/jsonApi.es6 +40 -45
- package/kernel/api/openApi.es6 +9 -11
- package/kernel/api/schemas/openApiSchema.js +61 -32
- package/kernel/babylon.es6 +31 -38
- package/kernel/bundle.es6 +230 -228
- package/kernel/cliKernel.es6 +157 -170
- package/kernel/command.es6 +17 -20
- package/kernel/commands/nodefonyCommand.es6 +111 -58
- package/kernel/commands/tasks/bundlesTask.es6 +14 -19
- package/kernel/controllers/controller.es6 +167 -180
- package/kernel/fixture.es6 +4 -7
- package/kernel/injections/injections.es6 +97 -103
- package/kernel/kernel.es6 +670 -397
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +65 -51
- package/kernel/reader.es6 +45 -47
- package/kernel/security/encoder.es6 +8 -6
- package/kernel/security/factories/factory.es6 +34 -37
- package/kernel/security/factories/passeportFactory.es6 +13 -14
- package/kernel/security/provider.es6 +11 -13
- package/kernel/security/providers/chainProvider.es6 +13 -28
- package/kernel/security/providers/memoryProvider.es6 +7 -11
- package/kernel/security/providers/providerManager.es6 +11 -14
- package/kernel/security/providers/userEntityProvider.es6 +7 -8
- package/kernel/security/role.es6 +3 -3
- package/kernel/security/secureArea.es6 +143 -152
- package/kernel/security/tokens/token.es6 +30 -32
- package/kernel/security/user.es6 +19 -19
- package/kernel/serviceRealTime.es6 +5 -7
- package/kernel/services/connectionsService.es6 +20 -22
- package/kernel/services/cron/cronService.es6 +14 -16
- package/kernel/task.es6 +20 -26
- package/kernel/templates.es6 +4 -5
- package/kernel/templating/twig.es6 +56 -47
- package/kernel/tests/cliTest.js +7 -11
- package/kernel/tests/containerTest.js +25 -37
- package/kernel/tests/kernelTest.js +9 -16
- package/nodefony.es6 +279 -256
- package/notificationsCenter.es6 +28 -20
- package/package.json +55 -55
- package/protocol.es6 +19 -21
- package/protocols/bayeux.es6 +35 -38
- package/protocols/jsonRpc/jsonrpc.es6 +12 -14
- package/result.es6 +11 -12
- package/service.es6 +62 -62
- package/syslog/pdu.es6 +99 -91
- package/syslog/syslog.es6 +101 -102
- package/watcher.es6 +21 -20
- package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
- package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
- package/cli/builder/project/skeletons/package.json.skeleton +0 -53
- package/cli/builder/sandbox/skeletons/bootstrap/awesome/font-awesome.config.js +0 -11
- package/cli/builder/skeletons/package.json +0 -61
|
@@ -1,53 +1,50 @@
|
|
|
1
1
|
class providerManager extends nodefony.Service {
|
|
2
|
-
|
|
3
|
-
constructor(firewall, providers = []) {
|
|
2
|
+
constructor (firewall, providers = []) {
|
|
4
3
|
super("providerManager", firewall.container);
|
|
5
4
|
this.providers = providers || [];
|
|
6
5
|
this.nbProviders = 0;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
getProvider(name) {
|
|
8
|
+
getProvider (name) {
|
|
10
9
|
if (this.providers[name]) {
|
|
11
10
|
return this.providers[name];
|
|
12
11
|
}
|
|
13
12
|
throw new Error(`Provider : ${name} nor found`);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
getProviders(name) {
|
|
15
|
+
getProviders (name) {
|
|
17
16
|
if (name) {
|
|
18
17
|
return this.getProvider(name);
|
|
19
18
|
}
|
|
20
19
|
return this.providers;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
addConfiguration(name, config) {
|
|
22
|
+
addConfiguration (name, config) {
|
|
24
23
|
if (name in this.providers) {
|
|
25
24
|
this.log(`Provider ${name} already exist`, "WARNING");
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
27
|
if (config) {
|
|
29
|
-
this.kernel.prependOnceListener("onBoot", async() => {
|
|
28
|
+
this.kernel.prependOnceListener("onBoot", async () => {
|
|
30
29
|
switch (true) {
|
|
31
|
-
case
|
|
30
|
+
case Boolean(config.entity):
|
|
32
31
|
if (config.class) {
|
|
33
32
|
if (config.class in nodefony.security.providers) {
|
|
34
33
|
this.providers[name] = new nodefony.security.providers[config.class](name, this, config.entity);
|
|
35
34
|
} else {
|
|
36
35
|
this.log(new Error(`provider class not exist : ${config.class}`), "ERROR");
|
|
37
36
|
}
|
|
38
|
-
} else {
|
|
39
|
-
|
|
40
|
-
this.providers[name] = new nodefony.security.providers.userProvider(name, this, config.entity);
|
|
41
|
-
}
|
|
37
|
+
} else if (nodefony.security.providers.userProvider) {
|
|
38
|
+
this.providers[name] = new nodefony.security.providers.userProvider(name, this, config.entity);
|
|
42
39
|
}
|
|
43
40
|
break;
|
|
44
|
-
case
|
|
41
|
+
case Boolean(config.chain):
|
|
45
42
|
this.providers[name] = new nodefony.security.providers.chainProvider(this, config.chain);
|
|
46
43
|
break;
|
|
47
|
-
case
|
|
44
|
+
case Boolean(config.memory):
|
|
48
45
|
this.providers[name] = new nodefony.security.providers.memoryProvider(this, config.memory);
|
|
49
46
|
break;
|
|
50
|
-
case
|
|
47
|
+
case Boolean(config.anonymous):
|
|
51
48
|
if (config.anonymous.provider) {
|
|
52
49
|
if (this.providers[config.anonymous.provider]) {
|
|
53
50
|
this.providers[name] = this.providers[config.anonymous.provider];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
class userEntityProvider extends nodefony.Provider {
|
|
2
|
-
|
|
3
|
-
constructor(name, manager, config) {
|
|
2
|
+
constructor (name, manager, config) {
|
|
4
3
|
super(name, manager);
|
|
5
4
|
this.entityName = config.name || "user";
|
|
6
5
|
this.userProperty = config.property || "username";
|
|
@@ -14,16 +13,16 @@ class userEntityProvider extends nodefony.Provider {
|
|
|
14
13
|
});
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
getEntity(name) {
|
|
16
|
+
getEntity (name) {
|
|
18
17
|
if (name) {
|
|
19
18
|
return this.orm.getEntity(name);
|
|
20
19
|
}
|
|
21
20
|
return this.orm.getEntity(this.entityName);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
async encodePassword(raw, salt) {
|
|
23
|
+
async encodePassword (raw, salt) {
|
|
25
24
|
try {
|
|
26
|
-
|
|
25
|
+
const ret = this.entity.hasEncoder();
|
|
27
26
|
if (ret) {
|
|
28
27
|
return await this.encoder.encodePassword(raw, salt);
|
|
29
28
|
}
|
|
@@ -33,11 +32,11 @@ class userEntityProvider extends nodefony.Provider {
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
async isPasswordValid(raw, encoded) {
|
|
35
|
+
async isPasswordValid (raw, encoded) {
|
|
37
36
|
try {
|
|
38
|
-
|
|
37
|
+
const ret = this.entity.hasEncoder();
|
|
39
38
|
if (ret) {
|
|
40
|
-
this.log(
|
|
39
|
+
this.log("Check Password Valid ", "DEBUG", `ENCODER ${this.encoder.name}`);
|
|
41
40
|
return await this.encoder.isPasswordValid(raw, encoded);
|
|
42
41
|
}
|
|
43
42
|
return await super.isPasswordValid(raw, encoded);
|
package/kernel/security/role.es6
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* eslint-disable max-lines-per-function */
|
|
2
|
+
module.exports = nodefony.register("SecuredArea", () => {
|
|
3
3
|
// context security
|
|
4
4
|
class securedArea extends nodefony.Service {
|
|
5
|
-
|
|
6
|
-
constructor(name, firewall) {
|
|
5
|
+
constructor (name, firewall) {
|
|
7
6
|
super(name, firewall.container, firewall.notificationsCenter);
|
|
8
7
|
this.firewall = firewall;
|
|
9
8
|
this.router = this.get("router");
|
|
10
9
|
this.sessionContext = "default";
|
|
11
10
|
this.cors = null;
|
|
12
|
-
this.pattern =
|
|
11
|
+
this.pattern = /.*/u;
|
|
13
12
|
this.factories = [];
|
|
14
13
|
this.nbFactories = 0;
|
|
15
14
|
this.provider = null;
|
|
@@ -26,37 +25,33 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
26
25
|
if (this.providerName) {
|
|
27
26
|
if (this.providerName in this.firewall.providerManager.providers) {
|
|
28
27
|
this.provider = this.firewall.providerManager.getProvider(this.providerName);
|
|
29
|
-
} else {
|
|
30
|
-
if (this.anonymous) {
|
|
31
|
-
this.providerName = "anonymous";
|
|
32
|
-
this.provider = this.firewall.providerManager.getProvider("anonymous");
|
|
33
|
-
} else {
|
|
34
|
-
throw new Error(`Provider : ${this.providerName} not found in firewall ${this.name}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
if (this.anonymous) {
|
|
28
|
+
} else if (this.anonymous) {
|
|
39
29
|
this.providerName = "anonymous";
|
|
40
30
|
this.provider = this.firewall.providerManager.getProvider("anonymous");
|
|
41
31
|
} else {
|
|
42
|
-
|
|
43
|
-
//this.provider = this.firewall.providerManager.getProvider("nodefony");
|
|
32
|
+
throw new Error(`Provider : ${this.providerName} not found in firewall ${this.name}`);
|
|
44
33
|
}
|
|
34
|
+
} else if (this.anonymous) {
|
|
35
|
+
this.providerName = "anonymous";
|
|
36
|
+
this.provider = this.firewall.providerManager.getProvider("anonymous");
|
|
37
|
+
} else {
|
|
38
|
+
// this.providerName = null; //"nodefony";
|
|
39
|
+
// this.provider = this.firewall.providerManager.getProvider("nodefony");
|
|
45
40
|
}
|
|
46
41
|
} catch (e) {
|
|
47
|
-
this.log(this.name
|
|
42
|
+
this.log(`${this.name} ${e}`, "ERROR");
|
|
48
43
|
}
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
log(pci, severity, msgid, msg) {
|
|
47
|
+
log (pci, severity, msgid, msg) {
|
|
53
48
|
if (!msgid) {
|
|
54
|
-
msgid =
|
|
49
|
+
msgid = `\x1b[36mSECURE AREA \x1b[31m${this.name} \x1b[0m`;
|
|
55
50
|
}
|
|
56
51
|
return super.log(pci, severity, msgid, msg);
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
handleCrossDomain(context) {
|
|
54
|
+
handleCrossDomain (context) {
|
|
60
55
|
let redirect = false;
|
|
61
56
|
if (context.security.redirect_Https &&
|
|
62
57
|
context.protocol === "https" &&
|
|
@@ -66,22 +61,22 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
66
61
|
if (context.crossDomain) {
|
|
67
62
|
if (this.cors) {
|
|
68
63
|
return this.cors.match(context, redirect);
|
|
69
|
-
} else {
|
|
70
|
-
if (redirect) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if( context.originUrl.href === "*"){
|
|
74
|
-
return 200;
|
|
75
|
-
}
|
|
76
|
-
return 401;
|
|
77
64
|
}
|
|
65
|
+
if (redirect) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (context.originUrl.href === "*") {
|
|
69
|
+
return 200;
|
|
70
|
+
}
|
|
71
|
+
return 401;
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
|
|
75
|
+
// eslint-disable-next-line complexity
|
|
76
|
+
handleError (context, e) {
|
|
82
77
|
let securityError = null;
|
|
83
78
|
switch (true) {
|
|
84
|
-
case
|
|
79
|
+
case e instanceof nodefony.securityError:
|
|
85
80
|
securityError = e;
|
|
86
81
|
break;
|
|
87
82
|
default:
|
|
@@ -91,7 +86,7 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
91
86
|
securityError.code = 401;
|
|
92
87
|
}
|
|
93
88
|
if (this.kernel.debug) {
|
|
94
|
-
//this.log(securityError, "ERROR");
|
|
89
|
+
// this.log(securityError, "ERROR");
|
|
95
90
|
}
|
|
96
91
|
switch (context.type) {
|
|
97
92
|
case "HTTP":
|
|
@@ -104,12 +99,12 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
104
99
|
}
|
|
105
100
|
if (this.formLogin) {
|
|
106
101
|
if (context.session) {
|
|
107
|
-
|
|
102
|
+
const area = context.session.getMetaBag("area");
|
|
108
103
|
if (area && area !== this.name) {
|
|
109
104
|
context.session.clearFlashBag("default_target_path");
|
|
110
105
|
}
|
|
111
106
|
context.session.setMetaBag("area", this.name);
|
|
112
|
-
|
|
107
|
+
const target_path = context.session.getFlashBag("default_target_path");
|
|
113
108
|
if (!target_path && context.method === "GET") {
|
|
114
109
|
context.session.setFlashBag("default_target_path", context.request.url.pathname);
|
|
115
110
|
}
|
|
@@ -118,7 +113,7 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
115
|
|
|
121
|
-
/*if (context.session &&
|
|
116
|
+
/* if (context.session &&
|
|
122
117
|
(context.request.url.pathname !== this.formLogin) &&
|
|
123
118
|
(context.request.url.pathname !== this.checkLogin)
|
|
124
119
|
) {
|
|
@@ -144,10 +139,11 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
144
139
|
if (context.isJson) {
|
|
145
140
|
return securityError;
|
|
146
141
|
}
|
|
147
|
-
//return this.redirect(context, this.formLogin);
|
|
142
|
+
// return this.redirect(context, this.formLogin);
|
|
148
143
|
context.resolver = this.overrideURL(context, this.formLogin);
|
|
149
144
|
return context;
|
|
150
145
|
} catch (e) {
|
|
146
|
+
// eslint-disable-next-line new-cap
|
|
151
147
|
return new nodefony.securityError(e, 500, this, context);
|
|
152
148
|
}
|
|
153
149
|
} else {
|
|
@@ -156,22 +152,20 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
156
152
|
}
|
|
157
153
|
return securityError;
|
|
158
154
|
}
|
|
159
|
-
break;
|
|
160
155
|
case "WEBSOCKET":
|
|
161
156
|
case "WEBSOCKET SECURE":
|
|
162
157
|
return securityError;
|
|
158
|
+
default:
|
|
163
159
|
}
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
handleFactories(context, index = 1) {
|
|
162
|
+
handleFactories (context, index = 1) {
|
|
167
163
|
return new Promise((resolve, reject) => {
|
|
168
164
|
if (this.nbFactories) {
|
|
169
165
|
try {
|
|
170
166
|
this.log(`Try Authentication Factory ${this.factories[index - 1].name}`, "DEBUG");
|
|
171
167
|
return this.factories[index - 1].handle(context)
|
|
172
|
-
.then((token) =>
|
|
173
|
-
return resolve(token);
|
|
174
|
-
})
|
|
168
|
+
.then((token) => resolve(token))
|
|
175
169
|
.catch((e) => {
|
|
176
170
|
this.factories[index - 1].log(e, "DEBUG");
|
|
177
171
|
if (index === this.nbFactories) {
|
|
@@ -188,108 +182,105 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
188
182
|
});
|
|
189
183
|
}
|
|
190
184
|
|
|
191
|
-
handle(context) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (context.session) {
|
|
202
|
-
context.session.setMetaBag("security", {
|
|
203
|
-
firewall: this.name,
|
|
204
|
-
token: null
|
|
205
|
-
});
|
|
206
|
-
if (context.user && context.user.lang) {
|
|
207
|
-
context.session.set("lang", context.user.lang);
|
|
208
|
-
} else {
|
|
209
|
-
if( ! context.session.get("lang") ){
|
|
210
|
-
context.session.set("lang", context.translation.defaultLocale);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return resolve(context);
|
|
215
|
-
}
|
|
185
|
+
handle (context) {
|
|
186
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
187
|
+
return new Promise((resolve, reject) => this.handleFactories(context)
|
|
188
|
+
.then((token) => {
|
|
189
|
+
let target = this.defaultTarget;
|
|
190
|
+
try {
|
|
191
|
+
if (token) {
|
|
192
|
+
context.user = token.user;
|
|
193
|
+
context.token = token;
|
|
194
|
+
} else {
|
|
216
195
|
if (context.session) {
|
|
217
|
-
//context.session.migrate();
|
|
218
196
|
context.session.setMetaBag("security", {
|
|
219
197
|
firewall: this.name,
|
|
220
|
-
token:
|
|
198
|
+
token: null
|
|
221
199
|
});
|
|
222
200
|
if (context.user && context.user.lang) {
|
|
223
201
|
context.session.set("lang", context.user.lang);
|
|
224
|
-
} else {
|
|
202
|
+
} else if (!context.session.get("lang")) {
|
|
225
203
|
context.session.set("lang", context.translation.defaultLocale);
|
|
226
204
|
}
|
|
227
|
-
if (!this.alwaysUseDefaultTarget) {
|
|
228
|
-
target = context.session.getFlashBag("default_target_path") || this.defaultTarget;
|
|
229
|
-
} else {
|
|
230
|
-
target = this.defaultTarget;
|
|
231
|
-
}
|
|
232
|
-
context.session.clearFlashBag("default_target_path");
|
|
233
|
-
}
|
|
234
|
-
} catch (e) {
|
|
235
|
-
let res = this.handleError(context, e);
|
|
236
|
-
if (res instanceof Error) {
|
|
237
|
-
return reject(res);
|
|
238
|
-
}
|
|
239
|
-
return resolve(res);
|
|
240
|
-
}
|
|
241
|
-
if (this.checkLogin) {
|
|
242
|
-
try {
|
|
243
|
-
delete context.resolver;
|
|
244
|
-
context.checkLogin = true;
|
|
245
|
-
context.resolver = this.overrideURL(context, this.checkLogin, target);
|
|
246
|
-
//context.resolver = this.router.resolveName(context, this.checkLogin);
|
|
247
|
-
return resolve(context);
|
|
248
|
-
} catch (e) {
|
|
249
|
-
throw e;
|
|
250
205
|
}
|
|
251
|
-
}
|
|
252
|
-
if (!target) {
|
|
253
206
|
return resolve(context);
|
|
254
207
|
}
|
|
255
|
-
if (context.
|
|
256
|
-
context.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
208
|
+
if (context.session) {
|
|
209
|
+
// context.session.migrate();
|
|
210
|
+
context.session.setMetaBag("security", {
|
|
211
|
+
firewall: this.name,
|
|
212
|
+
token: token ? token.serialize() : null
|
|
213
|
+
});
|
|
214
|
+
if (context.user && context.user.lang) {
|
|
215
|
+
context.session.set("lang", context.user.lang);
|
|
216
|
+
} else {
|
|
217
|
+
context.session.set("lang", context.translation.defaultLocale);
|
|
218
|
+
}
|
|
219
|
+
if (!this.alwaysUseDefaultTarget) {
|
|
220
|
+
target = context.session.getFlashBag("default_target_path") || this.defaultTarget;
|
|
221
|
+
} else {
|
|
222
|
+
target = this.defaultTarget;
|
|
223
|
+
}
|
|
224
|
+
context.session.clearFlashBag("default_target_path");
|
|
266
225
|
}
|
|
267
|
-
|
|
226
|
+
} catch (e) {
|
|
227
|
+
const res = this.handleError(context, e);
|
|
268
228
|
if (res instanceof Error) {
|
|
269
229
|
return reject(res);
|
|
270
230
|
}
|
|
271
231
|
return resolve(res);
|
|
272
|
-
}
|
|
273
|
-
|
|
232
|
+
}
|
|
233
|
+
if (this.checkLogin) {
|
|
234
|
+
try {
|
|
235
|
+
delete context.resolver;
|
|
236
|
+
context.checkLogin = true;
|
|
237
|
+
context.resolver = this.overrideURL(context, this.checkLogin, target);
|
|
238
|
+
// context.resolver = this.router.resolveName(context, this.checkLogin);
|
|
239
|
+
return resolve(context);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
throw e;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!target) {
|
|
245
|
+
return resolve(context);
|
|
246
|
+
}
|
|
247
|
+
if (context.isJson) {
|
|
248
|
+
context.resolver = this.overrideURL(context, target);
|
|
249
|
+
return resolve(context);
|
|
250
|
+
}
|
|
251
|
+
return resolve(this.redirect(context, target));
|
|
252
|
+
// return resolve(context);
|
|
253
|
+
})
|
|
254
|
+
.catch((error) => {
|
|
255
|
+
if (!error) {
|
|
256
|
+
error = new Error("");
|
|
257
|
+
}
|
|
258
|
+
const res = this.handleError(context, error);
|
|
259
|
+
if (res instanceof Error) {
|
|
260
|
+
return reject(res);
|
|
261
|
+
}
|
|
262
|
+
return resolve(res);
|
|
263
|
+
}));
|
|
274
264
|
}
|
|
275
265
|
|
|
276
|
-
logout(context) {
|
|
266
|
+
logout (context) {
|
|
277
267
|
return new Promise(async (resolve, reject) => {
|
|
278
|
-
|
|
279
|
-
this.log("Logout factories","DEBUG");
|
|
280
|
-
for await (
|
|
281
|
-
this.log(`Logout factory : ${factorie}`,"DEBUG")
|
|
268
|
+
const res = [];
|
|
269
|
+
this.log("Logout factories", "DEBUG");
|
|
270
|
+
for await (const factorie of this.factories) {
|
|
271
|
+
this.log(`Logout factory : ${factorie}`, "DEBUG");
|
|
282
272
|
res.push(await factorie.logout(context));
|
|
283
273
|
}
|
|
284
274
|
if (context.session) {
|
|
285
|
-
this.log(`Invalidate session Security : ${context.session.id}`,"DEBUG")
|
|
275
|
+
this.log(`Invalidate session Security : ${context.session.id}`, "DEBUG");
|
|
286
276
|
return context.session.invalidate()
|
|
287
277
|
.then(() => {
|
|
288
278
|
if (this.formLogin) {
|
|
289
279
|
return resolve(this.redirect(context, this.formLogin));
|
|
290
280
|
}
|
|
291
281
|
return resolve(context);
|
|
292
|
-
})
|
|
282
|
+
})
|
|
283
|
+
.catch((e) => {
|
|
293
284
|
this.log(e, "ERROR");
|
|
294
285
|
return reject(e);
|
|
295
286
|
});
|
|
@@ -299,7 +290,7 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
299
290
|
}
|
|
300
291
|
|
|
301
292
|
// Factory
|
|
302
|
-
setFactory(auth, options) {
|
|
293
|
+
setFactory (auth, options) {
|
|
303
294
|
if (auth) {
|
|
304
295
|
if (auth in nodefony.security.factories) {
|
|
305
296
|
let index = null;
|
|
@@ -311,20 +302,18 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
311
302
|
index = 0;
|
|
312
303
|
}
|
|
313
304
|
this.nbFactories++;
|
|
314
|
-
this.log(
|
|
305
|
+
this.log(`FACTORY ${auth} registered `, "DEBUG");
|
|
315
306
|
return this.factories[index];
|
|
316
|
-
} else {
|
|
317
|
-
this.log("FACTORY :" + auth + "NOT registered ", "ERROR");
|
|
318
|
-
throw new Error("FACTORY :" + auth + "NOT registered ");
|
|
319
307
|
}
|
|
308
|
+
this.log(`FACTORY :${auth}NOT registered `, "ERROR");
|
|
309
|
+
throw new Error(`FACTORY :${auth} NOT registered `);
|
|
320
310
|
}
|
|
311
|
+
throw new Error(`FACTORY :${auth} bad args`);
|
|
321
312
|
}
|
|
322
313
|
|
|
323
|
-
getFactory(name) {
|
|
314
|
+
getFactory (name) {
|
|
324
315
|
if (name) {
|
|
325
|
-
|
|
326
|
-
return factory.name === name;
|
|
327
|
-
});
|
|
316
|
+
const index = this.factories.findIndex((factory) => factory.name === name);
|
|
328
317
|
if (index >= 0) {
|
|
329
318
|
return this.factories[index];
|
|
330
319
|
}
|
|
@@ -333,70 +322,72 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
333
322
|
return null;
|
|
334
323
|
}
|
|
335
324
|
|
|
336
|
-
setProvider(provider) {
|
|
325
|
+
setProvider (provider) {
|
|
337
326
|
if (provider) {
|
|
338
327
|
this.provider = provider;
|
|
339
328
|
this.providerName = provider.name;
|
|
340
329
|
}
|
|
341
330
|
}
|
|
342
331
|
|
|
343
|
-
setProviderName(name) {
|
|
332
|
+
setProviderName (name) {
|
|
344
333
|
this.providerName = name;
|
|
345
334
|
}
|
|
346
335
|
|
|
347
|
-
getProvider() {
|
|
336
|
+
getProvider () {
|
|
348
337
|
return this.provider;
|
|
349
338
|
}
|
|
350
339
|
|
|
351
|
-
setStateLess(state) {
|
|
340
|
+
setStateLess (state) {
|
|
352
341
|
if (state === null) {
|
|
353
|
-
|
|
342
|
+
this.stateLess = true;
|
|
343
|
+
return true;
|
|
354
344
|
}
|
|
355
|
-
|
|
345
|
+
this.stateLess = state || false;
|
|
346
|
+
return state || false;
|
|
356
347
|
}
|
|
357
348
|
|
|
358
|
-
overrideURL(context, myUrl, target = null) {
|
|
359
|
-
try{
|
|
349
|
+
overrideURL (context, myUrl, target = null) {
|
|
350
|
+
try {
|
|
360
351
|
if (myUrl) {
|
|
361
352
|
context.request.url = url.parse(url.resolve(context.request.url, myUrl));
|
|
362
353
|
}
|
|
363
|
-
|
|
354
|
+
const resolver = this.router.resolve(context);
|
|
364
355
|
if (target) {
|
|
365
356
|
resolver.variables.push(target);
|
|
366
357
|
}
|
|
367
358
|
return resolver;
|
|
368
|
-
}catch(e){
|
|
369
|
-
if (e instanceof nodefony.Resolver
|
|
370
|
-
if (
|
|
371
|
-
throw e.exception
|
|
359
|
+
} catch (e) {
|
|
360
|
+
if (e instanceof nodefony.Resolver) {
|
|
361
|
+
if (e.exception) {
|
|
362
|
+
throw e.exception;
|
|
372
363
|
}
|
|
373
364
|
}
|
|
374
|
-
throw e
|
|
365
|
+
throw e;
|
|
375
366
|
}
|
|
376
367
|
}
|
|
377
368
|
|
|
378
|
-
redirectHttps(context) {
|
|
369
|
+
redirectHttps (context) {
|
|
379
370
|
// no cache
|
|
380
371
|
context.redirectHttps(301);
|
|
381
372
|
return context;
|
|
382
373
|
}
|
|
383
374
|
|
|
384
|
-
redirect(context, url) {
|
|
375
|
+
redirect (context, url) {
|
|
385
376
|
if (url) {
|
|
386
377
|
// no cache
|
|
387
378
|
return context.redirect(url, 302, true);
|
|
388
|
-
//return context;
|
|
379
|
+
// return context;
|
|
389
380
|
}
|
|
390
381
|
return context.redirect(context.request.url, 302, true);
|
|
391
|
-
//return context;
|
|
382
|
+
// return context;
|
|
392
383
|
}
|
|
393
384
|
|
|
394
|
-
match(context) {
|
|
395
|
-
|
|
385
|
+
match (context) {
|
|
386
|
+
const url = context.request.url ? context.request.url.pathname : context.request.resourceURL ? context.request.resourceURL.pathname : null;
|
|
396
387
|
return this.pattern.exec(url);
|
|
397
388
|
}
|
|
398
389
|
|
|
399
|
-
setPattern(pattern) {
|
|
390
|
+
setPattern (pattern) {
|
|
400
391
|
if (pattern instanceof RegExp) {
|
|
401
392
|
this.pattern = pattern;
|
|
402
393
|
this.stringPattern = pattern.toString();
|
|
@@ -407,32 +398,32 @@ module.exports = nodefony.register("SecuredArea", function () {
|
|
|
407
398
|
return this.pattern;
|
|
408
399
|
}
|
|
409
400
|
|
|
410
|
-
setCors(crossSettings) {
|
|
401
|
+
setCors (crossSettings) {
|
|
411
402
|
this.cors = this.firewall.corsManager.createCors(crossSettings);
|
|
412
403
|
return this.cors;
|
|
413
404
|
}
|
|
414
405
|
|
|
415
|
-
setFormLogin(route) {
|
|
406
|
+
setFormLogin (route) {
|
|
416
407
|
this.formLogin = route;
|
|
417
408
|
}
|
|
418
409
|
|
|
419
|
-
setCheckLogin(route) {
|
|
410
|
+
setCheckLogin (route) {
|
|
420
411
|
this.checkLogin = route;
|
|
421
412
|
}
|
|
422
413
|
|
|
423
|
-
setDefaultTarget(route) {
|
|
414
|
+
setDefaultTarget (route) {
|
|
424
415
|
this.defaultTarget = route;
|
|
425
416
|
}
|
|
426
417
|
|
|
427
|
-
setAlwaysUseDefaultTarget(data) {
|
|
418
|
+
setAlwaysUseDefaultTarget (data) {
|
|
428
419
|
this.alwaysUseDefaultTarget = data;
|
|
429
420
|
}
|
|
430
421
|
|
|
431
|
-
setContextSession(context) {
|
|
422
|
+
setContextSession (context) {
|
|
432
423
|
this.sessionContext = context;
|
|
433
424
|
}
|
|
434
425
|
|
|
435
|
-
setRedirectHttps(value) {
|
|
426
|
+
setRedirectHttps (value) {
|
|
436
427
|
this.redirect_Https = value || false;
|
|
437
428
|
}
|
|
438
429
|
}
|