Skip to content

Commit 57da4b1

Browse files
Fix compilation error
1 parent df8f496 commit 57da4b1

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

src/Graph.Rbac/Version1_6.20190326/ActiveDirectory/ActiveDirectoryClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public List<PSADObject> ListUserGroups(string principal)
260260
public List<PSADObject> GetObjectsByObjectId(List<string> objectIds)
261261
{
262262
List<PSADObject> result = new List<PSADObject>();
263-
IPage<AADObject> adObjects;
263+
IPage<DirectoryObject> adObjects;
264264
int objectIdBatchCount;
265265
for(int i=0; i<objectIds.Count; i+=1000)
266266
{
@@ -354,7 +354,7 @@ public void RemoveGroup(string groupObjectId)
354354

355355
public IEnumerable<PSADObject> GetGroupMembers(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
356356
{
357-
return new GenericPageEnumerable<AADObject>(
357+
return new GenericPageEnumerable<DirectoryObject>(
358358
delegate ()
359359
{
360360
return GraphClient.Groups.GetGroupMembers(options.Id);
@@ -450,7 +450,7 @@ public PSADApplication CreateApplication(CreatePSApplicationParameters createPar
450450
{
451451
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
452452
{
453-
AADObject currentUser = GraphClient.Objects.GetCurrentUser();
453+
User currentUser = GraphClient.SignedInUser.Get();
454454
if (currentUser != null && string.Equals(currentUser.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
455455
{
456456
throw new InvalidOperationException(ProjectResources.CreateApplicationNotAllowedGuestUser);
@@ -815,7 +815,7 @@ public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParam
815815
{
816816
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
817817
{
818-
AADObject currentUser = GraphClient.Objects.GetCurrentUser();
818+
User currentUser = GraphClient.SignedInUser.Get();
819819
if (currentUser != null && string.Equals(currentUser.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
820820
{
821821
throw new InvalidOperationException(ProjectResources.CreateServicePrincipalNotAllowedGuestUser);

src/Graph.Rbac/Version1_6.20190326/ActiveDirectory/ActiveDirectoryClientExtensions.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,56 +48,49 @@ public static PSADObject AssignObjectId(PSADObject adObj, string objectId)
4848
return adObj;
4949
}
5050

51-
public static PSADObject ToPSADObject(this AADObject obj)
51+
public static PSADObject ToPSADObject(this DirectoryObject obj)
5252
{
5353
if (obj == null) throw new ArgumentNullException();
5454

55-
if (obj.ObjectType == typeof(User).Name)
55+
if (obj is User user)
5656
{
5757
var adUser = new PSADUser()
5858
{
59-
DisplayName = obj.DisplayName,
60-
UserPrincipalName = obj.UserPrincipalName
59+
DisplayName = user.DisplayName,
60+
UserPrincipalName = user.UserPrincipalName
6161
};
6262

6363
return AssignObjectId(adUser, obj.ObjectId);
6464
}
65-
else if (obj.ObjectType == "Group")
65+
else if (obj is ADGroup group)
6666
{
6767
var adGroup = new PSADGroup()
6868
{
69-
DisplayName = obj.DisplayName,
70-
SecurityEnabled = obj.SecurityEnabled,
71-
MailNickname = obj.Mail
69+
DisplayName = group.DisplayName,
70+
SecurityEnabled = group.SecurityEnabled,
71+
MailNickname = group.Mail
7272
};
7373
return AssignObjectId(adGroup, obj.ObjectId);
7474
}
75-
else if (obj.ObjectType == typeof(ServicePrincipal).Name)
75+
else if (obj is ServicePrincipal servicePrincipal)
7676
{
7777
var adSp = new PSADServicePrincipal()
7878
{
79-
DisplayName = obj.DisplayName,
80-
ServicePrincipalNames = obj.ServicePrincipalNames.ToArray()
79+
DisplayName = servicePrincipal.DisplayName,
80+
ServicePrincipalNames = servicePrincipal.ServicePrincipalNames.ToArray()
8181
};
8282

8383
return AssignObjectId(adSp, obj.ObjectId);
8484
}
85-
else
86-
{
87-
var adObj = new PSADObject()
88-
{
89-
DisplayName = obj.DisplayName,
90-
};
9185

92-
return AssignObjectId(adObj, obj.ObjectId);
93-
}
86+
throw new NotSupportedException($"{obj.GetType()}");
9487
}
9588

96-
public static PSADObject ToPSADGroup(this AADObject obj)
89+
public static PSADObject ToPSADGroup(this DirectoryObject obj)
9790
{
9891
var adObj = new PSADObject()
9992
{
100-
DisplayName = obj.DisplayName,
93+
DisplayName = (obj as ADGroup).DisplayName,
10194
};
10295

10396
return AssignObjectId(adObj, obj.ObjectId);

0 commit comments

Comments
 (0)