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,79 @@
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 {Request, Response} from "express";
9
+ import {WebUser} from "../../web/WebUser";
10
+ import {AuthMethod} from "./AuthMethod";
11
+ import {InvalidConfigException} from "../../base";
12
+ import BaseChyz from "../../BaseChyz";
13
+
14
+ export class HttpBasicAuth extends AuthMethod {
15
+
16
+ /**
17
+ * @var string the HTTP header name
18
+ */
19
+ public header = 'Authorization';
20
+
21
+
22
+ /**
23
+ * @var string a pattern to use to extract the HTTP authentication value
24
+ */
25
+
26
+ public pattern = /^Basic\s+(.*?)$/;
27
+
28
+
29
+ public auth: any = null;
30
+
31
+ /**
32
+ * @throws InvalidConfigException
33
+ */
34
+ public init(): void {
35
+ super.init();
36
+
37
+ if (!this.pattern) {
38
+ throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
39
+ }
40
+
41
+ this.user = BaseChyz.getComponent("user") ?? null;
42
+ }
43
+
44
+
45
+ async authenticate(user: WebUser, request: Request, response: Response) {
46
+
47
+
48
+ let autHeader = this.getHeaderByKey(request.headers, this.header)
49
+ if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
50
+ return this.fail(response);
51
+ }
52
+
53
+ let identity = null;
54
+ let token = null;
55
+
56
+ let buff = new Buffer(autHeader[1], "base64");
57
+ let basicauth = buff.toString().split(":");
58
+
59
+ if (this.auth != null) {
60
+ identity = await this.auth(autHeader[1], ...arguments, basicauth)
61
+ } else {
62
+ identity = await user.loginByAccessToken(basicauth, "HttpBasicAuth");
63
+ }
64
+
65
+
66
+ if (identity == null) this.fail(response)
67
+ return identity;
68
+
69
+ }
70
+
71
+
72
+ /**
73
+ * @throws UnauthorizedHttpException
74
+ */
75
+ public fail(response: Response): void {
76
+ this.challenge(response)
77
+ this.handleFailure(response);
78
+ }
79
+ }
@@ -0,0 +1,34 @@
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 {HttpHeaderAuth} from "./HttpHeaderAuth";
9
+ import {Response} from "express";
10
+
11
+ export class HttpBearerAuth extends HttpHeaderAuth {
12
+
13
+ /**
14
+ * {@inheritdoc}
15
+ */
16
+ public header = 'Authorization';
17
+ // @ts-ignore
18
+ public pattern = /^Bearer\s+(.*?)$/;
19
+ /**
20
+ * @var string the HTTP authentication realm
21
+ */
22
+ public realm = 'api';
23
+
24
+
25
+ /**
26
+ * {@inheritdoc}
27
+ */
28
+ public challenge(response: Response):Response {
29
+ response.set('WWW-Authenticate', `Bearer realm="${this.realm}"`);
30
+ return response;
31
+ }
32
+
33
+
34
+ }
@@ -0,0 +1,61 @@
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 {AuthMethod} from "./AuthMethod";
9
+ import {WebUser} from "../../web/WebUser";
10
+ import {Utils} from "../../requiments/Utils";
11
+ import {Request, Response} from "express";
12
+
13
+ export class HttpHeaderAuth extends AuthMethod {
14
+ /**
15
+ * @var string the HTTP header name
16
+ */
17
+ public header = 'X-Api-Key';
18
+
19
+
20
+ /**
21
+ * @var string a pattern to use to extract the HTTP authentication value
22
+ */
23
+
24
+ public pattern!: string;
25
+
26
+
27
+ async authenticate(user: WebUser, request:Request, response:Response) {
28
+ let key = Object.keys(request.headers).find(key => key.toLowerCase() === this.header.toLowerCase())
29
+ if (key) {
30
+ let authHeader:any = request.headers[key];
31
+ if (!Utils.isEmpty(authHeader)) {
32
+ if (this.pattern) {
33
+ //preg_match
34
+ let matches = authHeader.match(this.pattern)
35
+ if (matches && matches.length > 0) {
36
+ authHeader = matches[1];
37
+ } else {
38
+ return this.fail(response);
39
+ }
40
+ }
41
+
42
+ let identity = await user.loginByAccessToken(authHeader, "HttpHeaderAuth");
43
+ if (identity === null) {
44
+ this.challenge(response);
45
+ this.handleFailure(response);
46
+ }
47
+
48
+ return identity;
49
+ }
50
+ }
51
+ return this.fail(response);
52
+ }
53
+
54
+ /**
55
+ * @throws UnauthorizedHttpException
56
+ */
57
+ public fail(response: Response): void {
58
+ this.challenge(response)
59
+ this.handleFailure(response);
60
+ }
61
+ }
@@ -0,0 +1,83 @@
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 {HttpBearerAuth} from "./HttpBearerAuth";
9
+ import {InvalidConfigException} from "../../base";
10
+ import {Response, Request} from "express";
11
+ import {WebUser} from "../../web/WebUser";
12
+
13
+ const JsonWebToken = require("jsonwebtoken");
14
+
15
+ export class JwtHttpBearerAuth extends HttpBearerAuth {
16
+ /**
17
+ * @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
18
+ * itself. By default it's assumes that component of ID "jwt" has been configured.
19
+ */
20
+ public jwt = 'jwt'
21
+ public auth: any = null;
22
+
23
+
24
+ /**
25
+ * @throws InvalidConfigException
26
+ */
27
+ public init(): void {
28
+ super.init();
29
+
30
+ if (!this.pattern) {
31
+ throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
32
+ }
33
+
34
+ this.user = BaseChyz.getComponent("user") ?? null;
35
+ }
36
+
37
+
38
+ public async authenticate(user: WebUser, request: Request, response: Response) // BC signature
39
+ {
40
+ let autHeader = this.getHeaderByKey(request.headers, this.header)
41
+ if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
42
+ return null ;
43
+ }
44
+
45
+ let identity = null;
46
+ let token = null;
47
+
48
+ try {
49
+ token = JsonWebToken.decode(autHeader[1], {complete: true})
50
+ if (!token) {
51
+ BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
52
+ this.fail(response);
53
+ }
54
+ } catch (e) {
55
+ BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.",autHeader,request.path);
56
+ this.fail(response);
57
+ }
58
+
59
+
60
+ if (token !== null) {
61
+ if (this.auth != null) {
62
+ identity = await this.auth(autHeader[1], ...arguments)
63
+ } else {
64
+ identity = await user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth")
65
+ }
66
+ }
67
+
68
+ if (identity == null) this.fail(response)
69
+
70
+
71
+ return identity;
72
+ }
73
+
74
+
75
+ /**
76
+ * @throws UnauthorizedHttpException
77
+ */
78
+ public fail(response: Response): void {
79
+ this.challenge(response)
80
+ this.handleFailure(response);
81
+ }
82
+
83
+ }
@@ -0,0 +1,114 @@
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 {HttpBearerAuth} from "./HttpBearerAuth";
9
+ import {InvalidConfigException} from "../../base/InvalidConfigException";
10
+ import {Request, Response} from "express";
11
+ import {WebUser} from "../../web/WebUser";
12
+
13
+ const JsonWebToken = require("jsonwebtoken");
14
+
15
+ export class KeyCloakHttpBearerAuth extends HttpBearerAuth {
16
+ /**
17
+ * @var string|array<string, mixed>|Jwt application component ID of the JWT handler, configuration array, or JWT handler object
18
+ * itself. By default it's assumes that component of ID "jwt" has been configured.
19
+ */
20
+ public jwt = 'jwt'
21
+ public auth: any = null;
22
+ public keycloak: any = null;
23
+
24
+
25
+ /**
26
+ * @throws InvalidConfigException
27
+ */
28
+ public init(): void {
29
+ super.init();
30
+
31
+ if (!this.pattern) {
32
+ throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
33
+ }
34
+
35
+ this.keycloak = BaseChyz.getMiddlewares("keycloak").keycloak ?? null;
36
+ this.user = BaseChyz.getComponent("user") ?? null;
37
+ this.auth = this.KeyCloakCheck;
38
+
39
+
40
+ }
41
+
42
+ public async KeyCloakCheck(token: string, request: Request, response: Response,) {
43
+ if (this.keycloak == null) return false;
44
+ // return await this.keycloak.protect('realm:user')(request, response, () => true /*next*/)
45
+ return await this.keycloak.protect()(request, response, () => true /*next*/);
46
+ }
47
+
48
+
49
+ public async authenticate(user: WebUser, request: Request, response: Response) // BC signature
50
+ {
51
+
52
+ let identity = null;
53
+ let token = null;
54
+
55
+ let autHeader = this.getHeaderByKey(request.headers, this.header)
56
+ if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
57
+ return this.fail(response);
58
+ }
59
+
60
+ token = JsonWebToken.decode(autHeader[1], {complete: true})
61
+ if (!token) {
62
+ BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
63
+ this.fail(response);
64
+ }
65
+
66
+ if (token !== null) {
67
+ identity = await this.KeyCloakCheck(autHeader[1], request, response)
68
+ BaseChyz.debug("KeyCloakCheck Result:", identity)
69
+ }
70
+
71
+ if (identity == null || identity == false) this.fail(response)
72
+
73
+ return identity;
74
+
75
+ /* let autHeader = this.getHeaderByKey(request.headers, this.header)
76
+ if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
77
+ return null;
78
+ }
79
+
80
+ BaseChyz.debug("JSON Web Token.",autHeader);
81
+ let identity = null;
82
+ let token = null;
83
+
84
+ token = JsonWebToken.decode(autHeader[1], {complete: true})
85
+ if (!token) {
86
+ BaseChyz.warning("Your request was made with invalid or expired JSON Web Token.");
87
+ this.fail(response);
88
+ }
89
+
90
+ if (token !== null) {
91
+ if (this.auth != null) {
92
+ identity = await this.auth(autHeader[1])
93
+ } else {
94
+ identity = await user.loginByAccessToken(autHeader[1], "JwtHttpBearerAuth")
95
+ }
96
+ }
97
+
98
+ if (identity == null) this.fail(response)
99
+
100
+
101
+
102
+ return identity;*/
103
+ }
104
+
105
+
106
+ /**
107
+ * @throws UnauthorizedHttpException
108
+ */
109
+ public fail(response: Response): void {
110
+ // this.challenge(response)
111
+ this.handleFailure(response);
112
+ }
113
+
114
+ }
@@ -0,0 +1,4 @@
1
+ export {JwtHttpBearerAuth} from "./JwtHttpBearerAuth"
2
+ export {HttpBearerAuth} from "./HttpBearerAuth"
3
+ export {HttpHeaderAuth} from "./HttpHeaderAuth"
4
+ export {HttpBasicAuth} from "./HttpBasicAuth"
@@ -0,0 +1,2 @@
1
+ export {AccessControl} from "./AccessControl"
2
+ export {AccessRule} from "./AccessRule"
package/index.ts ADDED
@@ -0,0 +1,80 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2022.. Chy Bilgisayar Bilisim
4
+ * Author: Cihan Ozturk
5
+ * E-mail: cihan@chy.com.tr
6
+ * Github:https://github.com/cihan53/
7
+ *
8
+ */
9
+
10
+ declare global {
11
+ interface String {
12
+ tokenReplace(obj: any): string;
13
+ }
14
+ }
15
+
16
+ declare namespace Express {
17
+ export interface Request {
18
+ identity?: string
19
+ }
20
+ }
21
+
22
+ import BaseChyz from "./BaseChyz";
23
+ import {RestClient} from "./base";
24
+
25
+
26
+ declare module "express-serve-static-core" {
27
+ interface Request {
28
+ identity: any;
29
+ }
30
+ }
31
+
32
+ String.prototype.tokenReplace = function (obj) {
33
+ let retStr: any = this;
34
+ for (let x in obj) {
35
+ // @ts-ignore
36
+ retStr = retStr.replace(new RegExp("\\:" + x, 'g'), obj[x]).toString();
37
+ }
38
+ return retStr;
39
+ };
40
+
41
+
42
+ /**
43
+ *
44
+ */
45
+ const Chyz = new BaseChyz();
46
+ const pjson = require('./package.json');
47
+ export const Chyz_Version = pjson.version;
48
+ export {Request, Response, NextFunction} from "./base/CRequest";
49
+ export {RouteDefinition} from "./model/RouteDefinition";
50
+ export {WebUser} from "./web/WebUser";
51
+ export {BaseChyz, RestClient}
52
+ export {
53
+ Logs,
54
+ ActionFilter,
55
+ BaseError,
56
+ Behavior,
57
+ Component,
58
+ Configurable,
59
+ CWebController,
60
+ DbConnection,
61
+ ForbiddenHttpException,
62
+ InvalidConfigException,
63
+ InvalidArgumentException,
64
+ NotFoundHttpException,
65
+ UnauthorizedHttpException,
66
+ DataErrorDbException,
67
+ ValidationHttpException,
68
+ Model,
69
+ ModelManager,
70
+ CEvents
71
+ } from "./base";
72
+ export * from "./filters";
73
+ export * from "./filters/auth";
74
+ export * from "./rbac/";
75
+
76
+ export * from "./decorator";
77
+ export * from "./requiments/Utils";
78
+
79
+ export default Chyz;
80
+
@@ -1,55 +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": "INFO",
48
- "enableCallStack": true
49
- },
50
- "http": {
51
- "level": "INFO",
52
- "appenders": [ "access" ]
53
- }
54
- }
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": "INFO",
48
+ "enableCallStack": true
49
+ },
50
+ "http": {
51
+ "level": "INFO",
52
+ "appenders": [ "access" ]
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,18 @@
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
+ export interface RouteDefinition {
9
+ //id
10
+ id:string;
11
+ // Path to our route
12
+ path: string;
13
+ // HTTP Request method (get, post, ...)
14
+ requestMethod: 'get' | 'post' | 'delete' | 'options' | 'put';
15
+ // Method name within our class responsible for this route
16
+ methodName: string;
17
+ }
18
+