You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
feat: Ability to use local override handlers if they exist
cbguard will first check the local handler for an `onAuthenticationFailure`
or `onAuthorizationFailure` function. If it exists, it will be called.
BREAKING CHANGE: Dropped support for Lucee 4.5 and ACF 11
Special thanks to @Adrian-Sanchez for this PR.
## Annotation driven guards for authentication and authorization in ColdBox
6
6
@@ -93,15 +93,15 @@ When a user is denied access to a action, an event of your choosing is executed
93
93
94
94
This is the event that is executed when the user is not logged in and is attempting to execute a secured action, whether or not that handler or action has permissions.
95
95
96
-
1.`authorizationOverrideEvent` (Default: same as `authenticationOverrideEvent`)
96
+
2.`authorizationOverrideEvent` (Default: same as `authenticationOverrideEvent`)
97
97
98
98
This is the event that is executed when the user is logged in and is attempting to execute a secured action but does not have the requisite permissions.
This is the event that is executed when the user is not logged in and is attempting to execute a secured action via ajax (`event.isAjax()`), whether or not that handler or action has permissions. By default, this will execute the same action that is configured for `authenticationOverrideEvent`.
103
103
104
-
1.`authorizationAjaxOverrideEvent` (Default: same as `authorizationOverrideEvent`)
104
+
4.`authorizationAjaxOverrideEvent` (Default: same as `authorizationOverrideEvent`)
105
105
106
106
This is the event that is executed when the user is logged in and is attempting to execute a secured action via ajax (`event.isAjax()`) but does not have the requisite permissions. By default, this will execute the same action that is configured for `authorizationOverrideEvent`.
107
107
@@ -160,7 +160,7 @@ moduleSettings = {
160
160
The default `authenticationService` for `cbguard` is `AuthenticationService@cbauth`. `cbauth` follows the `AuthenticationServiceInterface` out of the box.
161
161
162
162
163
-
### Advanced Setup
163
+
### config/ColdBox.cfc Settings
164
164
165
165
You can change the method names called on the `AuthenticationService` and the returned `User` if you need to. We highly discourage this use case, as it makes it harder to utilize the `cbguard` conventions across projects. However, should the need arise, you can modify the method names as follows:
166
166
@@ -219,6 +219,43 @@ component {
219
219
}
220
220
```
221
221
222
+
### Local Handler Overrides
223
+
224
+
If an `onAuthenticationFailure` or `onAuthorizationFailure` method exists on the handler being
225
+
secured, it will be used in the case of an authentication or authorization failure event,
226
+
respectively.
227
+
228
+
```
229
+
// handlers/Admin.cfc
230
+
component secured {
231
+
232
+
function index( event, rc, prc ) {
233
+
event.setView( "admin/index" );
234
+
}
235
+
236
+
function secret( event, rc, prc ) secured="superadmin" {
237
+
event.setView( "admin/secret" );
238
+
}
239
+
240
+
function onAuthenticationFailure( event, rc, prc ) {
241
+
relocate( "/login" );
242
+
}
243
+
244
+
function onAuthenticationFailure( event, rc, prc ) {
245
+
flash.put( "authorizationError", "You don't have the correct permissions to access that resource." );
246
+
redirectBack(); // from the redirectBack module
247
+
}
248
+
249
+
}
250
+
```
251
+
252
+
### Override Order
253
+
cbguard will process your authorization and authentication failures in the following order:
254
+
1. Inline handler methods (`onAuthenticationFailure` & `onAuthorizationFailure` within your handlers).
255
+
2. cbguard settings in the ModuleConfig of the handler's module. (Overrides in `modules_app/api/ModuleConfig.cfc` when the handler is in the module, i.e. `modules_app/api/handlers/Main.cfc`.)
256
+
3. Overrides in `config/ColdBox.cfc` using `moduleSettings`.
257
+
4. Default settings for the module.
258
+
222
259
## `autoRegisterInterceptor`
223
260
224
261
If you need more control over the order of your interceptors you can
0 commit comments