Skip to content

Commit 9fd8920

Browse files
committed
AD code changes
1 parent 91826ba commit 9fd8920

File tree

43 files changed

+1423
-667
lines changed

Some content is hidden

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

43 files changed

+1423
-667
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ private void HandleException(Exception exception)
7474
throw exception;
7575
}
7676
}
77-
77+
7878

7979
private Exception ParseResponse(GraphErrorException graphEx) {
8080
int exceptionMessageIndex = graphEx.Response.Content.IndexOf("\"value\":", StringComparison.CurrentCultureIgnoreCase);
81-
if (exceptionMessageIndex > 0)
81+
if (exceptionMessageIndex > 0)
8282
{
8383
string substring = graphEx.Response.Content.Substring(exceptionMessageIndex+9);
8484
// the start index is added 9, so as to remove the delimiter \"value\":\

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

Lines changed: 106 additions & 224 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public static PSADObject ToPSADObject(this AADObject obj)
5959
DisplayName = obj.DisplayName,
6060
Type = obj.ObjectType,
6161
Id = new Guid(obj.ObjectId),
62-
SecurityEnabled = obj.SecurityEnabled
62+
SecurityEnabled = obj.SecurityEnabled,
63+
MailNickname = obj.Mail
6364
};
6465

6566
}
@@ -111,7 +112,8 @@ public static PSADGroup ToPSADGroup(this ADGroup group)
111112
DisplayName = group.DisplayName,
112113
Id = new Guid(group.ObjectId),
113114
SecurityEnabled = group.SecurityEnabled,
114-
Type = group.ObjectType
115+
Type = group.ObjectType,
116+
MailNickname = group.Mail
115117
};
116118
}
117119

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public class PSADCredential
2424

2525
public string KeyId { get; set; }
2626

27-
public string Type { get; set; }
27+
public string Type { get; set; }
2828
}
2929
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ namespace Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory
1717
public class PSADGroup : PSADObject
1818
{
1919
public bool? SecurityEnabled { get; set; }
20+
21+
public string MailNickname { get; set; }
2022
}
2123
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static class ParameterSet
2020

2121
public const string UPN = "UPNParameterSet";
2222

23+
public const string UPNOrObjectId = "UPNOrObjectIdParameterSet";
24+
2325
public const string SPN = "SPNParameterSet";
2426

2527
public const string SignInName = "SignInNameParameterSet";
@@ -28,6 +30,10 @@ public static class ParameterSet
2830

2931
public const string ObjectId = "ObjectIdParameterSet";
3032

33+
public const string GroupObject = "GroupObjectParameterSet";
34+
35+
public const string ServicePrincipalObject = "ServicePrincipalObjectParameterSet";
36+
3137
public const string Scope = "ScopeParameterSet";
3238

3339
public const string ScopeWithSPN = "ScopeWithSPNParameterSet";
@@ -62,10 +68,24 @@ public static class ParameterSet
6268

6369
public const string ApplicationWithKeyCredential = "ApplicationWithKeyCredentialParameterSet";
6470

71+
public const string ApplicationObjectWithoutCredential = "ApplicationObjectWithoutCredentialParameterSet";
72+
73+
public const string ApplicationObjectWithPasswordPlain = "ApplicationObjectWithPasswordPlainParameterSet";
74+
75+
public const string ApplicationObjectWithPasswordCredential = "ApplicationObjectWithPasswordCredentialParameterSet";
76+
77+
public const string ApplicationObjectWithKeyPlain = "ApplicationObjectWithKeyPlainParameterSet";
78+
79+
public const string ApplicationObjectWithKeyCredential = "ApplicationObjectWithKeyCredentialParameterSet";
80+
6581
public const string ApplicationObjectIdWithPassword = "ApplicationObjectIdWithPasswordParameterSet";
6682

6783
public const string ApplicationObjectIdWithCertValue = "ApplicationObjectIdWithCertValueParameterSet";
6884

85+
public const string ApplicationObjectWithPassword = "ApplicationObjectWithPasswordParameterSet";
86+
87+
public const string ApplicationObjectWithCertValue = "ApplicationObjectWithCertValueParameterSet";
88+
6989
public const string ApplicationIdWithPassword = "ApplicationIdWithPasswordParameterSet";
7090

7191
public const string ApplicationIdWithCertValue = "ApplicationIdWithCertValueParameterSet";
@@ -74,6 +94,10 @@ public static class ParameterSet
7494

7595
public const string InputFile = "InputFileParameterSet";
7696

97+
public const string InputObject = "InputObjectParameterSet";
98+
99+
public const string InputObjectWithUpdateParams = "InputObjectWithUpdateParamsParameterSet";
100+
77101
public const string RoleDefinition = "RoleDefinitionParameterSet";
78102

79103
public const string RoleDefinitionName = "RoleDefinitionNameParameterSet";
@@ -86,6 +110,10 @@ public static class ParameterSet
86110

87111
public const string ApplicationObjectId = "ApplicationObjectIdParameterSet";
88112

113+
public const string ApplicationObject = "ApplicationObjectParameterSet";
114+
115+
public const string ApplicationObjectWithKeyId = "ApplicationObjectWithKeyIdParameterSet";
116+
89117
public const string ApplicationId = "ApplicationIdParameterSet";
90118

91119
public const string ApplicationDisplayName = "ApplicationDisplayNameParameterSet";
@@ -108,6 +136,10 @@ public static class ParameterSet
108136

109137
public const string SPNWithPassword = "SPNWithPasswordParameterSet";
110138

139+
public const string ServicePrincipalObjectWithCertValue = "ServicePrincipalObjectWithCertValueParameterSet";
140+
141+
public const string ServicePrincipalObjectWithPassword = "ServicePrincipalObjectWithPasswordParameterSet";
142+
111143
public const string ObjectIdWithKeyId = "ObjectIdWithKeyIdParameterSet";
112144

113145
public const string ObjectIdWithAll = "ObjectIdWithAllParameterSet";
@@ -116,6 +148,8 @@ public static class ParameterSet
116148

117149
public const string SPNWithAll = "SPNWithAllParameterSet";
118150

151+
public const string SPNObject = "SPNObjectParameterSet";
152+
119153
public const string ApplicationObjectIdWithUpdateParams = "ApplicationObjectIdWithUpdateParamsParameterSet";
120154

121155
public const string ApplicationIdWithUpdateParams = "ApplicationIdWithUpdateParamsParameterSet";
@@ -132,8 +166,14 @@ public static class ParameterSet
132166

133167
public const string SpObjectIdWithDisplayName = "SpObjectIdWithDisplayNameParameterSet";
134168

169+
public const string SpApplicationIdWithDisplayName = "SpApplicationIdWithDisplayNameParameterSet";
170+
171+
public const string InputObjectWithDisplayName = "InputObjectWithDisplayNameParameterSet";
172+
135173
public const string SPNWithDisplayName = "SPNWithDisplayNameParameterSet";
136174

137175
public const string RoleAssignment = "RoleAssignmentParameterSet";
176+
177+
public const string Explicit = "ExplicitParameterSet";
138178
}
139179
}

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

Lines changed: 9 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
<data name="ServicePrincipalDoesntExist" xml:space="preserve">
142142
<value>Service principal with object id '{0}' does not exist.</value>
143143
</data>
144+
<data name="ServicePrincipalWithAppIdDoesntExist" xml:space="preserve">
145+
<value>Service principal with AppId '{0}' does not exist.</value>
146+
</data>
144147
<data name="ServicePrincipalWithSPNDoesntExist" xml:space="preserve">
145148
<value>Service principal with SPN '{0}' does not exist.</value>
146149
</data>

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultManagementCmdletBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ private string GetObjectIdBySpn(string spn)
265265
if (!string.IsNullOrWhiteSpace(spn))
266266
{
267267
#if NETSTANDARD
268-
var servicePrincipal = ActiveDirectoryClient.FilterServicePrincipals(new ADObjectFilterOptions() { SPN = spn }).SingleOrDefault();
268+
var odataQuery = new Rest.Azure.OData.ODataQuery<Graph.RBAC.Version1_6.Models.ServicePrincipal>(s => s.ServicePrincipalNames.Contains(spn));
269+
var servicePrincipal = ActiveDirectoryClient.FilterServicePrincipals(odataQuery).SingleOrDefault();
269270
objId = servicePrincipal?.Id.ToString();
270271
#else
271272
var servicePrincipal = ActiveDirectoryClient.ServicePrincipals.Where(s =>

src/ResourceManager/KeyVault/Commands.KeyVault/Models/ModelExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public static string GetDisplayNameForADObject(string objectId, ActiveDirectoryC
113113
}
114114
else if (obj.Type.Equals("serviceprincipal", StringComparison.InvariantCultureIgnoreCase))
115115
{
116-
var servicePrincipal = adClient.FilterServicePrincipals(new ADObjectFilterOptions { Id = objectId }).FirstOrDefault();
116+
var odataQuery = new Rest.Azure.OData.ODataQuery<Graph.RBAC.Version1_6.Models.ServicePrincipal>(s => s.ObjectId == objectId);
117+
var servicePrincipal = adClient.FilterServicePrincipals(odataQuery).FirstOrDefault();
117118
displayName = servicePrincipal.DisplayName;
118119
upnOrSpn = servicePrincipal.ServicePrincipalNames.FirstOrDefault();
119120
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
16+
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
using Microsoft.Azure.Graph.RBAC.Version1_6.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using System;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.ActiveDirectory
23+
{
24+
/// <summary>
25+
/// Adds a user to a group.
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.Add, "AzureRmADGroupMember", SupportsShouldProcess = true, DefaultParameterSetName = ParameterSet.Explicit), OutputType(typeof(bool))]
28+
public class AddAzureADGroupMemberCommand : ActiveDirectoryBaseCmdlet
29+
{
30+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.Explicit, HelpMessage = "The object id of the member.")]
31+
[Parameter(Mandatory = true, ParameterSetName = ParameterSet.GroupObject, HelpMessage = "The object id of the member.")]
32+
[ValidateNotNullOrEmpty]
33+
public Guid MemberObjectId { get; set; }
34+
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.Explicit, HelpMessage = "The object id of the group to add the member to.")]
36+
[ValidateNotNullOrEmpty]
37+
public Guid GroupObjectId { get; set; }
38+
39+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet.GroupObject, HelpMessage = "The object representation of the group to add the member to.")]
40+
[ValidateNotNullOrEmpty]
41+
public PSADGroup GroupObject { get; set; }
42+
43+
[Parameter(Mandatory = true)]
44+
public SwitchParameter PassThru { get; set; }
45+
46+
public override void ExecuteCmdlet()
47+
{
48+
ExecutionBlock(() =>
49+
{
50+
if (this.IsParameterBound(c => GroupObject))
51+
{
52+
GroupObjectId = GroupObject.Id;
53+
}
54+
55+
var groupAddMemberParams = new GroupAddMemberParameters()
56+
{
57+
Url = string.Format("{0}/{1}/directoryObjects/{2}",
58+
AzureEnvironmentConstants.AzureGraphEndpoint,
59+
AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant,
60+
MemberObjectId)
61+
};
62+
63+
if (ShouldProcess(target: MemberObjectId.ToString(), action: string.Format("Adding user with object id '{0}' to group with object id '{1}'.", MemberObjectId, GroupObjectId)))
64+
{
65+
ActiveDirectoryClient.AddGroupMember(GroupObjectId.ToString(), groupAddMemberParams);
66+
}
67+
68+
if (PassThru.IsPresent)
69+
{
70+
WriteObject(true);
71+
}
72+
});
73+
}
74+
}
75+
}

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/GetAzureADAppCredentialCommand.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
17+
using System;
1618
using System.Management.Automation;
1719

1820
namespace Microsoft.Azure.Commands.ActiveDirectory
@@ -25,19 +27,27 @@ public class GetAzureADAppCredentialCommand : ActiveDirectoryBaseCmdlet
2527
{
2628
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationObjectId, HelpMessage = "The application object id.")]
2729
[ValidateNotNullOrEmpty]
28-
public string ObjectId { get; set; }
30+
public Guid ObjectId { get; set; }
2931

3032
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationId, HelpMessage = "The application id.")]
3133
[ValidateNotNullOrEmpty]
32-
public string ApplicationId { get; set; }
34+
public Guid ApplicationId { get; set; }
35+
36+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet.ApplicationObject, HelpMessage = "The application object.")]
37+
[ValidateNotNullOrEmpty]
38+
public PSADApplication ApplicationObject { get; set; }
3339

3440
public override void ExecuteCmdlet()
3541
{
3642
ExecutionBlock(() =>
3743
{
38-
if (!string.IsNullOrEmpty(ApplicationId))
44+
if (this.IsParameterBound(c => c.ApplicationObject))
45+
{
46+
ObjectId = ApplicationObject.ObjectId;
47+
}
48+
else if (this.IsParameterBound(c => c.ApplicationId))
3949
{
40-
ObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(ApplicationId);
50+
ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
4151
}
4252

4353
WriteObject(ActiveDirectoryClient.GetAppCredentials(ObjectId), enumerateCollection: true);

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/GetAzureADApplicationCommand.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
1616
using Microsoft.Azure.Graph.RBAC.Version1_6.Models;
1717
using Microsoft.WindowsAzure.Commands.Common;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1819
using System;
1920
using System.Collections.Generic;
2021
using System.Management.Automation;
@@ -24,7 +25,7 @@ namespace Microsoft.Azure.Commands.ActiveDirectory
2425
/// <summary>
2526
/// Gets the AD application.
2627
/// </summary>
27-
[Cmdlet(VerbsCommon.Get, "AzureRmADApplication", DefaultParameterSetName = ParameterSet.Empty), OutputType(typeof(List<PSADApplication>))]
28+
[Cmdlet(VerbsCommon.Get, "AzureRmADApplication", DefaultParameterSetName = ParameterSet.Empty, SupportsPaging = true), OutputType(typeof(List<PSADApplication>))]
2829
public class GetAzureADApplicationCommand : ActiveDirectoryBaseCmdlet
2930
{
3031
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationObjectId, HelpMessage = "The application object id.")]
@@ -47,29 +48,31 @@ public override void ExecuteCmdlet()
4748
{
4849
ExecutionBlock(() =>
4950
{
50-
if (ObjectId != Guid.Empty)
51+
if (this.IsParameterBound(c => c.ObjectId))
5152
{
52-
WriteObject(ActiveDirectoryClient.GetApplication(ObjectId.ToString()));
53+
WriteObject(ActiveDirectoryClient.GetApplication(ObjectId));
5354
}
5455
else
5556
{
5657
Rest.Azure.OData.ODataQuery<Application> odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>();
5758

58-
if (ApplicationId != Guid.Empty)
59+
if (this.IsParameterBound(c => c.ApplicationId))
5960
{
6061
string appId = ApplicationId.ToString();
6162
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == appId);
6263
}
63-
else if (!string.IsNullOrEmpty(DisplayNameStartWith))
64+
else if (this.IsParameterBound(c => c.DisplayNameStartWith))
6465
{
6566
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.DisplayName.StartsWith(DisplayNameStartWith));
6667
}
67-
else if (!string.IsNullOrEmpty(IdentifierUri))
68+
else if (this.IsParameterBound(c => c.IdentifierUri))
6869
{
6970
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.IdentifierUris.Contains(IdentifierUri));
7071
}
7172

72-
WriteObject(ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter), enumerateCollection: true);
73+
ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue;
74+
ulong skip = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0;
75+
WriteObject(ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter, first, skip), enumerateCollection: true);
7376
}
7477
});
7578
}

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/GetAzureADGroupCommand.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.ActiveDirectory
2222
/// <summary>
2323
/// Get AD groups.
2424
/// </summary>
25-
[Cmdlet(VerbsCommon.Get, "AzureRmADGroup", DefaultParameterSetName = ParameterSet.Empty), OutputType(typeof(List<PSADGroup>))]
25+
[Cmdlet(VerbsCommon.Get, "AzureRmADGroup", DefaultParameterSetName = ParameterSet.Empty, SupportsPaging = true), OutputType(typeof(List<PSADGroup>))]
2626
public class GetAzureADGroupCommand : ActiveDirectoryBaseCmdlet
2727
{
2828
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.SearchString,
@@ -48,11 +48,9 @@ public override void ExecuteCmdlet()
4848
Paging = true
4949
};
5050

51-
do
52-
{
53-
WriteObject(ActiveDirectoryClient.FilterGroups(options), true);
54-
} while (!string.IsNullOrEmpty(options.NextLink));
55-
51+
ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue;
52+
ulong skip = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0;
53+
WriteObject(ActiveDirectoryClient.FilterGroups(options, first, skip), true);
5654
});
5755
}
5856
}

0 commit comments

Comments
 (0)