chyz 2.0.1-rc.36 → 2.0.1-rc.37

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 (231) hide show
  1. package/dist/BaseChyz.d.ts +74 -0
  2. package/dist/BaseChyz.d.ts.map +1 -0
  3. package/dist/BaseChyz.js +586 -0
  4. package/dist/base/ActionFilter.d.ts +32 -0
  5. package/dist/base/ActionFilter.d.ts.map +1 -0
  6. package/dist/base/ActionFilter.js +90 -0
  7. package/dist/base/BadRequestHttpException.d.ts +6 -0
  8. package/dist/base/BadRequestHttpException.d.ts.map +1 -0
  9. package/dist/base/BadRequestHttpException.js +17 -0
  10. package/dist/base/BaseError.d.ts +44 -0
  11. package/dist/base/BaseError.d.ts.map +1 -0
  12. package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
  13. package/dist/base/Behavior.d.ts +4 -0
  14. package/dist/base/Behavior.d.ts.map +1 -0
  15. package/dist/base/Behavior.js +7 -0
  16. package/dist/base/CBaseObject.d.ts +5 -0
  17. package/dist/base/CBaseObject.d.ts.map +1 -0
  18. package/dist/base/CBaseObject.js +16 -0
  19. package/dist/base/CEvents.d.ts +13 -0
  20. package/dist/base/CEvents.d.ts.map +1 -0
  21. package/dist/base/CEvents.js +24 -0
  22. package/dist/base/CRequest.d.ts +2 -0
  23. package/dist/base/CRequest.d.ts.map +1 -0
  24. package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
  25. package/dist/base/CWebController.d.ts +44 -0
  26. package/dist/base/CWebController.d.ts.map +1 -0
  27. package/dist/base/CWebController.js +81 -0
  28. package/dist/base/Component.d.ts +21 -0
  29. package/dist/base/Component.d.ts.map +1 -0
  30. package/dist/base/Component.js +57 -0
  31. package/dist/base/Configurable.d.ts +3 -0
  32. package/dist/base/Configurable.d.ts.map +1 -0
  33. package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
  34. package/dist/base/DataErrorDbException.d.ts +6 -0
  35. package/dist/base/DataErrorDbException.d.ts.map +1 -0
  36. package/dist/base/DataErrorDbException.js +17 -0
  37. package/dist/base/DbConnection.d.ts +13 -0
  38. package/dist/base/DbConnection.d.ts.map +1 -0
  39. package/dist/base/DbConnection.js +53 -0
  40. package/dist/base/ForbiddenHttpException.d.ts +5 -0
  41. package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
  42. package/dist/base/ForbiddenHttpException.js +16 -0
  43. package/dist/base/InvalidArgumentException.d.ts +6 -0
  44. package/dist/base/InvalidArgumentException.d.ts.map +1 -0
  45. package/dist/base/InvalidArgumentException.js +17 -0
  46. package/dist/base/InvalidConfigException.d.ts +6 -0
  47. package/dist/base/InvalidConfigException.d.ts.map +1 -0
  48. package/dist/base/InvalidConfigException.js +17 -0
  49. package/dist/base/Logs.d.ts +22 -0
  50. package/dist/base/Logs.d.ts.map +1 -0
  51. package/{base/Logs.ts → dist/base/Logs.js} +24 -41
  52. package/dist/base/Model.d.ts +302 -0
  53. package/dist/base/Model.d.ts.map +1 -0
  54. package/{base/Model.ts → dist/base/Model.js} +158 -225
  55. package/dist/base/ModelManager.d.ts +2 -0
  56. package/dist/base/ModelManager.d.ts.map +1 -0
  57. package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
  58. package/dist/base/NotFoundHttpException.d.ts +6 -0
  59. package/dist/base/NotFoundHttpException.d.ts.map +1 -0
  60. package/dist/base/NotFoundHttpException.js +17 -0
  61. package/dist/base/RestClient.d.ts +7 -0
  62. package/dist/base/RestClient.d.ts.map +1 -0
  63. package/dist/base/RestClient.js +25 -0
  64. package/dist/base/UnauthorizedHttpException.d.ts +6 -0
  65. package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
  66. package/dist/base/UnauthorizedHttpException.js +17 -0
  67. package/dist/base/ValidationHttpException.d.ts +6 -0
  68. package/dist/base/ValidationHttpException.d.ts.map +1 -0
  69. package/dist/base/ValidationHttpException.js +17 -0
  70. package/dist/base/db/Exception.d.ts +7 -0
  71. package/dist/base/db/Exception.d.ts.map +1 -0
  72. package/dist/base/db/Exception.js +15 -0
  73. package/dist/base/index.d.ts +20 -0
  74. package/dist/base/index.d.ts.map +1 -0
  75. package/dist/base/index.js +41 -0
  76. package/dist/decorator/Middleware.d.ts +4 -0
  77. package/dist/decorator/Middleware.d.ts.map +1 -0
  78. package/dist/decorator/Middleware.js +10 -0
  79. package/dist/decorator/controller.d.ts +3 -0
  80. package/dist/decorator/controller.d.ts.map +1 -0
  81. package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
  82. package/dist/decorator/delete.d.ts +3 -0
  83. package/dist/decorator/delete.d.ts.map +1 -0
  84. package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
  85. package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
  88. package/dist/decorator/get.d.ts +3 -0
  89. package/dist/decorator/get.d.ts.map +1 -0
  90. package/{decorator/get.ts → dist/decorator/get.js} +10 -11
  91. package/dist/decorator/index.d.ts +6 -0
  92. package/dist/decorator/index.d.ts.map +1 -0
  93. package/dist/decorator/index.js +13 -0
  94. package/dist/decorator/post.d.ts +3 -0
  95. package/dist/decorator/post.d.ts.map +1 -0
  96. package/{decorator/post.ts → dist/decorator/post.js} +10 -10
  97. package/dist/decorator/put.d.ts +3 -0
  98. package/dist/decorator/put.d.ts.map +1 -0
  99. package/{decorator/put.ts → dist/decorator/put.js} +9 -9
  100. package/dist/filters/AccessControl.d.ts +12 -0
  101. package/dist/filters/AccessControl.d.ts.map +1 -0
  102. package/dist/filters/AccessControl.js +83 -0
  103. package/dist/filters/AccessRule.d.ts +83 -0
  104. package/dist/filters/AccessRule.d.ts.map +1 -0
  105. package/dist/filters/AccessRule.js +136 -0
  106. package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
  107. package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
  108. package/dist/filters/auth/AuthInterface.js +2 -0
  109. package/dist/filters/auth/AuthMethod.d.ts +38 -0
  110. package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
  111. package/dist/filters/auth/AuthMethod.js +82 -0
  112. package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
  113. package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
  114. package/dist/filters/auth/HttpBasicAuth.js +79 -0
  115. package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
  116. package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
  117. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  118. package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
  119. package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
  120. package/dist/filters/auth/HttpHeaderAuth.js +64 -0
  121. package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
  122. package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
  123. package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
  124. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
  125. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
  126. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
  127. package/dist/filters/auth/index.d.ts +5 -0
  128. package/dist/filters/auth/index.d.ts.map +1 -0
  129. package/dist/filters/auth/index.js +11 -0
  130. package/dist/filters/index.d.ts +3 -0
  131. package/dist/filters/index.d.ts.map +1 -0
  132. package/dist/filters/index.js +7 -0
  133. package/dist/index.d.ts +26 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +73 -0
  136. package/dist/log/log/config/log4js.json +55 -0
  137. package/dist/model/RouteDefinition.d.ts +7 -0
  138. package/dist/model/RouteDefinition.d.ts.map +1 -0
  139. package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
  140. package/dist/package.json +63 -0
  141. package/dist/rbac/AuthAssignment.d.ts +19 -0
  142. package/dist/rbac/AuthAssignment.d.ts.map +1 -0
  143. package/dist/rbac/AuthAssignment.js +44 -0
  144. package/dist/rbac/AuthItem.d.ts +27 -0
  145. package/dist/rbac/AuthItem.d.ts.map +1 -0
  146. package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
  147. package/dist/rbac/AuthItemChild.d.ts +19 -0
  148. package/dist/rbac/AuthItemChild.d.ts.map +1 -0
  149. package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
  150. package/dist/rbac/AuthManager.d.ts +112 -0
  151. package/dist/rbac/AuthManager.d.ts.map +1 -0
  152. package/dist/rbac/AuthManager.js +356 -0
  153. package/dist/rbac/index.d.ts +5 -0
  154. package/dist/rbac/index.d.ts.map +1 -0
  155. package/dist/rbac/index.js +28 -0
  156. package/dist/requiments/Glob.d.ts +3 -0
  157. package/dist/requiments/Glob.d.ts.map +1 -0
  158. package/dist/requiments/Glob.js +10 -0
  159. package/dist/requiments/ReflectUtil.d.ts +1 -0
  160. package/dist/requiments/ReflectUtil.d.ts.map +1 -0
  161. package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
  162. package/dist/requiments/Utils.d.ts +2 -0
  163. package/dist/requiments/Utils.d.ts.map +1 -0
  164. package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
  165. package/dist/validators/BooleanValidator.d.ts +1 -0
  166. package/dist/validators/BooleanValidator.d.ts.map +1 -0
  167. package/dist/validators/BooleanValidator.js +1 -0
  168. package/dist/validators/CompareValidator.d.ts +1 -0
  169. package/dist/validators/CompareValidator.d.ts.map +1 -0
  170. package/dist/validators/CompareValidator.js +1 -0
  171. package/dist/validators/DateValidator.d.ts +1 -0
  172. package/dist/validators/DateValidator.d.ts.map +1 -0
  173. package/dist/validators/DateValidator.js +1 -0
  174. package/dist/validators/EmailValidator.d.ts +1 -0
  175. package/dist/validators/EmailValidator.d.ts.map +1 -0
  176. package/dist/validators/EmailValidator.js +1 -0
  177. package/dist/validators/Validator.d.ts +18 -0
  178. package/dist/validators/Validator.d.ts.map +1 -0
  179. package/dist/validators/Validator.js +27 -0
  180. package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
  181. package/dist/web/IdentityInterface.d.ts.map +1 -0
  182. package/dist/web/IdentityInterface.js +8 -0
  183. package/dist/web/WebUser.d.ts +72 -0
  184. package/dist/web/WebUser.d.ts.map +1 -0
  185. package/dist/web/WebUser.js +165 -0
  186. package/package.json +16 -56
  187. package/BaseChyz.ts +0 -623
  188. package/base/ActionFilter.ts +0 -88
  189. package/base/BadRequestHttpException.ts +0 -14
  190. package/base/Behavior.ts +0 -6
  191. package/base/CBaseObject.ts +0 -17
  192. package/base/CEvents.ts +0 -24
  193. package/base/CWebController.ts +0 -90
  194. package/base/Component.ts +0 -66
  195. package/base/DataErrorDbException.ts +0 -16
  196. package/base/DbConnection.ts +0 -55
  197. package/base/ForbiddenHttpException.ts +0 -15
  198. package/base/InvalidArgumentException.ts +0 -16
  199. package/base/InvalidConfigException.ts +0 -16
  200. package/base/NotFoundHttpException.ts +0 -14
  201. package/base/RestClient.ts +0 -26
  202. package/base/UnauthorizedHttpException.ts +0 -17
  203. package/base/ValidationHttpException.ts +0 -14
  204. package/base/db/Exception.ts +0 -14
  205. package/base/index.ts +0 -19
  206. package/decorator/Middleware.ts +0 -9
  207. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  208. package/decorator/index.ts +0 -5
  209. package/filters/AccessControl.ts +0 -74
  210. package/filters/AccessRule.ts +0 -182
  211. package/filters/auth/AuthMethod.ts +0 -100
  212. package/filters/auth/HttpBasicAuth.ts +0 -79
  213. package/filters/auth/HttpBearerAuth.ts +0 -34
  214. package/filters/auth/HttpHeaderAuth.ts +0 -61
  215. package/filters/auth/JwtHttpBearerAuth.ts +0 -83
  216. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
  217. package/filters/auth/index.ts +0 -4
  218. package/filters/index.ts +0 -2
  219. package/index.ts +0 -80
  220. package/model/RouteDefinition.ts +0 -18
  221. package/rbac/AuthAssignment.ts +0 -50
  222. package/rbac/AuthManager.ts +0 -399
  223. package/rbac/index.ts +0 -12
  224. package/validators/BooleanValidator.ts +0 -0
  225. package/validators/CompareValidator.ts +0 -0
  226. package/validators/DateValidator.ts +0 -0
  227. package/validators/EmailValidator.ts +0 -0
  228. package/validators/Validator.ts +0 -27
  229. package/web/WebUser.ts +0 -187
  230. /package/{README.md → dist/README.md} +0 -0
  231. /package/{log → dist/log}/config/log4js.json +0 -0
@@ -1,182 +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
- import {Component} from "../base";
9
- import {InvalidConfigException} from "../base";
10
- import {Request} from "express";
11
- import {Utils} from "../requiments/Utils";
12
-
13
-
14
- export class AccessRule extends Component {
15
-
16
- /**
17
- * @var allow 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|Closure parameters to pass to the [[User::can()]] function for evaluating
45
- * user permissions in [[$roles]].
46
- *
47
- * If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
48
- * ID from the current request, you may use the following:
49
- *
50
- * ```php
51
- * ['postId' => Yii::$app->request->get('id')]
52
- * ```
53
- *
54
- * You may also specify a closure that returns an array. This can be used to
55
- * evaluate the array values only if they are needed, for example when a model needs to be
56
- * loaded like in the following code:
57
- *
58
- * ```php
59
- * 'rules' => [
60
- * [
61
- * 'allow' => true,
62
- * 'actions' => ['update'],
63
- * 'roles' => ['updatePost'],
64
- * 'roleParams' => function($rule) {
65
- * return ['post' => Post::findOne(Yii::$app->request->get('id'))];
66
- * },
67
- * ],
68
- * ],
69
- * ```
70
- *
71
- * A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
72
- *
73
- * @see roles
74
- * @since 2.0.12
75
- */
76
- public roleParams: any = [];
77
-
78
-
79
- /**
80
- * @var array list of user IP addresses that this rule applies to. An IP address
81
- * can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
82
- * For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
83
- * It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
84
- * 20-bit private network block in RFC1918.
85
- * If not set or empty, it means this rule applies to all IP addresses.
86
- */
87
- public ips: any;
88
-
89
-
90
- public async allows(action: any, user: WebUser, request: Request) {
91
- if (
92
- this.matchAction(action)
93
- && await this.matchRole(user)
94
- ) {
95
- return this.allow
96
- }
97
- // if (this.matchAction($action)
98
- // && this.matchRole($user)
99
- // && this.matchIP($request->getUserIP())
100
- // && this.matchVerb($request->getMethod())
101
- // && this.matchController($action->controller)
102
- // && this.matchCustom($action)
103
- // ) {
104
- // return $this->allow ? true : false;
105
- // }
106
-
107
- return null;
108
- }
109
-
110
- /**
111
- * @param action $action the action
112
- * @return bool whether the rule applies to the action
113
- */
114
- protected matchAction(action: any) {
115
- return Utils.isEmpty(this.actions) || this.actions.includes(action.id);
116
- }
117
-
118
- /**
119
- * @param controller $controller the controller
120
- * @return bool whether the rule applies to the controller
121
- */
122
- protected matchController(controller: any) {
123
- // if (empty($this->controllers)) {
124
- // return true;
125
- // }
126
- //
127
- // $id = $controller->getUniqueId();
128
- // foreach ($this->controllers as $pattern) {
129
- // if (StringHelper::matchWildcard($pattern, $id)) {
130
- // return true;
131
- // }
132
- // }
133
-
134
- return false;
135
- }
136
-
137
- protected async matchRole(user: WebUser) {
138
- let items = Utils.isEmpty(this.roles) ? [] : this.roles;
139
-
140
- if (!Utils.isEmpty(this.permissions)) {
141
- items = Utils.merge(items, this.permissions);
142
- }
143
-
144
- if (Utils.isEmpty(items)) {
145
- return true;
146
- }
147
-
148
-
149
- if (!user) {
150
- throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
151
- }
152
-
153
- // @ts-ignore
154
- let roleParams: any = [];
155
- for (const itemsKey in items) {
156
- let item = items[itemsKey];
157
- if (item === '?') {
158
- if (user.getIsGuest()) {
159
- return true;
160
- }
161
- } else if (item === '@') {
162
- if (!user.getIsGuest()) {
163
- return true;
164
- }
165
- } else {
166
- //role-params
167
- if (!Utils.isEmpty(this.roleParams)) {
168
- roleParams = !Utils.isArray(this.roleParams) ? this.roleParams.apply(this) : this.roleParams;
169
- }
170
-
171
- if (await user.can(item, this.roleParams)) {
172
- return true;
173
- }
174
- }
175
- }
176
-
177
-
178
- return false;
179
- }
180
-
181
-
182
- }
@@ -1,100 +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";
9
- import {AuthInterface} from "./AuthInterface";
10
- import {UnauthorizedHttpException} from "../../base";
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
- /**
35
- *
36
- * @param action
37
- * @param request
38
- * @param response
39
- */
40
- public async beforeAction(action: any, request: Request, response: Response) {
41
- let identity =await this.authenticate(
42
- this.user ?? new WebUser(),
43
- request,
44
- response
45
- )
46
-
47
- // @ts-ignore
48
- request.identity = identity;
49
-
50
- if (identity !== null) {
51
- return true;
52
- }
53
-
54
- this.challenge(response);
55
- this.handleFailure(response);
56
- return false;
57
- }
58
-
59
- /**
60
- *
61
- * @param user
62
- * @param request
63
- * @param response
64
- */
65
- authenticate(user: WebUser, request: Request, response: Response) {
66
-
67
- }
68
-
69
- // @ts-ignore
70
- challenge(response: Response): Response {
71
-
72
- }
73
-
74
- // @ts-ignore
75
- handleFailure(response: Response): Response {
76
- throw new UnauthorizedHttpException('Your request was made with invalid credentials.');
77
- }
78
-
79
- getHeaderByKey(headers: any, findKey: any) {
80
- let key = Object.keys(headers).find(key => key.toLowerCase() === findKey.toLowerCase())
81
- if (key) {
82
- return headers[key];
83
- }
84
-
85
- return null
86
- }
87
-
88
- patternCheck(headerText: any, pattern: RegExp) {
89
- if (pattern) {
90
- let matches = headerText.match(pattern)
91
- if (matches && matches.length > 0) {
92
- return matches;
93
- } else {
94
- return null
95
- }
96
- }
97
-
98
- return null
99
- }
100
- }
@@ -1,79 +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 {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
- }
@@ -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
-
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
- }
@@ -1,61 +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 {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
- }
@@ -1,83 +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 {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
- }
@@ -1,114 +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 {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
- }
@@ -1,4 +0,0 @@
1
- export {JwtHttpBearerAuth} from "./JwtHttpBearerAuth"
2
- export {HttpBearerAuth} from "./HttpBearerAuth"
3
- export {HttpHeaderAuth} from "./HttpHeaderAuth"
4
- export {HttpBasicAuth} from "./HttpBasicAuth"
package/filters/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export {AccessControl} from "./AccessControl"
2
- export {AccessRule} from "./AccessRule"