17
17
using System ;
18
18
using System . Collections . Generic ;
19
19
using System . Linq ;
20
- using System . Runtime . InteropServices ;
21
- using System . Security ;
22
- using System . Security . Permissions ;
23
20
using Microsoft . Azure . Commands . ResourceManager . Common . Tags ;
24
21
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
25
22
using Microsoft . Azure . Commands . Sql . Common ;
26
23
using Microsoft . WindowsAzure . Commands . Common ;
27
24
using Microsoft . Azure . Management . Internal . Resources . Utilities . Models ;
28
25
using Microsoft . Azure . Management . Sql . Models ;
29
- using Microsoft . Azure . Graph . RBAC . Version1_6 . ActiveDirectory ;
30
- using Microsoft . Azure . Graph . RBAC . Version1_6 . Models ;
26
+ using Microsoft . Azure . Commands . Common . MSGraph . Version1_0 ;
27
+ using Microsoft . Azure . Commands . Common . MSGraph . Version1_0 . Groups . Models ;
28
+ using Microsoft . Azure . Commands . Common . Authentication ;
29
+ using Microsoft . Azure . Commands . Common . MSGraph . Version1_0 . Applications . Models ;
30
+
31
31
using Microsoft . Rest . Azure . OData ;
32
- using ServicePrincipal = Microsoft . Azure . Graph . RBAC . Version1_6 . Models . ServicePrincipal ;
33
32
34
33
namespace Microsoft . Azure . Commands . Sql . ManagedInstance . Adapter
35
34
{
@@ -49,30 +48,25 @@ public class AzureSqlManagedInstanceAdapter
49
48
public IAzureContext Context { get ; set ; }
50
49
51
50
/// <summary>
52
- /// A private instance of ActiveDirectoryClient
51
+ /// A private instance of MicrosoftGraphClient
53
52
/// </summary>
54
- private ActiveDirectoryClient _activeDirectoryClient ;
53
+ private MicrosoftGraphClient _microsoftGraphClient ;
55
54
56
55
/// <summary>
57
- /// Gets or sets the Azure ActiveDirectoryClient instance
56
+ /// Gets or sets the Azure MicrosoftGraphClient instance
58
57
/// </summary>
59
- public ActiveDirectoryClient ActiveDirectoryClient
58
+ public MicrosoftGraphClient MicrosoftGraphClient
60
59
{
61
60
get
62
61
{
63
- if ( _activeDirectoryClient == null )
62
+ if ( _microsoftGraphClient == null )
64
63
{
65
- _activeDirectoryClient = new ActiveDirectoryClient ( Context ) ;
66
- if ( ! Context . Environment . IsEndpointSet ( AzureEnvironment . Endpoint . Graph ) )
67
- {
68
- throw new ArgumentException ( string . Format ( Microsoft . Azure . Commands . Sql . Properties . Resources . InvalidGraphEndpoint ) ) ;
69
- }
70
- _activeDirectoryClient = new ActiveDirectoryClient ( Context ) ;
64
+ _microsoftGraphClient = AzureSession . Instance . ClientFactory . CreateArmClient < MicrosoftGraphClient > ( Context , AzureEnvironment . Endpoint . Graph ) ;
65
+ _microsoftGraphClient . TenantID = Context . Tenant . Id ;
71
66
}
72
- return this . _activeDirectoryClient ;
67
+ return _microsoftGraphClient ;
73
68
}
74
-
75
- set { this . _activeDirectoryClient = value ; }
69
+ set { _microsoftGraphClient = value ; }
76
70
}
77
71
78
72
/// <summary>
@@ -317,18 +311,18 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
317
311
Guid tenantId = GetTenantId ( ) ;
318
312
319
313
// Check for a Azure Active Directory group. Recommended to always use group.
320
- IEnumerable < PSADGroup > groupList = null ;
321
- PSADGroup group = null ;
314
+ IEnumerable < MicrosoftGraphGroup > groupList = null ;
315
+ MicrosoftGraphGroup group = null ;
322
316
323
- var filter = new ADObjectFilterOptions ( )
317
+ var filter = new MicrosoftObjectFilterOptions ( )
324
318
{
325
319
Id = ( objectId != null && objectId != Guid . Empty ) ? objectId . ToString ( ) : null ,
326
320
SearchString = displayName ,
327
321
Paging = true ,
328
322
} ;
329
323
330
324
// Get a list of groups from Azure Active Directory
331
- groupList = ActiveDirectoryClient . FilterGroups ( filter ) . Where ( gr => string . Equals ( gr . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
325
+ groupList = MicrosoftGraphClient . FilterGroups ( filter ) . Where ( gr => string . Equals ( gr . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
332
326
333
327
if ( groupList != null && groupList . Count ( ) > 1 )
334
328
{
@@ -348,19 +342,19 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
348
342
}
349
343
350
344
// Lookup for serviceprincipals
351
- ODataQuery < ServicePrincipal > odataQueryFilter ;
345
+ ODataQuery < MicrosoftGraphServicePrincipal > odataQueryFilter ;
352
346
353
347
if ( ( objectId != null && objectId != Guid . Empty ) )
354
348
{
355
349
var applicationIdString = objectId . ToString ( ) ;
356
- odataQueryFilter = new Rest . Azure . OData . ODataQuery < ServicePrincipal > ( a => a . AppId == applicationIdString ) ;
350
+ odataQueryFilter = new Rest . Azure . OData . ODataQuery < MicrosoftGraphServicePrincipal > ( a => a . AppId == applicationIdString ) ;
357
351
}
358
352
else
359
353
{
360
- odataQueryFilter = new Rest . Azure . OData . ODataQuery < ServicePrincipal > ( a => a . DisplayName == displayName ) ;
354
+ odataQueryFilter = new Rest . Azure . OData . ODataQuery < MicrosoftGraphServicePrincipal > ( a => a . DisplayName == displayName ) ;
361
355
}
362
356
363
- var servicePrincipalList = ActiveDirectoryClient . FilterServicePrincipals ( odataQueryFilter ) ;
357
+ var servicePrincipalList = MicrosoftGraphClient . FilterServicePrincipals ( odataQueryFilter ) ;
364
358
365
359
if ( servicePrincipalList != null && servicePrincipalList . Count ( ) > 1 )
366
360
{
@@ -370,7 +364,7 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
370
364
else if ( servicePrincipalList != null && servicePrincipalList . Count ( ) == 1 )
371
365
{
372
366
// Only one user was found. Get the user display name and object id
373
- PSADServicePrincipal app = servicePrincipalList . First ( ) ;
367
+ MicrosoftGraphServicePrincipal app = servicePrincipalList . First ( ) ;
374
368
375
369
if ( displayName != null && string . CompareOrdinal ( displayName , app . DisplayName ) != 0 )
376
370
{
@@ -385,7 +379,7 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
385
379
return new ManagedInstanceExternalAdministrator ( )
386
380
{
387
381
Login = displayName ,
388
- Sid = app . ApplicationId ,
382
+ Sid = new Guid ( app . AppId ) ,
389
383
TenantId = tenantId ,
390
384
PrincipalType = "Application" ,
391
385
AzureADOnlyAuthentication = adOnlyAuth
@@ -397,50 +391,50 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
397
391
return new ManagedInstanceExternalAdministrator ( )
398
392
{
399
393
Login = group . DisplayName ,
400
- Sid = group . Id ,
394
+ Sid = new Guid ( group . Id ) ,
401
395
TenantId = tenantId ,
402
396
PrincipalType = "Group" ,
403
397
AzureADOnlyAuthentication = adOnlyAuth
404
398
} ;
405
399
}
406
400
407
401
// No group or service principal was found. Check for a user
408
- filter = new ADObjectFilterOptions ( )
402
+ filter = new MicrosoftObjectFilterOptions ( )
409
403
{
410
404
Id = ( objectId != null && objectId != Guid . Empty ) ? objectId . ToString ( ) : null ,
411
405
SearchString = displayName ,
412
406
Paging = true ,
413
407
} ;
414
408
415
409
// Get a list of user from Azure Active Directory
416
- var userList = ActiveDirectoryClient . FilterUsers ( filter ) . Where ( gr => string . Equals ( gr . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
410
+ var userList = MicrosoftGraphClient . FilterUsers ( filter ) . Where ( gr => string . Equals ( gr . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
417
411
418
412
// No user was found. Check if the display name is a UPN
419
413
if ( userList == null || userList . Count ( ) == 0 )
420
414
{
421
415
// Check if the display name is the UPN
422
- filter = new ADObjectFilterOptions ( )
416
+ filter = new MicrosoftObjectFilterOptions ( )
423
417
{
424
418
Id = ( objectId != null && objectId != Guid . Empty ) ? objectId . ToString ( ) : null ,
425
419
UPN = displayName ,
426
420
Paging = true ,
427
421
} ;
428
422
429
- userList = ActiveDirectoryClient . FilterUsers ( filter ) . Where ( gr => string . Equals ( gr . UserPrincipalName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
423
+ userList = MicrosoftGraphClient . FilterUsers ( filter ) . Where ( gr => string . Equals ( gr . UserPrincipalName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
430
424
}
431
425
432
426
// No user was found. Check if the display name is a guest user.
433
427
if ( userList == null || userList . Count ( ) == 0 )
434
428
{
435
429
// Check if the display name is the UPN
436
- filter = new ADObjectFilterOptions ( )
430
+ filter = new MicrosoftObjectFilterOptions ( )
437
431
{
438
432
Id = ( objectId != null && objectId != Guid . Empty ) ? objectId . ToString ( ) : null ,
439
433
Mail = displayName ,
440
434
Paging = true ,
441
435
} ;
442
436
443
- userList = ActiveDirectoryClient . FilterUsers ( filter ) ;
437
+ userList = MicrosoftGraphClient . FilterUsers ( filter ) ;
444
438
}
445
439
446
440
// No user was found
@@ -461,7 +455,7 @@ protected ManagedInstanceExternalAdministrator GetActiveDirectoryInformation(Man
461
455
return new ManagedInstanceExternalAdministrator ( )
462
456
{
463
457
Login = displayName ,
464
- Sid = obj . Id ,
458
+ Sid = new Guid ( obj . Id ) ,
465
459
TenantId = tenantId ,
466
460
PrincipalType = "User" ,
467
461
AzureADOnlyAuthentication = adOnlyAuth
0 commit comments