Skip to content

Commit 320f759

Browse files
authored
[SQL] Add support for service principals for setting SQL AAD Admin. (#12140)
* Allow Azure Active Directory applications to be set as SQL Server Azure Active Directory admin. * Remove IsAzureADOnlyAuthenticaion option from SetAzureSqlServerActiveDirectoryAdministrator command. We will be adding a new API to enable this option. * Update ChangeLog.md * Add Static analysis exception to exceptions file. * add support for service principal for set aad admin. Co-authored-by: Amol Agarwal <[email protected]>
1 parent cc92ebb commit 320f759

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/Sql/Sql/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* Added SyncMemberAzureDatabaseResourceId to `New-AzSqlSyncMember` and `Update-AzSqlSyncMember`
2626
* Added Guest user lookup support to Set SQL Server Azure Active Directory Admin cmdlet
2727
* Remove IsAzureADOnlyAuthentication parameter from Set-AzSqlServerActiveDirectoryAdministrator as it is not usable.
28+
* Added support for service principal for Set SQL Server Azure Active Directory Admin cmdlet
29+
2830

2931
## Version 2.6.1
3032
* Enhance performance of:

src/Sql/Sql/Properties/Resources.Designer.cs

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

src/Sql/Sql/Properties/Resources.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@
127127
<value>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}"</value>
128128
</data>
129129
<data name="ADApplicationMoreThanOneFound" xml:space="preserve">
130-
<value>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}"</value>
130+
<value>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}"</value>
131131
</data>
132132
<data name="ADApplicationDisplayNameMismatch" xml:space="preserve">
133-
<value>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}".</value>
133+
<value>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}".</value>
134134
</data>
135135
<data name="ADDuplicateGroupAndApplicationFound" xml:space="preserve">
136-
<value>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}".</value>
136+
<value>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}".</value>
137137
</data>
138138
<data name="DatabaseNameExists" xml:space="preserve">
139139
<value>Database with name: '{0}' already exists in server '{1}'.</value>

src/Sql/Sql/ServerActiveDirectoryAdministrator/Services/AzureSqlServerActiveDirectoryAdministratorAdapter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,30 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
208208
}
209209
}
210210

211-
// Lookup for applications
212-
ODataQuery<Application> odataQueryFilter;
211+
// Lookup for serviceprincipals
212+
ODataQuery<ServicePrincipal> odataQueryFilter;
213213

214214
if ((objectId != null && objectId != Guid.Empty))
215215
{
216216
var applicationIdString = objectId.ToString();
217-
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == applicationIdString);
217+
odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(a => a.AppId == applicationIdString);
218218
}
219219
else
220220
{
221-
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.DisplayName == displayName);
221+
odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(a => a.DisplayName == displayName);
222222
}
223223

224-
var applicationList = ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter);
224+
var srevicePrincipalList = ActiveDirectoryClient.FilterServicePrincipals(odataQueryFilter);
225225

226-
if (applicationList != null && applicationList.Count() > 1)
226+
if (srevicePrincipalList != null && srevicePrincipalList.Count() > 1)
227227
{
228-
// More than one application was found.
228+
// More than one service principal was found.
229229
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADApplicationMoreThanOneFound, displayName));
230230
}
231-
else if (applicationList != null && applicationList.Count() == 1)
231+
else if (srevicePrincipalList != null && srevicePrincipalList.Count() == 1)
232232
{
233233
// Only one user was found. Get the user display name and object id
234-
PSADApplication app = applicationList.First();
234+
PSADServicePrincipal app = srevicePrincipalList.First();
235235

236236
if (displayName != null && string.CompareOrdinal(displayName, app.DisplayName) != 0)
237237
{
@@ -261,7 +261,7 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
261261
};
262262
}
263263

264-
// No group or application was found. Check for a user
264+
// No group or service principal was found. Check for a user
265265
filter = new ADObjectFilterOptions()
266266
{
267267
Id = (objectId != null && objectId != Guid.Empty) ? objectId.ToString() : null,

0 commit comments

Comments
 (0)