Skip to content

Commit 91999f2

Browse files
authored
Performance optimizations for invalid event handler checks
Moved Coldbox version and the invalidEventHandlerBean null checks to the `configure()` method. Refactored the `isInvalidEventHandlerBean()` so it only checks whether the passed handlerBean is a match (removed the null check). Simplified the `if` statement in `processAnnotationRules()` for performance and legibility.
1 parent 4455bfe commit 91999f2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

interceptors/Security.cfc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ component accessors="true" extends="coldbox.system.Interceptor" {
5151

5252
// Load up the validator
5353
registerValidator( getInstance( getProperty( "validator" ) ) );
54+
55+
// Coldbox version 5 (and lower) needs a little extra invalid event handler checking.
56+
variables.enableInvalidHandlerCheck = ( listGetAt( controller.getColdboxSettings().version, 1, "." ) <= 5 );
5457
}
5558

5659
/**
@@ -229,8 +232,12 @@ component accessors="true" extends="coldbox.system.Interceptor" {
229232
// Get handler bean for the current event
230233
var handlerBean = variables.handlerService.getHandlerBean( arguments.event.getCurrentEvent() );
231234

235+
// Are we running Coldbox 5 or older?
236+
// is an onInvalidHandlerBean configured?
237+
// is the current handlerBean the configured onInvalidEventHandlerBean?
232238
if (
233-
listGetAt( controller.getColdboxSettings().version, 1, "." ) == 5 &&
239+
variables.enableInvalidHandlerCheck &&
240+
!isNull( variables.onInvalidEventHandlerBean ) &&
234241
isInvalidEventHandlerBean( handlerBean )
235242
) {
236243
// ColdBox tries to detect invalid event handler loops by keeping
@@ -725,11 +732,12 @@ component accessors="true" extends="coldbox.system.Interceptor" {
725732
return len( CGI.REMOTE_ADDR ) ? CGI.REMOTE_ADDR : "127.0.0.1";
726733
}
727734

735+
/**
736+
* Returns true of the passed handlerBean matches Coldbox's configured invalid event handler.
737+
*
738+
* @handlerBean the current handler bean to check against
739+
*/
728740
private boolean function isInvalidEventHandlerBean( required handlerBean ) {
729-
if ( isNull( variables.onInvalidEventHandlerBean ) ) {
730-
return false;
731-
}
732-
733741
return (
734742
variables.onInvalidEventHandlerBean.getInvocationPath() == arguments.handlerBean.getInvocationPath() &&
735743
variables.onInvalidEventHandlerBean.getHandler() == arguments.handlerBean.getHandler() &&

0 commit comments

Comments
 (0)