{"id":104,"date":"2008-03-15T08:34:20","date_gmt":"2008-03-15T08:34:20","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=104"},"modified":"2009-06-14T15:57:42","modified_gmt":"2009-06-14T15:57:42","slug":"getting-started-with-object-creation-and-deletion","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/getting-started-with-object-creation-and-deletion","title":{"rendered":"Getting Started with Provisioning"},"content":{"rendered":"<p>I&#8217;m now at the point, in this series of posts for ILM-newbies, where I can start to look at provisioning code.<\/p>\n<p><!--more--><\/p>\n<p>I introduced the Metaverse Extension in <a href=\"https:\/\/www.wapshere.com\/missmiis\/?p=102\">this post<\/a>, but to recap briefly: as far as ILM is concerned there is only <em>one<\/em> metaverse extension dll, which is run, in its entirity, against all types of metaverse object. For a project with more than, let&#8217;s say, four MAs you will find it easier to keep track of your code if you go for the <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms696018(VS.85).aspx\">MVRouter<\/a> approach where you can split your project down into a seperate dll for each MA (remebering that this split is notional only &#8211; ILM still runs <em>all<\/em> the code against <em>all<\/em> objects).<\/p>\n<h4>The simplest provisioning code<\/h4>\n<p>If you haven&#8217;t already done so, create your extension project as covered in <a href=\"https:\/\/www.wapshere.com\/missmiis\/?p=102\">this post<\/a>.<\/p>\n<p>You can get started right away by adding some code to the <strong>Sub Provision<\/strong>. All you need, in this subroutine, is some code bracketed with the StartNewConnector and CommitNewConnector statements:<br \/>\n<code><br \/>\nDim csentry As CSEntry<br \/>\nDim MA As ConnectedMA<br \/>\nMA = mventry.ConnectedMAs(<em>MA_Name<\/em>)<br \/>\ncsentry = MA.Connectors.StartNewConnector(\"<em>objecttype<\/em>\")<br \/>\n<em>&lt;..set name and attribute values of the new object&gt;<\/em><br \/>\ncsentry.CommitNewConnector()<\/code><\/p>\n<p>This will create an object of type <em>objecttype<\/em> in the MA called <em>MA_Name<\/em>.<\/p>\n<h4>Setting the object name in a flat directory<\/h4>\n<p>If you&#8217;re provisioning to something like a database table, or a text file, or other system where the objects have a simple name, then all you need, to name the object, is to set the appropriate attribute:<\/p>\n<p><code>csentry = MA.Connectors.StartNewConnector(\"record\")<br \/>\ncsentry(\"id\").Value = mventry(\"StaffID\").Value<br \/>\n<em>&lt;..set other attribute values&gt;<\/em><br \/>\ncsentry.CommitNewConnector()<\/code><\/p>\n<h4>Setting the object name in a relative directory<\/h4>\n<p>Relative (ie LDAP style) directories are a little more complicated, because the object name is the Distinguished Name, constructed from it&#8217;s relationship with a parent container. We have a little more coding to do in that case:<\/p>\n<p><code>Dim dn as ReferenceValue<br \/>\nDim rdn as String<br \/>\n'..Construct the dn from the cn and the OU<br \/>\nrdn = \"CN=\" &amp; mventry(\"cn\").Value<br \/>\nMA = mventry.ConnectedMAs(<em>MA_Name<\/em>)<br \/>\ndn = MA.EscapeDNComponent(rdn).Concat(<em>OU_Name<\/em>)<br \/>\n'..Create the cs object<br \/>\ncsentry = MA.Connectors.StartNewConnector(\"user\")<br \/>\ncsentry.DN = dn<br \/>\n<em>&lt;..set other attribute values&gt;<\/em><br \/>\ncsentry.CommitNewConnector()<\/code><\/p>\n<p>Note that the <em>OU_Name<\/em> you use here must be the fully distinguished name, eg: &#8220;CN=Users,DC=fabrikam,DC=com&#8221;.<\/p>\n<h4>Setting attribute values<\/h4>\n<p>Attribute values can either be set on the new object in the MVExtension, or by using <a href=\"https:\/\/www.wapshere.com\/missmiis\/?p=101\">flow rules<\/a>. It doesn&#8217;t much matter which way you do it, as long as the attributes reach the connector space object before it&#8217;s exported.<\/p>\n<p>Often you will want to set a few key attributes while creating the object and, this being the case, you <em>must<\/em> do it between the StartNewConnector<strong> <\/strong>and CommitNewConnector statements.<\/p>\n<p>So, to put that another way, <em>once a CS object exists you cannot modify its attributes in the MVExtension<\/em>. The only way you can modify attributes, from that point on, is using flow rules.<\/p>\n<p>To set an attribute value just use<\/p>\n<p><code>csentry(\"<em>attributeName<\/em>\").Value = ...<\/code><\/p>\n<h4>Disabled AD Account<\/h4>\n<p>In Active Directory the account will be created disabled unless a password is set. The following snippet sets the unicodePwd to some constant value, and then specifes that the account should be enabled (though the userAccountControl setting will be overridden by AD if your password is not strong enough to satisfiy its security settings).<\/p>\n<p><code>Const ADS_UF_NORMAL_ACCOUNT As Integer = &amp;H200<br \/>\ncsentry(\"UnicodePwd\").Values.Add(INITIAL_PASSWORD)<br \/>\ncsentry(\"userAccountControl\").IntegerValue = ADS_UF_NORMAL_ACCOUNT<\/code><\/p>\n<p>For a list of the other userAccountControl settings see <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms696026(VS.85).aspx\" target=\"_blank\">Example: Enabling or Disabling a User Account in Active Directory<\/a> in the Developer&#8217;s Reference.<\/p>\n<h4>Code Examples<\/h4>\n<p>See <a href=\"https:\/\/www.wapshere.com\/missmiis\/kiss-your-miis-installation\">this post<\/a> for a simple, flexible outline for a Provisioning sub.<\/p>\n<p>And also check out the Developer&#8217;s Reference for these examples:<\/p>\n<p>Simple AD provisioning code: <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms696059(VS.85).aspx\" target=\"_blank\">Example: Setting an Initial Password in Active Directory<\/a><\/p>\n<p>Simple LDAP provisioning code: <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms696060(VS.85).aspx\" target=\"_blank\">Example: Setting an Initial Password in Sun and Netscape Directory Servers<\/a><\/p>\n<h4>That should be enough to get you started&#8230;<\/h4>\n<p>Posts on xml lookup files and <a href=\"https:\/\/www.wapshere.com\/missmiis\/?p=103\">debugging<\/a> will be coming as I have time to write them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m now at the point, in this series of posts for ILM-newbies, where I can start to look at provisioning code.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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":[34,28,19,30],"tags":[],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-ilm2007","category-miis2003","category-newbie","category-vbnet"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-1G","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/104","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=104"}],"version-history":[{"count":3,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/104\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}