Thanks Peter. That's what I thought. I have roughly 50/50 split of secure vs
non secure events, so I thought it will be easier to set that up in the
event itself.

Thanks's for the code. I have similar setup. But, I'm thinking I will
probably just name my event as section.action.secure (orders.list.secure).
Actually, it might be good to do the combination of wild card and adding
".secure".

Can I user the matcher with M-II 1.8? Will it work if I just copy it in the
util folder?

Thanks,
Sumit


Sumit Verma
Partner / Vice President | ten24, LLC
office: 877.886.5806 x 103 | mobile: 617.290.8214
www.ten24web.com | www.linkedin.com/in/sverma | twitter: blogonria


On Fri, Jan 7, 2011 at 1:40 AM, Peter J. Farrell <[email protected]> wrote:

> Sumit Verma said the following on 01/06/2011 09:37 PM:
> > Hi Guys,
> >
> > Just wanted to confirm that event args set in the xml config are not
> > available in the preEvent plugin method. e.g.
> No, event-args set in an event-handler are not available in the
> preProcess plugin point. They are set when the event-handler is processed.
> > <event-handler event="home" access="public">
> >       <event-arg name="foo" value="bar" />
> > </event-handler>
> >
> > So, in this case foo is not available in the preProcess or preEvent
> > plugin method. I was setting up security and was hoping to just set
> > <event-arg name="secureEvent" value="true" /> and then check for login
> > in the preEvent.
>
> Here's an example of using event-handler name matching.  It uses the
> simple pattern matcher that is part of Mach-II 1.9 to do the wildcard *
> type matching:
>
> <plugin name="login" type="WebAssess.plugins.loginPlugin">
>    <parameters>
>        <parameter name="ignoreEvents">
>            <array>
>                <element value="home"/>
>                <element value="login*"/>
>                <element value="logout"/>
>                <element value="preview.*"/>
>                <element value="help.*"/>
>                <element value="sys.heartbeat"/>
>                <element value="${properties.exceptionEvent}"/>
>            </array>
>        </parameter>
>        <parameter name="notLoggedInEvent" value="login"/>
>    </parameters>
> </plugin>
>
> Example code
>
>
> <cfcomponent
>    displayname="loginPlugin"
>    extends="MachII.framework.Plugin"
>    depends="sessionFacade"
>    output="false"
>    hint="Checks if a user is logged in.">
>
>    <!---
>    PROPERTIES
>    --->
>    <cfset variables.instance = StructNew() />
>    <cfset variables.matcher = CreateObject("component",
> "MachII.util.matching.SimplePatternMatcher").init() />
>
>    <!---
>    INITIALIZATION / CONFIGURATION
>    --->
>    <cffunction name="configure" access="public" returntype="void"
> output="false"
>        hint="Configures the plugin.">
>
>        <cfif isParameterDefined("ignoreEvents") AND
> IsArray(getParameter("ignoreEvents"))>
>            <cfset
> setIgnoreEvents(buildIgnoreEvents(getParameter("ignoreEvents"))) />
>        <cfelse>
>            <cfthrow type="LoginPlugin.invalidParameter"
>                message="The parameter named 'ingoreEvents' is either
> not defined in the plugin registration XML or not an array." />
>        </cfif>
>
>        <cfif isParameterDefined("notLoggedInEvent") AND
> Len(getParameter("notLoggedInEvent"))>
>            <cfset setNotLoggedInEvent(getParameter("notLoggedInEvent")) />
>        <cfelse>
>            <cfthrow type="LoginPlugin.invalidParameter"
>                message="The parameter named 'notLoggedInEvent' is
> either not defined in the plugin registration XML or does not have a
> value." />
>        </cfif>
>    </cffunction>
>
>    <!---
>    PUBLIC FUNCTIONS
>    --->
>    <cffunction name="preProcess" access="public" returntype="void"
> output="false"
>        hint="Checks to see if the user is logged in during the
> preProcess plugin point.">
>        <cfargument name="eventContext"
> type="MachII.framework.EventContext" required="true" />
>
>        <cfset var event = arguments.eventContext.getNextEvent() />
>        <cfset var eventName = event.getRequestName() />
>        <cfset var ignoreEvents = getIgnoreEvents() / >
>        <cfset var eH = "" />
>        <cfset var persistData = StructNew() />
>        <cfset var persistId = "" />
>        <cfset var location = "" />
>
>        <cfif NOT ignoreEvents.contains(eventName)
>            AND NOT getSessionFacade().isLoggedIn()>
>
>            <!--- Redirect the user to the login page --->
>        </cfif>
>    </cffunction>
>
>    <!---
>    PROTECTED FUNCTIONS
>    --->
>    <cffunction name="buildIgnoreEvents" access="private"
> returntype="any" output="false"
>        hint="Builds a HashSet of ignore events.">
>        <cfargument name="rawIgnoreEvents" type="array" required="true" />
>
>        <cfset var ignoreEvents = CreateObject("java",
> "java.util.HashSet").init() />
>        <cfset var pattern = "" />
>        <cfset var eventHandlers =
> getAppManager().getEventManager().getEventNames() />
>        <cfset var i = 0 />
>        <cfset var j = 0 />
>
>        <cfloop from="1" to="#ArrayLen(arguments.rawIgnoreEvents)#"
> index="i">
>            <cfif variables.matcher.isPattern(arguments.rawIgnoreEvents[i])>
>                <cfloop from="1" to="#ArrayLen(eventHandlers)#" index="j">
>                    <cfif
> variables.matcher.match(arguments.rawIgnoreEvents[i], eventHandlers[j])>
>                        <cfset ignoreEvents.add(eventHandlers[j]) />
>                    </cfif>
>                </cfloop>
>            <cfelse>
>                <cfset ignoreEvents.add(bindValue(i,
> arguments.rawIgnoreEvents[i])) />
>            </cfif>
>        </cfloop>
>
>        <cfreturn ignoreEvents />
>    </cffunction>
>
>    <!---
>    ACCESSORS
>    --->
>    <cffunction name="setIgnoreEvents" access="private"
> returntype="void" output="false">
>        <cfargument name="ignoreEvents" type="any" required="true" />
>        <cfset variables.instance.ignoreEvents = arguments.ignoreEvents />
>    </cffunction>
>    <cffunction name="getIgnoreEvents" access="private" returntype="any"
> output="false">
>        <cfreturn variables.instance.ignoreEvents />
>    </cffunction>
>
>    <cffunction name="setNotLoggedInEvent" access="private"
> returntype="void" output="false">
>        <cfargument name="notLoggedInEvent" type="string" required="true" />
>        <cfset variables.instance.notLoggedInEvent =
> arguments.notLoggedInEvent />
>    </cffunction>
>    <cffunction name="getNotLoggedInEvent" access="private"
> returntype="string" output="false">
>        <cfreturn variables.instance.notLoggedInEvent />
>    </cffunction>
>
> </cfcomponent>
>
> --
> You received this message because you are subscribed to Mach-II for CFML
> list.
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
>
> SVN: http://svn.mach-ii.com/machii/
> Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/
>

-- 
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to