14
14
15
15
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
16
16
using Microsoft . Azure . Commands . Sql . ServerActiveDirectoryAdministrator . Model ;
17
- using Microsoft . Azure . Commands . Sql . Services ;
18
- using Microsoft . Azure . Management . Sql . LegacySdk . Models ;
17
+ using Microsoft . Azure . Management . Sql . Models ;
19
18
using Microsoft . Azure . Graph . RBAC . Version1_6 . ActiveDirectory ;
20
19
using System ;
21
20
using System . Collections . Generic ;
@@ -113,10 +112,7 @@ internal ICollection<AzureSqlServerActiveDirectoryAdministratorModel> ListServer
113
112
/// <returns>The upserted Azure SQL Server Active Directory administrator</returns>
114
113
internal AzureSqlServerActiveDirectoryAdministratorModel UpsertServerActiveDirectoryAdministrator ( string resourceGroup , string serverName , AzureSqlServerActiveDirectoryAdministratorModel model )
115
114
{
116
- var resp = Communicator . CreateOrUpdate ( resourceGroup , serverName , new ServerAdministratorCreateOrUpdateParameters ( )
117
- {
118
- Properties = GetActiveDirectoryInformation ( model . DisplayName , model . ObjectId )
119
- } ) ;
115
+ var resp = Communicator . CreateOrUpdate ( resourceGroup , serverName , GetActiveDirectoryInformation ( model . DisplayName , model . ObjectId , model . IsAzureADOnlyAuthentication ) ) ;
120
116
121
117
return CreateServerActiveDirectoryAdministratorModelFromResponse ( resourceGroup , serverName , resp ) ;
122
118
}
@@ -131,40 +127,59 @@ public void RemoveServerActiveDirectoryAdministrator(string resourceGroupName, s
131
127
Communicator . Remove ( resourceGroupName , serverName ) ;
132
128
}
133
129
130
+ /// <summary>
131
+ /// Disable Azure Active Directory only authentication on a Azure SQL Server
132
+ /// </summary>
133
+ /// <param name="resourceGroup">The name of the resource group</param>
134
+ /// <param name="serverName">The name of the Azure Sql ServerActiveDirectoryAdministrator Server</param>
135
+ /// <returns>The upserted Azure SQL Server Active Directory administrator</returns>
136
+ internal AzureSqlServerActiveDirectoryAdministratorModel DisableAzureADOnlyAuthenticaion ( string resourceGroup , string serverName )
137
+ {
138
+ var resp = Communicator . Disable ( resourceGroup , serverName ) ;
139
+
140
+ return CreateServerActiveDirectoryAdministratorModelFromResponse ( resourceGroup , serverName , resp ) ;
141
+ }
142
+
134
143
/// <summary>
135
144
/// Converts the response from the service to a powershell database object
136
145
/// </summary>
137
146
/// <param name="resourceGroupName">The resource group the server is in</param>
138
147
/// <param name="serverName">The name of the Azure Sql ServerActiveDirectoryAdministrator Server</param>
139
148
/// <param name="admin">The service response</param>
140
149
/// <returns>The converted model</returns>
141
- public static AzureSqlServerActiveDirectoryAdministratorModel CreateServerActiveDirectoryAdministratorModelFromResponse ( string resourceGroup , string serverName , Management . Sql . LegacySdk . Models . ServerAdministrator admin )
150
+ public static AzureSqlServerActiveDirectoryAdministratorModel CreateServerActiveDirectoryAdministratorModelFromResponse ( string resourceGroup , string serverName , Management . Sql . Models . ServerAzureADAdministrator admin )
142
151
{
143
- AzureSqlServerActiveDirectoryAdministratorModel model = new AzureSqlServerActiveDirectoryAdministratorModel ( ) ;
144
-
145
- model . ResourceGroupName = resourceGroup ;
146
- model . ServerName = serverName ;
147
- model . DisplayName = admin . Properties . Login ;
148
- model . ObjectId = admin . Properties . Sid ;
152
+ if ( admin != null )
153
+ {
154
+ AzureSqlServerActiveDirectoryAdministratorModel model = new AzureSqlServerActiveDirectoryAdministratorModel ( ) ;
155
+
156
+ model . ResourceGroupName = resourceGroup ;
157
+ model . ServerName = serverName ;
158
+ model . DisplayName = admin . Login ;
159
+ model . ObjectId = admin . Sid ;
160
+ model . IsAzureADOnlyAuthentication = admin . AzureADOnlyAuthentication ;
161
+ return model ;
162
+ }
149
163
150
- return model ;
164
+ return null ;
151
165
}
152
166
153
167
/// <summary>
154
168
/// Verifies that the Azure Active Directory user or group exists, and will get the object id if it is not set.
155
169
/// </summary>
156
170
/// <param name="displayName">Azure Active Directory user or group display name</param>
157
171
/// <param name="objectId">Azure Active Directory user or group object id</param>
172
+ /// <param name="isAzureADOnlyAuthentication">Allow only Azure Active Directory authentication</param>
158
173
/// <returns></returns>
159
- protected ServerAdministratorCreateOrUpdateProperties GetActiveDirectoryInformation ( string displayName , Guid objectId )
174
+ protected ServerAzureADAdministrator GetActiveDirectoryInformation ( string displayName , Guid objectId , bool ? isAzureADOnlyAuthentication )
160
175
{
161
176
// Gets the default Tenant id for the subscriptions
162
177
Guid tenantId = GetTenantId ( ) ;
163
178
164
179
// Check for a Azure Active Directory group. Recommended to always use group.
165
180
IEnumerable < PSADGroup > groupList = null ;
166
181
167
- var filter = new ADObjectFilterOptions ( )
182
+ var filter = new ADObjectFilterOptions ( )
168
183
{
169
184
Id = ( objectId != null && objectId != Guid . Empty ) ? objectId . ToString ( ) : null ,
170
185
SearchString = displayName ,
@@ -190,11 +205,13 @@ protected ServerAdministratorCreateOrUpdateProperties GetActiveDirectoryInformat
190
205
throw new ArgumentException ( string . Format ( Microsoft . Azure . Commands . Sql . Properties . Resources . InvalidADGroupNotSecurity , displayName ) ) ;
191
206
}
192
207
193
- return new ServerAdministratorCreateOrUpdateProperties ( )
208
+
209
+ return new ServerAzureADAdministrator ( )
194
210
{
195
211
Login = group . DisplayName ,
196
212
Sid = group . Id ,
197
213
TenantId = tenantId ,
214
+ AzureADOnlyAuthentication = isAzureADOnlyAuthentication ,
198
215
} ;
199
216
}
200
217
@@ -238,11 +255,12 @@ protected ServerAdministratorCreateOrUpdateProperties GetActiveDirectoryInformat
238
255
// Only one user was found. Get the user display name and object id
239
256
var obj = userList . First ( ) ;
240
257
241
- return new ServerAdministratorCreateOrUpdateProperties ( )
258
+ return new ServerAzureADAdministrator ( )
242
259
{
243
260
Login = displayName ,
244
261
Sid = obj . Id ,
245
262
TenantId = tenantId ,
263
+ AzureADOnlyAuthentication = isAzureADOnlyAuthentication ,
246
264
} ;
247
265
}
248
266
}
0 commit comments