Skip to content

Commit 323d072

Browse files
committed
secureview finalized
1 parent 11a6532 commit 323d072

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

interceptors/Security.cfc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ component accessors="true" extends="coldbox.system.Interceptor" {
1111
// DI
1212
property name="rulesLoader" inject="rulesLoader@cbSecurity";
1313
property name="handlerService" inject="coldbox:handlerService";
14+
property name="cbSecurity" inject="@cbSecurity";
1415

1516
/**
1617
* The reference to the security validator for this interceptor
@@ -185,6 +186,9 @@ component accessors="true" extends="coldbox.system.Interceptor" {
185186
prc,
186187
buffer
187188
){
189+
// Add SecureView() into the requestcontext
190+
arguments.event.secureView = variables.cbSecurity.secureViewProxy;
191+
188192
// Execute Rule processing
189193
if ( getProperty( "rules" ).len() ) {
190194
processRules(

models/CBSecurity.cfc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,40 @@ component singleton accessors="true" {
368368
return this;
369369
}
370370

371+
/**
372+
* This is the method proxy injected into the request context that will act like the
373+
* `secureView()` method velow
374+
*
375+
* @permissions One, a list or an array of permissions
376+
* @successView The view to set in the request context if the permissions pass
377+
* @failView The view to set in the request context if the permissions fails, optional
378+
*/
379+
function secureViewProxy( required permissions, required successView, failView ){
380+
arguments.event = this;
381+
controller
382+
.getWireBox()
383+
.getInstance( dsl = "@cbSecurity" )
384+
.secureView( argumentCollection=arguments );
385+
return this;
386+
}
387+
388+
/**
389+
* This method is injected into all request contex's in order to allow you to easily
390+
* switch between views if the permissions are not found in the user.
391+
*
392+
* @event The proxied request context
393+
* @permissions One, a list or an array of permissions
394+
* @successView The view to set in the request context if the permissions pass
395+
* @failView The view to set in the request context if the permissions fails, optional
396+
*/
397+
function secureView( required event, required permissions, required successView, failView ){
398+
if( has( arguments.permissions ) ){
399+
arguments.event.setView( arguments.successView );
400+
} else if ( !isNull( arguments.failView ) ){
401+
arguments.event.setView( arguments.failView );
402+
}
403+
}
404+
371405
/***************************************************************/
372406
/* Private Methods
373407
/***************************************************************/

test-harness/handlers/Main.cfc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ component {
3737
return cbsecure().getSettings();
3838
}
3939

40+
function secureView( event, rc, prc ){
41+
event.secureView( "test", "main/index" );
42+
}
43+
4044
}

0 commit comments

Comments
 (0)