ColdBox SSL Interceptor
Made a SSL interceptor today, here's the code:
STEP 1
Include the following in ColdBox.xml.cfm (between the interceptors tags of course):
<Interceptor class="{YOUR APP NAME HERE}.interceptors.ssl">
<Property name="isSSLCheck">true</Property>
</Interceptor>
STEP 2
Create a file ssl.cfc in place it in the interceptor directory.
Open ssl.cfc and copy/paste the following code:
<cfcomponent name="ssl" output="false" extends="coldbox.system.interceptor">
<cffunction name="preEvent" access="public" returntype="void" output="false" >
<cfargument name="event" required="true" type="coldbox.system.beans.requestContext">
<!--- SSL check? --->
<cfif getProperty('isSSLCheck')>
<cfset sslCheck()>
</cfif>
</cffunction>
<cffunction name="sslCheck" access="public" returntype="void" output="false" >
<!--- SSL check? --->
<cfif not isSSL()>
<!--- redirect with SSL (any post data is lost) --->
<cflocation url="https://#cgi.server_name##cgi.script_name#?#cgi.query_string#" addtoken="no">
</cfif>
</cffunction>
<cffunction name="isSSL" access="public" returntype="boolean">
<cfset var isSSL = false>
<!--- SSL Connection? --->
<cfif isBoolean(cgi.server_port_secure) and cgi.server_port_secure>
<cfset isSSL = true>
</cfif>
<cfreturn isSSL>
</cffunction>
</cfcomponent>
That's it!
The interceptor checks if there is a ssl connection, if not, the current event is redirected with ssl.


There are no comments for this entry.
[Add Comment]