Skip to content

Commit fc0e0df

Browse files
committed
Merge pull request #284 from Azure/dev
.
2 parents 10e6ff4 + 08914d0 commit fc0e0df

File tree

17 files changed

+589
-25
lines changed

17 files changed

+589
-25
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Commands.KeyVault.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
6666
</Reference>
6767
<Reference Include="Microsoft.Azure.Graph.RBAC">
68-
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
68+
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7171
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/KeyVault/Commands.KeyVault/Commands.KeyVault.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
125125
</Reference>
126126
<Reference Include="Microsoft.Azure.Graph.RBAC">
127-
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
127+
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
128128
</Reference>
129129
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
130130
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Graph.RBAC">
6464
<SpecificVersion>False</SpecificVersion>
65-
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.2-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
65+
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6666
</Reference>
6767
<Reference Include="Microsoft.Azure.Insights">
6868
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.7.7-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,29 @@ function Test-NewADApplication
467467

468468
# Assert
469469
Assert-NotNull $application
470+
471+
# Get Application by ApplicationObjectId
472+
$app1 = Get-AzureRmADApplication -ApplicationObjectId $application.ApplicationObjectId
473+
Assert-NotNull $app1
474+
Assert-AreEqual $app1.Count 1
475+
476+
# Get Application by ApplicationId
477+
$app1 = Get-AzureRmADApplication -ApplicationId $application.ApplicationId
478+
Assert-NotNull $app1
479+
Assert-AreEqual $app1.Count 1
480+
481+
# Get Application by IdentifierUri
482+
$app1 = Get-AzureRmADApplication -IdentifierUri $application.IdentifierUris[0]
483+
Assert-NotNull $app1
484+
Assert-AreEqual $app1.Count 1
485+
486+
# Get Application by DisplayName
487+
$app1 = Get-AzureRmADApplication -DisplayNameStartWith $application.DisplayName
488+
Assert-NotNull $app1
489+
Assert-True { $app1.Count -ge 1}
490+
491+
# Delete
492+
Remove-AzureRmADApplication -ApplicationObjectId $application.ApplicationObjectId -Force
470493
}
471494

472495
<#

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests/TestNewADApplication.json

Lines changed: 396 additions & 15 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.Azure.Common.Authentication" version="1.5.1-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.2-preview" targetFramework="net45" />
8+
<package id="Microsoft.Azure.Graph.RBAC" version="1.8.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Insights" version="0.7.7-preview" targetFramework="net45" />
1010
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Authorization" version="1.1.0" targetFramework="net45" />
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.ActiveDirectory.Models;
16+
using Microsoft.Azure.Commands.Resources.Models.ActiveDirectory;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System;
20+
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
21+
using Microsoft.WindowsAzure.Commands.Common;
22+
using Microsoft.Azure.Graph.RBAC.Models;
23+
24+
namespace Microsoft.Azure.Commands.ActiveDirectory
25+
{
26+
/// <summary>
27+
/// Gets the AD application.
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureRmADApplication", DefaultParameterSetName = ParameterSet.Empty), OutputType(typeof(List<PSADApplication>))]
30+
public class GetAzureADApplicationCommand : ActiveDirectoryBaseCmdlet
31+
{
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationObjectId, HelpMessage = "The application object id.")]
33+
[ValidateGuidNotEmpty]
34+
public Guid ApplicationObjectId { get; set; }
35+
36+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationId, HelpMessage = "The application id.")]
37+
[ValidateGuidNotEmpty]
38+
public Guid ApplicationId { get; set; }
39+
40+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationDisplayName, HelpMessage = "The display name.")]
41+
[ValidateNotNullOrEmpty]
42+
public string DisplayNameStartWith { get; set; }
43+
44+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationIdentifierUri, HelpMessage = "The identifierUri of the application.")]
45+
[ValidateNotNullOrEmpty]
46+
public string IdentifierUri { get; set; }
47+
48+
public override void ExecuteCmdlet()
49+
{
50+
if (ApplicationObjectId != Guid.Empty)
51+
{
52+
WriteObject(ActiveDirectoryClient.GetApplication(ApplicationObjectId.ToString()));
53+
}
54+
else
55+
{
56+
ApplicationFilterParameters parameters = new ApplicationFilterParameters();
57+
if (ApplicationId != Guid.Empty)
58+
{
59+
parameters.AppId = ApplicationId;
60+
}
61+
else if (!string.IsNullOrEmpty(DisplayNameStartWith))
62+
{
63+
parameters.DisplayNameStartsWith = DisplayNameStartWith;
64+
}
65+
else if (!string.IsNullOrEmpty(IdentifierUri))
66+
{
67+
parameters.IdentifierUri = IdentifierUri;
68+
}
69+
70+
WriteObject(ActiveDirectoryClient.GetApplicationWithFilters(parameters), enumerateCollection: true);
71+
}
72+
}
73+
}
74+
}

src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</Reference>
6767
<Reference Include="Microsoft.Azure.Graph.RBAC">
6868
<SpecificVersion>False</SpecificVersion>
69-
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.2-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
69+
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
7070
</Reference>
7171
<Reference Include="Microsoft.Azure.Management.Authorization">
7272
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
@@ -133,6 +133,7 @@
133133
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
134134
</ItemGroup>
135135
<ItemGroup>
136+
<Compile Include="ActiveDirectory\GetAzureADApplicationCommand.cs" />
136137
<Compile Include="ActiveDirectory\GetAzureADGroupMemberCommand.cs" />
137138
<Compile Include="ActiveDirectory\GetAzureADGroupCommand.cs" />
138139
<Compile Include="ActiveDirectory\GetAzureADServicePrincipalCommand.cs" />

src/ResourceManager/Resources/Commands.Resources/Models.ActiveDirectory/ActiveDirectoryClient.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Hyak.Common;
1516
using Microsoft.Azure.Common.Authentication;
1617
using Microsoft.Azure.Common.Authentication.Models;
1718
using Microsoft.Azure.Graph.RBAC;
@@ -20,6 +21,7 @@
2021
using System.Collections.Generic;
2122
using System.Diagnostics;
2223
using System.Linq;
24+
using System.Net;
2325
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
2426

2527
namespace Microsoft.Azure.Commands.Resources.Models.ActiveDirectory
@@ -371,14 +373,40 @@ public PSADApplication CreateApplication(CreatePSApplicationParameters createPar
371373
KeyCredentials = keyCredentials
372374
};
373375

374-
return GraphClient.Application.Create(graphParameters).Application.ToPSADApplication();
376+
try
377+
{
378+
return GraphClient.Application.Create(graphParameters).Application.ToPSADApplication();
379+
}
380+
catch (CloudException ce)
381+
{
382+
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
383+
{
384+
GetCurrentUserResult currentUser = GraphClient.Objects.GetCurrentUser();
385+
if (currentUser.AADObject != null && string.Equals(currentUser.AADObject.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
386+
{
387+
throw new InvalidOperationException(ProjectResources.CreateApplicationNotAllowedGuestUser);
388+
}
389+
}
390+
391+
throw;
392+
}
375393
}
376394

377395
public void RemoveApplication(string applicationObjectId)
378396
{
379397
GraphClient.Application.Delete(applicationObjectId.ToString());
380398
}
381399

400+
public PSADApplication GetApplication(string applicationObjectId)
401+
{
402+
return GraphClient.Application.Get(applicationObjectId.ToString()).Application.ToPSADApplication();
403+
}
404+
405+
public IEnumerable<PSADApplication> GetApplicationWithFilters(ApplicationFilterParameters parameters)
406+
{
407+
return GraphClient.Application.List(parameters).Applications.Select(a => a.ToPSADApplication());
408+
}
409+
382410
public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParameters createParameters)
383411
{
384412
ServicePrincipalCreateParameters graphParameters = new ServicePrincipalCreateParameters
@@ -387,7 +415,23 @@ public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParam
387415
AccountEnabled = createParameters.AccountEnabled
388416
};
389417

390-
return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
418+
try
419+
{
420+
return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
421+
}
422+
catch (CloudException ce)
423+
{
424+
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
425+
{
426+
GetCurrentUserResult currentUser = GraphClient.Objects.GetCurrentUser();
427+
if (currentUser.AADObject != null && string.Equals(currentUser.AADObject.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
428+
{
429+
throw new InvalidOperationException(ProjectResources.CreateServicePrincipalNotAllowedGuestUser);
430+
}
431+
}
432+
433+
throw;
434+
}
391435
}
392436

393437
public PSADServicePrincipal RemoveServicePrincipal(string objectId)

src/ResourceManager/Resources/Commands.Resources/Models.ActiveDirectory/ActiveDirectoryClientExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public static PSADApplication ToPSADApplication(this Application application)
140140
ApplicationObjectId = Guid.Parse(application.ObjectId),
141141
Type = application.ObjectType,
142142
ApplicationId = Guid.Parse(application.AppId),
143+
IdentifierUris = application.IdentifierUris,
144+
DisplayName= application.DisplayName,
145+
ReplyUrls = application.ReplyUrls,
143146
AppPermissions = application.AppPermissions,
144147
AvailableToOtherTenants = application.AvailableToOtherTenants
145148
};

src/ResourceManager/Resources/Commands.Resources/Models.ActiveDirectory/PSADApplication.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace Microsoft.Azure.Commands.Resources.Models.ActiveDirectory
1919
{
2020
public class PSADApplication
2121
{
22+
public string DisplayName { get; set; }
23+
2224
public string Type { get; set; }
2325

2426
public Guid ApplicationId { get; set; }
@@ -28,5 +30,9 @@ public class PSADApplication
2830
public bool AvailableToOtherTenants { get; set; }
2931

3032
public IList<string> AppPermissions { get; set; }
33+
34+
public IList<string> IdentifierUris { get; set; }
35+
36+
public IList<string> ReplyUrls { get; set; }
3137
}
3238
}

src/ResourceManager/Resources/Commands.Resources/Models.ActiveDirectory/ParameterSet.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,13 @@ internal static class ParameterSet
7575
public const string RoleIdWithScopeAndObjectId = "RoleIdWithScopeAndObjectIdParameterSet";
7676

7777
public const string RoleDefinitionCustom = "RoleDefinitionCustomParameterSet";
78+
79+
public const string ApplicationObjectId = "ApplicationObjectIdParameterSet";
80+
81+
public const string ApplicationId = "ApplicationIdParameterSet";
82+
83+
public const string ApplicationDisplayName = "ApplicationDisplayNameParameterSet";
84+
85+
public const string ApplicationIdentifierUri = "ApplicationIdentifierUriParameterSet";
7886
}
7987
}

src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs

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

src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,10 @@
339339
<data name="RemoveRoleDefinitionWithName" xml:space="preserve">
340340
<value>Are you sure you want to remove role definition with name '{0}'.</value>
341341
</data>
342+
<data name="CreateApplicationNotAllowedGuestUser" xml:space="preserve">
343+
<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>
344+
</data>
345+
<data name="CreateServicePrincipalNotAllowedGuestUser" xml:space="preserve">
346+
<value>You are a guest user in the directory and are not allowed to create a service principal. Please contact the administrator of the directory.</value>
347+
</data>
342348
</root>

src/ResourceManager/Resources/Commands.Resources/RoleDefinitions/GetAzureRoleDefinitionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Resources
2828
[Cmdlet(VerbsCommon.Get, "AzureRmRoleDefinition"), OutputType(typeof(List<PSRoleDefinition>))]
2929
public class GetAzureRoleDefinitionCommand : ResourcesBaseCmdlet
3030
{
31-
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName, HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
31+
[Parameter(Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName, HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
3232
[ValidateNotNullOrEmpty]
3333
public string Name { get; set; }
3434

src/ResourceManager/Resources/Commands.Resources/RoleDefinitions/RemoveAzureRoleDefinitionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RemoveAzureRoleDefinitionCommand : ResourcesBaseCmdlet
3333
[ValidateGuidNotEmpty]
3434
public Guid Id { get; set; }
3535

36-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName,
36+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName,
3737
HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
3838
[ValidateNotNullOrEmpty]
3939
public string Name { get; set; }

src/ResourceManager/Resources/Commands.Resources/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.Azure.Common.Authentication" version="1.5.1-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.2-preview" targetFramework="net45" />
8+
<package id="Microsoft.Azure.Graph.RBAC" version="1.8.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
1111
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />

0 commit comments

Comments
 (0)