chyz 1.0.13-rc.3 → 1.0.13-rc.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.
Files changed (176) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
  2. package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/{dist/base → base}/ActionFilter.js +0 -0
  6. package/{dist/base → base}/ActionFilter.js.map +0 -0
  7. package/{dist/base → base}/BaseError.js +0 -0
  8. package/{dist/base → base}/BaseError.js.map +0 -0
  9. package/{dist/base → base}/BaseObject.js +0 -0
  10. package/{dist/base → base}/BaseObject.js.map +0 -0
  11. package/{dist/base → base}/Behavior.js +0 -0
  12. package/{dist/base → base}/Behavior.js.map +0 -0
  13. package/{dist/base → base}/Component.js +0 -0
  14. package/{dist/base → base}/Component.js.map +0 -0
  15. package/{dist/base → base}/Configurable.js +0 -0
  16. package/{dist/base → base}/Configurable.js.map +0 -0
  17. package/{dist/base → base}/Controller.js +0 -0
  18. package/{dist/base → base}/Controller.js.map +0 -0
  19. package/{dist/base → base}/DataErrorDbException.js +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  21. package/{dist/base → base}/DbConnection.js +0 -0
  22. package/{dist/base → base}/DbConnection.js.map +0 -0
  23. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  25. package/{dist/base → base}/InvalidConfigException.js +0 -0
  26. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  27. package/{dist/base → base}/Model.js +0 -0
  28. package/{dist/base → base}/Model.js.map +0 -0
  29. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  30. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  31. package/{dist/base → base}/RestClient.js +0 -0
  32. package/{dist/base → base}/RestClient.js.map +0 -0
  33. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  34. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  35. package/{dist/base → base}/ValidationHttpException.js +0 -0
  36. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  37. package/{dist/base → base}/db/Exception.js +0 -0
  38. package/{dist/base → base}/db/Exception.js.map +0 -0
  39. package/{dist/base → base}/index.js +0 -0
  40. package/{dist/base → base}/index.js.map +0 -0
  41. package/{dist/decorator → decorator}/Middleware.js +0 -0
  42. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  43. package/{dist/decorator → decorator}/controller.js +0 -0
  44. package/{dist/decorator → decorator}/controller.js.map +0 -0
  45. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  46. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  47. package/{dist/decorator → decorator}/get.js +0 -0
  48. package/{dist/decorator → decorator}/get.js.map +0 -0
  49. package/{dist/decorator → decorator}/index.js +0 -0
  50. package/{dist/decorator → decorator}/index.js.map +0 -0
  51. package/{dist/decorator → decorator}/post.js +0 -0
  52. package/{dist/decorator → decorator}/post.js.map +0 -0
  53. package/{dist/filters → filters}/AccessControl.js +0 -0
  54. package/{dist/filters → filters}/AccessControl.js.map +0 -0
  55. package/{dist/filters → filters}/AccessRule.js +0 -0
  56. package/{dist/filters → filters}/AccessRule.js.map +0 -0
  57. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  58. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  59. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  60. package/{dist/filters → filters}/auth/AuthMethod.js.map +0 -0
  61. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  62. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  63. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  64. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  65. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  66. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  67. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +0 -0
  68. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +0 -0
  69. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  70. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  71. package/{dist/filters → filters}/auth/index.js +0 -0
  72. package/{dist/filters → filters}/auth/index.js.map +0 -0
  73. package/{dist/filters → filters}/index.js +0 -0
  74. package/{dist/filters → filters}/index.js.map +0 -0
  75. package/{dist/index.js → index.js} +0 -0
  76. package/{dist/index.js.map → index.js.map} +0 -0
  77. package/{dist/model → model}/RouteDefinition.js +0 -0
  78. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  79. package/package.json +1 -1
  80. package/{dist/requiments → requiments}/Glob.js +0 -0
  81. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  82. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  83. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  84. package/{dist/requiments → requiments}/Utils.js +0 -0
  85. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  86. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  87. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  88. package/{dist/validators → validators}/CompareValidator.js +0 -0
  89. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  90. package/{dist/validators → validators}/DateValidator.js +0 -0
  91. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  92. package/{dist/validators → validators}/EmailValidator.js +0 -0
  93. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  94. package/{dist/validators → validators}/Validator.js +0 -0
  95. package/{dist/validators → validators}/Validator.js.map +0 -0
  96. package/{dist/web → web}/IdentityInterface.js +0 -0
  97. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  98. package/{dist/web → web}/WebUser.js +0 -0
  99. package/{dist/web → web}/WebUser.js.map +0 -0
  100. package/BaseChyz.ts +0 -361
  101. package/Chyz.ts +0 -11
  102. package/Examples/Controllers/ApiController.ts +0 -131
  103. package/Examples/Controllers/KeyCloakController.ts +0 -100
  104. package/Examples/Controllers/PublicController.ts +0 -42
  105. package/Examples/Controllers/SiteController.ts +0 -139
  106. package/Examples/Models/Categories.ts +0 -36
  107. package/Examples/Models/Customer.ts +0 -115
  108. package/Examples/Models/KeycloakUser.ts +0 -66
  109. package/Examples/Models/Order.ts +0 -64
  110. package/Examples/Models/OrderItem.ts +0 -27
  111. package/Examples/Models/ProductModels.ts +0 -50
  112. package/Examples/Models/ProductToCategories.ts +0 -35
  113. package/Examples/Models/Products.ts +0 -49
  114. package/Examples/Models/Stocks.ts +0 -60
  115. package/Examples/Models/User.ts +0 -100
  116. package/Examples/Models/UserPermission.ts +0 -37
  117. package/Examples/index-keycloack.ts +0 -78
  118. package/Examples/index.ts +0 -39
  119. package/Examples/keycloak.json +0 -7
  120. package/Examples/log/access.log +0 -0
  121. package/Examples/log/app.log +0 -923
  122. package/Examples/log/errors.log +0 -80
  123. package/Examples/package.json +0 -46
  124. package/Examples/tsconfig.json +0 -20
  125. package/base/ActionFilter.ts +0 -71
  126. package/base/BaseError.ts +0 -26
  127. package/base/BaseObject.ts +0 -19
  128. package/base/Behavior.ts +0 -6
  129. package/base/Component.ts +0 -66
  130. package/base/Configurable.ts +0 -10
  131. package/base/Controller.ts +0 -84
  132. package/base/DataErrorDbException.ts +0 -16
  133. package/base/DbConnection.ts +0 -51
  134. package/base/ForbiddenHttpException.ts +0 -15
  135. package/base/InvalidConfigException.ts +0 -16
  136. package/base/Model.ts +0 -354
  137. package/base/NotFoundHttpException.ts +0 -14
  138. package/base/RestClient.ts +0 -28
  139. package/base/UnauthorizedHttpException.ts +0 -17
  140. package/base/ValidationHttpException.ts +0 -14
  141. package/base/db/Exception.ts +0 -14
  142. package/base/index.ts +0 -16
  143. package/decorator/Middleware.ts +0 -9
  144. package/decorator/controller.ts +0 -22
  145. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  146. package/decorator/get.ts +0 -37
  147. package/decorator/index.ts +0 -3
  148. package/decorator/post.ts +0 -36
  149. package/dist/README.md +0 -270
  150. package/dist/log/config/log4js.json +0 -55
  151. package/dist/package.json +0 -55
  152. package/filters/AccessControl.ts +0 -64
  153. package/filters/AccessRule.ts +0 -137
  154. package/filters/auth/AuthInterface.ts +0 -34
  155. package/filters/auth/AuthMethod.ts +0 -88
  156. package/filters/auth/HttpBasicAuth.ts +0 -7
  157. package/filters/auth/HttpBearerAuth.ts +0 -31
  158. package/filters/auth/HttpHeaderAuth.ts +0 -53
  159. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  160. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  161. package/filters/auth/index.ts +0 -3
  162. package/filters/index.ts +0 -2
  163. package/index.ts +0 -14
  164. package/model/RouteDefinition.ts +0 -18
  165. package/package-lock.json +0 -5259
  166. package/requiments/Glob.ts +0 -9
  167. package/requiments/ReflectUtil.ts +0 -26
  168. package/requiments/Utils.ts +0 -57
  169. package/tsconfig.json +0 -18
  170. package/validators/BooleanValidator.ts +0 -0
  171. package/validators/CompareValidator.ts +0 -0
  172. package/validators/DateValidator.ts +0 -0
  173. package/validators/EmailValidator.ts +0 -0
  174. package/validators/Validator.ts +0 -27
  175. package/web/IdentityInterface.ts +0 -62
  176. package/web/WebUser.ts +0 -100
package/dist/README.md DELETED
@@ -1,270 +0,0 @@
1
- Hızlı şekilde microservis hazırlama için geliştirmeye başladım<br>
2
-
3
- Temel olarak yii2 php framework'ten örnekler alındı<br>
4
-
5
- Temel olarak basit bir Controller geliştirildi, ayrıca authentication geliştirildi.<br>
6
-
7
- Klasör Yapısı<br>
8
- *---Controllers <br>
9
- *---Models<br>
10
- *---Log<br>
11
- *---Framework<br>
12
- index.ts<br>
13
-
14
- `##Başlangıç<br>
15
- yarn start
16
-
17
- ## index.ts alanlar düzenlenmeli.
18
-
19
- ```typescript
20
- require('dotenv-flow').config();
21
-
22
- import BaseChyz from "chyz/dist/BaseChyz";
23
- import Chyz, {DbConnection} from "chyz/dist";
24
- import {WebUser} from "../web/WebUser";
25
- import {User} from "./Models/User";
26
-
27
- let config = {
28
- components: {
29
- db: {
30
- class: DbConnection,
31
- database: process.env.DBDATABASE,
32
- username: process.env.DBUSER,
33
- password: process.env.DBPASS,
34
- options: {
35
- host: process.env.DBHOST,
36
- dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
37
- // disable logging; default: console.log
38
- logging: false
39
- }
40
- },
41
- user: {
42
- 'class': WebUser,
43
- 'identityClass': User
44
- }
45
- }
46
- }
47
- Chyz.app(config).Start();
48
- ```
49
-
50
- ## Create Model
51
-
52
- Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
53
-
54
- ```typescript
55
- import {Model, DataTypes} from "chyz/base/Model";
56
-
57
- export class CustomerCLass extends Model {
58
- public tableName() {
59
- return 'customer';
60
- }
61
-
62
- public attributes() {
63
- return {
64
- username: {
65
- type: DataTypes.STRING,
66
- allowNull: false,
67
- validate: {
68
- notEmpty: true,
69
- len: [4, 255],
70
- }
71
- },
72
- email: {
73
- type: DataTypes.STRING,
74
- validate: {
75
- isEmail: true
76
- }
77
- },
78
- firstname: {
79
- type: DataTypes.STRING,
80
- allowNull: false
81
- },
82
- lastname: {
83
- type: DataTypes.STRING,
84
- },
85
- }
86
- }
87
-
88
- }
89
- const Customer= new CustomerCLass();
90
- export { Customer };
91
-
92
- ```
93
- ````typescript
94
- export class ProductsClass extends Model {
95
- [x: string]: any;
96
-
97
- tableName() {
98
- return 'products';
99
- }
100
-
101
- attributes() {
102
- return {
103
- // Model attributes are defined here
104
- title: {
105
- type: DataTypes.STRING,
106
- allowNull: false
107
- },
108
- model_id: {
109
- type: DataTypes.INTEGER,
110
- allowNull: false
111
- },
112
- properties: {
113
- type: DataTypes.STRING,
114
- allowNull: false
115
- }
116
-
117
- }
118
- }
119
-
120
- relations(): Relation[] {
121
- return [
122
- {
123
- type: "hasOne",
124
- foreignKey: "id",
125
- sourceKey: "customer_id",
126
- model: Customer.model()
127
- }
128
- ]
129
- }
130
- }
131
-
132
- const Products = new ProductsClass()
133
- export {Products}
134
- ````
135
-
136
- ## Http POST ve GET verilerini model'e yükleme
137
-
138
- ````typescript
139
-
140
- /**
141
- * post data
142
- * {
143
- * "Customer":{
144
- * "firstname":"cihan",
145
- * "lastname":"ozturk"
146
- * ....
147
- * }
148
- * }
149
- * @type {Customer}
150
- */
151
- import {Customer} from "./Customer";
152
- //Customer Model Create
153
- let customer: Customer = Customer;
154
- customer.load(req.body, "Customer");//load customer data
155
- let cus: any = await customer.save();
156
-
157
-
158
- ````
159
- ## Transaction
160
- Transaction oluşturma
161
-
162
-
163
- ```typescript
164
- let transaction
165
- try {
166
- // get transaction
167
- transaction = await BaseChyz.getComponent("db").transaction();
168
- //Customer Model Create
169
- let customer: Customer = new Customer();
170
- customer.load(data, "Customer");//load customer data
171
- let cus: any = await customer.save({}, {transaction});
172
- if (!cus) {
173
- throw new ValidationHttpException(customer.errors);
174
- }
175
- } catch (e) {
176
- if (transaction) {
177
- await transaction.rollback();
178
- BaseChyz.warn("Rollback transaction")
179
- }
180
- ...
181
- }
182
- ```
183
-
184
- ## Yetkilendirme için kullanıcı modeli
185
-
186
- ```typescript
187
- /*
188
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
189
- * Author: Cihan Ozturk
190
- * E-mail: cihan@chy.com.tr
191
- * Github:https://github.com/cihan53/
192
- */
193
- import {IdentityInterface} from "chyz/web/IdentityInterface";
194
- // @ts-ignore
195
- import {DataTypes} from "chyz/base";
196
- import {Model} from "chyz/base";
197
- import BaseChyz from "chyz/BaseChyz";
198
-
199
- const bcrypt = require('bcrypt');
200
- const JsonWebToken = require("jsonwebtoken");
201
-
202
- export class User extends Model implements IdentityInterface {
203
- public tableName() {
204
- return 'users';
205
- }
206
- findIdentity(id: number) {
207
- throw new Error("Method not implemented.");
208
- }
209
-
210
- getId(): number {
211
- throw new Error("Method not implemented.");
212
- }
213
-
214
- getAuthKey(): string {
215
- throw new Error("Method not implemented.");
216
- }
217
-
218
- validateAuthKey(authKey: string): boolean {
219
- throw new Error("Method not implemented.");
220
- }
221
-
222
- public attributes() {
223
- return {
224
- // Model attributes are defined here
225
- username: {
226
- type: DataTypes.STRING,
227
- allowNull: false
228
- },
229
- password: {
230
- type: DataTypes.STRING,
231
- allowNull: false
232
- },
233
- user_role: {
234
- type: DataTypes.STRING,
235
- allowNull: false
236
- },
237
- salt_text: {
238
- type: DataTypes.STRING
239
- // allowNull defaults to true
240
- }
241
- }
242
- }
243
-
244
- async findIdentityByAccessToken(token, type) {
245
- let decoded = JsonWebToken.decode(token, {complete: true})
246
- let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
247
- if(identity){
248
- BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
249
- try {
250
- JsonWebToken.verify(token, identity.salt_text);
251
- BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
252
- return identity;
253
- } catch(err) {
254
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
255
- return null;
256
- }
257
- }
258
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
259
- return null;
260
- }
261
-
262
-
263
- }
264
-
265
-
266
-
267
-
268
-
269
-
270
- ```
@@ -1,55 +0,0 @@
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
- }
package/dist/package.json DELETED
@@ -1,55 +0,0 @@
1
- {
2
- "name": "chyz",
3
- "version": "1.0.13-rc.3",
4
- "description": "Nodejs MicroServis Framework",
5
- "main": "index.js",
6
- "scripts": {
7
- "dev": "nodemon index.ts",
8
- "debug": "ts-node index.ts",
9
- "build": "rmdir /S /Q .\\dist && npx tsc && xcopy .\\log .\\dist\\log /e /i /h /Y && copy .\\package.json .\\dist\\package.json && copy .\\README.md .\\dist\\README.md ",
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "postversion": "git push && git push --tags"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/cihan53/Chy-Nodejs-Framework.git"
16
- },
17
- "author": "Cihan Ozturk",
18
- "license": "MIT",
19
- "bugs": {
20
- "url": "https://github.com/cihan53/Chy-Nodejs-Framework/issues"
21
- },
22
- "homepage": "https://github.com/cihan53/Chy-Nodejs-Framework#readme",
23
- "dependencies": {
24
- "axios": "^0.23.0",
25
- "babel-plugin-transform-decorators-legacy": "^1.3.5",
26
- "body-parser": "^1.19.0",
27
- "dotenv-flow": "^3.2.0",
28
- "express": "^4.17.1",
29
- "express-session": "^1.17.2",
30
- "glob": "^7.1.7",
31
- "ip": "^1.1.5",
32
- "jsonwebtoken": "^8.5.1",
33
- "lodash": "^4.17.21",
34
- "log4js": "^6.3.0",
35
- "method-override": "^3.0.0",
36
- "passport": "^0.4.1",
37
- "pg": "^8.7.1",
38
- "pg-hstore": "^2.3.4",
39
- "reflect-metadata": "^0.1.13",
40
- "sequelize": "^6.6.5"
41
- },
42
- "devDependencies": {
43
- "@types/express": "^4.17.13",
44
- "@types/node": "^16.6.1",
45
- "@types/validator": "^13.6.3",
46
- "nodemon": "^2.0.12",
47
- "ts-node": "^10.2.0",
48
- "typescript": "^4.3.5"
49
- },
50
- "keywords": [
51
- "Framework",
52
- "RespAPI",
53
- "microservice"
54
- ]
55
- }
@@ -1,64 +0,0 @@
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
- }
@@ -1,137 +0,0 @@
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
- }
@@ -1,34 +0,0 @@
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 {Request, Response} from "express";
8
-
9
- export interface AuthInterface{
10
- /**
11
- * Authenticates the current user.
12
- * @param User $user
13
- * @param Request $request
14
- * @param Response $response
15
- * @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
16
- * @throws UnauthorizedHttpException if authentication information is provided but is invalid.
17
- */
18
- authenticate(user:any, request:Request, response:Response):any;
19
-
20
- /**
21
- * Generates challenges upon authentication failure.
22
- * For example, some appropriate HTTP headers may be generated.
23
- * @param Response $response
24
- */
25
- challenge(response:Response):Response;
26
-
27
- /**
28
- * Handles authentication failure.
29
- * The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.
30
- * @param Response $response
31
- * @throws UnauthorizedHttpException
32
- */
33
- handleFailure(response:Response):Response;
34
- }
@@ -1,88 +0,0 @@
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
-
8
- import {ActionFilter} from "../../base/ActionFilter";
9
- import {AuthInterface} from "./AuthInterface";
10
- import {UnauthorizedHttpException} from "../../base/UnauthorizedHttpException";
11
- import {WebUser} from "../../web/WebUser";
12
- import {Request, Response} from "express";
13
-
14
- export abstract class AuthMethod extends ActionFilter implements AuthInterface {
15
-
16
- /**
17
- * @var User the user object representing the user authentication status. If not set, the `user` application component will be used.
18
- */
19
- public user: WebUser | undefined;
20
-
21
- /**
22
- * @var Request the current request. If not set, the `request` application component will be used.
23
- */
24
- public request: Request | undefined;
25
-
26
- /**
27
- * @var Response the response to be sent. If not set, the `response` application component will be used.
28
- */
29
- public response: Response | undefined;
30
-
31
-
32
- public optional = [];
33
-
34
- public async beforeAction(action: any, request: Request, response: Response) {
35
- let identity = await this.authenticate(
36
- this.user ?? new WebUser(),
37
- request,
38
- response
39
- )
40
-
41
-
42
- // @ts-ignore
43
- request.identity = identity;
44
-
45
- if (identity !== null) {
46
- return true;
47
- }
48
-
49
- this.challenge(response);
50
- this.handleFailure(response);
51
- return false;
52
- }
53
-
54
- authenticate(user: WebUser, request: Request, response: Response) {
55
-
56
- }
57
-
58
- // @ts-ignore
59
- challenge(response: Response): void {
60
- }
61
-
62
- // @ts-ignore
63
- handleFailure(response: Response) {
64
- throw new UnauthorizedHttpException('Your request was made with invalid credentials.');
65
- }
66
-
67
- getHeaderByKey(headers: any, findKey: any) {
68
- let key = Object.keys(headers).find(key => key.toLowerCase() === findKey.toLowerCase())
69
- if (key) {
70
- return headers[key];
71
- }
72
-
73
- return null
74
- }
75
-
76
- patternCheck(headerText:any, pattern:RegExp) {
77
- if (pattern) {
78
- let matches = headerText.match(pattern)
79
- if (matches && matches.length > 0) {
80
- return matches;
81
- } else {
82
- return null
83
- }
84
- }
85
-
86
- return null
87
- }
88
- }