From c3ed01b6c75c44cfeca650b43deb058b1551a9bb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 19 Dec 2018 14:52:54 +0200 Subject: Moved machine studio update azure !!! --- .../Update/MachineStudioUpdateService.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs new file mode 100644 index 000000000..aae1fe70d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Update +{ + public class MachineStudioUpdateService : IMachineStudioUpdateService + { + private string address; + private WebTransportClient _client; + + public MachineStudioUpdateService() + { + address = SettingsManager.Default.GetOrCreate().MachineServiceAddress + "/api/MachineStudio/"; + _client = new WebTransportClient(); + } + + public Task CheckForUpdates(CheckForUpdatesRequest request) + { + return _client.PostJson(address + "CheckForUpdates", request); + } + + public Task UploadVersion(UploadVersionRequest request) + { + return _client.PostJson(address + "UploadVersion", request); + } + + public Task NotifyUploadCompleted(UploadCompletedRequest request) + { + return _client.PostJson(address + "NotifyUploadCompleted", request); + } + + public Task GetLatestVersion(LatestVersionRequest request) + { + return _client.PostJson(address + "GetLatestVersion", request); + } + } +} -- cgit v1.3.1 From 9e42e1c87f3a206f0babc74760ac9a02d8d328f4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 27 Dec 2018 15:14:10 +0200 Subject: Implemented Deployment Slots! Implemented Environment AD Groups. Implemented Machine Studio environment selection. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Tango.MachineStudio.Common/DeploymentSlots.cs | 21 +++++++ .../MachineStudioSettings.cs | 22 +++++-- .../Tango.MachineStudio.Common.csproj | 1 + .../Update/MachineStudioUpdateService.cs | 2 +- .../DefaultAuthenticationProvider.cs | 13 +--- .../ViewModels/LoginViewVM.cs | 18 +++++- .../Tango.MachineStudio.UI/Views/LoginView.xaml | 8 ++- .../Visual_Studio/Tango.Editors/EnumExtensions.cs | 30 +++++----- .../ActiveDirectory/ActiveDirectoryManager.cs | 66 +++++++++++++++++++++ Software/Visual_Studio/Tango.Web/DeploymentSlot.cs | 21 +++++++ .../Tango.Web/Helpers/AzureDirectoryHelper.cs | 19 ------ Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 19 +++++- Software/Visual_Studio/Tango.Web/WebConfig.cs | 39 +++++++++++- Software/Visual_Studio/Tango.Web/app.config | 31 ++++++++++ Software/Visual_Studio/Tango.Web/packages.config | 5 ++ .../Controllers/MachineStudioController.cs | 32 +++++++++- .../Properties/PublishProfiles/Development.pubxml | 28 +++++++++ .../MachineService - Web Deploy.pubxml | 28 --------- .../Properties/PublishProfiles/Production.pubxml | 28 +++++++++ .../Properties/PublishProfiles/Testing.pubxml | 28 +++++++++ .../Tango.MachineService.csproj | 4 +- .../Web/Tango.MachineService/Web.config | 15 +++++ 24 files changed, 389 insertions(+), 89 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/DeploymentSlots.cs create mode 100644 Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs create mode 100644 Software/Visual_Studio/Tango.Web/DeploymentSlot.cs delete mode 100644 Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs create mode 100644 Software/Visual_Studio/Tango.Web/app.config create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 4e3d0ff71..4d95d4af0 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 0ab7d6108..09bd3ccb1 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/DeploymentSlots.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/DeploymentSlots.cs new file mode 100644 index 000000000..857f1e5ba --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/DeploymentSlots.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common +{ + public enum DeploymentSlots + { + [Description("https://machineservice-dev.twine-srv.com")] + Development, + [Description("https://machineservice-test.twine-srv.com")] + Testing, + [Description("https://machineservice-stage.twine-srv.com")] + Staging, + [Description("https://machineservice.twine-srv.com")] + Production + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index 2de954cbe..cbaeb9d2e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -44,11 +45,6 @@ namespace Tango.MachineStudio.Common /// public String LastVirtualMachineSerialNumber { get; set; } - /// - /// Gets or sets the machine service address. - /// - public String MachineServiceAddress { get; set; } - /// /// Gets or sets the allow beta release. /// @@ -99,6 +95,20 @@ namespace Tango.MachineStudio.Common /// public WorkingEnvironment Environment { get; set; } + /// + /// Gets or sets the deployment slot. + /// + public DeploymentSlots DeploymentSlot { get; set; } + + /// + /// Gets the machine service address. + /// + /// + public String GetMachineServiceAddress() + { + return DeploymentSlot.ToDescription(); + } + /// /// Initializes a new instance of the class. /// @@ -106,10 +116,10 @@ namespace Tango.MachineStudio.Common { LastBounds = new Rect(); LoggingCategories = new List(); - MachineServiceAddress = "http://machineservice.twine-srv.com/"; DefaultIssueReportTags = new List(); StudioModulesBounds = new List(); Environment = WorkingEnvironment.Remote; + DeploymentSlot = DeploymentSlots.Development; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 85b194173..58a0d5f7e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -94,6 +94,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs index aae1fe70d..77828d490 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs @@ -15,7 +15,7 @@ namespace Tango.MachineStudio.Common.Update public MachineStudioUpdateService() { - address = SettingsManager.Default.GetOrCreate().MachineServiceAddress + "/api/MachineStudio/"; + address = SettingsManager.Default.GetOrCreate().GetMachineServiceAddress() + "/api/MachineStudio/"; _client = new WebTransportClient(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 19192020e..ccaedb359 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -56,7 +56,7 @@ namespace Tango.MachineStudio.UI.Authentication IWebTransportClient service = new WebTransportClient(); - var response = service.PostJson(settings.MachineServiceAddress + "/api/MachineStudio/Login", new LoginRequest() + var response = service.PostJson(settings.GetMachineServiceAddress() + "/api/MachineStudio/Login", new LoginRequest() { Email = email, @@ -90,17 +90,6 @@ namespace Tango.MachineStudio.UI.Authentication throw new AuthenticationException("Invalid credentials for " + email); } - if (!user.HasPermission(Permissions.RunMachineStudio)) - { - throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator."); - } - - if (user != null) - { - user.LastLogin = DateTime.UtcNow; - db.SaveChanges(); - } - CurrentUser = user; return user; } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 730027a67..edae820e7 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -46,6 +46,9 @@ namespace Tango.MachineStudio.UI.ViewModels } private String _password; + /// + /// Gets or sets the password. + /// [Required(ErrorMessage = "Password is required")] public String Password { @@ -53,6 +56,16 @@ namespace Tango.MachineStudio.UI.ViewModels set { _password = value; RaisePropertyChangedAuto(); } } + private DeploymentSlots _deploymentSlot; + /// + /// Gets or sets the deployment slot. + /// + public DeploymentSlots DeploymentSlot + { + get { return _deploymentSlot; } + set { _deploymentSlot = value; RaisePropertyChangedAuto(); } + } + private bool _isLogging; /// /// Gets or sets a value indicating whether this instance is logging. @@ -96,6 +109,7 @@ namespace Tango.MachineStudio.UI.ViewModels cryptographer = new Rfc2898Cryptographer(); Email = _settings.LastLoginEmail; + DeploymentSlot = _settings.DeploymentSlot; RememberMe = _settings.RememberMe; try @@ -122,14 +136,16 @@ namespace Tango.MachineStudio.UI.ViewModels await Task.Factory.StartNew(() => { + _settings.DeploymentSlot = DeploymentSlot; + _authenticationProvider.Login(Email, Password); _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); _navigationManager.NavigateTo(NavigationView.MainView); + _settings.LastLoginEmail = Email; _settings.RememberMe = RememberMe; - _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; _settings.Save(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml index 68334ad24..c344e867a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml @@ -9,6 +9,7 @@ xmlns:automation="clr-namespace:Tango.MachineStudio.Common.Automation;assembly=Tango.MachineStudio.Common" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:helpers="clr-namespace:Tango.SharedUI.Helpers;assembly=Tango.SharedUI" + xmlns:common="clr-namespace:Tango.MachineStudio.Common;assembly=Tango.MachineStudio.Common" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1280" DataContext="{Binding LoginViewVM, Source={StaticResource Locator}}" Background="Transparent"> @@ -17,6 +18,7 @@ + @@ -28,7 +30,7 @@ Machine Studio - + @@ -44,6 +46,10 @@ + + + + Remember me diff --git a/Software/Visual_Studio/Tango.Editors/EnumExtensions.cs b/Software/Visual_Studio/Tango.Editors/EnumExtensions.cs index 95783fef7..ab3201cf3 100644 --- a/Software/Visual_Studio/Tango.Editors/EnumExtensions.cs +++ b/Software/Visual_Studio/Tango.Editors/EnumExtensions.cs @@ -8,21 +8,21 @@ using System.Threading.Tasks; public static class EnumExtensions { - /// - /// Gets the Enum value description. - /// - /// The value. - /// - public static String ToDescription(this Enum value) - { - FieldInfo fi = value.GetType().GetField(value.ToString()); + ///// + ///// Gets the Enum value description. + ///// + ///// The value. + ///// + //public static String ToDescription(this Enum value) + //{ + // FieldInfo fi = value.GetType().GetField(value.ToString()); - DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + // DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - if (attributes != null && - attributes.Length > 0) - return attributes[0].Description; - else - return value.ToString(); - } + // if (attributes != null && + // attributes.Length > 0) + // return attributes[0].Description; + // else + // return value.ToString(); + //} } diff --git a/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs b/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs new file mode 100644 index 000000000..d2eeb15a5 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/ActiveDirectory/ActiveDirectoryManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Azure.ActiveDirectory.GraphClient; +using Microsoft.Azure.ActiveDirectory.GraphClient.Extensions; +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web.ActiveDirectory +{ + public class ActiveDirectoryManager + { + private String _service_root = $"https://login.microsoftonline.com/{WebConfig.TENANT_ID}"; + + public AuthenticationResult ValidateUserCredentials(String email, String password) + { + var authContext = new AuthenticationContext(_service_root); + UserCredential userCredential = new UserCredential(email, password); + AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", WebConfig.CLIENT_ID, userCredential); + return authResult; + } + + private AuthenticationResult GetAppAuthenticationResult() + { + var authContext = new AuthenticationContext(_service_root); + ClientCredential clientCredentials = new ClientCredential(WebConfig.CLIENT_ID, WebConfig.APP_SECRET); + AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", clientCredentials); + return authResult; + } + + public List GetUserGroups(String email) + { + var authResult = GetAppAuthenticationResult(); + ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri($"https://graph.windows.net/{WebConfig.TENANT_ID}"), async () => await Task.FromResult(authResult.AccessToken)); + var user = activeDirectoryClient.Users.Where(x => x.UserPrincipalName == email).ExecuteSingleAsync().Result; + + var userFetcher = (IUserFetcher)user; + + List groups = new List(); + + IPagedCollection pagedCollection = userFetcher.MemberOf.ExecuteAsync().Result; + do + { + List directoryObjects = pagedCollection.CurrentPage.ToList(); + foreach (IDirectoryObject directoryObject in directoryObjects) + { + if (directoryObject is Group) + { + var group = directoryObject as Group; + groups.Add(group); + } + } + pagedCollection = pagedCollection.GetNextPageAsync().Result; + } while (pagedCollection != null); + + return groups; + } + + public bool CanUserAccessCurrentEnvironment(String email) + { + var groups = GetUserGroups(email); + return groups.Exists(x => x.DisplayName == WebConfig.ENVIRONMENT_GROUP); + } + } +} diff --git a/Software/Visual_Studio/Tango.Web/DeploymentSlot.cs b/Software/Visual_Studio/Tango.Web/DeploymentSlot.cs new file mode 100644 index 000000000..676d0dc50 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/DeploymentSlot.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web +{ + public enum DeploymentSlot + { + [Description("Development")] + DEV, + [Description("Testing")] + TEST, + [Description("Staging")] + STAGE, + [Description("Production")] + PROD + } +} diff --git a/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs b/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs deleted file mode 100644 index 27b5e7cf5..000000000 --- a/Software/Visual_Studio/Tango.Web/Helpers/AzureDirectoryHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.Web.Helpers -{ - public static class AzureDirectoryHelper - { - public static AuthenticationResult AuthenticateUser(String email, String password) - { - var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); - UserCredential userCredential = new UserCredential(email, password); - AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); - return authResult; - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 385b3bde8..70ac28e6e 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -69,11 +69,23 @@ ..\packages\Microsoft.ApplicationInsights.2.2.0\lib\net46\Microsoft.ApplicationInsights.dll + + ..\packages\Microsoft.Azure.ActiveDirectory.GraphClient.2.1.1\lib\portable-net4+sl5+win+wpa+wp8\Microsoft.Azure.ActiveDirectory.GraphClient.dll + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + ..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll + + + ..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll + + + ..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.10707.1513-rc\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll @@ -186,6 +198,9 @@ + + ..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll @@ -228,13 +243,14 @@ GlobalVersionInfo.cs + + - @@ -243,6 +259,7 @@ + diff --git a/Software/Visual_Studio/Tango.Web/WebConfig.cs b/Software/Visual_Studio/Tango.Web/WebConfig.cs index c970fa3a1..d9566a7c5 100644 --- a/Software/Visual_Studio/Tango.Web/WebConfig.cs +++ b/Software/Visual_Studio/Tango.Web/WebConfig.cs @@ -8,18 +8,55 @@ namespace Tango.Web { public class WebConfig { + /// + /// Gets the database address. + /// public static String DB_ADDRESS => ConfigurationManager.AppSettings[nameof(DB_ADDRESS)].ToString(); + + /// + /// Gets the name of the database user. + /// public static String DB_USER_NAME => ConfigurationManager.AppSettings[nameof(DB_USER_NAME)].ToString(); + + /// + /// Gets the database password. + /// public static String DB_PASSWORD => ConfigurationManager.AppSettings[nameof(DB_PASSWORD)].ToString(); + + /// + /// Gets the database catalog. + /// public static String DB_CATALOG => ConfigurationManager.AppSettings[nameof(DB_CATALOG)].ToString(); + /// + /// Gets the storage account URL. + /// public static String STORAGE_ACCOUNT => ConfigurationManager.AppSettings[nameof(STORAGE_ACCOUNT)].ToString(); + /// + /// Gets the tenant identifier. + /// public static String TENANT_ID => ConfigurationManager.AppSettings[nameof(TENANT_ID)].ToString(); + + /// + /// Gets the client identifier. + /// public static String CLIENT_ID => ConfigurationManager.AppSettings[nameof(CLIENT_ID)].ToString(); + + /// + /// Gets the application secret. + /// public static String APP_SECRET => ConfigurationManager.AppSettings[nameof(APP_SECRET)].ToString(); - public static String DEPLOYMENT_SLOT => ConfigurationManager.AppSettings[nameof(DEPLOYMENT_SLOT)].ToString(); + /// + /// Gets the deployment slot (DEV/TEST/STAGE/PROD). + /// + public static DeploymentSlot DEPLOYMENT_SLOT => (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), ConfigurationManager.AppSettings[nameof(DEPLOYMENT_SLOT)].ToString()); + + /// + /// Gets the environment active directory user group (Tango DEV / Tango TEST / Tango STAGE / Tango PROD). + /// + public static String ENVIRONMENT_GROUP => ConfigurationManager.AppSettings[nameof(ENVIRONMENT_GROUP)].ToString(); } } diff --git a/Software/Visual_Studio/Tango.Web/app.config b/Software/Visual_Studio/Tango.Web/app.config new file mode 100644 index 000000000..7c02d45bb --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/app.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/packages.config b/Software/Visual_Studio/Tango.Web/packages.config index 6266503ba..e7bb554d1 100644 --- a/Software/Visual_Studio/Tango.Web/packages.config +++ b/Software/Visual_Studio/Tango.Web/packages.config @@ -19,7 +19,11 @@ + + + + @@ -27,5 +31,6 @@ + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index d21a23ca1..4aff8fd39 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -19,6 +19,7 @@ using Tango.Web.Controllers; using Tango.Web.Helpers; using Tango.Web.Storage; using Tango.Web.Authentication; +using Tango.Web.ActiveDirectory; namespace Tango.MachineService.Controllers { @@ -26,6 +27,7 @@ namespace Tango.MachineService.Controllers { private static TokensManager _tokens_manager; private static List _pendingUploads; + private ActiveDirectoryManager _ad_manager; static MachineStudioController() { @@ -33,6 +35,11 @@ namespace Tango.MachineService.Controllers _pendingUploads = new List(); } + public MachineStudioController() : base() + { + _ad_manager = new ActiveDirectoryManager(); + } + #region Update [HttpPost] @@ -189,7 +196,12 @@ namespace Tango.MachineService.Controllers [HttpPost] public LoginResponse Login(LoginRequest request) { - AuthenticationResult authResult = AzureDirectoryHelper.AuthenticateUser(request.Email, request.Password); + var authResult =_ad_manager.ValidateUserCredentials(request.Email, request.Password); + + if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email)) + { + throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment."); + } using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { @@ -217,11 +229,25 @@ namespace Tango.MachineService.Controllers FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName, Email = request.Email, }; - new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User)); - new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.MachineStudioUser)); + + db.UsersRoles.Add(new UsersRole() + { + User = new_user, + Role = db.Roles.Single(x => (Roles)x.Code == Roles.User), + }); + + db.UsersRoles.Add(new UsersRole() + { + User = new_user, + Role = db.Roles.Single(x => (Roles)x.Code == Roles.MachineStudioUser), + }); + + new_user.LastLogin = DateTime.UtcNow; + db.Users.Add(new_user); } else { + user.LastLogin = DateTime.UtcNow; user.Password = g.Encrypt(request.Password); } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml new file mode 100644 index 000000000..e847adbd8 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml @@ -0,0 +1,28 @@ + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice/slots/MachineService-DEV + Tango + AzureWebSite + Debug + Any CPU + http://machineservice-machineservice-dev.azurewebsites.net + True + False + machineservice-machineservice-dev.scm.azurewebsites.net:443 + machineservice__MachineService-DEV + + True + False + WMSVC + True + $machineservice__MachineService-DEV + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml deleted file mode 100644 index 612e38bfb..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - MSDeploy - /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/MachineService - Tango - AzureWebSite - Debug - Any CPU - http://machineservice.azurewebsites.net - True - False - machineservice.scm.azurewebsites.net:443 - MachineService - - True - False - WMSVC - True - $MachineService - <_SavePWD>True - <_DestinationType>AzureWebSite - - \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml new file mode 100644 index 000000000..a611d5ffd --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml @@ -0,0 +1,28 @@ + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/MachineService + Tango + AzureWebSite + Release + Any CPU + https://machineservice.twine-srv.com + True + False + machineservice.scm.azurewebsites.net:443 + MachineService + + True + False + WMSVC + True + $MachineService + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml new file mode 100644 index 000000000..12e2de377 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml @@ -0,0 +1,28 @@ + + + + + MSDeploy + /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice/slots/MachineService-TEST + Tango + AzureWebSite + Release + Any CPU + http://machineservice-machineservice-test.azurewebsites.net + True + False + machineservice-machineservice-test.scm.azurewebsites.net:443 + machineservice__MachineService-TEST + + True + False + WMSVC + True + $machineservice__MachineService-TEST + <_SavePWD>True + <_DestinationType>AzureWebSite + + \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index ca1376ff7..63c8521da 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -346,7 +346,9 @@ - + + + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 097943016..2d700244b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -27,6 +27,9 @@ + + +