Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Commit 72ba3d0

Browse files
authored
perf(cbguard): Use ColdBox 5.6's handler metadata cache
ColdBox cache's handler metadata as of 5.6. Use that instead of instantiating the handler and computing its metadata each time. BREAKING CHANGE: Must use ColdBox 5.6 for this feature
1 parent 2dbdc53 commit 72ba3d0

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

box.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"type":"modules",
1717
"dependencies":{},
1818
"devDependencies":{
19-
"coldbox":"^5.0.0",
19+
"coldbox":"^5.6.0",
2020
"testbox":"^2.4.0+80"
2121
},
2222
"installPaths":{

interceptors/SecuredEventInterceptor.cfc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,11 @@ component extends="coldbox.system.Interceptor"{
2626
}
2727
}
2828

29-
if( listFirst( coldboxVersion, "." ) >= 5 ){
30-
var handlerBean = handlerService.getHandlerBean( event.getCurrentEvent() );
31-
} else {
32-
var handlerBean = handlerService.getRegisteredHandler( event.getCurrentEvent() );
29+
var handlerBean = handlerService.getHandlerBean( event.getCurrentEvent() );
30+
if ( ! handlerBean.isMetadataLoaded() ) {
31+
handlerService.getHandler( handlerBean, event );
3332
}
34-
var handler = handlerService.getHandler(
35-
handlerBean,
36-
event
37-
);
38-
39-
var handlerMetadata = getMetadata( handler );
33+
var handlerMetadata = handlerBean.getHandlerMetadata();
4034

4135
return notAuthorizedForHandler( handlerMetadata, event, overrides ) ||
4236
notAuthorizedForAction( handlerMetadata, event, overrides );

tests/specs/integration/AuthorizationSpec.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
5959
expect( event.getValue( "event", "" ) ).toBe( "PermissionActionSecured.fooPermissionAction" );
6060
} );
6161

62-
it( "redirects the user if the component has a secured annotatoin with a list of permissions and the user has at least one of the required permissions but the action also has a secured annotation with a list of permissions and the user does not have any of the required permissions", function() {
62+
it( "redirects the user if the component has a secured annotation with a list of permissions and the user has at least one of the required permissions but the action also has a secured annotation with a list of permissions and the user does not have any of the required permissions", function() {
6363
authenticationService.login( createUser( { permissions = [ "one" ] } ) );
6464
var event = execute( event = "DoubleSecured.securedAction" );
6565
expect( event.getValue( "relocate_EVENT", "" ) ).toBe( "Main.onAuthorizationFailure" );
6666
} );
6767

68-
it( "does not redirect the user if the component has a secured annotatoin with a list of permissions and the user has at least one of the required permissions and the action also has a secured annotation with a list of permissions and the user has at least one of the required permissions", function() {
68+
it( "does not redirect the user if the component has a secured annotation with a list of permissions and the user has at least one of the required permissions and the action also has a secured annotation with a list of permissions and the user has at least one of the required permissions", function() {
6969
authenticationService.login( createUser( { permissions = [ "one", "two" ] } ) );
7070
var event = execute( event = "DoubleSecured.securedAction" );
7171
expect( event.getValue( "event", "" ) ).toBe( "DoubleSecured.securedAction" );

tests/specs/integration/ModuleAuthorizationSpec.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
6161
expect( event.getValue( "event", "" ) ).toBe( "myModule:PermissionActionSecured.fooPermissionAction" );
6262
} );
6363

64-
it( "redirects the user if the component has a secured annotatoin with a list of permissions and the user has at least one of the required permissions but the action also has a secured annotation with a list of permissions and the user does not have any of the required permissions", function() {
64+
it( "redirects the user if the component has a secured annotation with a list of permissions and the user has at least one of the required permissions but the action also has a secured annotation with a list of permissions and the user does not have any of the required permissions", function() {
6565
authenticationService.login( createUser( { permissions = [ "one" ] } ) );
6666
var event = execute( event = "myModule:DoubleSecured.securedAction" );
6767
expect( event.getValue( "relocate_EVENT", "" ) ).toBe( "myModule:Main.onAuthorizationFailure" );
6868
} );
6969

70-
it( "does not redirect the user if the component has a secured annotatoin with a list of permissions and the user has at least one of the required permissions and the action also has a secured annotation with a list of permissions and the user has at least one of the required permissions", function() {
70+
it( "does not redirect the user if the component has a secured annotation with a list of permissions and the user has at least one of the required permissions and the action also has a secured annotation with a list of permissions and the user has at least one of the required permissions", function() {
7171
authenticationService.login( createUser( { permissions = [ "one", "two" ] } ) );
7272
var event = execute( event = "myModule:DoubleSecured.securedAction" );
7373
expect( event.valueExists( "relocate_EVENT" ) ).toBeFalse();

0 commit comments

Comments
 (0)