Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[coldbox-5.6.2] Prehandler not preventing handler from executing when auth fails

42 views
Skip to first unread message

Jen K

unread,
Sep 3, 2020, 7:15:33 PM9/3/20
to ColdBox Platform
Hi,
I'm using a prehandler in my API call similar to the one in the example here:
https://coldbox.ortusbooks.com/digging-deeper/recipes/building-rest-apis

My API is set up the same way as the examples in the link above.

The prehandler does not prevent the index handler from executing despite failing user auth.

<cffunction name="preHandler" output="false" hint="preHandler">
        <cfargument name="event">
        <cfargument name="rc">
        <cfargument name="prc">
        <cfargument name="action">
        <cfargument name="eventArguments">

        [my code removed but confirmed working]
        <cfif !  FALSE>
            <cfset event.renderData( type="json", data={data}, statusCode=403, statusMessage="not authorized") />
        </cfif>
        
    </cffunction>

<cffunction name="index" returntype="void" output="false" hint="customer at risk list">
        <cfargument name="event">
        <cfargument name="rc">
        <cfargument name="prc">

       [my stuff}
        <cfset event.renderData( type="json", data=local.response, statusCode=local.response["statuscode"], statusMessage=local.response["message"]) />
    </cffunction>

How can the prehandler stop the index method from firing?

Jen K

unread,
Sep 4, 2020, 11:16:21 AM9/4/20
to ColdBox Platform
I tried adding event.noExecution() after renderData in the preHandler but it still executes the preHandler and the index event resulting in the index renderData being shown.

When I comment out the index renderData the preHandler renderData is shown so it's running just not stopping the event from continuing to the index event.

I'm still not sure how to stop the index event from happening in the preHandler. 

Jen K

unread,
Sep 4, 2020, 12:10:36 PM9/4/20
to ColdBox Platform
Gave up on the prehander and used a preProcess interceptor instead.  

Sana Ullah

unread,
Sep 4, 2020, 12:18:35 PM9/4/20
to col...@googlegroups.com
Hi Jen

If authentication failed then in preHandler you can override the event (redirect to another handler or method )


--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/4e88b886-28c7-48b9-bbe7-d6e55be3495an%40googlegroups.com.

Jen K

unread,
Sep 4, 2020, 12:21:39 PM9/4/20
to ColdBox Platform
Yes, override to another event worked but that's not what I wanted. I wanted the renderData function to execute to return the failure reason and then stop the event from processing.

I ended up using an interceptor preProcess function and it works as I intended it to.

Thank you for responding, Sana.

Reply all
Reply to author
Forward
0 new messages