[ColdBox 4.1] overrideEvent from module

In one of our module’s handers I am trying to run an overrrideEvent when access is denied to something. I am using event.overrideEvent(“security.noAccessToFile”). I thought it would recognize a main handler function from a module but it seems like I am missing something. Any thoughts?

You told us what you’re attempting, but not what the result is. If there is a behavior you don’t expect, please describe it. If there is an error message, please paste it in.



ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

If you’re not seeing the method executing, it may be because overrideEvent() will only work if used within preHandler or around the handler. If it’s called within the handler action, the rest of the action will still execute and you’ll see the output of that method.

When I need to override an event from within a handler action, I use a function that sets the headers, flushes and aborts the request, like so:

function onAuthorizationFailure(event=getRequestContext(),rc=getRequestCollection(),prc=getRequestCollection(private=true)){
        log.warn( "Authorization Failure", getHTTPRequestData() );
        header statusCode=STATUS.NOT_AUTHORIZED statusText="Not Authorized";
        writeOutput(serializeJSON({'message':'Your permissions do not allow this operation'}));

So when a user gets denied to downloading a file in our file management module, I am trying to use event.overrideEvent(“security.noAccessToFile”) where the event has a setView to a generic page that access is denied. The event basically just has a setView (
event.setView(view="_templates/v_fileaccessdenied",layout=“lay_default”);). The error I get is that a PRC value is not defined which is used in our default layout. As you can see below it is trying to use a default view which is similar to the event. I am guessing it can’t find the view I am setting in the security.noAccessToFile handler/function? If i just use a setView instead of the overrideEvent in my module then it works.

Event: security.noAccessToFile
Routed URL: fileexchange/main/feFileDownload/file_id/7/
Layout: lay_main (Module: )
View: security/noaccesstofile
Timestamp: 11/23/2015 05:55:08 PM