{"id":1422,"date":"2011-05-04T06:29:40","date_gmt":"2011-05-04T06:29:40","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=1422"},"modified":"2011-05-04T06:29:40","modified_gmt":"2011-05-04T06:29:40","slug":"why-running-some-actions-in-the-authz-phase-is-a-good-idea","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/why-running-some-actions-in-the-authz-phase-is-a-good-idea","title":{"rendered":"Why running some actions in the AuthZ phase is a good idea"},"content":{"rendered":"<p>I wanted to follow up the <a href=\"https:\/\/www.wapshere.com\/missmiis\/bpos-powershell-activity?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+missmiis+%28missmiis%29\">BPOS Powershell Activity<\/a> with an explanation of why I&#8217;m running some of the powershell actions in the Authorization phase.<br \/>\n<!--more--><\/p>\n<h3>The roll back problem<\/h3>\n<p>I was thinking about the best way to roll back a change in the Portal if the powershell failed. Say I add a forwarding address in the Portal, triggering the BPOS Powershell Activity to run the relevant cmdlet, but the cmdlet returned a failure status. I now have incorrect data in the Portal:\u00c2\u00a0a forwarding address appears to be set but in reality this is not the case.<\/p>\n<p>If you&#8217;re running the powershell in the Action phase the data has already been committed to the database so\u00c2\u00a0for a failure you will actually have to roll back the change. Unfortunately this is not so simple. By this time you don&#8217;t know the previous state of the changed attribute (or attributes), and you can&#8217;t get that information from the Request object. The only sure way would have been to run a custom activity in the AuthZ phase which writes the previous values to custom attributes on the Request object and &#8230; no I can&#8217;t go on, my brain\u00c2\u00a0is saying\u00c2\u00a0&#8220;YUCK&#8221; too loudly to continue.<\/p>\n<p>About the only thing you can do is clear the attribute if the change failed. This will in fact work fine for the forwarding address, where there either is an address or there isn&#8217;t, but won&#8217;t be applicable to all cases.<\/p>\n<h3>So run the powershell before committing the change<\/h3>\n<p>And now to the AuthZ phase. Here the change is not yet committed and so, if the powershell fails, we can throw an error and prevent the change. In fact you can look at it like this: our powershell activity is actually authorizing the change to the database, based on whether it succeeds or fails.<\/p>\n<p>But (and there&#8217;s always a But) it&#8217;s much trickier to get at the changed attribute(s) in the AuthZ phase. Beacuse they&#8217;re not yet written to the Target you have to get them from the Request object and that&#8217;s not nearly so straight-forward. It&#8217;s even trickier when there are reference attributes involved (as in the forwarding address example). In any case, more custom activity writing will be necessary.<\/p>\n<h3>The compromise<\/h3>\n<p>Here&#8217;s my compromise: For BPOS powershell activities, I run activities which add stuff in the Action phase, and activities which remove stuff in the AuthZ phase.<\/p>\n<p>The big advantage from a pure workflow pov is that I only ever need to use attributes already written to the Target. When doing a remove I&#8217;m interested in the &#8220;before&#8221; values, and for an add it&#8217;s the &#8220;after&#8221; values.<\/p>\n<p>Going back to the forwarding address, if I change the forwarding object then I actually have to run a Remove on the old value, followed by an Add on the new value.<\/p>\n<p>Which brings me to another advantage: by running the Remove in the AuthZ phase and the Add in the Action phase I can <em>ensure they run in that order<\/em>. Important!<\/p>\n<p>And also, from a general functionality perspectve, I think it bad to let people think something is deleted when it is not.<\/p>\n<h3>Another example<\/h3>\n<p>I am also managing BPOS mailbox delegations in the FIM Portal so let&#8217;s work through some scenarios.<\/p>\n<p>A delegation is added which gives Full Access to a mailbox. The powershell fails for some reason. Using\u00c2\u00a0the &#8220;Clear Attribute on Failure&#8221; option in my <a href=\"https:\/\/www.wapshere.com\/missmiis\/bpos-powershell-activity?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+missmiis+%28missmiis%29\">BPOS Powershell Activity<\/a> I still create the <a href=\"https:\/\/www.wapshere.com\/missmiis\/why-create-a-delegation-resource-type-in-the-fim-portal\">delegation object<\/a>, but I empty all its settings, and I send a Failure Notification email.<\/p>\n<p>Now imagine an existing delegation is changed. In the AuthZ phase I remove all the previous permissions, and then in the Action phase I add all the current permissions. This makes the workflow nice and simple &#8211; I actually don&#8217;t care which attributes were changed because I remove-all and then add-all based on the pre- and post-change state of the Target.<\/p>\n<p>Finally a delegation is deleted. And again the powershell fails for some reason* but this time, as we were running the Remove in the AuthZ phase, the change is not committed and it&#8217;s still clear that the delagation exists.<\/p>\n<p>*Note: I&#8217;ve never seen the powershell cmdlets randomly fail, there&#8217;s always a good reason &#8211; but best to be prepared right?<\/p>\n<h3>Access Denied<\/h3>\n<p>The one big problem with this approach is that any failure in the AuthZ phase will result in an &#8220;Access Denied&#8221; error. I do write a detailed message to the Request object, so the real reason if there if the user knows how to find it, but still, it would be nice to be able to tailor this message.<\/p>\n<h3>In Conclusion<\/h3>\n<p>Make sure you think through\u00c2\u00a0the failure\u00c2\u00a0scenarios when designing your FIM Portal activities. In some cases the AuthZ phase is ideal for actions as no roll back is required should the action fail &#8211; but in other cases\u00c2\u00a0the uncomitted data in this phase increases the complexity of the Workflow. It is important as ever to weigh up functionality against simplicity, try to be consistent, and remember that someone other than you may have to support this system one day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to follow up the BPOS Powershell Activity with an explanation of why I&#8217;m running some of the powershell actions in the Authorization phase.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[47,42,45],"tags":[],"class_list":["post-1422","post","type-post","status-publish","format-standard","hentry","category-bpos","category-fim-2010","category-workflow"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-mW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=1422"}],"version-history":[{"count":7,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1422\/revisions"}],"predecessor-version":[{"id":1444,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1422\/revisions\/1444"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=1422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=1422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=1422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}