Skip to content

Commit 0bb3cfe

Browse files
committed
Resolve review comments
1 parent c8957df commit 0bb3cfe

File tree

56 files changed

+1263
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1263
-240
lines changed

src/Common/Commands.Common.Graph.RBAC/ActiveDirectory/ActiveDirectoryClient.cs

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static string Normalize(string s)
8484

8585
public IEnumerable<PSADServicePrincipal> FilterServicePrincipals(Rest.Azure.OData.ODataQuery<ServicePrincipal> odataQuery, ulong first = ulong.MaxValue, ulong skip = 0)
8686
{
87-
return new PageEnumerable<ServicePrincipal>(
87+
return new GenericPageEnumerable<ServicePrincipal>(
8888
delegate ()
8989
{
9090
return GraphClient.ServicePrincipals.List(odataQuery);
@@ -146,8 +146,18 @@ public IEnumerable<PSADUser> FilterUsers(ADObjectFilterOptions options, ulong fi
146146
}
147147
else
148148
{
149-
var odataQuery = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName.StartsWith(options.SearchString));
150-
return new PageEnumerable<User>(
149+
Rest.Azure.OData.ODataQuery<User> odataQuery = null;
150+
if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
151+
{
152+
options.SearchString = options.SearchString.TrimEnd('*');
153+
odataQuery = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName.StartsWith(options.SearchString));
154+
}
155+
else
156+
{
157+
odataQuery = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName == options.SearchString);
158+
}
159+
160+
return new GenericPageEnumerable<User>(
151161
delegate ()
152162
{
153163
return GraphClient.Users.List(odataQuery.ToString());
@@ -197,6 +207,22 @@ public List<PSADObject> GetObjectsByObjectId(List<string> objectIds)
197207
return result;
198208
}
199209

210+
public PSADGroup GetGroupByDisplayName(string displayName)
211+
{
212+
var group = FilterGroups(new ADObjectFilterOptions() { SearchString = displayName });
213+
if (group.Count() > 1)
214+
{
215+
throw new InvalidOperationException(string.Format(ProjectResources.MultipleGroupsWithDisplayNameFound, displayName));
216+
}
217+
218+
if (group.Count() == 0)
219+
{
220+
throw new InvalidOperationException(string.Format(ProjectResources.GroupWithDisplayNameDoesntExist, displayName));
221+
}
222+
223+
return group.FirstOrDefault();
224+
}
225+
200226
public IEnumerable<PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
201227
{
202228
if (!string.IsNullOrEmpty(options.Id))
@@ -221,10 +247,18 @@ public IEnumerable<PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong
221247
}
222248
else
223249
{
224-
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
250+
if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
251+
{
252+
options.SearchString = options.SearchString.TrimEnd('*');
253+
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
254+
}
255+
else
256+
{
257+
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName == options.SearchString);
258+
}
225259
}
226260

227-
return new PageEnumerable<ADGroup>(
261+
return new GenericPageEnumerable<ADGroup>(
228262
delegate ()
229263
{
230264
return GraphClient.Groups.List(odataQuery);
@@ -251,7 +285,7 @@ public void RemoveGroup(string groupObjectId)
251285

252286
public IEnumerable<PSADObject> GetGroupMembers(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
253287
{
254-
return new PageEnumerable<AADObject>(
288+
return new GenericPageEnumerable<AADObject>(
255289
delegate ()
256290
{
257291
return GraphClient.Groups.GetGroupMembers(options.Id);
@@ -458,16 +492,50 @@ public void RemoveAllAppCredentials(Guid appObjectId)
458492

459493
public Guid GetAppObjectIdFromApplicationId(Guid applicationId)
460494
{
461-
var appId = applicationId.ToString();
462-
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == appId);
495+
var applicationIdString = applicationId.ToString();
496+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == applicationIdString);
463497
var app = GetApplicationWithFilters(odataQueryFilter).SingleOrDefault();
464498
if (app == null)
465499
{
466-
throw new InvalidOperationException(String.Format(ProjectResources.ApplicationWithAppIdDoesntExist, applicationId));
500+
throw new InvalidOperationException(string.Format(ProjectResources.ApplicationWithAppIdDoesntExist, applicationId));
467501
}
468502
return app.ObjectId;
469503
}
470504

505+
public Guid GetAppObjectIdFromDisplayName(string displayName)
506+
{
507+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.DisplayName == displayName);
508+
var app = GetApplicationWithFilters(odataQueryFilter);
509+
if (app == null || app.FirstOrDefault() == null)
510+
{
511+
throw new InvalidOperationException(string.Format(ProjectResources.ApplicationWithDisplayNameDoesntExist, displayName));
512+
}
513+
514+
if (app.Count() > 1)
515+
{
516+
throw new InvalidOperationException(string.Format(ProjectResources.MultipleApplicationsWithDisplayNameFound, displayName));
517+
}
518+
519+
return app.FirstOrDefault().ObjectId;
520+
}
521+
522+
public Guid GetUserObjectIdFromDisplayName(string displayName)
523+
{
524+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName == displayName);
525+
var user = GraphClient.Users.List(odataQueryFilter.ToString());
526+
if (user == null || user.FirstOrDefault() == null)
527+
{
528+
throw new InvalidOperationException(string.Format(ProjectResources.UserWithDisplayNameDoesntExist, displayName));
529+
}
530+
531+
if (user.Count() > 1)
532+
{
533+
throw new InvalidOperationException(string.Format(ProjectResources.MultipleUsersWithDisplayNameFound, displayName));
534+
}
535+
536+
return new Guid(user.FirstOrDefault().ObjectId);
537+
}
538+
471539
private List<KeyCredential> GetSpKeyCredentials(Guid spObjectId)
472540
{
473541
return GraphClient.ServicePrincipals.ListKeyCredentials(spObjectId.ToString()).ToList();
@@ -594,6 +662,23 @@ public Guid GetObjectIdFromSPN(string spn)
594662
return new Guid(sp.ObjectId);
595663
}
596664

665+
public Guid GetObjectIdFromServicePrincipalDisplayName(string displayName)
666+
{
667+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(s => s.DisplayName == displayName);
668+
var sp = GraphClient.ServicePrincipals.List(odataQueryFilter.ToString());
669+
if (sp == null || sp.FirstOrDefault() == null)
670+
{
671+
throw new InvalidOperationException(string.Format(ProjectResources.ServicePrincipalWithDisplayNameDoesntExist, displayName));
672+
}
673+
674+
if (sp.Count() > 1)
675+
{
676+
throw new InvalidOperationException(string.Format(ProjectResources.MultipleServicePrincipalsWithDisplayNameFound, displayName));
677+
}
678+
679+
return new Guid(sp.FirstOrDefault().ObjectId);
680+
}
681+
597682
public void RemoveApplication(Guid applicationObjectId)
598683
{
599684
GraphClient.Applications.Delete(applicationObjectId.ToString());
@@ -606,7 +691,7 @@ public PSADApplication GetApplication(Guid applicationObjectId)
606691

607692
public IEnumerable<PSADApplication> GetApplicationWithFilters(Rest.Azure.OData.ODataQuery<Application> odataQueryFilter, ulong first = ulong.MaxValue, ulong skip = 0)
608693
{
609-
return new PageEnumerable<Application>(
694+
return new GenericPageEnumerable<Application>(
610695
delegate ()
611696
{
612697
return GraphClient.Applications.List(odataQueryFilter);
@@ -652,12 +737,12 @@ public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParam
652737

653738
public PSADServicePrincipal RemoveServicePrincipal(Guid objectId)
654739
{
655-
var objId = objectId.ToString();
656-
Rest.Azure.OData.ODataQuery<ServicePrincipal> odataQuery = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(s => s.ObjectId == objId);
740+
var objectIdString = objectId.ToString();
741+
Rest.Azure.OData.ODataQuery<ServicePrincipal> odataQuery = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(s => s.ObjectId == objectIdString);
657742
PSADServicePrincipal servicePrincipal = FilterServicePrincipals(odataQuery).FirstOrDefault();
658743
if (servicePrincipal != null)
659744
{
660-
GraphClient.ServicePrincipals.Delete(objId);
745+
GraphClient.ServicePrincipals.Delete(objectIdString);
661746
}
662747
else
663748
{

src/Common/Commands.Common.Graph.RBAC/ActiveDirectory/ParameterSet.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public static class ParameterSet
9090

9191
public const string ApplicationIdWithCertValue = "ApplicationIdWithCertValueParameterSet";
9292

93+
public const string DisplayNameWithPassword = "DisplayNameWithPasswordParameterSet";
94+
95+
public const string DisplayNameWithCertValue = "DisplayNameWithCertValueParameterSet";
96+
9397
public const string Empty = "EmptyParameterSet";
9498

9599
public const string InputFile = "InputFileParameterSet";
@@ -140,6 +144,8 @@ public static class ParameterSet
140144

141145
public const string ServicePrincipalObjectWithPassword = "ServicePrincipalObjectWithPasswordParameterSet";
142146

147+
public const string DisplayNameWithKeyId = "DisplayNameWithKeyIdParameterSet";
148+
143149
public const string ObjectIdWithKeyId = "ObjectIdWithKeyIdParameterSet";
144150

145151
public const string ObjectIdWithAll = "ObjectIdWithAllParameterSet";
@@ -154,6 +160,8 @@ public static class ParameterSet
154160

155161
public const string ApplicationIdWithUpdateParams = "ApplicationIdWithUpdateParamsParameterSet";
156162

163+
public const string DisplayName = "DisplayNameParameterSet";
164+
157165
public const string DisplayNameWithoutCredential = "DisplayNameWithoutCredentialParameterSet";
158166

159167
public const string DisplayNameWithPasswordPlain = "DisplayNameWithPasswordPlainParameterSet";
@@ -175,5 +183,17 @@ public static class ParameterSet
175183
public const string RoleAssignment = "RoleAssignmentParameterSet";
176184

177185
public const string Explicit = "ExplicitParameterSet";
186+
187+
public const string MemberUPNWithGroupDisplayName = "MemberUPNWithGroupDisplayNameParameterSet";
188+
189+
public const string MemberUPNWithGroupObjectId = "MemberUPNWithGroupObjectIdParameterSet";
190+
191+
public const string MemberUPNWithGroupObject = "MemberUPNWithGroupObjectParameterSet";
192+
193+
public const string MemberObjectIdWithGroupDisplayName = "MemberObjectIdWithGroupDisplayName";
194+
195+
public const string MemberObjectIdWithGroupObjectId = "MemberObjectIdWithGroupObjectId";
196+
197+
public const string MemberObjectIdWithGroupObject = "MemberObjectIdWithGroupObject";
178198
}
179199
}

src/Common/Commands.Common.Graph.RBAC/Properties/Resources.Designer.cs

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common.Graph.RBAC/Properties/Resources.resx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<data name="ApplicationWithAppIdDoesntExist" xml:space="preserve">
121121
<value>Application with AppId '{0}' does not exist.</value>
122122
</data>
123+
<data name="ApplicationWithDisplayNameDoesntExist" xml:space="preserve">
124+
<value>Application with display name '{0}' does not exist.</value>
125+
</data>
123126
<data name="CreateApplicationNotAllowedGuestUser" xml:space="preserve">
124127
<value>You are a guest user in the directory and are not allowed to create an application. Please contact the administrator of the directory.</value>
125128
</data>
@@ -132,9 +135,24 @@
132135
<data name="GraphException" xml:space="preserve">
133136
<value>Received exception from graph. ErrorCode: {0}, Message: {1}</value>
134137
</data>
138+
<data name="GroupWithDisplayNameDoesntExist" xml:space="preserve">
139+
<value>Group with display name '{0}' does not exist.</value>
140+
</data>
135141
<data name="KeyCredentialNotValid" xml:space="preserve">
136142
<value>KeyCredential object is not valid.</value>
137143
</data>
144+
<data name="MultipleApplicationsWithDisplayNameFound" xml:space="preserve">
145+
<value>More than one application found with display name '{0}'. Please use the Get-AzureRmADApplication cmdlet to get the object id of the desired application.</value>
146+
</data>
147+
<data name="MultipleGroupsWithDisplayNameFound" xml:space="preserve">
148+
<value>More than one group found with the display name '{0}'. Please use the Get-AzureRmADGroup cmdlet to get the object id of the desired group.</value>
149+
</data>
150+
<data name="MultipleServicePrincipalsWithDisplayNameFound" xml:space="preserve">
151+
<value>More than one service principal found with display name '{0}'. Please use the Get-AzureRmADServicePrincipal cmdlet to get the object id of the desired service principal.</value>
152+
</data>
153+
<data name="MultipleUsersWithDisplayNameFound" xml:space="preserve">
154+
<value>More than one user found with display name '{0}'. Please use the Get-AzureRmADUser cmdlet to get the object id of the desired user.</value>
155+
</data>
138156
<data name="PasswordCredentialNotValid" xml:space="preserve">
139157
<value>PasswordCredential object is not valid.</value>
140158
</data>
@@ -144,9 +162,15 @@
144162
<data name="ServicePrincipalWithAppIdDoesntExist" xml:space="preserve">
145163
<value>Service principal with AppId '{0}' does not exist.</value>
146164
</data>
165+
<data name="ServicePrincipalWithDisplayNameDoesntExist" xml:space="preserve">
166+
<value>Service principal with display name '{0}' does not exist.</value>
167+
</data>
147168
<data name="ServicePrincipalWithSPNDoesntExist" xml:space="preserve">
148169
<value>Service principal with SPN '{0}' does not exist.</value>
149170
</data>
171+
<data name="UserWithDisplayNameDoesntExist" xml:space="preserve">
172+
<value>User with display name '{0}' does not exist.</value>
173+
</data>
150174
<data name="UserWithUPNDoesntExist" xml:space="preserve">
151175
<value>User with UPN '{0}' does not exist.</value>
152176
</data>

0 commit comments

Comments
 (0)