Event Filter Question

11 views
Skip to first unread message

geomunir

unread,
Dec 16, 2009, 2:36:23 AM12/16/09
to Mach-II for CFML
I'm trying to get filter working, but for some reason its not working
as expected. Maybe, something in my logic or i'm not getting the
filter right.

Whats happening?: Well, I see the event filter is being triggered, but
nothing happens, regular page is displayed. I'm logged in as not
authorized user (role_id=4), and reguired role_id = 3 (parameter).

When i'm not authorized, i should be redirected to
sysadmin.accessDenied event.

Here is the code:

mach-ii.xml
--
<event-filters>
<event-filter name="permissionValidation"
type="blaz.filters.permissionValidation" />
</event-filters>

<event-handler event="sysadmin.server_setting" access="public">
<event-filter name="permissionValidation">
<parameter name="role_id" value="3" />
</event-filter>

<view-page name="sysadmin.act_server_setting"/>
<view-page name="sysadmin.server_setting"
contentArg="layout.content" />
<execute subroutine="sysadmin.compileLayout" />

</event-handler>


permissionValidation.cfc
<cfcomponent extends="MachII.framework.EventFilter" hint="Permision
Validation">
<cffunction name="configure" access="public" output="false"
returntype="void" hint="Configures the filter">
<!--- Does nothing --->
</cffunction>


<!--- Authenticate Specfic Role --->
<cffunction name="filterEvent" returntype="boolean">
<!--- Required Arguments --->
<cfargument name="event" type="MachII.framework.Event"
required="true" />
<cfargument name="eventContext"
type="MachII.framework.EventContext" required="true" />
<cfargument name="paramArgs" type="struct" required="false"
default="#StructNew()#" />


<cfscript>
//Declare variable and assign initial value
var validationBoolean = false;

//If logged in user matches with Required role
if(isUserInRole(event.getArg(role_id)))
{
//Assign value to a variable
validationBoolean = true;
}
else
{
//Assign value to a variable
validationBoolean = false;

//Announce Mach-II Event-Handler
arguments.eventContext.announceEvent("sysadmin.accessDenied",
arguments.event.getArgs());
}

</cfscript>




<cfreturn validationBoolean>
</cffunction>

</cfcomponent>

Peter J. Farrell

unread,
Dec 16, 2009, 3:18:31 AM12/16/09
to mach-ii-for...@googlegroups.com
ParamArgs (nested inside your filter when you declare it in an event-handler) are passed.  Change:
if(isUserInRole(event.getArg(role_id)))
to
if(isUserInRole(arguments.paramArgs.role_id))
I'd also clear the event-queue before annnouncing your access denied event:

arguments.eventContext.clearEventQueue():

Also, you can change this:
arguments.eventContext.announceEvent("sysadmin.accessDenied",
to this:
announceEvent("sysadmin.accessDenied", arguments.event.getArgs());
AnnounceEvent() is one of the built in methods in the BaseComponent class that MachII.framework.EventFilter inherits from.

HTH,
.Peter


geomunir said the following on 12/16/2009 01:36 AM:
--

The Harmonious Programmer

Peter J. Farrell
Email: pe...@mach-ii.com | pjf@maestropublishing
Blog: The Harmonious Programmer
Twitter/Identi.ca: @maestrofjp

Mike Fransblow

unread,
Dec 16, 2009, 12:23:20 PM12/16/09
to mach-ii-for...@googlegroups.com
Hey geo,

It doesn't look like your filter is comparing the required role_id with
what the event has access to.
I'd get a handle on the required role_id by adding

<cfset var required_role_id = arguments.paramArgs.role_id />


to the filter after the argument declarations. This is the value that
you've added to the event in you xml config.
Then change the logic where you check the permission to:

if(isUserInRole(required_role_id))


That should do it.
If you know that required_role_id won't change event to event (unlikely
is my guess, but I'll point it out anyway) then I would put the default
in the filter definition as:

<event-filters>
<event-filter name="permissionValidation" type="blaz.filters.permissionValidation">
<parameter name="role_id" value="3"/>
</event-filter>
</event-filters>

That way you don't have to add it to every event in your xml.

hope this helps.

MikeF

geomunir

unread,
Dec 16, 2009, 2:06:58 PM12/16/09
to Mach-II for CFML
I made the changes, however, it does not seems to be working. First of
all, i dont see permissionValidation.cfc initiated at all. If its not
initiating, then sysadmin.accessDenied wont be announced.

If i change to something like this, then it does:
<event-handler event="sysadmin.server_setting" access="public">
<event-filter name="permissionValidation">
<parameter name="role_id" value="3" />
<view-page name="sysadmin.act_server_setting"/>
<view-page name="sysadmin.server_setting"
contentArg="layout.content" />
<execute subroutine="sysadmin.compileLayout" />
</event-filter>
</event-handler>


But, after the change, nothing happens. Blank page is shown.


Mike,
role_id does change, from event to event.
> The Harmonious Programmer
> <http://feeds.feedburner.com/%7Er/TheHarmoniousProgrammer/%7E6/1>
>
> *Peter J. Farrell*
> Email: pe...@mach-ii.com | pjf@maestropublishing
> Blog: The Harmonious Programmer <http://blog.maestropublishing.com>
> Twitter/Identi.ca: @maestrofjp
>
>  TheHarmoniousProgrammer.1.gif
> 64KViewDownload- Hide quoted text -
>
> - Show quoted text -

Peter J. Farrell

unread,
Dec 16, 2009, 2:25:00 PM12/16/09
to mach-ii-for...@googlegroups.com
You can't nest other commands inside an filter command -- they will just be ignored.  Also, the command name is "filter" not "event-filter" when you declare it in an event-handler:
<event-handler event="sysadmin.server_setting" access="public">
	<filter name="permissionValidation">
		<parameter name="role_id" value="3" />
	</filter>
	<view-page name="sysadmin.act_server_setting"/>
	<view-page name="sysadmin.server_setting" contentArg="layout.content" />
	<execute subroutine="sysadmin.compileLayout" />
</event-handler>
For future reference, I'd look at the XML Quick Reference Guide:
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/ConfigFileExplained

And I'd use an XML editor that offers DTD validation so you can use the DTD that comeswith Mach-II to validate your XML file for validity:

http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/FAQUsingDTD

geomunir said the following on 12/16/2009 01:06 PM:
--

The Harmonious Programmer

Peter J. Farrell


Email: pe...@mach-ii.com | pjf@maestropublishing
Blog: The Harmonious Programmer

Twitter/Identi.ca: @maestrofjp

Mike Fransblow

unread,
Dec 16, 2009, 3:01:29 PM12/16/09
to mach-ii-for...@googlegroups.com
I wouldn't wrap the views within the event-filter.
There are a few things you can do to figure out where it's going wrong.

In you xml config  you can add logging as a property, which will tell you what's happening during the event life cycle. Add:
<property name="Logging" type="MachII.logging.LoggingProperty" />

This is kind of like CF debugging.

More common and it will tell you exactly what's going on in the filter is to add

<cfdump var=""/><cfabort/>

at certain steps in the filter. If the filter is not running you'll know right away. I would cfdump your role_id and the boolean return value to debug it.
Do you have a sysadmin.accessDenied event defined? From your original post I did not see that in the config?

geomunir

unread,
Dec 16, 2009, 3:31:17 PM12/16/09
to Mach-II for CFML
Yup, that did it. I was using <event-filter> instead of <filter>. I
must've i wasnt paying attention when i was reading the doc.

And thanks for the link, i have bookmarked it for future reference.

On Dec 16, 11:25 am, "Peter J. Farrell" <pe...@mach-ii.com> wrote:
> You can't nest other commands inside an filter command -- they will just
> be ignored.  Also, the command name is "filter" not "event-filter" when
> you declare it in an event-handler:
>
> <event-handler event="sysadmin.server_setting" access="public">
>         <filter name="permissionValidation">
>                 <parameter name="role_id" value="3" />
>         </filter>
>         <view-page name="sysadmin.act_server_setting"/>
>         <view-page name="sysadmin.server_setting" contentArg="layout.content" />
>         <execute subroutine="sysadmin.compileLayout" />
> </event-handler>
>
> For future reference, I'd look at the XML Quick Reference Guide:http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/ConfigFileExpla...
> 65KViewDownload- Hide quoted text -

geomunir

unread,
Dec 16, 2009, 4:17:06 PM12/16/09
to Mach-II for CFML
Yes, i have defined sysadmin.accessDenied event. I didnt post it
here.

I think that the filter was not initiating because of incorrect xml
node. After Peter pointed out, that we have to use <filter>, that
fixed the issue. I also validated xml using online to verify i have
other nodes correct.

Side question, Do you guys have mach-ii extension for dreamweaver? I
didnt see anywhere on mach-ii website.


On Dec 16, 12:01 pm, Mike Fransblow <mi...@alluradirect.com> wrote:
> I wouldn't wrap the views within the event-filter.
> There are a few things you can do to figure out where it's going wrong.
> In you xml config  you can add logging as a property, which will tell you what's happening during the event life cycle. Add:
> <property name="Logging" type="MachII.logging.LoggingProperty" />
> This is kind of like CF debugging.
> More common and it will tell you exactly what's going on in the filter is to add
> <cfdump var=""/><cfabort/>
> at certain steps in the filter. If the filter is not running you'll know right away. I would cfdump your role_id and the boolean return value to debug it.
> Do you have a sysadmin.accessDenied event defined? From your original post I did not see that in the config?
> geomunir wrote:I made the changes, however, it does not seems to be working. First of all, i dont see permissionValidation.cfc initiated at all. If its not initiating, then sysadmin.accessDenied wont be announced. If i change to something like this, then it does: <event-handler event="sysadmin.server_setting" access="public"> <event-filter name="permissionValidation"> <parameter name="role_id" value="3" /> <view-page name="sysadmin.act_server_setting"/> <view-page name="sysadmin.server_setting" contentArg="layout.content" /> <execute subroutine="sysadmin.compileLayout" /> </event-filter> </event-handler> But, after the change, nothing happens. Blank page is shown. Mike, role_id does change, from event to event. On Dec 16, 12:18 am, "Peter J. Farrell"<pe...@mach-ii.com>wrote:ParamArgs (nested inside your filter when you declare it in an event-handler) are passed.  Change: if(isUserInRole(event.getArg(role_id))) to if(isUserInRole(arguments.paramArgs.role_id)) I'd also clear the event-queue before annnouncing your access denied event: arguments.eventContext.clearEventQueue(): Also, you can change this: arguments.eventContext.announceEvent("sysadmin.accessDenied", to this: announceEvent("sysadmin.accessDenied", arguments.event.getArgs()); AnnounceEvent() is one of the built in methods in the BaseComponent class that MachII.framework.EventFilter inherits from. HTH, .Peter geomunir said the following on 12/16/2009 01:36 AM:I'm trying to get filter working, but for some reason its not working as expected. Maybe, something in my logic or i'm not getting the filter right.Whats happening?: Well, I see the event filter is being triggered, but nothing happens, regular page is displayed. I'm logged in as not authorized user (role_id=4), and reguired role_id = 3 (parameter).When i'm not authorized, i should be redirected to sysadmin.accessDenied event.Here is the code:mach-ii.xml --    <event-filters>            <event-filter name="permissionValidation" type="blaz.filters.permissionValidation" />    </event-filters>   <event-handler event="sysadmin.server_setting" access="public">            <event-filter name="permissionValidation">                    <parameter name="role_id" value="3" />            </event-filter>           <view-page name="sysadmin.act_server_setting"/>            <view-page name="sysadmin.server_setting" contentArg="layout.content" />            <execute subroutine="sysadmin.compileLayout" />   </event-handler>permissionValidation.cfc <cfcomponent extends="MachII.framework.EventFilter" hint="Permision Validation">     <cffunction name="configure" access="public" output="false" returntype="void" hint="Configures the filter">            <!--- Does nothing --->     </cffunction>   <!--- Authenticate Specfic Role  --->     <cffunction name="filterEvent" returntype="boolean">            <!--- Required Arguments --->         <cfargument name="event" type="MachII.framework.Event" required="true" />         <cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />         <cfargument name="paramArgs" type="struct" required="false" default="#StructNew()#" />        <cfscript>                    //Declare variable and assign initial value                    var validationBoolean = false;                   //If logged in user matches with Required role                    if(isUserInRole(event.getArg(role_id)))                    {                            //Assign value to a variable                            validationBoolean = true;                    }                    else                    {                            //Assign value to a variable                            validationBoolean = false;                           //Announce Mach-II Event-Handler                            arguments.eventContext.announceEvent("sysadmin.accessDenied", arguments.event.getArgs());                    }           </cfscript>           <cfreturn validationBoolean>     </cffunction></cfcomponent>-- The Harmonious Programmer<http://feeds.feedburner.com/%7Er/TheHarmoniousProgrammer/%7E6/1>*Peter J. Farrell* Email:pe...@mach-ii.com| pjf@maestropublishing Blog: The Harmonious Programmer<http://blog.maestropublishing.com>Twitter/Identi.ca: @maestrofjp  TheHarmoniousProgrammer.1.gif 64KViewDownload- Hide quoted text - - Show quoted text -
Reply all
Reply to author
Forward
0 new messages