diff --git a/AzureCP/AuthenticationHelper.cs b/AzureCP/AuthenticationHelper.cs index 8b673d04..fa136cd3 100644 --- a/AzureCP/AuthenticationHelper.cs +++ b/AzureCP/AuthenticationHelper.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.Azure.ActiveDirectory.GraphClient; using Microsoft.IdentityModel.Clients.ActiveDirectory; +using Microsoft.SharePoint.Utilities; namespace azurecp { @@ -38,11 +39,14 @@ public static string GetTokenForApplication(string tenantName, string clientId, /// ActiveDirectoryClient for Application. public static ActiveDirectoryClient GetActiveDirectoryClientAsApplication(string tenantName, string tenantId, string clientId, string clientSecret) { - Uri servicePointUri = new Uri(Constants.ResourceUrl); - Uri serviceRoot = new Uri(servicePointUri, tenantId); - ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, - async () => await AcquireTokenAsyncForApplication(tenantName, clientId, clientSecret)); - return activeDirectoryClient; + using (new SPMonitoredScope(String.Format("[AzureCP] Getting access token for tenant {0} by connecting to '{1}' ", tenantName, Constants.ResourceUrl), 1000)) + { + Uri servicePointUri = new Uri(Constants.ResourceUrl); + Uri serviceRoot = new Uri(servicePointUri, tenantId); + ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, + async () => await AcquireTokenAsyncForApplication(tenantName, clientId, clientSecret)); + return activeDirectoryClient; + } } ///// diff --git a/AzureCP/AzureCP.cs b/AzureCP/AzureCP.cs index eaf7af19..0e122099 100644 --- a/AzureCP/AzureCP.cs +++ b/AzureCP/AzureCP.cs @@ -716,6 +716,9 @@ private List QueryAzureAD(AzureTenant coco, Expression allADResults = new List(); diff --git a/AzureCP/AzureCP.csproj b/AzureCP/AzureCP.csproj index a8ca2478..c2b04149 100644 --- a/AzureCP/AzureCP.csproj +++ b/AzureCP/AzureCP.csproj @@ -89,8 +89,12 @@ - - + + False + + + False + @@ -165,6 +169,6 @@ - "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64\gacutil.exe" /f /i "$(TargetPath)" + "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\gacutil.exe" /f /i "$(TargetPath)" \ No newline at end of file diff --git a/AzureCP/Properties/AssemblyInfo.cs b/AzureCP/Properties/AssemblyInfo.cs index 965080bf..fd3bfeaf 100644 --- a/AzureCP/Properties/AssemblyInfo.cs +++ b/AzureCP/Properties/AssemblyInfo.cs @@ -34,5 +34,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("2.6")] +[assembly: AssemblyFileVersion("2.6.1")] diff --git a/AzureCP/TEMPLATE/ADMIN/AzureCP/AzureCPSettings.aspx.cs b/AzureCP/TEMPLATE/ADMIN/AzureCP/AzureCPSettings.aspx.cs index f97cb1aa..099bb529 100644 --- a/AzureCP/TEMPLATE/ADMIN/AzureCP/AzureCPSettings.aspx.cs +++ b/AzureCP/TEMPLATE/ADMIN/AzureCP/AzureCPSettings.aspx.cs @@ -24,6 +24,7 @@ public partial class AzureCPSettings : LayoutsPageBase string TextErrorNoTrustAssociation = "AzureCP is currently not associated with any TrustedLoginProvider. It is mandatory because it cannot create permission for a trust if it is not associated to it.
Visit http://ldapcp.codeplex.com/ to see how to associate it.
Settings on this page will not be available as long as AzureCP will not associated to a trut."; string TextErrorAzureTenantFieldsMissing = "Some mandatory fields are missing."; string TextErrorTestAzureADConnection = "Unable to connect to Azure tenant
It may be expected if w3wp process of central admin has intentionally no access to Azure.
{0}"; + string TextErrorTestAzureADConnectionTenantNotFound = "Tenant was not found."; string TextConnectionSuccessful = "Connection successful."; string TextErrorNoIdentityClaimType = "The TrustedLoginProvider {0} is set with identity claim type \"{1}\" but it is not in the claims list of AzureCP.
Please visit AzureCP page \"claims mapping\" in Security tab to set it and return to this page afterwards."; string TextErrorPersistedObjectStale = "Modification is cancelled because persisted object was modified since last load of the page. Please refresh the page and try again."; @@ -48,7 +49,7 @@ protected void Page_Load(object sender, EventArgs e) return; } - SPSecurity.RunWithElevatedPrivileges(delegate() + SPSecurity.RunWithElevatedPrivileges(delegate () { // Get SPPersisted Object and create it if it doesn't exist PersistedObject = AzureCPConfig.GetFromConfigDB(); @@ -208,7 +209,7 @@ protected void UpdateTrustConfiguration() void UpdatePersistedObject() { // Update object in database - SPSecurity.RunWithElevatedPrivileges(delegate() + SPSecurity.RunWithElevatedPrivileges(delegate () { this.Web.AllowUnsafeUpdates = true; PersistedObject.Update(); @@ -238,22 +239,22 @@ protected void ValidateAzureTenantConnection() string clientId = this.TxtClientId.Text; string clientSecret = this.TxtClientSecret.Text; + // Get access token activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsApplication(tenantName, tenantId, clientId, clientSecret); - - ITenantDetail tenant = null; - TenantDetail tenantDetail = null; - List tenantsList = activeDirectoryClient.TenantDetails + // Get information on tenant + ITenantDetail tenant = activeDirectoryClient.TenantDetails .Where(tDetail => tDetail.ObjectId.Equals(tenantId)) - .ExecuteAsync().Result.CurrentPage.ToList(); - if (tenantsList.Count > 0) + .ExecuteAsync() + .Result.CurrentPage.FirstOrDefault(); + if (tenant != null) { - tenant = tenantsList.First(); - tenantDetail = (TenantDetail)tenant; + this.LabelTestTenantConnectionOK.Text = TextConnectionSuccessful; + this.LabelTestTenantConnectionOK.Text += "
" + tenant.DisplayName; + } + else + { + this.LabelErrorTestLdapConnection.Text = TextErrorTestAzureADConnectionTenantNotFound = "Tenant was not found."; } - - this.LabelTestTenantConnectionOK.Text = TextConnectionSuccessful; - this.LabelTestTenantConnectionOK.Text += "
" + tenantDetail.DisplayName; - activeDirectoryClient = null; } catch (AuthenticationException ex)