chyz 1.0.13-rc.4 → 1.0.13-rc.5
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/BaseChyz.ts +384 -0
- package/Chyz.ts +11 -0
- package/Examples/Controllers/ApiController.ts +140 -0
- package/Examples/Controllers/KeyCloakController.ts +100 -0
- package/Examples/Controllers/PublicController.ts +42 -0
- package/Examples/Controllers/SiteController.ts +139 -0
- package/Examples/Models/Categories.ts +48 -0
- package/Examples/Models/Customer.ts +115 -0
- package/Examples/Models/KeycloakUser.ts +66 -0
- package/Examples/Models/Order.ts +64 -0
- package/Examples/Models/OrderItem.ts +27 -0
- package/Examples/Models/ProductModels.ts +49 -0
- package/Examples/Models/ProductToCategories.ts +46 -0
- package/Examples/Models/Products.ts +50 -0
- package/Examples/Models/Stocks.ts +60 -0
- package/Examples/Models/User.ts +100 -0
- package/Examples/Models/UserPermission.ts +37 -0
- package/Examples/Models/index.ts +19 -0
- package/Examples/index-keycloack.ts +78 -0
- package/Examples/index.ts +40 -0
- package/Examples/keycloak.json +7 -0
- package/Examples/log/access.log +0 -0
- package/Examples/log/app.log +6057 -0
- package/Examples/log/errors.log +1526 -0
- package/Examples/package.json +46 -0
- package/Examples/tsconfig.json +21 -0
- package/base/ActionFilter.ts +71 -0
- package/base/BaseError.ts +26 -0
- package/base/BaseObject.ts +19 -0
- package/base/Behavior.ts +6 -0
- package/base/Component.ts +66 -0
- package/base/Configurable.ts +10 -0
- package/base/Controller.ts +84 -0
- package/base/DataErrorDbException.ts +16 -0
- package/base/DbConnection.ts +51 -0
- package/base/ForbiddenHttpException.ts +15 -0
- package/base/InvalidConfigException.ts +16 -0
- package/base/Model.ts +358 -0
- package/base/ModelManager.ts +14 -0
- package/base/NotFoundHttpException.ts +14 -0
- package/base/RestClient.ts +28 -0
- package/base/UnauthorizedHttpException.ts +17 -0
- package/base/ValidationHttpException.ts +14 -0
- package/base/db/Exception.ts +14 -0
- package/base/index.ts +17 -0
- package/decorator/Middleware.ts +9 -0
- package/decorator/controller.ts +22 -0
- package/decorator/enums/ControllerDecoratorParams.ts +5 -0
- package/decorator/get.ts +37 -0
- package/decorator/index.ts +3 -0
- package/decorator/post.ts +36 -0
- package/{BaseChyz.js → dist/BaseChyz.js} +29 -4
- package/dist/BaseChyz.js.map +1 -0
- package/{Chyz.js → dist/Chyz.js} +0 -0
- package/{Chyz.js.map → dist/Chyz.js.map} +0 -0
- package/{base → dist/base}/ActionFilter.js +0 -0
- package/{base → dist/base}/ActionFilter.js.map +0 -0
- package/{base → dist/base}/BaseError.js +0 -0
- package/{base → dist/base}/BaseError.js.map +0 -0
- package/{base → dist/base}/BaseObject.js +0 -0
- package/{base → dist/base}/BaseObject.js.map +0 -0
- package/{base → dist/base}/Behavior.js +0 -0
- package/{base → dist/base}/Behavior.js.map +0 -0
- package/{base → dist/base}/Component.js +0 -0
- package/{base → dist/base}/Component.js.map +0 -0
- package/{base → dist/base}/Configurable.js +0 -0
- package/{base → dist/base}/Configurable.js.map +0 -0
- package/{base → dist/base}/Controller.js +0 -0
- package/{base → dist/base}/Controller.js.map +0 -0
- package/{base → dist/base}/DataErrorDbException.js +0 -0
- package/{base → dist/base}/DataErrorDbException.js.map +0 -0
- package/{base → dist/base}/DbConnection.js +0 -0
- package/{base → dist/base}/DbConnection.js.map +0 -0
- package/{base → dist/base}/ForbiddenHttpException.js +0 -0
- package/{base → dist/base}/ForbiddenHttpException.js.map +0 -0
- package/{base → dist/base}/InvalidConfigException.js +0 -0
- package/{base → dist/base}/InvalidConfigException.js.map +0 -0
- package/{base → dist/base}/Model.js +32 -28
- package/dist/base/Model.js.map +1 -0
- package/dist/base/ModelManager.js +17 -0
- package/dist/base/ModelManager.js.map +1 -0
- package/{base → dist/base}/NotFoundHttpException.js +0 -0
- package/{base → dist/base}/NotFoundHttpException.js.map +0 -0
- package/{base → dist/base}/RestClient.js +0 -0
- package/{base → dist/base}/RestClient.js.map +0 -0
- package/{base → dist/base}/UnauthorizedHttpException.js +0 -0
- package/{base → dist/base}/UnauthorizedHttpException.js.map +0 -0
- package/{base → dist/base}/ValidationHttpException.js +0 -0
- package/{base → dist/base}/ValidationHttpException.js.map +0 -0
- package/{base → dist/base}/db/Exception.js +0 -0
- package/{base → dist/base}/db/Exception.js.map +0 -0
- package/{base → dist/base}/index.js +1 -0
- package/{base → dist/base}/index.js.map +1 -1
- package/{decorator → dist/decorator}/Middleware.js +0 -0
- package/{decorator → dist/decorator}/Middleware.js.map +0 -0
- package/{decorator → dist/decorator}/controller.js +0 -0
- package/{decorator → dist/decorator}/controller.js.map +0 -0
- package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js +0 -0
- package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js.map +0 -0
- package/{decorator → dist/decorator}/get.js +0 -0
- package/{decorator → dist/decorator}/get.js.map +0 -0
- package/{decorator → dist/decorator}/index.js +0 -0
- package/{decorator → dist/decorator}/index.js.map +0 -0
- package/{decorator → dist/decorator}/post.js +0 -0
- package/{decorator → dist/decorator}/post.js.map +0 -0
- package/{filters → dist/filters}/AccessControl.js +0 -0
- package/{filters → dist/filters}/AccessControl.js.map +0 -0
- package/{filters → dist/filters}/AccessRule.js +0 -0
- package/{filters → dist/filters}/AccessRule.js.map +0 -0
- package/{filters → dist/filters}/auth/AuthInterface.js +0 -0
- package/{filters → dist/filters}/auth/AuthInterface.js.map +0 -0
- package/{filters → dist/filters}/auth/AuthMethod.js +0 -0
- package/{filters → dist/filters}/auth/AuthMethod.js.map +0 -0
- package/{filters → dist/filters}/auth/HttpBasicAuth.js +0 -0
- package/{filters → dist/filters}/auth/HttpBasicAuth.js.map +0 -0
- package/{filters → dist/filters}/auth/HttpBearerAuth.js +0 -0
- package/{filters → dist/filters}/auth/HttpBearerAuth.js.map +0 -0
- package/{filters → dist/filters}/auth/HttpHeaderAuth.js +0 -0
- package/{filters → dist/filters}/auth/HttpHeaderAuth.js.map +0 -0
- package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js +0 -0
- package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js.map +0 -0
- package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
- package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
- package/{filters → dist/filters}/auth/index.js +0 -0
- package/{filters → dist/filters}/auth/index.js.map +0 -0
- package/{filters → dist/filters}/index.js +0 -0
- package/{filters → dist/filters}/index.js.map +0 -0
- package/{index.js → dist/index.js} +0 -0
- package/{index.js.map → dist/index.js.map} +0 -0
- package/dist/log/config/log4js.json +55 -0
- package/{model → dist/model}/RouteDefinition.js +0 -0
- package/{model → dist/model}/RouteDefinition.js.map +0 -0
- package/{requiments → dist/requiments}/Glob.js +0 -0
- package/{requiments → dist/requiments}/Glob.js.map +0 -0
- package/{requiments → dist/requiments}/ReflectUtil.js +0 -0
- package/{requiments → dist/requiments}/ReflectUtil.js.map +0 -0
- package/{requiments → dist/requiments}/Utils.js +0 -0
- package/{requiments → dist/requiments}/Utils.js.map +0 -0
- package/{validators → dist/validators}/BooleanValidator.js +0 -0
- package/{validators → dist/validators}/BooleanValidator.js.map +0 -0
- package/{validators → dist/validators}/CompareValidator.js +0 -0
- package/{validators → dist/validators}/CompareValidator.js.map +0 -0
- package/{validators → dist/validators}/DateValidator.js +0 -0
- package/{validators → dist/validators}/DateValidator.js.map +0 -0
- package/{validators → dist/validators}/EmailValidator.js +0 -0
- package/{validators → dist/validators}/EmailValidator.js.map +0 -0
- package/{validators → dist/validators}/Validator.js +0 -0
- package/{validators → dist/validators}/Validator.js.map +0 -0
- package/{web → dist/web}/IdentityInterface.js +0 -0
- package/{web → dist/web}/IdentityInterface.js.map +0 -0
- package/{web → dist/web}/WebUser.js +0 -0
- package/{web → dist/web}/WebUser.js.map +0 -0
- package/filters/AccessControl.ts +64 -0
- package/filters/AccessRule.ts +137 -0
- package/filters/auth/AuthInterface.ts +34 -0
- package/filters/auth/AuthMethod.ts +88 -0
- package/filters/auth/HttpBasicAuth.ts +7 -0
- package/filters/auth/HttpBearerAuth.ts +31 -0
- package/filters/auth/HttpHeaderAuth.ts +53 -0
- package/filters/auth/JwtHttpBearerAuth.ts +80 -0
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/filters/auth/index.ts +3 -0
- package/filters/index.ts +2 -0
- package/index.ts +14 -0
- package/model/RouteDefinition.ts +18 -0
- package/package-lock.json +5259 -0
- package/package.json +3 -3
- package/requiments/Glob.ts +9 -0
- package/requiments/ReflectUtil.ts +26 -0
- package/requiments/Utils.ts +57 -0
- package/tsconfig.json +18 -0
- package/validators/BooleanValidator.ts +0 -0
- package/validators/CompareValidator.ts +0 -0
- package/validators/DateValidator.ts +0 -0
- package/validators/EmailValidator.ts +0 -0
- package/validators/Validator.ts +27 -0
- package/web/IdentityInterface.ts +62 -0
- package/web/WebUser.ts +100 -0
- package/BaseChyz.js.map +0 -1
- package/base/Model.js.map +0 -1
package/{Chyz.js → dist/Chyz.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -95,39 +95,15 @@ class Model extends Component_1.Component {
|
|
|
95
95
|
if (!Utils_1.default.isEmpty(this.attributes())) {
|
|
96
96
|
this._model = this._sequelize.define(this.constructor.name, this.attributes(), {
|
|
97
97
|
tableName: this.tableName(),
|
|
98
|
-
timestamps: false
|
|
98
|
+
timestamps: false,
|
|
99
|
+
createdAt: false,
|
|
100
|
+
updateAt: false
|
|
99
101
|
});
|
|
100
|
-
/**
|
|
101
|
-
* init buraya
|
|
102
|
-
*/
|
|
103
|
-
for (const relation of this.relations()) {
|
|
104
|
-
let m = relation.model;
|
|
105
|
-
if (relation.type == "hasOne") {
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
delete relation.model;
|
|
108
|
-
this.model().hasOne(m, relation);
|
|
109
|
-
}
|
|
110
|
-
if (relation.type == "hasMany") {
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
delete relation.model;
|
|
113
|
-
this.model().hasMany(m, relation);
|
|
114
|
-
}
|
|
115
|
-
if (relation.type == "belongsTo") {
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
delete relation.model;
|
|
118
|
-
this.model().belongsTo(m, relation);
|
|
119
|
-
}
|
|
120
|
-
if (relation.type == "belongsToMany") {
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
delete relation.model;
|
|
123
|
-
this.model().belongsToMany(m, relation);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
102
|
}
|
|
127
103
|
else {
|
|
128
104
|
throw new InvalidConfigException_1.InvalidConfigException(BaseChyz_1.default.t("Invalid model configuration, is not emty attributes"));
|
|
129
105
|
}
|
|
130
|
-
this.init();
|
|
106
|
+
// this.init();
|
|
131
107
|
}
|
|
132
108
|
/**
|
|
133
109
|
* Returns the database connection used by this AR class.
|
|
@@ -155,6 +131,34 @@ class Model extends Component_1.Component {
|
|
|
155
131
|
}
|
|
156
132
|
init() {
|
|
157
133
|
BaseChyz_1.default.debug("Model init....", this.constructor.name);
|
|
134
|
+
/**
|
|
135
|
+
* init buraya
|
|
136
|
+
*/
|
|
137
|
+
BaseChyz_1.default.debug("Relation init....", this.constructor.name);
|
|
138
|
+
for (const relation of this.relations()) {
|
|
139
|
+
let m = relation.model;
|
|
140
|
+
if (relation.type == "hasOne") {
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
delete relation.model;
|
|
143
|
+
this.model().hasOne(m, relation);
|
|
144
|
+
}
|
|
145
|
+
//
|
|
146
|
+
if (relation.type == "hasMany") {
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
delete relation.model;
|
|
149
|
+
this.model().hasMany(m, relation);
|
|
150
|
+
}
|
|
151
|
+
if (relation.type == "belongsTo") {
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
delete relation.model;
|
|
154
|
+
this.model().belongsTo(m, relation);
|
|
155
|
+
}
|
|
156
|
+
if (relation.type == "belongsToMany") {
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
delete relation.model;
|
|
159
|
+
this.model().belongsToMany(m, relation);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
158
162
|
}
|
|
159
163
|
tableName() {
|
|
160
164
|
return this._tableName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.js","sourceRoot":"","sources":["../../base/Model.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;AAEH,2DAAmC;AACnC,gEAAwC;AACxC,2CAAsC;AACtC,qEAAgE;AAChE,yCAAgL;AAChL,8CAAyC;AAEzC,uCAAyC;AAAjC,sGAAA,SAAS,OAAA;AAAE,gGAAA,GAAG,OAAA;AAatB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,MAAa,KAAM,SAAQ,qBAAS;IAQhC,YAAY,SAAuB;QAC/B,KAAK,EAAE,CAAC;QALJ,gBAAW,GAAQ,EAAE,CAAC;QACtB,YAAO,GAAQ,EAAE,CAAA;QAKrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QACxC,oDAAoD;QACpD,IAAI,SAAS,IAAI,IAAI;YACjB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;;YAE5B,IAAI,CAAC,UAAU,GAAG,kBAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAErD,IAAI,CAAC,eAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE;YACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,W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GAAG,IAAI;QAC5C,IAAI,MAAM,YAAY,MAAM,EAAE;YAC1B,IAAI,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACnC,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE;gBAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE;oBACjD,aAAa;oBACb,kBAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,yBAAyB,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;oBAClG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;iBACjD;aACJ;SACJ;IACL,CAAC;IAEM,UAAU;QACb,OAAO,EAAE,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACI,SAAS;QACZ,OAAO,EAAE,CAAA;IACb,CAAC;CACJ;AApRD,sBAoRC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021.. Chy Bilgisayar Bilisim
|
|
5
|
+
* Author: Cihan Ozturk
|
|
6
|
+
* E-mail: cihan@chy.com.tr
|
|
7
|
+
* Github:https://github.com/cihan53/
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ModelManager = void 0;
|
|
12
|
+
exports.ModelManager = {
|
|
13
|
+
_register(map) {
|
|
14
|
+
Object.assign(this, map);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=ModelManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelManager.js","sourceRoot":"","sources":["../../base/ModelManager.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEU,QAAA,YAAY,GAAQ;IAC7B,SAAS,CAAC,GAAQ;QACd,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC5B,CAAC;CACJ,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -26,4 +26,5 @@ __exportStar(require("./DataErrorDbException"), exports);
|
|
|
26
26
|
__exportStar(require("./ValidationHttpException"), exports);
|
|
27
27
|
__exportStar(require("./Model"), exports);
|
|
28
28
|
__exportStar(require("./RestClient"), exports);
|
|
29
|
+
__exportStar(require("./ModelManager"), exports);
|
|
29
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../base/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8B;AAC9B,+CAA4B;AAC5B,8CAA2B;AAC3B,6CAA0B;AAC1B,8CAA2B;AAC3B,iDAA8B;AAC9B,+CAA4B;AAC5B,iDAA8B;AAC9B,2DAAwC;AACxC,2DAAwC;AACxC,0DAAuC;AACvC,8DAA2C;AAC3C,yDAAsC;AACtC,4DAAyC;AACzC,0CAAuB;AACvB,+CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../base/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8B;AAC9B,+CAA4B;AAC5B,8CAA2B;AAC3B,6CAA0B;AAC1B,8CAA2B;AAC3B,iDAA8B;AAC9B,+CAA4B;AAC5B,iDAA8B;AAC9B,2DAAwC;AACxC,2DAAwC;AACxC,0DAAuC;AACvC,8DAA2C;AAC3C,yDAAsC;AACtC,4DAAyC;AACzC,0CAAuB;AACvB,+CAA4B;AAC5B,iDAA8B"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"appenders": {
|
|
3
|
+
"access": {
|
|
4
|
+
"type": "dateFile",
|
|
5
|
+
"filename": "log/access.log",
|
|
6
|
+
"pattern": "-yyyy-MM-dd",
|
|
7
|
+
"category": "http",
|
|
8
|
+
"layout": {
|
|
9
|
+
"type": "pattern",
|
|
10
|
+
"pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"app": {
|
|
14
|
+
"type": "file",
|
|
15
|
+
"filename": "log/app.log",
|
|
16
|
+
"maxLogSize": 10485760,
|
|
17
|
+
"numBackups": 3,
|
|
18
|
+
"layout": {
|
|
19
|
+
"type": "pattern",
|
|
20
|
+
"pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"errorFile": {
|
|
24
|
+
"type": "file",
|
|
25
|
+
"filename": "log/errors.log",
|
|
26
|
+
"layout": {
|
|
27
|
+
"type": "pattern",
|
|
28
|
+
"pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"errors": {
|
|
32
|
+
"type": "logLevelFilter",
|
|
33
|
+
"level": "ERROR",
|
|
34
|
+
"appender": "errorFile",
|
|
35
|
+
"layout": {
|
|
36
|
+
"type": "pattern",
|
|
37
|
+
"pattern": "[%d{yyyy-MM-ddThh.mm.ss.SSS}] [%p] %c [%l] [%f] - %m"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"console": {
|
|
41
|
+
"type": "stdout"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"categories": {
|
|
45
|
+
"default": {
|
|
46
|
+
"appenders": ["console","app" ,"errors" ],
|
|
47
|
+
"level": "ALL",
|
|
48
|
+
"enableCallStack": true
|
|
49
|
+
},
|
|
50
|
+
"http": {
|
|
51
|
+
"level": "INFO",
|
|
52
|
+
"appenders": [ "access" ]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
import BaseChyz from "../BaseChyz";
|
|
8
|
+
import {ForbiddenHttpException} from "../base/ForbiddenHttpException";
|
|
9
|
+
import {ActionFilter} from "../base/ActionFilter";
|
|
10
|
+
import {AccessRule} from "./AccessRule";
|
|
11
|
+
import {WebUser} from "../web/WebUser";
|
|
12
|
+
import Utils from "../requiments/Utils";
|
|
13
|
+
import {NextFunction, Request, Response} from "express";
|
|
14
|
+
|
|
15
|
+
var _ = require('lodash');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export class AccessControl extends ActionFilter {
|
|
19
|
+
|
|
20
|
+
public user: any = null;
|
|
21
|
+
public rules: any;
|
|
22
|
+
|
|
23
|
+
public init() {
|
|
24
|
+
super.init()
|
|
25
|
+
|
|
26
|
+
if (this.user == undefined) {
|
|
27
|
+
this.user = Utils.cloneDeep(BaseChyz.getComponent("user")) ?? new WebUser();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.rules.forEach((rule:any, index:number) => {
|
|
31
|
+
if (rule === Object(rule)) {
|
|
32
|
+
this.rules[index] = Utils.createObject(new AccessRule(), rule);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
public async beforeAction(action:any, request:Request) {
|
|
39
|
+
let allow;
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
let user = request.user ?? this.user;
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
user.identity = request.identity ?? null;
|
|
44
|
+
|
|
45
|
+
for (const rulesKey in this.rules) {
|
|
46
|
+
if ((allow = this.rules[rulesKey].allows(action, user, request))) {
|
|
47
|
+
return true;
|
|
48
|
+
} else if (allow === false) {
|
|
49
|
+
this.denyAccess(user);
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.denyAccess(user);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public denyAccess(user: WebUser) {
|
|
59
|
+
if (user != undefined && user.getIsGuest()) {
|
|
60
|
+
user.loginRequired();
|
|
61
|
+
} else throw new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
import {WebUser} from "../web/WebUser";
|
|
8
|
+
|
|
9
|
+
var _ = require('lodash');
|
|
10
|
+
import {Component} from "../base/Component";
|
|
11
|
+
import {InvalidConfigException} from "../base/InvalidConfigException";
|
|
12
|
+
import {Request, Response} from "express";
|
|
13
|
+
|
|
14
|
+
export class AccessRule extends Component {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @var bool whether this is an 'allow' rule or 'deny' rule.
|
|
18
|
+
*/
|
|
19
|
+
public allow:any;
|
|
20
|
+
/**
|
|
21
|
+
* @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
|
|
22
|
+
* If not set or empty, it means this rule applies to all actions.
|
|
23
|
+
*/
|
|
24
|
+
public actions:any;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @var array list of the controller IDs that this rule applies to.
|
|
28
|
+
*/
|
|
29
|
+
public controllers:any;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* - `?`: matches a guest user (not authenticated yet)
|
|
33
|
+
* - `@`: matches an authenticated user
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
public roles:any;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
|
|
40
|
+
*/
|
|
41
|
+
public permissions:any;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @var array list of user IP addresses that this rule applies to. An IP address
|
|
45
|
+
* can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
|
|
46
|
+
* For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
|
|
47
|
+
* It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
|
|
48
|
+
* 20-bit private network block in RFC1918.
|
|
49
|
+
* If not set or empty, it means this rule applies to all IP addresses.
|
|
50
|
+
*/
|
|
51
|
+
public ips:any;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public allows(action:any, user:WebUser, request:Request) {
|
|
55
|
+
if (
|
|
56
|
+
this.matchAction(action)
|
|
57
|
+
&& this.matchRole(user)
|
|
58
|
+
) {
|
|
59
|
+
return this.allow
|
|
60
|
+
}
|
|
61
|
+
// if (this.matchAction($action)
|
|
62
|
+
// && this.matchRole($user)
|
|
63
|
+
// && this.matchIP($request->getUserIP())
|
|
64
|
+
// && this.matchVerb($request->getMethod())
|
|
65
|
+
// && this.matchController($action->controller)
|
|
66
|
+
// && this.matchCustom($action)
|
|
67
|
+
// ) {
|
|
68
|
+
// return $this->allow ? true : false;
|
|
69
|
+
// }
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param Action $action the action
|
|
76
|
+
* @return bool whether the rule applies to the action
|
|
77
|
+
*/
|
|
78
|
+
protected matchAction(action:any) {
|
|
79
|
+
return _.isEmpty(this.actions) || this.actions.includes(action.id);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param Controller $controller the controller
|
|
84
|
+
* @return bool whether the rule applies to the controller
|
|
85
|
+
*/
|
|
86
|
+
protected matchController(controller:any) {
|
|
87
|
+
// if (empty($this->controllers)) {
|
|
88
|
+
// return true;
|
|
89
|
+
// }
|
|
90
|
+
//
|
|
91
|
+
// $id = $controller->getUniqueId();
|
|
92
|
+
// foreach ($this->controllers as $pattern) {
|
|
93
|
+
// if (StringHelper::matchWildcard($pattern, $id)) {
|
|
94
|
+
// return true;
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected matchRole(user:any) {
|
|
102
|
+
let items = _.isEmpty(this.roles) ? [] : this.roles;
|
|
103
|
+
|
|
104
|
+
if (!_.isEmpty(this.permissions)) {
|
|
105
|
+
items = _.merge(items, this.permissions);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (_.isEmpty(items)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if (user === false) {
|
|
114
|
+
throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const itemsKey in items) {
|
|
118
|
+
let item = items[itemsKey];
|
|
119
|
+
if (item === '?') {
|
|
120
|
+
if (user.getIsGuest()) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
} else if (item === '@') {
|
|
124
|
+
if (!user.getIsGuest()) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
//roleparams
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
}
|