nodefony 7.0.0-beta.2 → 7.0.0-beta.21
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 +534 -8028
- package/README.md +33 -30
- 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 +25 -30
- 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 +4 -3
- 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 -75
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- 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 +13 -15
- 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 -36
- 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 +27 -25
- package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
- 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 +119 -70
- 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 +33 -30
- 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 +70 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -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 +280 -228
- 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 +252 -220
- 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 +476 -384
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +68 -48
- 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 -149
- 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 +40 -40
- 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 -52
- package/cli/builder/skeletons/package.json +0 -61
package/kernel/reader.es6
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
const defaultSetting = {
|
|
2
2
|
parserXml: {
|
|
3
|
-
//explicitCharkey: true,
|
|
3
|
+
// explicitCharkey: true,
|
|
4
4
|
explicitArray: true,
|
|
5
5
|
explicitRoot: false,
|
|
6
6
|
mergeAttrs: true
|
|
7
7
|
},
|
|
8
8
|
readFile: {
|
|
9
|
-
encoding:
|
|
9
|
+
encoding: "utf8"
|
|
10
10
|
},
|
|
11
11
|
twig: {
|
|
12
|
-
|
|
12
|
+
"twig options": {
|
|
13
13
|
async: false,
|
|
14
14
|
cache: true
|
|
15
15
|
},
|
|
@@ -19,16 +19,16 @@ let defaultSetting = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const load = function (name, pathFile) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const mypath = pathFile;
|
|
23
|
+
const ext = path.extname(pathFile);
|
|
24
|
+
const basename = path.basename(pathFile);
|
|
25
|
+
const plug = this.plugins[name];
|
|
26
26
|
if (!plug) {
|
|
27
|
-
this.log(
|
|
27
|
+
this.log(`DROP FILE : ${mypath} NO PLUGIN FIND : ${name}`, "WARNING");
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const myName = Array.prototype.shift.call(arguments);
|
|
31
|
+
const file = Array.prototype.shift.call(arguments);
|
|
32
32
|
let txt = null;
|
|
33
33
|
try {
|
|
34
34
|
switch (ext) {
|
|
@@ -37,9 +37,9 @@ const load = function (name, pathFile) {
|
|
|
37
37
|
Array.prototype.unshift.call(arguments, txt);
|
|
38
38
|
if (plug.xml) {
|
|
39
39
|
return plug.xml.apply(this, arguments);
|
|
40
|
-
} else {
|
|
41
|
-
return this.pluginConfig.xml.apply(this, arguments);
|
|
42
40
|
}
|
|
41
|
+
return this.pluginConfig.xml.apply(this, arguments);
|
|
42
|
+
|
|
43
43
|
break;
|
|
44
44
|
case ".json":
|
|
45
45
|
txt = this.readFileSync(file);
|
|
@@ -51,9 +51,9 @@ const load = function (name, pathFile) {
|
|
|
51
51
|
Array.prototype.unshift.call(arguments, txt);
|
|
52
52
|
if (plug.yml) {
|
|
53
53
|
return plug.yml.apply(this, arguments);
|
|
54
|
-
} else {
|
|
55
|
-
return this.pluginConfig.yml.apply(this, arguments);
|
|
56
54
|
}
|
|
55
|
+
return this.pluginConfig.yml.apply(this, arguments);
|
|
56
|
+
|
|
57
57
|
break;
|
|
58
58
|
case ".js":
|
|
59
59
|
case ".es6":
|
|
@@ -64,20 +64,19 @@ const load = function (name, pathFile) {
|
|
|
64
64
|
case new RegExp("^(.+)Controller.js$").test(basename):
|
|
65
65
|
if (plug.annotations) {
|
|
66
66
|
return plug.annotations.apply(this, arguments);
|
|
67
|
-
} else {
|
|
68
|
-
return this.pluginConfig.annotations.apply(this, arguments);
|
|
69
67
|
}
|
|
68
|
+
return this.pluginConfig.annotations.apply(this, arguments);
|
|
69
|
+
|
|
70
70
|
break;
|
|
71
71
|
default:
|
|
72
72
|
if (plug.javascript) {
|
|
73
73
|
return plug.javascript.apply(this, arguments);
|
|
74
|
-
} else {
|
|
75
|
-
return this.pluginConfig.javascript.apply(this, arguments);
|
|
76
74
|
}
|
|
75
|
+
return this.pluginConfig.javascript.apply(this, arguments);
|
|
77
76
|
}
|
|
78
77
|
break;
|
|
79
78
|
default:
|
|
80
|
-
this.log(
|
|
79
|
+
this.log(`DROP FILE : ${mypath} PLUGIN ${myName} NO EXTENTION FIND : ${ext}`, "WARNING");
|
|
81
80
|
}
|
|
82
81
|
} catch (e) {
|
|
83
82
|
throw e;
|
|
@@ -97,8 +96,7 @@ const load = function (name, pathFile) {
|
|
|
97
96
|
*
|
|
98
97
|
*/
|
|
99
98
|
class Reader extends nodefony.Service {
|
|
100
|
-
|
|
101
|
-
constructor(container, localSettings) {
|
|
99
|
+
constructor (container, localSettings) {
|
|
102
100
|
super("READER", container);
|
|
103
101
|
this.settings = nodefony.extend(true, {}, defaultSetting, localSettings);
|
|
104
102
|
this.plugins = {};
|
|
@@ -110,18 +108,18 @@ class Reader extends nodefony.Service {
|
|
|
110
108
|
this.annotations = new nodefony.Annotations(container, this.notificationsCenter);
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
pluginConfig() {
|
|
111
|
+
pluginConfig () {
|
|
114
112
|
const json = function (file, bundle, callback, parser) {
|
|
115
113
|
if (parser) {
|
|
116
114
|
file = this.render(file, parser.data, parser.options);
|
|
117
115
|
}
|
|
118
116
|
try {
|
|
119
|
-
|
|
117
|
+
const json = JSON.parse(file);
|
|
120
118
|
if (callback) {
|
|
121
119
|
callback(json);
|
|
122
120
|
}
|
|
123
121
|
} catch (e) {
|
|
124
|
-
throw
|
|
122
|
+
throw e;
|
|
125
123
|
}
|
|
126
124
|
};
|
|
127
125
|
const yml = function (file, bundle, callback, parser) {
|
|
@@ -129,12 +127,12 @@ class Reader extends nodefony.Service {
|
|
|
129
127
|
file = this.render(file, parser.data, parser.options);
|
|
130
128
|
}
|
|
131
129
|
try {
|
|
132
|
-
|
|
130
|
+
const json = yaml.load(file);
|
|
133
131
|
if (callback) {
|
|
134
132
|
callback(json);
|
|
135
133
|
}
|
|
136
134
|
} catch (e) {
|
|
137
|
-
throw
|
|
135
|
+
throw e;
|
|
138
136
|
}
|
|
139
137
|
};
|
|
140
138
|
const xml = function (file, bundle, callback, parser) {
|
|
@@ -143,7 +141,7 @@ class Reader extends nodefony.Service {
|
|
|
143
141
|
}
|
|
144
142
|
this.xmlParser.parseString(file, (error, node) => {
|
|
145
143
|
if (error) {
|
|
146
|
-
throw
|
|
144
|
+
throw error;
|
|
147
145
|
}
|
|
148
146
|
if (callback) {
|
|
149
147
|
callback(this.xmlToJson(node));
|
|
@@ -166,19 +164,19 @@ class Reader extends nodefony.Service {
|
|
|
166
164
|
};
|
|
167
165
|
|
|
168
166
|
const annotations = function (file) {
|
|
169
|
-
throw new Error(
|
|
167
|
+
throw new Error(`Annotation is not defined for this file ${file}`);
|
|
170
168
|
};
|
|
171
169
|
|
|
172
170
|
return {
|
|
173
|
-
xml
|
|
174
|
-
json
|
|
175
|
-
yml
|
|
176
|
-
javascript
|
|
177
|
-
annotations
|
|
171
|
+
xml,
|
|
172
|
+
json,
|
|
173
|
+
yml,
|
|
174
|
+
javascript,
|
|
175
|
+
annotations
|
|
178
176
|
};
|
|
179
177
|
}
|
|
180
178
|
|
|
181
|
-
readFile(file, localSettings) {
|
|
179
|
+
readFile (file, localSettings) {
|
|
182
180
|
if (!file) {
|
|
183
181
|
throw new Error("READE no file path in readFile");
|
|
184
182
|
}
|
|
@@ -197,7 +195,7 @@ class Reader extends nodefony.Service {
|
|
|
197
195
|
});
|
|
198
196
|
}
|
|
199
197
|
|
|
200
|
-
readFileSync(file, localSettings) {
|
|
198
|
+
readFileSync (file, localSettings) {
|
|
201
199
|
try {
|
|
202
200
|
return fs.readFileSync(file, nodefony.extend({}, this.settings.readFile, localSettings));
|
|
203
201
|
} catch (e) {
|
|
@@ -210,7 +208,7 @@ class Reader extends nodefony.Service {
|
|
|
210
208
|
* @method render
|
|
211
209
|
*
|
|
212
210
|
*/
|
|
213
|
-
render(str, data) {
|
|
211
|
+
render (str, data) {
|
|
214
212
|
return this.engine.twig({
|
|
215
213
|
data: str
|
|
216
214
|
}).render(data);
|
|
@@ -220,9 +218,9 @@ class Reader extends nodefony.Service {
|
|
|
220
218
|
* @method loadPlugin
|
|
221
219
|
*
|
|
222
220
|
*/
|
|
223
|
-
loadPlugin(name, plugin) {
|
|
221
|
+
loadPlugin (name, plugin) {
|
|
224
222
|
this.plugins[name] = plugin;
|
|
225
|
-
|
|
223
|
+
const context = this;
|
|
226
224
|
return function () {
|
|
227
225
|
Array.prototype.unshift.call(arguments, name);
|
|
228
226
|
return load.apply(context, arguments);
|
|
@@ -233,16 +231,16 @@ class Reader extends nodefony.Service {
|
|
|
233
231
|
* @method xmlToJson
|
|
234
232
|
*
|
|
235
233
|
*/
|
|
236
|
-
xmlToJson(node) {
|
|
237
|
-
|
|
234
|
+
xmlToJson (node) {
|
|
235
|
+
const json = {};
|
|
238
236
|
if (node instanceof Array) {
|
|
239
237
|
for (let key = 0; key < node.length; key++) {
|
|
240
|
-
|
|
238
|
+
let param = null;
|
|
241
239
|
if (node[key] instanceof Object) {
|
|
242
240
|
if (node[key].id) {
|
|
243
241
|
json[node[key].id] = {};
|
|
244
242
|
for (param in node[key]) {
|
|
245
|
-
if (param !==
|
|
243
|
+
if (param !== "id") {
|
|
246
244
|
if (node[key][param] instanceof Array) {
|
|
247
245
|
json[node[key].id][param] = node[key][param];
|
|
248
246
|
for (let elm = 0; elm < json[node[key].id][param].length; elm++) {
|
|
@@ -261,7 +259,7 @@ class Reader extends nodefony.Service {
|
|
|
261
259
|
json[node[key].key] = node[key]._;
|
|
262
260
|
} else if (node[key].key && !node[key]._) {
|
|
263
261
|
for (param in node[key]) {
|
|
264
|
-
if (param !==
|
|
262
|
+
if (param !== "key") {
|
|
265
263
|
json[node[key].key] = {};
|
|
266
264
|
json[node[key].key][param] = this.xmlToJson(node[key][param]);
|
|
267
265
|
}
|
|
@@ -275,13 +273,13 @@ class Reader extends nodefony.Service {
|
|
|
275
273
|
}
|
|
276
274
|
return json;
|
|
277
275
|
} else if (node instanceof Object) {
|
|
278
|
-
for (
|
|
276
|
+
for (const mykey in node) {
|
|
279
277
|
json[mykey] = this.xmlToJson(node[mykey]);
|
|
280
278
|
}
|
|
281
279
|
return json;
|
|
282
|
-
} else {
|
|
283
|
-
return node;
|
|
284
280
|
}
|
|
281
|
+
return node;
|
|
282
|
+
|
|
285
283
|
return json;
|
|
286
284
|
}
|
|
287
285
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
class Encoder {
|
|
2
|
-
constructor(name, options = {}) {
|
|
2
|
+
constructor (name, options = {}) {
|
|
3
3
|
this.name = name;
|
|
4
4
|
this.settings = options;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
async encodePassword (/* raw, salt*/) {
|
|
8
|
+
throw new Error("Encoder class must overload encodePassword method");
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
async isPasswordValid (/* encoded, raw, salt*/) {
|
|
12
|
+
throw new Error("Encoder class must overload isPasswordValid method");
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
nodefony.Encoder = Encoder;
|
|
15
|
-
module.exports = Encoder;
|
|
17
|
+
module.exports = Encoder;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
class Factory extends nodefony.Service {
|
|
2
|
-
|
|
3
|
-
constructor(name, security, settings = {}) {
|
|
2
|
+
constructor (name, security, settings = {}) {
|
|
4
3
|
super(name, security.container, security.notificationsCenter);
|
|
5
4
|
this.settings = settings || {};
|
|
6
5
|
this.security = security;
|
|
7
|
-
this.providerName = this.settings.provider
|
|
6
|
+
this.providerName = this.settings.provider || this.security.providerName;
|
|
8
7
|
this.provider = null;
|
|
9
8
|
this.kernel.once("onReady", () => {
|
|
10
|
-
//console.log("onReady factory", this.name, this.providerName)
|
|
9
|
+
// console.log("onReady factory", this.name, this.providerName)
|
|
11
10
|
if (!this.providerName) {
|
|
12
11
|
if (this.providerName !== false) {
|
|
13
12
|
this.providerName = this.security.providerName;
|
|
14
13
|
}
|
|
15
14
|
}
|
|
15
|
+
// eslint-disable-next-line no-negated-condition
|
|
16
16
|
if (this.providerName !== this.security.providerName) {
|
|
17
17
|
if (this.providerName) {
|
|
18
18
|
this.provider = this.security.getProvider(this.providerName);
|
|
@@ -23,90 +23,87 @@ class Factory extends nodefony.Service {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
logger(pci, severity, msgid, msg) {
|
|
26
|
+
logger (pci, severity, msgid, msg) {
|
|
27
27
|
if (!msgid) {
|
|
28
28
|
msgid = `\x1b[36mFACTORY ${this.name}\x1b[0m`;
|
|
29
29
|
}
|
|
30
30
|
return super.logger(pci, severity, msgid, msg);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
handle(context) {
|
|
33
|
+
handle (context) {
|
|
34
34
|
return this.authenticate(context)
|
|
35
|
-
.then(token =>
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
.catch(error => {
|
|
35
|
+
.then((token) => token)
|
|
36
|
+
.catch((error) => {
|
|
39
37
|
throw error;
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
logout(context) {
|
|
44
|
-
if (
|
|
41
|
+
logout (context) {
|
|
42
|
+
if (context.session) {
|
|
45
43
|
this.log(`Factory ${this.name} : invalide session`, "DEBUG");
|
|
46
44
|
return context.session.invalidate()
|
|
47
|
-
.then(() =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw e ;
|
|
45
|
+
.then(() => context)
|
|
46
|
+
.catch((e) => {
|
|
47
|
+
throw e;
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
50
|
return new Promise((resolve) => {
|
|
54
|
-
|
|
51
|
+
resolve(context);
|
|
55
52
|
});
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
authenticate(context) {
|
|
55
|
+
authenticate (context) {
|
|
59
56
|
return new Promise((resolve, reject) => {
|
|
60
|
-
this.log(
|
|
57
|
+
this.log(`FACTORY AUTHENTICATION ${this.name}`, "DEBUG");
|
|
61
58
|
let token = null;
|
|
62
59
|
try {
|
|
63
60
|
token = this.createToken(context, this.provider);
|
|
64
61
|
if (!this.supportsToken(token)) {
|
|
65
|
-
|
|
62
|
+
reject(new nodefony.Error(`Factory ${this.name} Token Unauthorized !! `));
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
.then((
|
|
64
|
+
this.authenticateToken(token)
|
|
65
|
+
.then((Token) => {
|
|
69
66
|
token.setAuthenticated(true);
|
|
70
67
|
token.setFactory(this.name);
|
|
71
|
-
return resolve(
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
});
|
|
68
|
+
return resolve(Token);
|
|
69
|
+
})
|
|
70
|
+
.catch((e) => reject(e));
|
|
75
71
|
} catch (e) {
|
|
76
|
-
|
|
72
|
+
reject(e);
|
|
77
73
|
}
|
|
78
74
|
});
|
|
79
75
|
}
|
|
80
76
|
|
|
81
|
-
createToken(context = null, provider = null) {
|
|
77
|
+
createToken (context = null, provider = null) {
|
|
82
78
|
let token = null;
|
|
83
79
|
if (context.metaSecurity) {
|
|
84
80
|
if (context.metaSecurity.token && context.metaSecurity.token.user) {
|
|
81
|
+
// eslint-disable-next-line new-cap
|
|
85
82
|
token = new nodefony.security.tokens.userPassword(context.metaSecurity.token.user);
|
|
86
83
|
token.unserialize(context.metaSecurity.token);
|
|
87
84
|
}
|
|
88
85
|
} else {
|
|
86
|
+
// eslint-disable-next-line new-cap
|
|
89
87
|
token = new nodefony.security.tokens.userPassword();
|
|
90
88
|
}
|
|
91
89
|
token.setProvider(provider || this.provider);
|
|
92
90
|
return token;
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
supportsToken(
|
|
93
|
+
supportsToken (/* token*/) {
|
|
96
94
|
return true;
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
authenticateToken(token, provider) {
|
|
97
|
+
authenticateToken (token, provider) {
|
|
100
98
|
if (provider) {
|
|
101
99
|
return provider.authenticate(token);
|
|
102
|
-
} else {
|
|
103
|
-
if (!this.provider) {
|
|
104
|
-
return new Promise((resolve) => {
|
|
105
|
-
return resolve(token);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return this.provider.authenticate(token);
|
|
109
100
|
}
|
|
101
|
+
if (!this.provider) {
|
|
102
|
+
return new Promise((resolve) => {
|
|
103
|
+
resolve(token);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return this.provider.authenticate(token);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
class passeportFactory extends nodefony.Factory {
|
|
2
|
-
|
|
3
|
-
constructor(name, security, settings) {
|
|
2
|
+
constructor (name, security, settings) {
|
|
4
3
|
super(name, security, settings);
|
|
5
4
|
|
|
6
|
-
//this.passport = security.firewall.passport;
|
|
5
|
+
// this.passport = security.firewall.passport;
|
|
7
6
|
const passport = security.firewall.newPassport();
|
|
8
|
-
this.passport = passport.framework(security.firewall.nodefonyPassport(security.firewall));
|
|
9
|
-
//console.log(this.passport)
|
|
7
|
+
this.passport = passport.framework(security.firewall.nodefonyPassport(security.firewall, passport));
|
|
10
8
|
|
|
11
9
|
this.getStrategy(this.settings)
|
|
12
10
|
.then((strategy) => {
|
|
11
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
13
12
|
if (this.name in this.passport._strategies) {
|
|
14
13
|
this.log(`Passport Strategy ${this.name} Already Defined in firewall !!!
|
|
15
|
-
${clc.green(
|
|
14
|
+
${clc.green("Only one Factory with passport strategy type must be use in firewall config")}
|
|
16
15
|
Secure Area : ${clc.blue(security.name)}
|
|
17
16
|
Factory : ${clc.blue(this.name)}
|
|
18
17
|
Settings : ${clc.blue(util.inspect(this.settings))}
|
|
@@ -22,23 +21,23 @@ class passeportFactory extends nodefony.Factory {
|
|
|
22
21
|
if (this.strategy) {
|
|
23
22
|
this.passport.use(this.strategy);
|
|
24
23
|
}
|
|
25
|
-
})
|
|
24
|
+
})
|
|
25
|
+
.catch((e) => {
|
|
26
26
|
this.log(e, "ERROR");
|
|
27
27
|
throw e;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
getStrategy(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
31
|
+
getStrategy (/* options*/) {
|
|
32
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
33
|
+
return new Promise((resolve, reject) => reject(new Error("Passport Factory must redefine getStrategy method")));
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
authenticate(context) {
|
|
36
|
+
authenticate (context) {
|
|
38
37
|
return new Promise((resolve, reject) => {
|
|
39
38
|
try {
|
|
40
39
|
this.passport.authenticate(this.name, {
|
|
41
|
-
session: false
|
|
40
|
+
session: false
|
|
42
41
|
})(context, (error, token) => {
|
|
43
42
|
if (error) {
|
|
44
43
|
return reject(error);
|
|
@@ -52,7 +51,7 @@ class passeportFactory extends nodefony.Factory {
|
|
|
52
51
|
return resolve(null);
|
|
53
52
|
});
|
|
54
53
|
} catch (error) {
|
|
55
|
-
|
|
54
|
+
reject(error);
|
|
56
55
|
}
|
|
57
56
|
});
|
|
58
57
|
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
class Provider extends nodefony.Service {
|
|
2
|
-
|
|
3
|
-
constructor(name, manager) {
|
|
2
|
+
constructor (name, manager) {
|
|
4
3
|
super(name, manager.container);
|
|
5
4
|
this.manager = manager;
|
|
6
5
|
this.encoder = null;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
log(pci, severity, msgid, msg) {
|
|
8
|
+
log (pci, severity, msgid, msg) {
|
|
10
9
|
if (!msgid) {
|
|
11
|
-
msgid =
|
|
10
|
+
msgid = `PROVIDER ${this.name}`;
|
|
12
11
|
}
|
|
13
12
|
return super.log(pci, severity, msgid, msg);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
authenticate(token) {
|
|
15
|
+
authenticate (token) {
|
|
17
16
|
return new Promise((resolve, reject) => {
|
|
18
17
|
if (token && this.supports(token)) {
|
|
19
18
|
return this.loadUserByUsername(token.getUsername())
|
|
@@ -28,30 +27,29 @@ class Provider extends nodefony.Service {
|
|
|
28
27
|
return reject(new nodefony.Error(`user ${token.getUsername()} Incorrect password`, 401));
|
|
29
28
|
}
|
|
30
29
|
return reject(new nodefony.Error(`user ${token.getUsername()} not found `));
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
});
|
|
30
|
+
})
|
|
31
|
+
.catch((error) => reject(error));
|
|
34
32
|
}
|
|
35
|
-
return reject(new nodefony.Error(
|
|
33
|
+
return reject(new nodefony.Error(`The token is not supported by this authentication provider ${this.name}`));
|
|
36
34
|
});
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
async loadUserByUsername(
|
|
37
|
+
async loadUserByUsername (/* username*/) {
|
|
40
38
|
throw new nodefony.Error(`Provider : ${this.name} loadUserByUsername method not defined`);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
async isPasswordValid(raw, encoded) {
|
|
41
|
+
async isPasswordValid (raw, encoded) {
|
|
44
42
|
return encoded === raw;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
async refreshUser(user) {
|
|
45
|
+
async refreshUser (user) {
|
|
48
46
|
if (user instanceof nodefony.User) {
|
|
49
47
|
return await this.loadUserByUsername(user.getUsername());
|
|
50
48
|
}
|
|
51
49
|
throw new nodefony.Error("refreshUser bad user type");
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
supports(
|
|
52
|
+
supports (/* token*/) {
|
|
55
53
|
return true;
|
|
56
54
|
}
|
|
57
55
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module.exports = nodefony.registerProvider("chainProvider", () => {
|
|
2
|
-
|
|
3
2
|
class chainProvider extends nodefony.Provider {
|
|
4
|
-
|
|
5
|
-
constructor(manager, config) {
|
|
3
|
+
constructor (manager, config) {
|
|
6
4
|
super("chainProvider", manager);
|
|
7
5
|
this.config = config;
|
|
8
6
|
this.providers = [];
|
|
@@ -17,8 +15,8 @@ module.exports = nodefony.registerProvider("chainProvider", () => {
|
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
setProvider(name) {
|
|
21
|
-
|
|
18
|
+
setProvider (name) {
|
|
19
|
+
const provider = this.manager.getProvider(name);
|
|
22
20
|
if (provider) {
|
|
23
21
|
this.providers.push(provider);
|
|
24
22
|
this.nbProviders++;
|
|
@@ -27,7 +25,7 @@ module.exports = nodefony.registerProvider("chainProvider", () => {
|
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
authenticateProviders(token, index = 1) {
|
|
28
|
+
authenticateProviders (token, index = 1) {
|
|
31
29
|
return new Promise((resolve, reject) => {
|
|
32
30
|
if (this.nbProviders) {
|
|
33
31
|
try {
|
|
@@ -55,26 +53,18 @@ module.exports = nodefony.registerProvider("chainProvider", () => {
|
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
authenticate(token) {
|
|
59
|
-
return new Promise((resolve, reject) =>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return resolve(token);
|
|
63
|
-
})
|
|
64
|
-
.catch((e) => {
|
|
65
|
-
return reject(e);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
56
|
+
authenticate (token) {
|
|
57
|
+
return new Promise((resolve, reject) => this.authenticateProviders(token)
|
|
58
|
+
.then((token) => resolve(token))
|
|
59
|
+
.catch((e) => reject(e)));
|
|
68
60
|
}
|
|
69
61
|
|
|
70
|
-
loadUsersByUsername(username, index = 1) {
|
|
62
|
+
loadUsersByUsername (username, index = 1) {
|
|
71
63
|
return new Promise((resolve, reject) => {
|
|
72
64
|
if (this.provider.length) {
|
|
73
65
|
try {
|
|
74
66
|
return this.provider[index - 1].loadUserByUsername(username)
|
|
75
|
-
.then((user) =>
|
|
76
|
-
return resolve(user);
|
|
77
|
-
})
|
|
67
|
+
.then((user) => resolve(user))
|
|
78
68
|
.catch((e) => {
|
|
79
69
|
this.providers[index - 1].logger(e, "ERROR");
|
|
80
70
|
if (index === this.provider.length) {
|
|
@@ -88,27 +78,22 @@ module.exports = nodefony.registerProvider("chainProvider", () => {
|
|
|
88
78
|
} else {
|
|
89
79
|
return reject(new Error("No provider valid "));
|
|
90
80
|
}
|
|
91
|
-
|
|
92
81
|
});
|
|
93
82
|
}
|
|
94
83
|
|
|
95
|
-
loadUserByUsername(username) {
|
|
84
|
+
loadUserByUsername (username) {
|
|
96
85
|
if (this.provider.length) {
|
|
97
86
|
return this.loadUsersByUsername(username);
|
|
98
|
-
} else {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
return reject(new Error(`Chain Provider not ready`));
|
|
101
|
-
});
|
|
102
87
|
}
|
|
88
|
+
return new Promise((resolve, reject) => reject(new Error("Chain Provider not ready")));
|
|
103
89
|
}
|
|
104
90
|
|
|
105
|
-
refreshUser(user) {
|
|
91
|
+
refreshUser (user) {
|
|
106
92
|
if (user instanceof nodefony.User) {
|
|
107
93
|
return this.provider.loadUserByUsername(user.getUsername());
|
|
108
94
|
}
|
|
109
95
|
throw new Error("refreshUser bad user type");
|
|
110
96
|
}
|
|
111
|
-
|
|
112
97
|
}
|
|
113
98
|
return chainProvider;
|
|
114
99
|
});
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
module.exports = nodefony.registerProvider("memoryProvider", () => {
|
|
2
|
-
|
|
3
2
|
class memoryProvider extends nodefony.Provider {
|
|
4
|
-
|
|
5
|
-
constructor(security, config) {
|
|
3
|
+
constructor (security, config) {
|
|
6
4
|
super("memoryProvider", security);
|
|
7
5
|
this.config = config;
|
|
8
6
|
this.users = {};
|
|
9
7
|
if (this.config.users) {
|
|
10
|
-
for (
|
|
8
|
+
for (const user in this.config.users) {
|
|
11
9
|
this.setUser(this.config.users[user]);
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
loadUserByUsername(username) {
|
|
14
|
+
loadUserByUsername (username) {
|
|
17
15
|
return new Promise((resolve, reject) => {
|
|
18
16
|
if (username in this.users) {
|
|
19
17
|
return resolve(this.users[username]);
|
|
20
|
-
} else {
|
|
21
|
-
return reject(new Error(`Provider : ${this.name} loadUserByUsername user ${username} not Found `));
|
|
22
18
|
}
|
|
19
|
+
return reject(new Error(`Provider : ${this.name} loadUserByUsername user ${username} not Found `));
|
|
23
20
|
});
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
setUser(user) {
|
|
23
|
+
setUser (user) {
|
|
27
24
|
if (user.username) {
|
|
28
25
|
this.users[user.username] = new nodefony.User(
|
|
29
26
|
user.username,
|
|
@@ -45,10 +42,9 @@ module.exports = nodefony.registerProvider("memoryProvider", () => {
|
|
|
45
42
|
} else {
|
|
46
43
|
throw new Error("Bad user format memory");
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
refreshUser(user) {
|
|
47
|
+
refreshUser (user) {
|
|
52
48
|
if (user instanceof nodefony.User) {
|
|
53
49
|
return this.loadUserByUsername(user.getUsername());
|
|
54
50
|
}
|
|
@@ -56,4 +52,4 @@ module.exports = nodefony.registerProvider("memoryProvider", () => {
|
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
return memoryProvider;
|
|
59
|
-
});
|
|
55
|
+
});
|