<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cranky Bit &#187; Transfer</title>
	<atom:link href="http://blog.crankybit.com/tag/transfer/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crankybit.com</link>
	<description>Take a byte out of tech!</description>
	<lastBuildDate>Wed, 09 Mar 2011 17:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Generating a Decrypted Memento for a Transfer Decorator</title>
		<link>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/</link>
		<comments>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 12:57:27 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=319</guid>
		<description><![CDATA[In my last blog post, I discussed how to efficiently handle multiple encrypted fields while using Transfer. The key was using onMissingMethod in the Transfer decorator. However, what about when we use the memento with Transfer's getMemento() method? This approach can be especially handy to quickly transfer an object's properties when using web services to [...]]]></description>
			<content:encoded><![CDATA[<p>In my last blog post, I discussed how to efficiently handle multiple encrypted fields while using Transfer. The key was using onMissingMethod in the Transfer decorator. However, what about when we use the memento with Transfer's getMemento() method? This approach can be especially handy to quickly transfer an object's properties when using web services to Flex or AJAX front ends.</p>
<p>For reference, here was the object definition we were using in our sample Transfer configuration.</p>
<div class="igBar"><span id="lxml-3"><a href="#" onclick="javascript:showCodeTxt('xml-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-3">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;object</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Reg"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"Regs"</span> <span style="color: #000066;">decorator</span>=<span style="color: #ff0000;">"MyProj.com.Reg"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ID"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegID"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"numeric"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"FName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegFName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LastMod"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLastMod"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegExpires"</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">"true"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncHome"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regHome"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncWork"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regWork"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncMobile"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regMobile"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncSMS"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regSMS"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/object<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The process is very simple. Recall that we prefixed our Transfer properties with "Enc" to know which fields are encrypted. Let's create a getDecryptedMemento() method. It will loop through all of the keys in the memento, which is just a struct, and decrypt any of the encrypted fields, saving them as new keys in the struct (i.e. "EncHome" is decrypted as "Home" in the struct). </p>
<p>Something like this will do the trick:</p>
<div class="igBar"><span id="lcfm-4"><a href="#" onclick="javascript:showCodeTxt('cfm-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-4">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"getDecryptedMemento"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> returntype=<span style="color: #009900;">"struct"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> memento=getMemento<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> key=<span style="color: #009900;">""</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> newkey=<span style="color: #009900;">""</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfloop</span> <span style="color: #0000FF">index</span>=<span style="color: #009900;">"key"</span> <span style="color: #0000FF">list</span>=<span style="color: #009900;">"#StructKeyList(memento)#"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfif</span> <span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span>key,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span> is <span style="color: #009900;">"Enc"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> newkey=<span style="color: #0000FF;">RemoveChars</span><span style="color: #0000FF;">&#40;</span>key,<span style="color: #FF0000;color:#800000;">1</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> memento<span style="color: #0000FF;">&#91;</span>newkey<span style="color: #0000FF;">&#93;</span>=decryptValue<span style="color: #0000FF;">&#40;</span>memento<span style="color: #0000FF;">&#91;</span>key<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cfif&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cfloop&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> memento&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Not much to it. Note that we would use the same decryption function as we are using in onMissingMethod for the dynamic accessors. I'm calling it decryptValue() for this sample.</p>
<p>In the end, our getDecryptedMemento() method returns a memento that looks just like the Transfer-generated getMemento() output, with decrypted versions of the encrypted fields!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Multiple Encrypted Fields in a Transfer Decorator</title>
		<link>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/</link>
		<comments>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 12:55:55 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=318</guid>
		<description><![CDATA[I had a recent project that had multiple fields in a particular table that needed to be encrypted for privacy and security considerations. I was using Transfer for the project. The typical way to handle the encryption is to create custom accessor methods in a decorator component. The Transfer wiki has a decent explanation of [...]]]></description>
			<content:encoded><![CDATA[<p>I had a recent project that had multiple fields in a particular table that needed to be encrypted for privacy and security considerations. I was using <a href="http://docs.transfer-orm.com/" target="_blank">Transfer</a> for the project. The typical way to handle the encryption is to create custom accessor methods in a <a href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank">decorator</a> component. The Transfer wiki has a decent explanation of this concept on a page entitled <a href="http://docs.transfer-orm.com/wiki/How_to_Encrypt_User_Passwords_Using_a_Decorator.cfm" target="_blank">How to Encrypt User Passwords Using a Decorator</a>. However, it is intentionally simple, demonstrating a single property. Multiply your getter/setter methods by how many properties you will be working with, and the lines of code can add up. This framework stuff is supposed to prevent that kind of repetition! Well, utilizing onMissingMethod() and the core concept on the Transfer decorator example, we can handle this scenario efficiently.</p>
<p>First, let's consider the object definition in our sample Transfer configuration file.</p>
<div class="igBar"><span id="lxml-7"><a href="#" onclick="javascript:showCodeTxt('xml-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-7">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;object</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Reg"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"Regs"</span> <span style="color: #000066;">decorator</span>=<span style="color: #ff0000;">"MyProj.com.Reg"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ID"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegID"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"numeric"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"FName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegFName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LastMod"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLastMod"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegExpires"</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">"true"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncHome"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regHome"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncWork"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regWork"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncMobile"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regMobile"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncSMS"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regSMS"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/object<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Note that I have prefixed the Transfer properties with "Enc". This isn't required, but will simplify our processing later on. So in this sample, we have 4 properties: Home, Work, Mobile, and SMS. The concept is that these are client phone numbers that we want to protect with encryption. So, Transfer will generate getEncHome(), getEncWork(), getEncMobile(), getEncSMS(), and corresponding setters. However, we want to provide getHome(), getWork(), getMobile(), getSMS(), and corresponding setters, that get and set the properties <em>after</em> encryption/decryption.</p>
<p><strong>Use onMissingMethod()</strong></p>
<p>To accomplish this, we might have an onMissingMethod() function in the decorator like this:</p>
<div class="igBar"><span id="lcfm-8"><a href="#" onclick="javascript:showCodeTxt('cfm-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-8">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"onMissingMethod"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> returntype=<span style="color: #009900;">"any"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"missingMethodName"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"string"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"missingMethodArguments"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"struct"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> func=<span style="color: #009900;">""</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> encList=<span style="color: #009900;">"Home,Mobile,SMS,Work"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">method</span>=Arguments.missingMethodName;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> args=Arguments.missingMethodArguments;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> firstArg=args<span style="color: #0000FF;">&#91;</span><span style="color: #0000FF;">ListFirst</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">StructKeyList</span><span style="color: #0000FF;">&#40;</span>args<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> prop=<span style="color: #0000FF;">RemoveChars</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">1</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Handle encryption/decryption of encrypted values:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">ListFindNoCase</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"get,set"</span>,<span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> and </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ListFindNoCase</span><span style="color: #0000FF;">&#40;</span>encList,prop<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; func=variables<span style="color: #0000FF;">&#91;</span><span style="color: #0000FF;">Insert</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"Enc"</span>,<span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span> is <span style="color: #009900;">"get"</span><span style="color: #0000FF;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; return decryptValue<span style="color: #0000FF;">&#40;</span>func<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; func<span style="color: #0000FF;">&#40;</span>encryptValue<span style="color: #0000FF;">&#40;</span>firstArg<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As a good security measure, we use an "encList" string to check that only proper methods can be called. Then we examine the method name. If it starts with "get" or "set" and ends with one of the list items, we proceed. Thus, we'll process a method like getHome(), but not a method like getFoo(). We then call getEncHome() and decrypt it for getters, encrypt and call setEncHome() for setters. </p>
<p><strong>Dynamic Method Calling</strong></p>
<p>But alas, how do we do this dynamically without a long if-then-else chain? We call the proper method by referencing it from the component's variables scope. Terrence Ryan describes this in his blog post <a href="http://www.terrenceryan.com/blog/post.cfm/cheap-and-easy-dynamic-method-calling-in-cfscript" target="_blank">Cheap and Easy Dynamic Method Calling in CFScript</a>. We construct the method name, in our case, by inserting "Enc" after the "get" or "set" prefix of the method name passed into onMissingMethod (thus "getHome" becomes the Transfer method "getEncHome"). Assign the function to the local "func" variable, then call it as if "func" was the function. Finally, handle any encryption or decryption that you will be doing. For this sample, I have encryptValue() and decryptValue() methods handling the details of that work.</p>
<p><strong>Summary</strong></p>
<p>We've used two solutions to handle multiple encrypted fields in the decorator. First, we used onMissingMethod() to handle processing of all of the properties in a single method. Then, we used dynamic method calling to call the Transfer-generated accessors within onMissingMethod().</p>
<p>The end result is being able to use setHome(), getHome(), etc. with the encryption and decryption being handled automatically. Great!</p>
<p>In addition to accessors, we may sometimes want to use the object's memento with the Transfer method getMemento(). In my next blog post, I'll demonstrate how that process can also be done very efficiently.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memento Pattern is Great for Web Services</title>
		<link>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/</link>
		<comments>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/#comments</comments>
		<pubDate>Fri, 02 May 2008 21:34:28 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=298</guid>
		<description><![CDATA[Nothing Earth-shattering here. I've just come to appreciate how useful the memento design pattern can be to do web services a bit more efficiently sometimes. My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' getMemento() or getPropertyMemento() methods. I had [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing Earth-shattering here. I've just come to appreciate how useful the <a href="http://en.wikipedia.org/wiki/Memento_pattern" target="_blank">memento design pattern</a> can be to do web services a bit more efficiently sometimes.</p>
<p>My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' <strong>getMemento()</strong> or <strong>getPropertyMemento()</strong> methods.</p>
<p>I had a method in the web service that would accept several arguments and perform the simple task of processing them and saving them to the database. It returned a single boolean indicating success or failure.</p>
<p>The web service is just used by another web server that doesn't have access to the database and can't run Transfer (because it is currently running CFMX 6). This web server hosts a page with a form; when the user submits the form, the action page invokes the web service to process and save the information.</p>
<p>I needed the action page to display some data that wasn't available in the form data that was transmitted. For instance, a pull-down menu allowed the user to select from a list of sessions, but all that is transmitted is the database ID of the session they chose. My action page can't display any details about that session unless it makes another web service call to retrieve the details of that session. <em>And </em>I have to write the code for that web service method, which up to this point was unnecessary.</p>
<p>Aha! I changed the web service to return a <strong>struct</strong> that still contained the success/failure boolean, but also contained mementos of the objects that were created or referenced when processing the request. Now my web server invoking the web service has all the details of the session at its disposal for display on the action page.</p>
<p>What's the big deal, right? Who cares about one more web service call? Well, I'd like to keep the chatter between the two machines down to a minimally required amount, and besides, thanks to <strong>getMemento()</strong>, adding all of that data to the web service's response took one line of code, and way less time than it would take to write that extra web service method to retrieve session data, and also way less time than it took to even write this blog post. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here's the general thought process of the code in the web service (abbreviated to just show the point of mementos):</p>
<p>
<div class="igBar"><span id="lcfm-10"><a href="#" onclick="javascript:showCodeTxt('cfm-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-10">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"add"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"remote"</span> returntype=<span style="color: #009900;">"struct"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> ret=<span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> mySession=SessionService.getSession<span style="color: #0000FF;">&#40;</span>Arguments.SID<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic; background-color:#FFFF99;">/* Do Processing */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Success=true;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Session=mySession.getMemento<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;cfreturn</span> ret&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

