chyz 2.0.1-rc.3 → 2.0.1-rc.36

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 (229) hide show
  1. package/BaseChyz.ts +623 -0
  2. package/README.md +518 -518
  3. package/base/ActionFilter.ts +88 -0
  4. package/base/BadRequestHttpException.ts +14 -0
  5. package/base/{BaseError.js → BaseError.ts} +26 -18
  6. package/base/Behavior.ts +6 -0
  7. package/base/CBaseObject.ts +17 -0
  8. package/base/CEvents.ts +24 -0
  9. package/base/{CRequest.js → CRequest.ts} +6 -2
  10. package/base/CWebController.ts +90 -0
  11. package/base/Component.ts +66 -0
  12. package/{model/RouteDefinition.js → base/Configurable.ts} +4 -2
  13. package/base/DataErrorDbException.ts +16 -0
  14. package/base/DbConnection.ts +55 -0
  15. package/base/ForbiddenHttpException.ts +15 -0
  16. package/base/InvalidArgumentException.ts +16 -0
  17. package/base/InvalidConfigException.ts +16 -0
  18. package/base/{Logs.js → Logs.ts} +41 -24
  19. package/base/{Model.js → Model.ts} +225 -158
  20. package/base/{ModelManager.js → ModelManager.ts} +7 -7
  21. package/base/NotFoundHttpException.ts +14 -0
  22. package/base/RestClient.ts +26 -0
  23. package/base/UnauthorizedHttpException.ts +17 -0
  24. package/base/ValidationHttpException.ts +14 -0
  25. package/base/db/Exception.ts +14 -0
  26. package/base/index.ts +19 -0
  27. package/decorator/Middleware.ts +9 -0
  28. package/decorator/{controller.js → controller.ts} +7 -9
  29. package/decorator/{delete.js → delete.ts} +9 -9
  30. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  31. package/decorator/{get.js → get.ts} +11 -10
  32. package/decorator/index.ts +5 -0
  33. package/decorator/{post.js → post.ts} +10 -10
  34. package/decorator/{put.js → put.ts} +9 -9
  35. package/filters/AccessControl.ts +74 -0
  36. package/filters/AccessRule.ts +182 -0
  37. package/filters/auth/{AuthInterface.d.ts → AuthInterface.ts} +15 -7
  38. package/filters/auth/AuthMethod.ts +100 -0
  39. package/filters/auth/HttpBasicAuth.ts +79 -0
  40. package/filters/auth/HttpBearerAuth.ts +34 -0
  41. package/filters/auth/HttpHeaderAuth.ts +61 -0
  42. package/filters/auth/JwtHttpBearerAuth.ts +83 -0
  43. package/filters/auth/KeyCloakHttpBearerAuth.ts +114 -0
  44. package/filters/auth/index.ts +4 -0
  45. package/filters/index.ts +2 -0
  46. package/index.ts +80 -0
  47. package/log/config/log4js.json +55 -55
  48. package/model/RouteDefinition.ts +18 -0
  49. package/package.json +63 -61
  50. package/rbac/AuthAssignment.ts +50 -0
  51. package/rbac/{AuthItem.js → AuthItem.ts} +22 -16
  52. package/rbac/{AuthItemChild.js → AuthItemChild.ts} +21 -14
  53. package/rbac/AuthManager.ts +399 -0
  54. package/rbac/index.ts +12 -0
  55. package/{web/IdentityInterface.js → requiments/Glob.ts} +3 -2
  56. package/requiments/{ReflectUtil.js → ReflectUtil.ts} +6 -4
  57. package/requiments/{Utils.js → Utils.ts} +40 -34
  58. package/validators/BooleanValidator.ts +0 -0
  59. package/validators/CompareValidator.ts +0 -0
  60. package/validators/DateValidator.ts +0 -0
  61. package/validators/EmailValidator.ts +0 -0
  62. package/validators/Validator.ts +27 -0
  63. package/web/{IdentityInterface.d.ts → IdentityInterface.ts} +15 -2
  64. package/web/WebUser.ts +187 -0
  65. package/BaseChyz.d.ts +0 -74
  66. package/BaseChyz.d.ts.map +0 -1
  67. package/BaseChyz.js +0 -569
  68. package/base/ActionFilter.d.ts +0 -33
  69. package/base/ActionFilter.d.ts.map +0 -1
  70. package/base/ActionFilter.js +0 -90
  71. package/base/BadRequestHttpException.d.ts +0 -6
  72. package/base/BadRequestHttpException.d.ts.map +0 -1
  73. package/base/BadRequestHttpException.js +0 -17
  74. package/base/BaseError.d.ts +0 -44
  75. package/base/BaseError.d.ts.map +0 -1
  76. package/base/Behavior.d.ts +0 -4
  77. package/base/Behavior.d.ts.map +0 -1
  78. package/base/Behavior.js +0 -7
  79. package/base/CBaseObject.d.ts +0 -5
  80. package/base/CBaseObject.d.ts.map +0 -1
  81. package/base/CBaseObject.js +0 -16
  82. package/base/CEvents.d.ts +0 -13
  83. package/base/CEvents.d.ts.map +0 -1
  84. package/base/CEvents.js +0 -24
  85. package/base/CRequest.d.ts +0 -2
  86. package/base/CRequest.d.ts.map +0 -1
  87. package/base/CWebController.d.ts +0 -44
  88. package/base/CWebController.d.ts.map +0 -1
  89. package/base/CWebController.js +0 -81
  90. package/base/Component.d.ts +0 -21
  91. package/base/Component.d.ts.map +0 -1
  92. package/base/Component.js +0 -57
  93. package/base/Configurable.d.ts +0 -3
  94. package/base/Configurable.d.ts.map +0 -1
  95. package/base/Configurable.js +0 -8
  96. package/base/DataErrorDbException.d.ts +0 -6
  97. package/base/DataErrorDbException.d.ts.map +0 -1
  98. package/base/DataErrorDbException.js +0 -17
  99. package/base/DbConnection.d.ts +0 -13
  100. package/base/DbConnection.d.ts.map +0 -1
  101. package/base/DbConnection.js +0 -53
  102. package/base/ForbiddenHttpException.d.ts +0 -5
  103. package/base/ForbiddenHttpException.d.ts.map +0 -1
  104. package/base/ForbiddenHttpException.js +0 -16
  105. package/base/InvalidArgumentException.d.ts +0 -6
  106. package/base/InvalidArgumentException.d.ts.map +0 -1
  107. package/base/InvalidArgumentException.js +0 -17
  108. package/base/InvalidConfigException.d.ts +0 -6
  109. package/base/InvalidConfigException.d.ts.map +0 -1
  110. package/base/InvalidConfigException.js +0 -17
  111. package/base/Logs.d.ts +0 -22
  112. package/base/Logs.d.ts.map +0 -1
  113. package/base/Model.d.ts +0 -302
  114. package/base/Model.d.ts.map +0 -1
  115. package/base/ModelManager.d.ts +0 -2
  116. package/base/ModelManager.d.ts.map +0 -1
  117. package/base/NotFoundHttpException.d.ts +0 -6
  118. package/base/NotFoundHttpException.d.ts.map +0 -1
  119. package/base/NotFoundHttpException.js +0 -17
  120. package/base/RestClient.d.ts +0 -7
  121. package/base/RestClient.d.ts.map +0 -1
  122. package/base/RestClient.js +0 -25
  123. package/base/UnauthorizedHttpException.d.ts +0 -6
  124. package/base/UnauthorizedHttpException.d.ts.map +0 -1
  125. package/base/UnauthorizedHttpException.js +0 -17
  126. package/base/ValidationHttpException.d.ts +0 -6
  127. package/base/ValidationHttpException.d.ts.map +0 -1
  128. package/base/ValidationHttpException.js +0 -17
  129. package/base/db/Exception.d.ts +0 -7
  130. package/base/db/Exception.d.ts.map +0 -1
  131. package/base/db/Exception.js +0 -15
  132. package/base/index.d.ts +0 -20
  133. package/base/index.d.ts.map +0 -1
  134. package/base/index.js +0 -41
  135. package/decorator/Middleware.d.ts +0 -4
  136. package/decorator/Middleware.d.ts.map +0 -1
  137. package/decorator/Middleware.js +0 -11
  138. package/decorator/controller.d.ts +0 -3
  139. package/decorator/controller.d.ts.map +0 -1
  140. package/decorator/delete.d.ts +0 -3
  141. package/decorator/delete.d.ts.map +0 -1
  142. package/decorator/enums/ControllerDecoratorParams.d.ts +0 -6
  143. package/decorator/enums/ControllerDecoratorParams.d.ts.map +0 -1
  144. package/decorator/enums/ControllerDecoratorParams.js +0 -9
  145. package/decorator/get.d.ts +0 -3
  146. package/decorator/get.d.ts.map +0 -1
  147. package/decorator/index.d.ts +0 -6
  148. package/decorator/index.d.ts.map +0 -1
  149. package/decorator/index.js +0 -13
  150. package/decorator/post.d.ts +0 -3
  151. package/decorator/post.d.ts.map +0 -1
  152. package/decorator/put.d.ts +0 -3
  153. package/decorator/put.d.ts.map +0 -1
  154. package/filters/AccessControl.d.ts +0 -13
  155. package/filters/AccessControl.d.ts.map +0 -1
  156. package/filters/AccessControl.js +0 -83
  157. package/filters/AccessRule.d.ts +0 -83
  158. package/filters/AccessRule.d.ts.map +0 -1
  159. package/filters/AccessRule.js +0 -136
  160. package/filters/auth/AuthInterface.d.ts.map +0 -1
  161. package/filters/auth/AuthInterface.js +0 -2
  162. package/filters/auth/AuthMethod.d.ts +0 -38
  163. package/filters/auth/AuthMethod.d.ts.map +0 -1
  164. package/filters/auth/AuthMethod.js +0 -82
  165. package/filters/auth/HttpBasicAuth.d.ts +0 -24
  166. package/filters/auth/HttpBasicAuth.d.ts.map +0 -1
  167. package/filters/auth/HttpBasicAuth.js +0 -78
  168. package/filters/auth/HttpBearerAuth.d.ts +0 -18
  169. package/filters/auth/HttpBearerAuth.d.ts.map +0 -1
  170. package/filters/auth/HttpBearerAuth.js +0 -33
  171. package/filters/auth/HttpHeaderAuth.d.ts +0 -19
  172. package/filters/auth/HttpHeaderAuth.d.ts.map +0 -1
  173. package/filters/auth/HttpHeaderAuth.js +0 -64
  174. package/filters/auth/JwtHttpBearerAuth.d.ts +0 -21
  175. package/filters/auth/JwtHttpBearerAuth.d.ts.map +0 -1
  176. package/filters/auth/JwtHttpBearerAuth.js +0 -87
  177. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +0 -23
  178. package/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +0 -1
  179. package/filters/auth/KeyCloakHttpBearerAuth.js +0 -116
  180. package/filters/auth/index.d.ts +0 -5
  181. package/filters/auth/index.d.ts.map +0 -1
  182. package/filters/auth/index.js +0 -11
  183. package/filters/index.d.ts +0 -3
  184. package/filters/index.d.ts.map +0 -1
  185. package/filters/index.js +0 -7
  186. package/index.d.ts +0 -26
  187. package/index.d.ts.map +0 -1
  188. package/index.js +0 -72
  189. package/model/RouteDefinition.d.ts +0 -7
  190. package/model/RouteDefinition.d.ts.map +0 -1
  191. package/rbac/AuthAssignment.d.ts +0 -19
  192. package/rbac/AuthAssignment.d.ts.map +0 -1
  193. package/rbac/AuthAssignment.js +0 -44
  194. package/rbac/AuthItem.d.ts +0 -27
  195. package/rbac/AuthItem.d.ts.map +0 -1
  196. package/rbac/AuthItemChild.d.ts +0 -19
  197. package/rbac/AuthItemChild.d.ts.map +0 -1
  198. package/rbac/AuthManager.d.ts +0 -112
  199. package/rbac/AuthManager.d.ts.map +0 -1
  200. package/rbac/AuthManager.js +0 -356
  201. package/rbac/index.d.ts +0 -5
  202. package/rbac/index.d.ts.map +0 -1
  203. package/rbac/index.js +0 -28
  204. package/requiments/Glob.d.ts +0 -3
  205. package/requiments/Glob.d.ts.map +0 -1
  206. package/requiments/Glob.js +0 -10
  207. package/requiments/ReflectUtil.d.ts +0 -1
  208. package/requiments/ReflectUtil.d.ts.map +0 -1
  209. package/requiments/Utils.d.ts +0 -2
  210. package/requiments/Utils.d.ts.map +0 -1
  211. package/validators/BooleanValidator.d.ts +0 -1
  212. package/validators/BooleanValidator.d.ts.map +0 -1
  213. package/validators/BooleanValidator.js +0 -1
  214. package/validators/CompareValidator.d.ts +0 -1
  215. package/validators/CompareValidator.d.ts.map +0 -1
  216. package/validators/CompareValidator.js +0 -1
  217. package/validators/DateValidator.d.ts +0 -1
  218. package/validators/DateValidator.d.ts.map +0 -1
  219. package/validators/DateValidator.js +0 -1
  220. package/validators/EmailValidator.d.ts +0 -1
  221. package/validators/EmailValidator.d.ts.map +0 -1
  222. package/validators/EmailValidator.js +0 -1
  223. package/validators/Validator.d.ts +0 -18
  224. package/validators/Validator.d.ts.map +0 -1
  225. package/validators/Validator.js +0 -27
  226. package/web/IdentityInterface.d.ts.map +0 -1
  227. package/web/WebUser.d.ts +0 -72
  228. package/web/WebUser.d.ts.map +0 -1
  229. package/web/WebUser.js +0 -165
@@ -0,0 +1,399 @@
1
+ import {Component, InvalidConfigException, ModelManager} from "../base";
2
+ import {BaseChyz, InvalidArgumentException} from "../index";
3
+ import {Utils} from "../requiments/Utils";
4
+
5
+
6
+ interface Role {
7
+ type: number;
8
+ name: string;
9
+ description: string;
10
+ ruleName: string;
11
+ data: string;
12
+ params: string;
13
+ }
14
+
15
+ interface Permission {
16
+ type: number;
17
+ name: string;
18
+ description: string;
19
+ ruleName: string;
20
+ data: string;
21
+ params: string;
22
+ }
23
+
24
+
25
+ export class AuthManager extends Component {
26
+ static readonly TYPE_ROLE = 1;
27
+ static readonly TYPE_PERMISSION = 2;
28
+
29
+ init() {
30
+ BaseChyz.info("Auth Manager init....")
31
+ }
32
+
33
+ /**
34
+ * @var Item[] all auth items (name => Item)
35
+ */
36
+ protected items: any;
37
+ checkAccessAssignments: any = {}
38
+ defaultRoles: any = {}
39
+
40
+
41
+ /**
42
+ *
43
+ */
44
+
45
+ public async checkAccess(userId: number, permissionName: string, params: any[] = []): Promise<boolean> {
46
+ let assignments: any;
47
+
48
+ if (!userId) return false;
49
+
50
+ if (!this.checkAccessAssignments[userId.toString()]) {
51
+ assignments = await this.getAssignments(userId);
52
+ this.checkAccessAssignments[userId.toString()] = assignments;
53
+ } else {
54
+ assignments = this.checkAccessAssignments[userId.toString()]
55
+ }
56
+
57
+
58
+ // BaseChyz.info("assignments",assignments)
59
+ if (this.hasNoAssignments(assignments)) {
60
+ return false;
61
+ }
62
+
63
+
64
+ return await this.checkAccessRecursive(userId, permissionName, params, assignments);
65
+ }
66
+
67
+ async checkAccessFromCache() {
68
+
69
+
70
+ }
71
+
72
+ public async checkAccessRecursive(user: string | number, itemname: string, params: any[], assignments: any): Promise<boolean> {
73
+ let item: any = await this.getItem(itemname);
74
+ if (!item) return false;
75
+
76
+ /**
77
+ * @todo
78
+ * Rule test edilmeli
79
+ */
80
+
81
+ if (assignments[itemname] || Utils.find(this.defaultRoles, itemname)) {
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * item child
87
+ */
88
+ let parents = await ModelManager.AuthItemChild.findAll({attributes: ["parent"], where: {child: itemname}});
89
+ for (const parent of parents) {
90
+ let r = await this.checkAccessRecursive(user, parent.parent, params, assignments);
91
+ if (r) {
92
+ return true;
93
+ }
94
+ }
95
+
96
+ return false;
97
+
98
+ }
99
+
100
+ /**
101
+ *
102
+ * @param name
103
+ */
104
+ public async getItem(name: string) {
105
+ if (!name) return null;
106
+
107
+ return await ModelManager.AuthItem.findOne({where: {name: name}})
108
+
109
+ }
110
+
111
+ public async getItems(type: number) {
112
+ let items: any = {};
113
+ let _items = await ModelManager.AuthItem.findAll({where: {type: type}})
114
+ if (_items)
115
+ _items.forEach((item: any) => {
116
+ items[item["name"]] = item.dataValues as Role;
117
+ })
118
+
119
+ return items
120
+
121
+ }
122
+
123
+ public async getRolesByUser(userId: number) {
124
+ if (this.isEmptyUserId(userId.toString())) {
125
+ return [];
126
+ }
127
+
128
+
129
+ let roles: any = {}
130
+ let items = await ModelManager.AuthAssignment.findAll({
131
+ where: {
132
+ user_id: userId.toString(),
133
+ '$AuthItemClasses.type$': AuthManager.TYPE_ROLE
134
+ },
135
+ include: [{
136
+ model: ModelManager.AuthItem.model()
137
+ }]
138
+ })
139
+ for (const item of items) {
140
+ for (const i of item.AuthItemClasses)
141
+ roles[i["name"]] = i.dataValues as Role;
142
+ }
143
+
144
+ return roles;
145
+
146
+ }
147
+
148
+ /**
149
+ *
150
+ * @param roleName
151
+ */
152
+ public async getChildRoles(roleName: string) {
153
+ let role = await this.getRole(roleName);
154
+ if (role === null) {
155
+ throw new InvalidArgumentException(`Role "${roleName}" not found.`);
156
+ }
157
+ const result: any = {result: {}};
158
+ await this.getChildrenRecursive(roleName, await this.getChildrenList(), result);
159
+ let roles: any = {};
160
+ roles[roleName] = role;
161
+ let _roles = await this.getRoles();
162
+ let _r: any = {};
163
+ Utils.forEach(_roles, (item: Role) => {
164
+ if (result.result[item.name])
165
+ _r[item.name] = item;
166
+ })
167
+
168
+
169
+ return Utils.merge(roles, _r);
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param roleName
175
+ */
176
+ public async getPermissionsByRole(roleName: string) {
177
+ let childrenList = this.getChildrenList();
178
+ const result = {result: {}}
179
+ let permissions: any = {}
180
+ await this.getChildrenRecursive(roleName, childrenList, result);
181
+ if (Utils.isEmpty(result.result)) {
182
+ return {};
183
+ }
184
+
185
+ let itemResult = await ModelManager.AuthItem.findAll({
186
+ where: {
187
+ type: AuthManager.TYPE_PERMISSION,
188
+ name: Object.keys(result.result)
189
+ }
190
+ });
191
+ for (const itemElement of itemResult) {
192
+ permissions[itemElement["name"]] = itemElement.dataValues as Permission
193
+ }
194
+
195
+ return permissions;
196
+
197
+ }
198
+
199
+ /**
200
+ *
201
+ * @param userId
202
+ */
203
+ public async getPermissionsByUser(userId: number) {
204
+
205
+ if (this.isEmptyUserId(userId.toString())) {
206
+ return {};
207
+ }
208
+
209
+ let directPermission = await this.getDirectPermissionsByUser(userId);
210
+ let inheritedPermission = await this.getInheritedPermissionsByUser(userId);
211
+
212
+ return Utils.merge(directPermission, inheritedPermission);
213
+ }
214
+
215
+ /**
216
+ * Returns all permissions that are directly assigned to user.
217
+ * @return Permission[] all direct permissions that the user has. The array is indexed by the permission names.
218
+ */
219
+ protected async getDirectPermissionsByUser(userId: number) {
220
+ let permissions: any = {}
221
+ let result = await ModelManager.AuthAssignment.findAll({
222
+ where: {
223
+ user_id: userId.toString(),
224
+ '$AuthItemClasses.type$': AuthManager.TYPE_PERMISSION
225
+ },
226
+ include: [
227
+ {
228
+ model: ModelManager.AuthItem.model()
229
+ }
230
+ ]
231
+ })
232
+
233
+ for (const resultElement of result) {
234
+ for (const i of resultElement.AuthItemClasses)
235
+ permissions[i["name"]] = i.dataValues as Permission;
236
+ }
237
+
238
+
239
+ return permissions;
240
+ }
241
+
242
+ protected async getInheritedPermissionsByUser(userId: number) {
243
+ let userAssignment = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}, attributes: ["item_name"]});
244
+ let childrenList = await this.getChildrenList();
245
+ const result: any = {result: {}}
246
+ let permissions: any = {}
247
+
248
+ for (const userAssignmentElement of userAssignment) {
249
+ this.getChildrenRecursive(userAssignmentElement.item_name, childrenList, result);
250
+ }
251
+
252
+ if (Utils.isEmpty(result.result)) {
253
+ return {};
254
+ }
255
+
256
+ let itemResult = await ModelManager.AuthItem.findAll({
257
+ where: {
258
+ type: AuthManager.TYPE_PERMISSION,
259
+ name: Object.keys(result.result)
260
+ }
261
+ });
262
+ for (const itemElement of itemResult) {
263
+ permissions[itemElement["name"]] = itemElement.dataValues as Permission
264
+ }
265
+
266
+ return permissions;
267
+ }
268
+
269
+
270
+ /**
271
+ *
272
+ * @param userId
273
+ */
274
+ public async getItemsByUser(userId: number) {
275
+ return await ModelManager.AuthAssignment.findAll({
276
+ where: {
277
+ user_id: userId.toString()
278
+ },
279
+ include: [{
280
+ model: ModelManager.AuthItem.model()
281
+ }]
282
+ });
283
+ }
284
+
285
+
286
+ /**
287
+ * Returns all role assignment information for the specified role.
288
+ * @param $roleName
289
+ */
290
+ public async getUserIdsByRole(roleName: number) {
291
+ if (!roleName) return [];
292
+
293
+ return await ModelManager.AuthAssignment.findAll({where: {"item_name": roleName}, attributes: ["user_id"]});
294
+ }
295
+
296
+
297
+ /**
298
+ * {@inheritdoc}
299
+ */
300
+ public async getRole(name: string) {
301
+ let item: Role = await this.getItem(name);
302
+ return item && item.type == AuthManager.TYPE_ROLE ? item : null;
303
+ }
304
+
305
+
306
+ /**
307
+ * {@inheritdoc}
308
+ */
309
+ public getRoles() {
310
+ return this.getItems(AuthManager.TYPE_ROLE);
311
+ }
312
+
313
+ /**
314
+ * Recursively finds all children and grand children of the specified item.
315
+ * @param string $name the name of the item whose children are to be looked for.
316
+ * @param array $childrenList the child list built via [[getChildrenList()]]
317
+ * @param array $result the children and grand children (in array keys)
318
+ */
319
+ protected getChildrenRecursive(name: string, childrenList: any, model: any) {
320
+ if (childrenList[name]) {
321
+ for (const child of childrenList[name]) {
322
+ model.result[child] = true;
323
+ this.getChildrenRecursive(child, childrenList, model);
324
+ }
325
+ }
326
+
327
+ }
328
+
329
+
330
+ /**
331
+ *
332
+ * @param roleName
333
+ * @param userId
334
+ */
335
+ public getAssignment(roleName: string, userId: string) {
336
+ if (this.isEmptyUserId(userId)) {
337
+ return [];
338
+ }
339
+ return ModelManager.AuthAssignment.findAll({where: {user_id: userId, items_name: roleName}});
340
+
341
+ }
342
+
343
+ /**
344
+ *
345
+ */
346
+ public async getAssignments(userId: number) {
347
+ if (this.isEmptyUserId(userId.toString())) {
348
+ return {};
349
+ }
350
+
351
+ let assignments: any = {};
352
+ try {
353
+
354
+ let as = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}});
355
+ for (const a of as) {
356
+ assignments[a["item_name"]] = a;
357
+ }
358
+ } catch (e) {
359
+ throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
360
+ }
361
+ return assignments;
362
+ }
363
+
364
+ /**
365
+ * Returns the children for every parent.
366
+ * @return array the children list. Each array key is a parent item name,
367
+ * and the corresponding array value is a list of child item names.
368
+ */
369
+ protected async getChildrenList() {
370
+ let items = await ModelManager.AuthItemChild.findAll();
371
+ let parents: any = {};
372
+ for (const item of items) {
373
+ parents[item["parent"]] = Utils.concat(parents[item["parent"]] || [], [item["child"]]);
374
+ }
375
+
376
+ return parents
377
+ }
378
+
379
+ /**
380
+ * Check whether $userId is empty.
381
+ * @param mixed $userId
382
+ * @return bool
383
+ * @since 2.0.26
384
+ */
385
+ protected isEmptyUserId(userId: string) {
386
+ return !userId || userId === '';
387
+ }
388
+
389
+ /**
390
+ * Checks whether array of $assignments is empty and [[defaultRoles]] property is empty as well.
391
+ *
392
+ * @param Assignment[] $assignments array of user's assignments
393
+ * @return bool whether array of $assignments is empty and [[defaultRoles]] property is empty as well
394
+ * @since 2.0.11
395
+ */
396
+ protected hasNoAssignments(assignments: any) {
397
+ return Utils.isEmpty(assignments) && Utils.isEmpty(this.defaultRoles)
398
+ }
399
+ }
package/rbac/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2023.. Chy Bilgisayar Bilisim
4
+ * Author: Cihan Ozturk
5
+ * E-mail: cihan@chy.com.tr
6
+ * Github:https://github.com/cihan53/
7
+ *
8
+ */
9
+ export * from "./AuthManager";
10
+ export * from "./AuthItem";
11
+ export * from "./AuthAssignment";
12
+ export * from "./AuthItemChild";
@@ -1,8 +1,9 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
3
  * Author: Cihan Ozturk
5
4
  * E-mail: cihan@chy.com.tr
6
5
  * Github:https://github.com/cihan53/
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
7
+
8
+ const Glob = require("glob");
9
+ export default Glob;
@@ -1,10 +1,10 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
3
  * Author: Cihan Ozturk
5
4
  * E-mail: cihan@chy.com.tr
6
5
  * Github:https://github.com/cihan53/
7
6
  */
7
+
8
8
  /**
9
9
  * @param strClass:
10
10
  * class name
@@ -12,13 +12,15 @@
12
12
  * constructor arguments
13
13
  */
14
14
  // @ts-ignore
15
- Reflect.newInstance = function (strClass) {
15
+ Reflect.newInstance = function (strClass: string) {
16
16
  const args = Array.prototype.slice.call(arguments, 1);
17
17
  const clsClass = eval(strClass);
18
+
18
19
  const F = () => {
19
20
  return clsClass.apply(this, args);
20
- };
21
+ }
22
+
21
23
  F.prototype = clsClass.prototype;
22
24
  // @ts-ignore
23
25
  return new F();
24
- };
26
+ };
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*
3
2
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
4
3
  * Author: Cihan Ozturk
@@ -6,8 +5,7 @@
6
5
  * Github:https://github.com/cihan53/
7
6
  */
8
7
  // import _ from "lodash";
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Utils = void 0;
8
+
11
9
  const _ = require('lodash');
12
10
  /**
13
11
  *
@@ -15,20 +13,17 @@ const _ = require('lodash');
15
13
  * @param val
16
14
  * @param top
17
15
  */
18
- const buildParams = function (prefix, val, top) {
19
- if (_.isUndefined(top))
20
- top = true;
16
+ const buildParams = function (prefix: string, val: any, top?: boolean) {
17
+ if (_.isUndefined(top)) top = true;
21
18
  if (_.isArray(val)) {
22
- return _.map(val, function (value, key) {
19
+ return _.map(val, function (value: any, key: string) {
23
20
  return buildParams(top ? key : prefix + '[]', value, false);
24
21
  }).join('&');
25
- }
26
- else if (_.isObject(val)) {
27
- return _.map(val, function (value, key) {
22
+ } else if (_.isObject(val)) {
23
+ return _.map(val, function (value: any, key: string) {
28
24
  return buildParams(top ? key : prefix + '[' + key + ']', value, false);
29
25
  }).join('&');
30
- }
31
- else {
26
+ } else {
32
27
  return encodeURIComponent(prefix) + '=' + encodeURIComponent(val);
33
28
  }
34
29
  };
@@ -36,38 +31,41 @@ const buildParams = function (prefix, val, top) {
36
31
  *Creates a query string from a hash
37
32
  * @param obj
38
33
  */
39
- const toQuery = function (obj) {
34
+ const toQuery = function (obj: any) {
40
35
  return buildParams('', obj);
41
- };
36
+ }
37
+
42
38
  /**
43
39
  *
44
40
  * @param object
45
41
  * @param params
46
42
  */
47
- const createObject = (object, params) => {
48
- let newParams = {};
43
+ const createObject = (object: any, params: any) => {
44
+ let newParams: any = {}
49
45
  Object.keys(params).forEach((param) => {
50
- newParams[param] = {};
46
+ newParams[param] = {}
51
47
  Object.assign(newParams[param], {
52
48
  writable: true,
53
49
  configurable: true,
54
50
  value: params[param]
55
51
  });
56
- });
52
+ })
57
53
  return Object.create(object, newParams);
58
- };
54
+ }
59
55
  /**
60
56
  *
61
57
  * @param object
62
58
  * @param findKey
63
59
  */
64
- const findKeyValue = (object, findKey) => {
65
- let key = Object.keys(object).find(key => key.toLowerCase() === findKey.toLowerCase());
60
+ const findKeyValue = (object: any, findKey: string) => {
61
+ let key = Object.keys(object).find(key => key.toLowerCase() === findKey.toLowerCase())
66
62
  if (key) {
67
63
  return object[key];
68
64
  }
69
- return null;
70
- };
65
+
66
+ return null
67
+ }
68
+
71
69
  /**
72
70
  *
73
71
  * @param seconds
@@ -76,40 +74,48 @@ const sleep = (seconds = 1) => {
76
74
  const waitTill = new Date(new Date().getTime() + seconds * 1000);
77
75
  while (waitTill > new Date()) {
78
76
  }
79
- };
77
+ }
78
+
80
79
  /**
81
80
  *
82
81
  * @param wildcard
83
82
  * @param str
84
83
  */
85
- function wildTest(wildcard, str) {
84
+ function wildTest(wildcard: string, str: string) {
86
85
  let w = wildcard.replace(/[.+^${}()|[\]\\]/g, '\\$&'); // regexp escape
87
- const re = new RegExp(`^${w.replace(/\*/g, '.*').replace(/\?/g, '.')}$`, 'i');
86
+ const re = new RegExp(`^${w.replace(/\*/g,'.*').replace(/\?/g,'.')}$`, 'i');
88
87
  return re.test(str); // remove last 'i' above to have case sensitive
89
88
  }
89
+
90
90
  /**
91
91
  *
92
92
  * @param pattern
93
93
  * @param string
94
94
  * @param options
95
95
  */
96
- const matchWildcard = (pattern, string, options = {}) => {
97
- return wildTest(pattern, string);
98
- };
96
+ const matchWildcard = (pattern: string, string: string, options: any = {}) => {
97
+ return wildTest(pattern, string)
98
+ }
99
+
100
+
99
101
  /**
100
102
  * random string genrate
101
103
  * @param length
102
104
  * @param randomString
103
105
  */
104
- const generateRandomString = function (length, randomString = "") {
106
+ const generateRandomString = function (length: number, randomString = ""): string {
105
107
  randomString += Math.random().toString(20).substring(2, length);
106
- if (randomString.length > length)
107
- return randomString.slice(0, length);
108
+ if (randomString.length > length) return randomString.slice(0, length);
108
109
  return generateRandomString(length, randomString);
109
110
  };
110
- exports.Utils = Object.assign({ findKeyValue,
111
+
112
+ export const Utils = {
113
+ findKeyValue,
111
114
  createObject,
112
115
  sleep,
113
116
  matchWildcard,
114
117
  toQuery,
115
- generateRandomString }, _);
118
+ generateRandomString,
119
+ ..._
120
+ }
121
+
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ import {Component} from "../base";
2
+
3
+ export class Validator extends Component {
4
+ public static builtInValidators = {
5
+ 'boolean': '',
6
+ 'email': '',
7
+ }
8
+
9
+
10
+ /**
11
+ * @var array|string attributes to be validated by this validator. For multiple attributes,
12
+ * please specify them as an array; for single attribute, you may use either a string or an array.
13
+ */
14
+ public attributes = [];
15
+ public message: string = "";
16
+
17
+ public except = [];
18
+ public isEmpty = [];
19
+
20
+ public init() {
21
+ super.init();
22
+ }
23
+
24
+ public static createValidator(type: any, model: any, attributes: any, params = []) {
25
+
26
+ }
27
+ }
@@ -1,3 +1,10 @@
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
+
1
8
  export interface IdentityInterface {
2
9
  /**
3
10
  * Finds an identity by the given ID.
@@ -6,7 +13,8 @@ export interface IdentityInterface {
6
13
  * Null should be returned if such an identity cannot be found
7
14
  * or the identity is not in an active state (disabled, deleted, etc.)
8
15
  */
9
- findIdentity(id: number): any;
16
+ findIdentity(id: number): any
17
+
10
18
  /**
11
19
  * Finds an identity by the given token.
12
20
  * For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
@@ -18,11 +26,13 @@ export interface IdentityInterface {
18
26
  * @param any
19
27
  */
20
28
  findIdentityByAccessToken(token: any, type: string): any;
29
+
21
30
  /**
22
31
  * Returns an ID that can uniquely identify a user identity.
23
32
  * @return string|int an ID that uniquely identifies a user identity.
24
33
  */
25
34
  getId(): number;
35
+
26
36
  /**
27
37
  * Returns a key that can be used to check the validity of a given identity ID.
28
38
  *
@@ -40,6 +50,7 @@ export interface IdentityInterface {
40
50
  * @see validateAuthKey()
41
51
  */
42
52
  getAuthKey(): string;
53
+
43
54
  /**
44
55
  * Validates the given auth key.
45
56
  *
@@ -48,9 +59,11 @@ export interface IdentityInterface {
48
59
  * @see getAuthKey()
49
60
  */
50
61
  validateAuthKey(authKey: string): (boolean | null);
62
+
63
+
51
64
  /**
52
65
  *
53
66
  */
54
67
  can(permissionName: string, params: any[], allowCaching: boolean): Promise<(boolean | null)>;
68
+
55
69
  }
56
- //# sourceMappingURL=IdentityInterface.d.ts.map