diff --git a/src/Sql/Sql/ChangeLog.md b/src/Sql/Sql/ChangeLog.md index 4064b2a8c216..07f4eb1b19de 100644 --- a/src/Sql/Sql/ChangeLog.md +++ b/src/Sql/Sql/ChangeLog.md @@ -25,6 +25,8 @@ * Added SyncMemberAzureDatabaseResourceId to `New-AzSqlSyncMember` and `Update-AzSqlSyncMember` * Added Guest user lookup support to Set SQL Server Azure Active Directory Admin cmdlet * Remove IsAzureADOnlyAuthentication parameter from Set-AzSqlServerActiveDirectoryAdministrator as it is not usable. +* Added support for service principal for Set SQL Server Azure Active Directory Admin cmdlet + ## Version 2.6.1 * Enhance performance of: diff --git a/src/Sql/Sql/Properties/Resources.Designer.cs b/src/Sql/Sql/Properties/Resources.Designer.cs index a8e4a79d0fd7..432258fe029f 100644 --- a/src/Sql/Sql/Properties/Resources.Designer.cs +++ b/src/Sql/Sql/Properties/Resources.Designer.cs @@ -61,7 +61,7 @@ internal Resources() { } /// - /// Looks up a localized string similar to Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with application display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADApplication -SearchString "{1}".. + /// Looks up a localized string similar to Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with any service principal display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADServicePrincipal -SearchString "{1}".. /// internal static string ADApplicationDisplayNameMismatch { get { @@ -70,7 +70,7 @@ internal static string ADApplicationDisplayNameMismatch { } /// - /// Looks up a localized string similar to More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}". + /// Looks up a localized string similar to More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or use use Get-AzADServicePrincipal -SearchString "{0}". /// internal static string ADApplicationMoreThanOneFound { get { @@ -88,7 +88,7 @@ internal static string AddingStorageBlobDataContributorRoleForStorageAccountIsFo } /// - /// Looks up a localized string similar to Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the application or object id of the group to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}".. + /// Looks up a localized string similar to Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the service principal or object id of the group to select the correct application. To get the application id use Get-AzADServicePrincipal -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}".. /// internal static string ADDuplicateGroupAndApplicationFound { get { diff --git a/src/Sql/Sql/Properties/Resources.resx b/src/Sql/Sql/Properties/Resources.resx index 9a37cf5d4b1e..0d17cb1076c2 100644 --- a/src/Sql/Sql/Properties/Resources.resx +++ b/src/Sql/Sql/Properties/Resources.resx @@ -127,13 +127,13 @@ More than one Azure Active Directory user with the display name '{0}' was found. Please provide an Azure Active Directory object id to select the correct user. To get the object id use Get-AzADUser -SearchString "{0}" - More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" + More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or use use Get-AzADServicePrincipal -SearchString "{0}" - Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with application display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADApplication -SearchString "{1}". + Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with any service principal display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADServicePrincipal -SearchString "{1}". - Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the application or object id of the group to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}". + Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the service principal or object id of the group to select the correct application. To get the application id use Get-AzADServicePrincipal -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}". Database with name: '{0}' already exists in server '{1}'. diff --git a/src/Sql/Sql/ServerActiveDirectoryAdministrator/Services/AzureSqlServerActiveDirectoryAdministratorAdapter.cs b/src/Sql/Sql/ServerActiveDirectoryAdministrator/Services/AzureSqlServerActiveDirectoryAdministratorAdapter.cs index 87b900f59a45..365a3a02f15f 100644 --- a/src/Sql/Sql/ServerActiveDirectoryAdministrator/Services/AzureSqlServerActiveDirectoryAdministratorAdapter.cs +++ b/src/Sql/Sql/ServerActiveDirectoryAdministrator/Services/AzureSqlServerActiveDirectoryAdministratorAdapter.cs @@ -208,30 +208,30 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa } } - // Lookup for applications - ODataQuery odataQueryFilter; + // Lookup for serviceprincipals + ODataQuery odataQueryFilter; if ((objectId != null && objectId != Guid.Empty)) { var applicationIdString = objectId.ToString(); - odataQueryFilter = new Rest.Azure.OData.ODataQuery(a => a.AppId == applicationIdString); + odataQueryFilter = new Rest.Azure.OData.ODataQuery(a => a.AppId == applicationIdString); } else { - odataQueryFilter = new Rest.Azure.OData.ODataQuery(a => a.DisplayName == displayName); + odataQueryFilter = new Rest.Azure.OData.ODataQuery(a => a.DisplayName == displayName); } - var applicationList = ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter); + var srevicePrincipalList = ActiveDirectoryClient.FilterServicePrincipals(odataQueryFilter); - if (applicationList != null && applicationList.Count() > 1) + if (srevicePrincipalList != null && srevicePrincipalList.Count() > 1) { - // More than one application was found. + // More than one service principal was found. throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADApplicationMoreThanOneFound, displayName)); } - else if (applicationList != null && applicationList.Count() == 1) + else if (srevicePrincipalList != null && srevicePrincipalList.Count() == 1) { // Only one user was found. Get the user display name and object id - PSADApplication app = applicationList.First(); + PSADServicePrincipal app = srevicePrincipalList.First(); if (displayName != null && string.CompareOrdinal(displayName, app.DisplayName) != 0) { @@ -261,7 +261,7 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa }; } - // No group or application was found. Check for a user + // No group or service principal was found. Check for a user filter = new ADObjectFilterOptions() { Id = (objectId != null && objectId != Guid.Empty) ? objectId.ToString() : null,