Skip to content

. #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 31, 2015
Merged

. #284

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.2-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Insights">
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.7.7-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,29 @@ function Test-NewADApplication

# Assert
Assert-NotNull $application

# Get Application by ApplicationObjectId
$app1 = Get-AzureRmADApplication -ApplicationObjectId $application.ApplicationObjectId
Assert-NotNull $app1
Assert-AreEqual $app1.Count 1

# Get Application by ApplicationId
$app1 = Get-AzureRmADApplication -ApplicationId $application.ApplicationId
Assert-NotNull $app1
Assert-AreEqual $app1.Count 1

# Get Application by IdentifierUri
$app1 = Get-AzureRmADApplication -IdentifierUri $application.IdentifierUris[0]
Assert-NotNull $app1
Assert-AreEqual $app1.Count 1

# Get Application by DisplayName
$app1 = Get-AzureRmADApplication -DisplayNameStartWith $application.DisplayName
Assert-NotNull $app1
Assert-True { $app1.Count -ge 1}

# Delete
Remove-AzureRmADApplication -ApplicationObjectId $application.ApplicationObjectId -Force
}

<#
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Microsoft.Azure.Common.Authentication" version="1.5.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Graph.RBAC" version="1.8.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Insights" version="0.7.7-preview" targetFramework="net45" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="1.1.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ActiveDirectory.Models;
using Microsoft.Azure.Commands.Resources.Models.ActiveDirectory;
using System.Collections.Generic;
using System.Management.Automation;
using System;
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.Azure.Graph.RBAC.Models;

namespace Microsoft.Azure.Commands.ActiveDirectory
{
/// <summary>
/// Gets the AD application.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureRmADApplication", DefaultParameterSetName = ParameterSet.Empty), OutputType(typeof(List<PSADApplication>))]
public class GetAzureADApplicationCommand : ActiveDirectoryBaseCmdlet
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationObjectId, HelpMessage = "The application object id.")]
[ValidateGuidNotEmpty]
public Guid ApplicationObjectId { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationId, HelpMessage = "The application id.")]
[ValidateGuidNotEmpty]
public Guid ApplicationId { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationDisplayName, HelpMessage = "The display name.")]
[ValidateNotNullOrEmpty]
public string DisplayNameStartWith { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationIdentifierUri, HelpMessage = "The identifierUri of the application.")]
[ValidateNotNullOrEmpty]
public string IdentifierUri { get; set; }

public override void ExecuteCmdlet()
{
if (ApplicationObjectId != Guid.Empty)
{
WriteObject(ActiveDirectoryClient.GetApplication(ApplicationObjectId.ToString()));
}
else
{
ApplicationFilterParameters parameters = new ApplicationFilterParameters();
if (ApplicationId != Guid.Empty)
{
parameters.AppId = ApplicationId;
}
else if (!string.IsNullOrEmpty(DisplayNameStartWith))
{
parameters.DisplayNameStartsWith = DisplayNameStartWith;
}
else if (!string.IsNullOrEmpty(IdentifierUri))
{
parameters.IdentifierUri = IdentifierUri;
}

WriteObject(ActiveDirectoryClient.GetApplicationWithFilters(parameters), enumerateCollection: true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.2-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.8.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Authorization">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
Expand Down Expand Up @@ -133,6 +133,7 @@
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveDirectory\GetAzureADApplicationCommand.cs" />
<Compile Include="ActiveDirectory\GetAzureADGroupMemberCommand.cs" />
<Compile Include="ActiveDirectory\GetAzureADGroupCommand.cs" />
<Compile Include="ActiveDirectory\GetAzureADServicePrincipalCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Hyak.Common;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.Azure.Graph.RBAC;
Expand All @@ -20,6 +21,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;

namespace Microsoft.Azure.Commands.Resources.Models.ActiveDirectory
Expand Down Expand Up @@ -371,14 +373,40 @@ public PSADApplication CreateApplication(CreatePSApplicationParameters createPar
KeyCredentials = keyCredentials
};

return GraphClient.Application.Create(graphParameters).Application.ToPSADApplication();
try
{
return GraphClient.Application.Create(graphParameters).Application.ToPSADApplication();
}
catch (CloudException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
{
GetCurrentUserResult currentUser = GraphClient.Objects.GetCurrentUser();
if (currentUser.AADObject != null && string.Equals(currentUser.AADObject.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
{
throw new InvalidOperationException(ProjectResources.CreateApplicationNotAllowedGuestUser);
}
}

throw;
}
}

public void RemoveApplication(string applicationObjectId)
{
GraphClient.Application.Delete(applicationObjectId.ToString());
}

public PSADApplication GetApplication(string applicationObjectId)
{
return GraphClient.Application.Get(applicationObjectId.ToString()).Application.ToPSADApplication();
}

public IEnumerable<PSADApplication> GetApplicationWithFilters(ApplicationFilterParameters parameters)
{
return GraphClient.Application.List(parameters).Applications.Select(a => a.ToPSADApplication());
}

public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParameters createParameters)
{
ServicePrincipalCreateParameters graphParameters = new ServicePrincipalCreateParameters
Expand All @@ -387,7 +415,23 @@ public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParam
AccountEnabled = createParameters.AccountEnabled
};

return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
try
{
return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
}
catch (CloudException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
{
GetCurrentUserResult currentUser = GraphClient.Objects.GetCurrentUser();
if (currentUser.AADObject != null && string.Equals(currentUser.AADObject.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
{
throw new InvalidOperationException(ProjectResources.CreateServicePrincipalNotAllowedGuestUser);
}
}

throw;
}
}

public PSADServicePrincipal RemoveServicePrincipal(string objectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public static PSADApplication ToPSADApplication(this Application application)
ApplicationObjectId = Guid.Parse(application.ObjectId),
Type = application.ObjectType,
ApplicationId = Guid.Parse(application.AppId),
IdentifierUris = application.IdentifierUris,
DisplayName= application.DisplayName,
ReplyUrls = application.ReplyUrls,
AppPermissions = application.AppPermissions,
AvailableToOtherTenants = application.AvailableToOtherTenants
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Microsoft.Azure.Commands.Resources.Models.ActiveDirectory
{
public class PSADApplication
{
public string DisplayName { get; set; }

public string Type { get; set; }

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

public IList<string> AppPermissions { get; set; }

public IList<string> IdentifierUris { get; set; }

public IList<string> ReplyUrls { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@ internal static class ParameterSet
public const string RoleIdWithScopeAndObjectId = "RoleIdWithScopeAndObjectIdParameterSet";

public const string RoleDefinitionCustom = "RoleDefinitionCustomParameterSet";

public const string ApplicationObjectId = "ApplicationObjectIdParameterSet";

public const string ApplicationId = "ApplicationIdParameterSet";

public const string ApplicationDisplayName = "ApplicationDisplayNameParameterSet";

public const string ApplicationIdentifierUri = "ApplicationIdentifierUriParameterSet";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,10 @@
<data name="RemoveRoleDefinitionWithName" xml:space="preserve">
<value>Are you sure you want to remove role definition with name '{0}'.</value>
</data>
<data name="CreateApplicationNotAllowedGuestUser" xml:space="preserve">
<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>
</data>
<data name="CreateServicePrincipalNotAllowedGuestUser" xml:space="preserve">
<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>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Resources
[Cmdlet(VerbsCommon.Get, "AzureRmRoleDefinition"), OutputType(typeof(List<PSRoleDefinition>))]
public class GetAzureRoleDefinitionCommand : ResourcesBaseCmdlet
{
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName, HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
[Parameter(Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName, HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RemoveAzureRoleDefinitionCommand : ResourcesBaseCmdlet
[ValidateGuidNotEmpty]
public Guid Id { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName,
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName,
HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Microsoft.Azure.Common.Authentication" version="1.5.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Graph.RBAC" version="1.8.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
Expand Down