Produced by Araxis Merge on 2/1/2017 2:57:06 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\VB\HelperCode | SystemUserProvider.vb | Tue Dec 20 19:51:47 2016 UTC |
| 2 | Wed Feb 1 19:57:06 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 403 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | ' ======== ========== ========== ========== ========== ========== ========== = | |||||
| 2 | ' This fi le is part of the Mi crosoft Dy namics CRM SDK code samples. | |||||
| 3 | ' | |||||
| 4 | ' Copyrig ht (C) Mic rosoft Cor poration. All right s reserved . | |||||
| 5 | ' | |||||
| 6 | ' This so urce code is intende d only as a suppleme nt to Micr osoft | |||||
| 7 | ' Develop ment Tools and/or on -line docu mentation. See thes e other | |||||
| 8 | ' materia ls for det ailed info rmation re garding Mi crosoft co de samples . | |||||
| 9 | ' | |||||
| 10 | ' THIS CO DE AND INF ORMATION A RE PROVIDE D "AS IS" WITHOUT WA RRANTY OF ANY | |||||
| 11 | ' KIND, E ITHER EXPR ESSED OR I MPLIED, IN CLUDING BU T NOT LIMI TED TO THE | |||||
| 12 | ' IMPLIED WARRANTIE S OF MERCH ANTABILITY AND/OR FI TNESS FOR A | |||||
| 13 | ' PARTICU LAR PURPOS E. | |||||
| 14 | ' ======== ========== ========== ========== ========== ========== ========== = | |||||
| 15 | ||||||
| 16 | '<snippetS ystemUserP rovider> | |||||
| 17 | Imports Mi crosoft.Vi sualBasic | |||||
| 18 | Imports Sy stem | |||||
| 19 | Imports Sy stem.Colle ctions.Gen eric | |||||
| 20 | Imports Sy stem.Direc toryServic es | |||||
| 21 | Imports Sy stem.Threa ding | |||||
| 22 | ||||||
| 23 | ' These na mespaces a re found i n the Micr osoft.Xrm. Sdk.dll as sembly | |||||
| 24 | ' located in the SDK \bin folde r of the S DK downloa d. | |||||
| 25 | Imports Mi crosoft.Xr m.Sdk | |||||
| 26 | Imports Mi crosoft.Xr m.Sdk.Quer y | |||||
| 27 | Imports Mi crosoft.Xr m.Sdk.Clie nt | |||||
| 28 | Imports Mi crosoft.Xr m.Sdk.Mess ages | |||||
| 29 | ||||||
| 30 | ' This nam espace is found in t he Microso ft.Crm.Sdk .Proxy.dll assembly | |||||
| 31 | ' located in the SDK \bin folde r of the S DK downloa d. | |||||
| 32 | Imports Mi crosoft.Cr m.Sdk.Mess ages | |||||
| 33 | ||||||
| 34 | Namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | ''' <s ummary> | |||||
| 36 | ''' Th is class c ontains me thods whic h retrieve the IDs o f several fictitious Microsoft Dynamics | |||||
| 37 | ''' CR M system u sers. Sev eral SDK s amples req uire these additiona l user acc ounts in o rder to ru n. | |||||
| 38 | ''' </ summary> | |||||
| 39 | ''' <r emarks>For On-premis es and IFD deploymen ts, if the se users d o not exis t they are created i n | |||||
| 40 | ''' Ac tive Direc tory. This assumes t hat the sy stem user account un der which the applic ation runs has | |||||
| 41 | ''' sy stem admin istrator p rivileges. Since it is not pos sible to p rogrammati cally crea te user ac counts | |||||
| 42 | ''' in Microsoft account, when runni ng this co de against a Microso ft Dynamic s CRM Onli ne server, you will have | |||||
| 43 | ''' to manually add these users.</re marks> | |||||
| 44 | Public Class Sys temUserPro vider | |||||
| 45 | Publ ic Shared Function R etrieveSal esManager( ByVal prox y As Organ izationSer viceProxy) As Guid | |||||
| 46 | Dim ld apPath As String = S tring.Empt y | |||||
| 47 | Return RetrieveS ystemUser( "kcook", " Kevin", "C ook", "Sal es Manager ", proxy, ldapPath) | |||||
| 48 | End Function | |||||
| 49 | Publ ic Shared Function R etrieveSal esManager( ByVal prox y As Organ izationSer viceProxy, ByRef lda pPath As S tring) As Guid | |||||
| 50 | Return RetrieveS ystemUser( "kcook", " Kevin", "C ook", "Sal es Manager ", proxy, ldapPath) | |||||
| 51 | End Function | |||||
| 52 | ||||||
| 53 | Publ ic Shared Function R etrieveSal espersons( ByVal prox y As Organ izationSer viceProxy, ByRef lda pPath As S tring) As List(Of Gu id) | |||||
| 54 | Dim re ps As New List(Of Gu id)() | |||||
| 55 | ||||||
| 56 | reps.A dd(Retriev eSystemUse r("nanders on", "Nanc y", "Ander son", "Sal esperson", proxy, ld apPath)) | |||||
| 57 | reps.A dd(Retriev eSystemUse r("dbristo l", "David ", "Bristo l", "Sales person", p roxy, ldap Path)) | |||||
| 58 | ||||||
| 59 | Return reps | |||||
| 60 | End Function | |||||
| 61 | ||||||
| 62 | Publ ic Shared Function R etrieveDel egates(ByV al proxy A s Organiza tionServic eProxy, By Ref ldapPa th As Stri ng) As Lis t(Of Guid) | |||||
| 63 | Dim de legates As New List( Of Guid)() | |||||
| 64 | ||||||
| 65 | delega tes.Add(Re trieveSyst emUser("dw ilson", "D an", "Wils on", "Dele gate", pro xy, ldapPa th)) | |||||
| 66 | delega tes.Add(Re trieveSyst emUser("ca nderson", "Christen" , "Anderso n", "Deleg ate", prox y, ldapPat h)) | |||||
| 67 | Return delegates | |||||
| 68 | End Function | |||||
| 69 | ||||||
| 70 | Publ ic Shared Function R etrieveVPS ales(ByVal proxy As Organizati onServiceP roxy, ByRe f ldapPath As String ) As Guid | |||||
| 71 | Return RetrieveS ystemUser( "mtucker", "Michael" , "Tucker" , "Vice Pr esident of Sales", p roxy, ldap Path) | |||||
| 72 | End Function | |||||
| 73 | ||||||
| 74 | Publ ic Shared Function R etrieveMar ketingMana ger(ByVal proxy As O rganizatio nServicePr oxy) As Gu id | |||||
| 75 | Dim ld apPath As String = S tring.Empt y | |||||
| 76 | Return RetrieveM arketingMa nager(prox y, ldapPat h) | |||||
| 77 | End Function | |||||
| 78 | ||||||
| 79 | Publ ic Shared Function R etrieveMar ketingMana ger(ByVal proxy As O rganizatio nServicePr oxy, ByRef ldapPath As String) As Guid | |||||
| 80 | Return RetrieveS ystemUser( "ssmith", "Samantha" , "Smith", "Marketin g Manager" , proxy, l dapPath) | |||||
| 81 | End Function | |||||
| 82 | ||||||
| 83 | Publ ic Shared Function R etrieveAUs erWithoutA nyRoleAssi gned(ByVal proxy As Organizati onServiceP roxy) As G uid | |||||
| 84 | Dim ld apPath As String = S tring.Empt y | |||||
| 85 | Return RetrieveS ystemUser( "dpark", " Dan", "Par k", "", pr oxy, ldapP ath) | |||||
| 86 | End Function | |||||
| 87 | ||||||
| 88 | '' ' <summary > | |||||
| 89 | '' ' Retrieve s the requ ested Syst emUser rec ord. If t he record does not e xist, a ne w | |||||
| 90 | '' ' Microsof t Dynamics CRM Syste mUser reco rd is crea ted and an associate d Active | |||||
| 91 | '' ' Director y account is created , if it do esn't curr ently exis t. | |||||
| 92 | '' ' </summar y> | |||||
| 93 | '' ' <param n ame="userN ame">The u sername fi eld as set in Micros oft Dynami cs CRM</pa ram> | |||||
| 94 | '' ' <param n ame="first Name">The first name of the sy stem user to be retr ieved</par am> | |||||
| 95 | '' ' <param n ame="lastN ame">The l ast name o f the syst em user to be retrie ved</param > | |||||
| 96 | '' ' <param n ame="roleS tr">The st ring repre senting th e Microsof t Dynamics CRM secur ity | |||||
| 97 | '' ' role for the user< /param> | |||||
| 98 | '' ' <param n ame="servi ceProxy">T he Organiz ationServi ceProxy ob ject to yo ur Microso ft | |||||
| 99 | '' ' Dynamics CRM envir onment</pa ram> | |||||
| 100 | '' ' <param n ame="ldapP ath">The L DAP path f or your ne twork - yo u can eith er call | |||||
| 101 | '' ' ConsoleP romptForLD APPath() t o prompt t he user or provide a value in code</para m> | |||||
| 102 | '' ' <returns ></returns > | |||||
| 103 | Pu blic Share d Function RetrieveS ystemUser( ByVal user Name As St ring, ByVa l firstNam e As Strin g, ByVal l astName As String, _ | |||||
| 104 | ByVal role Str As Str ing, ByVal servicePr oxy As Org anizationS erviceProx y, _ | |||||
| 105 | ByRef ldap Path As St ring) As G uid | |||||
| 106 | Dim doma in As Stri ng | |||||
| 107 | Dim user Id As Guid = Guid.Em pty | |||||
| 108 | ||||||
| 109 | If servi ceProxy Is Nothing T hen | |||||
| 110 | Thro w New Argu mentNullEx ception("s erviceProx y") | |||||
| 111 | End If | |||||
| 112 | ||||||
| 113 | If Strin g.IsNullOr WhiteSpace (userName) Then | |||||
| 114 | Thro w New Argu mentNullEx ception("U serName") | |||||
| 115 | End If | |||||
| 116 | ||||||
| 117 | If Strin g.IsNullOr WhiteSpace (firstName ) Then | |||||
| 118 | Thro w New Argu mentNullEx ception("F irstName") | |||||
| 119 | End If | |||||
| 120 | ||||||
| 121 | If Strin g.IsNullOr WhiteSpace (lastName) Then | |||||
| 122 | Thro w New Argu mentNullEx ception("L astName") | |||||
| 123 | End If | |||||
| 124 | ||||||
| 125 | ' Obtain the curre nt user's informatio n. | |||||
| 126 | Dim who As New Who AmIRequest () | |||||
| 127 | Dim whoR esp As Who AmIRespons e = CType( servicePro xy.Execute (who), Who AmIRespons e) | |||||
| 128 | Dim curr entUserId As Guid = whoResp.Us erId | |||||
| 129 | ||||||
| 130 | Dim curr entUser As SystemUse r = servic eProxy.Ret rieve(Syst emUser.Ent ityLogical Name, curr entUserId, _ | |||||
| 131 | New Colu mnSet("dom ainname")) .ToEntity( Of SystemU ser)() | |||||
| 132 | ||||||
| 133 | ' Extrac t the doma in and cre ate the LD AP object. | |||||
| 134 | Dim user Path() As String = c urrentUser .DomainNam e.Split(Ne w Char() { "\"c}) | |||||
| 135 | If userP ath.Length > 1 Then | |||||
| 136 | doma in = userP ath(0) & " \" | |||||
| 137 | Else | |||||
| 138 | doma in = Strin g.Empty | |||||
| 139 | End If | |||||
| 140 | ||||||
| 141 | ||||||
| 142 | Dim ex istingUser As System User = Get UserIdIfEx ist(servic eProxy, do main, user Name, firs tName, las tName) | |||||
| 143 | ||||||
| 144 | ||||||
| 145 | If exist ingUser Is Not Nothin g Then | |||||
| 146 | user Id = exist ingUser.Sy stemUserId .Value | |||||
| 147 | ||||||
| 148 | If Not S tring.IsNu llOrWhiteS pace(roleS tr) Then | |||||
| 149 | ' Ch eck to mak e sure the user is a ssigned th e correct role. | |||||
| 150 | Dim role_Renam ed As Role = Retriev eRoleByNam e(serviceP roxy, role Str) | |||||
| 151 | ||||||
| 152 | ' As sociate th e user wit h the role when need ed. | |||||
| 153 | If N ot UserInR ole(servic eProxy, us erId, role _Renamed.I d) Then | |||||
| 154 | Dim associ ate As New Associate Request() With { _ | |||||
| 155 | .Targe t = New En tityRefere nce(System User.Entit yLogicalNa me, userId ), _ | |||||
| 156 | .Relat edEntities = New Ent ityReferen ceCollecti on() From {New Entit yReference (Role.Enti tyLogicalN ame, role_ Renamed.Id )}, _ | |||||
| 157 | .Relat ionship = New Relati onship("sy stemuserro les_associ ation")} | |||||
| 158 | servicePro xy.Execute (associate ) | |||||
| 159 | End If | |||||
| 160 | End If | |||||
| 161 | Else | |||||
| 162 | ' Create the syste m user in Microsoft Dynamics C RM if the user doesn 't | |||||
| 163 | ' alread y exist. | |||||
| 164 | user Id = Creat eSystemUse r(userName , firstNam e, lastNam e, domain, roleStr, servicePro xy, ldapPa th) | |||||
| 165 | End If | |||||
| 166 | ||||||
| 167 | Return u serId | |||||
| 168 | En d Function | |||||
| 169 | ||||||
| 170 | ''' <summary> | |||||
| 171 | ''' Helper met hod to che ck if syst em user al ready exis t with eit her given username o r first an d last nam e. | |||||
| 172 | ''' </summary> | |||||
| 173 | ''' <param nam e="service Proxy">The Organizat ionService Proxy obje ct to your Microsoft | |||||
| 174 | ''' Dynamics C RM environ ment</para m> | |||||
| 175 | ''' <param nam e="domainN ame">Curre nt domain name of th e account. </param> | |||||
| 176 | ''' <param nam e="userNam e">The use rname fiel d as set i n Microsof t Dynamics CRM</para m> | |||||
| 177 | ''' <param nam e="firstNa me">The fi rst name o f the syst em user to be retrie ved</param > | |||||
| 178 | ''' <param nam e="lastNam e">The las t name of the system user to b e retrieve d</param> | |||||
| 179 | ''' <returns>< /returns> | |||||
| 180 | Pu blic Share d Function GetUserId IfExist(By Val servic eProxy As Organizati onServiceP roxy, | |||||
| 181 | By Val domain Name As St ring, | |||||
| 182 | By Val userNa me As Stri ng, | |||||
| 183 | By Val firstN ame As Str ing, | |||||
| 184 | By Val lastNa me As Stri ng) As Sys temUser | |||||
| 185 | Dim user Query As Q ueryExpres sion = New QueryExpr ession Wit h | |||||
| 186 | { | |||||
| 187 | .EntityNa me = Syste mUser.Enti tyLogicalN ame, | |||||
| 188 | .ColumnSe t = New Co lumnSet("s ystemuseri d") | |||||
| 189 | } | |||||
| 190 | userQuer y.Criteria .Filters.A dd(New Fil terExpress ion(Logica lOperator. And)) | |||||
| 191 | userQuer y.Criteria .Filters(0 ).AddCondi tion(New C onditionEx pression(" domainname ", Conditi onOperator .Equal, do mainName & userName) ) | |||||
| 192 | userQuer y.Criteria .Filters.A dd(New Fil terExpress ion(Logica lOperator. And)) | |||||
| 193 | userQuer y.Criteria .Filters(1 ).AddCondi tion(New C onditionEx pression(" firstname" , Conditio nOperator. Equal, fir stName)) | |||||
| 194 | userQuer y.Criteria .Filters(1 ).AddCondi tion(New C onditionEx pression(" lastname", Condition Operator.E qual, last Name)) | |||||
| 195 | userQuer y.Criteria .FilterOpe rator = Lo gicalOpera tor.Or | |||||
| 196 | ||||||
| 197 | Dim exis tingUsers As DataCol lection(Of Entity) = CType(ser viceProxy. RetrieveMu ltiple(use rQuery).En tities, Da taCollecti on(Of Enti ty)) | |||||
| 198 | ||||||
| 199 | ||||||
| 200 | ||||||
| 201 | If exist ingUsers.C ount > 0 T hen | |||||
| 202 | Retu rn existin gUsers(0). ToEntity(O f SystemUs er)() | |||||
| 203 | End If | |||||
| 204 | Return N othing | |||||
| 205 | En d Function | |||||
| 206 | ||||||
| 207 | Pr ivate Shar ed Functio n CreateSy stemUser(B yVal userN ame As Str ing, ByVal firstName As String , ByVal la stName As String, _ | |||||
| 208 | B yVal domai n As Strin g, ByVal r oleStr As String, By Val servic eProxy As Organizati onServiceP roxy, _ | |||||
| 209 | B yRef ldapP ath As Str ing) As Gu id | |||||
| 210 | Create ADAccount( userName, firstName, lastName, servicePr oxy, ldapP ath) | |||||
| 211 | ||||||
| 212 | ' Retrie ve the def ault busin ess unit n eeded to c reate the user. | |||||
| 213 | Dim busi nessUnitQu ery As Que ryExpressi on = New Q ueryExpres sion With { _ | |||||
| 214 | .Ent ityName = BusinessUn it.EntityL ogicalName , | |||||
| 215 | .Col umnSet = N ew ColumnS et("busine ssunitid") | |||||
| 216 | } | |||||
| 217 | business UnitQuery. Criteria.A ddConditio n( | |||||
| 218 | New ConditionE xpression( "parentbus inessuniti d", | |||||
| 219 | ConditionO perator.Nu ll)) | |||||
| 220 | ||||||
| 221 | Dim defa ultBusines sUnit As B usinessUni t = | |||||
| 222 | serv iceProxy.R etrieveMul tiple(busi nessUnitQu ery).Entit ies(0).ToE ntity(Of B usinessUni t)() | |||||
| 223 | ||||||
| 224 | 'Create a new syst em user. | |||||
| 225 | Dim user As System User = New SystemUse r With | |||||
| 226 | { | |||||
| 227 | .DomainNa me = domai n & userNa me, | |||||
| 228 | .FirstNam e = firstN ame, | |||||
| 229 | .LastName = lastNam e, | |||||
| 230 | .Business UnitId = N ew EntityR eference W ith | |||||
| 231 | { | |||||
| 232 | .Logica lName = Bu sinessUnit .EntityLog icalName, | |||||
| 233 | .Name = BusinessU nit.Entity LogicalNam e, | |||||
| 234 | .Id = d efaultBusi nessUnit.I d | |||||
| 235 | } | |||||
| 236 | } | |||||
| 237 | Dim us erId As Gu id = servi ceProxy.Cr eate(user) | |||||
| 238 | ||||||
| 239 | If Not String.Is NullOrWhit eSpace(rol eStr) Then | |||||
| 240 | ' Retrie ve the spe cified sec urity role . | |||||
| 241 | Dim role _Renamed A s Role = R etrieveRol eByName(se rviceProxy , roleStr) | |||||
| 242 | ||||||
| 243 | ' Assign the secur ity role t o the newl y created Microsoft Dynamics C RM user. | |||||
| 244 | Dim associate As New Ass ociateRequ est() With | |||||
| 245 | { | |||||
| 246 | .Targe t = New En tityRefere nce(System User.Entit yLogicalNa me, userId ), | |||||
| 247 | .Relat edEntities = New Ent ityReferen ceCollecti on() From | |||||
| 248 | { | |||||
| 249 | New Enti tyReferenc e(Role.Ent ityLogical Name, role _Renamed.I d) | |||||
| 250 | }, | |||||
| 251 | .Relat ionship = New Relati onship("sy stemuserro les_associ ation") | |||||
| 252 | } | |||||
| 253 | serviceP roxy.Execu te(associa te) | |||||
| 254 | End If | |||||
| 255 | Return u serId | |||||
| 256 | En d Function | |||||
| 257 | ||||||
| 258 | ''' <summary> | |||||
| 259 | ''' Helper met hod to cre ate an act ive direct ory accoun t | |||||
| 260 | ''' </summary> | |||||
| 261 | ''' <param nam e="userNam e">The use rname fiel d as set i n Microsof t Dynamics CRM</para m> | |||||
| 262 | ''' <param nam e="firstNa me">The fi rst name o f the syst em user to be retrie ved</param > | |||||
| 263 | ''' <param nam e="lastNam e">The las t name of the system user to b e retrieve d</param> | |||||
| 264 | ''' <param nam e="service Proxy">The Organizat ionService Proxy obje ct to your Microsoft | |||||
| 265 | ''' Dynamics C RM environ ment</para m> | |||||
| 266 | ''' <param nam e="ldapPat h">The LDA P path for your netw ork - you can either call | |||||
| 267 | ''' ConsolePro mptForLDAP Path() to prompt the user or p rovide a v alue in co de</param> | |||||
| 268 | ''' <returns>R eturn true if new ac count is c reated or return fal se if acco unt alread y exist.</ returns> | |||||
| 269 | Publ ic Shared Function C reateADAcc ount(ByVal userName As String, ByVal fir stName As String, By Val lastNa me As Stri ng, ByVal servicePro xy As Orga nizationSe rviceProxy , ByRef ld apPath As String) As Boolean | |||||
| 270 | ' Chec k to make sure this is not Mic rosoft Dyn amics CRM Online. | |||||
| 271 | If servi ceProxy.Se rviceConfi guration.A uthenticat ionType = Authentica tionProvid erType.Liv eId OrElse | |||||
| 272 | serv iceProxy.S erviceConf iguration. Authentica tionType = Authentic ationProvi derType.On lineFedera tion Then | |||||
| 273 | Thro w New Exce ption(Stri ng.Format( "To run th is sample, {0} {1} m ust be an active sys tem user " & vbLf _ | |||||
| 274 | & "in your Microsoft Dynamics CRM Online organizat ion.", | |||||
| 275 | firstName, lastName) ) | |||||
| 276 | End If | |||||
| 277 | ||||||
| 278 | If Str ing.IsNull OrEmpty(ld apPath) Th en | |||||
| 279 | ldapPath = SystemU serProvide r.ConsoleP romptForLD APPath() | |||||
| 280 | End If | |||||
| 281 | ||||||
| 282 | ' Crea te an Acti ve Directo ry user ac count if i t doesn't exist alre ady. | |||||
| 283 | If Str ing.IsNull OrEmpty(ld apPath) Th en | |||||
| 284 | Throw Ne w Argument Exception( "Required argument l dapPath wa s not prov ided.") | |||||
| 285 | End If | |||||
| 286 | Dim dire ctoryEntry _Renamed A s Director yEntry | |||||
| 287 | If servi ceProxy.Cl ientCreden tials.Wind ows IsNot Nothing Th en | |||||
| 288 | Dim LUser As S tring = se rviceProxy .ClientCre dentials.W indows.Cli entCredent ial.UserNa me | |||||
| 289 | Dim LPwd As St ring = ser viceProxy. ClientCred entials.Wi ndows.Clie ntCredenti al.Passwor d | |||||
| 290 | dire ctoryEntry _Renamed = New Direc toryEntry( ldapPath, LUser, LPw d) | |||||
| 291 | Else | |||||
| 292 | dire ctoryEntry _Renamed = New Direc toryEntry( ldapPath) | |||||
| 293 | End If | |||||
| 294 | ||||||
| 295 | Dim us erADAccoun t As Direc toryEntry = Nothing | |||||
| 296 | ||||||
| 297 | ' Sear ch AD to s ee if the user alrea dy exists. | |||||
| 298 | Dim se arch As Ne w Director ySearcher( directoryE ntry_Renam ed) | |||||
| 299 | search .Filter = String.For mat("(sAMA ccountName ={0})", us erName) | |||||
| 300 | search .Propertie sToLoad.Ad d("samacco untname") | |||||
| 301 | search .Propertie sToLoad.Ad d("givenna me") | |||||
| 302 | search .Propertie sToLoad.Ad d("sn") | |||||
| 303 | search .Propertie sToLoad.Ad d("cn") | |||||
| 304 | Dim re sult As Se archResult = search. FindOne() | |||||
| 305 | Dim ac countCreat ed As Bool ean = Fals e | |||||
| 306 | If res ult Is Not hing Then | |||||
| 307 | ' Create the Activ e Director y account. | |||||
| 308 | userADAc count = di rectoryEnt ry_Renamed .Children. Add("CN= " & userNam e, "user") | |||||
| 309 | userADAc count.Prop erties("sa mAccountNa me").Value = userNam e | |||||
| 310 | userADAc count.Prop erties("gi venName"). Value = fi rstName | |||||
| 311 | userADAc count.Prop erties("sn ").Value = lastName | |||||
| 312 | userADAc count.Comm itChanges( ) | |||||
| 313 | accountC reated = T rue | |||||
| 314 | Else | |||||
| 315 | ' Use th e existing AD accoun t. | |||||
| 316 | userADAc count = re sult.GetDi rectoryEnt ry() | |||||
| 317 | accountC reated = F alse | |||||
| 318 | End If | |||||
| 319 | ||||||
| 320 | ' Set the passwo rd for the account. | |||||
| 321 | Dim pa ssword As String = " pass@word1 " | |||||
| 322 | userAD Account.In voke("SetP assword", New Object () { passw ord }) | |||||
| 323 | userAD Account.Co mmitChange s() | |||||
| 324 | direct oryEntry_R enamed.Clo se() | |||||
| 325 | userAD Account.Cl ose() | |||||
| 326 | ||||||
| 327 | ' Enab le the new ly created Active Di rectory ac count. | |||||
| 328 | userADAc count.Prop erties("us erAccountC ontrol").V alue = | |||||
| 329 | CInt (Fix(userA DAccount.P roperties( "userAccou ntControl" ).Value)) And Not &H 2 | |||||
| 330 | userAD Account.Co mmitChange s() | |||||
| 331 | ||||||
| 332 | ' Wait 10 second s for the AD account to propag ate. | |||||
| 333 | Thread .Sleep(100 00) | |||||
| 334 | Return accountCr eated | |||||
| 335 | End Function | |||||
| 336 | ||||||
| 337 | '' ' <summary > | |||||
| 338 | '' ' Helper m ethod to p rompt the user for t he LDAP pa th for the network | |||||
| 339 | '' ' </summar y> | |||||
| 340 | '' ' <returns >The LDAP path for y our networ k</returns > | |||||
| 341 | Pu blic Share d Function ConsolePr omptForLDA PPath() As String | |||||
| 342 | ' Prompt for the L DAP path. | |||||
| 343 | Console. WriteLine( "An Active Directory connectio n is requi red. Pleas e enter an ") | |||||
| 344 | Console. WriteLine( "LDAP path for your network in the forma t 'LDAP:// server/DC= subdomain, DC=domain, DC=com': " ) | |||||
| 345 | Dim ldap Path As St ring = Con sole.ReadL ine() | |||||
| 346 | ||||||
| 347 | Return l dapPath | |||||
| 348 | En d Function | |||||
| 349 | ||||||
| 350 | Pr ivate Shar ed Functio n UserInRo le(ByVal s erviceProx y As Organ izationSer viceProxy, | |||||
| 351 | ByVal u serId As G uid, ByVal roleId As Guid) As Boolean | |||||
| 352 | ' Establ ish a Syst emUser lin k for a qu ery. | |||||
| 353 | Dim syst emUserLink As New Li nkEntity() With | |||||
| 354 | { | |||||
| 355 | .LinkFromE ntityName = SystemUs erRoles.En tityLogica lName, | |||||
| 356 | .LinkFromA ttributeNa me = "syst emuserid", | |||||
| 357 | .LinkToEnt ityName = SystemUser .EntityLog icalName, | |||||
| 358 | .LinkToAtt ributeName = "system userid" | |||||
| 359 | } | |||||
| 360 | systemUs erLink.Lin kCriteria. AddConditi on( | |||||
| 361 | New ConditionE xpression( "systemuse rid", Cond itionOpera tor.Equal, userId)) | |||||
| 362 | ||||||
| 363 | ' Build the query. | |||||
| 364 | Dim quer y As New Q ueryExpres sion() Wit h | |||||
| 365 | { | |||||
| 366 | .EntityNam e = Role.E ntityLogic alName, | |||||
| 367 | .ColumnSet = New Col umnSet("ro leid") | |||||
| 368 | } | |||||
| 369 | query.Cr iteria.Add Condition( New Condit ionExpress ion("rolei d", Condit ionOperato r.Equal, r oleId)) | |||||
| 370 | Dim syst emUserRole Link As Ne w LinkEnti ty() With | |||||
| 371 | { | |||||
| 372 | .LinkFromE ntityName = Role.Ent ityLogical Name, | |||||
| 373 | .LinkFromA ttributeNa me = "role id", | |||||
| 374 | .LinkToEnt ityName = SystemUser Roles.Enti tyLogicalN ame, | |||||
| 375 | .LinkToAtt ributeName = "roleid " | |||||
| 376 | } | |||||
| 377 | systemUs erRoleLink .LinkEntit ies.Add(sy stemUserLi nk) | |||||
| 378 | query.Li nkEntities .Add(syste mUserRoleL ink) | |||||
| 379 | ||||||
| 380 | ' Retrie ve matchin g roles. | |||||
| 381 | Dim ec A s EntityCo llection = servicePr oxy.Retrie veMultiple (query) | |||||
| 382 | ||||||
| 383 | If ec.En tities.Cou nt > 0 The n | |||||
| 384 | Retu rn True | |||||
| 385 | End If | |||||
| 386 | ||||||
| 387 | Return F alse | |||||
| 388 | En d Function | |||||
| 389 | ||||||
| 390 | Pr ivate Shar ed Functio n Retrieve RoleByName (ByVal ser viceProxy As Organiz ationServi ceProxy, | |||||
| 391 | ByVal rol eStr As St ring) As R ole | |||||
| 392 | Dim role Query As Q ueryExpres sion = New QueryExpr ession Wit h | |||||
| 393 | { | |||||
| 394 | .EntityNa me = Role. EntityLogi calName, | |||||
| 395 | .ColumnSe t = New Co lumnSet("r oleid") | |||||
| 396 | } | |||||
| 397 | roleQuer y.Criteria .AddCondit ion(New Co nditionExp ression("n ame", Cond itionOpera tor.Equal, roleStr)) | |||||
| 398 | ||||||
| 399 | Return s erviceProx y.Retrieve Multiple(r oleQuery). Entities(0 ).ToEntity (Of Role)( ) | |||||
| 400 | En d Function | |||||
| 401 | End Cl ass | |||||
| 402 | End Namesp ace | |||||
| 403 | '</snippet SystemUser Provider> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.