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/CheckForUpdatesRequest.cs | 8 ++--- .../Update/CheckForUpdatesResponse.cs | 23 +++--------- .../Update/IMachineStudioUpdateService.cs | 14 +++----- .../Update/LatestVersionRequest.cs | 15 ++++++++ .../Update/LatestVersionResponse.cs | 15 ++++++++ .../Update/MachineStudioUpdateService.cs | 42 ++++++++++++++++++++++ .../Update/UploadCompletedRequest.cs | 5 ++- .../Update/UploadCompletedResponse.cs | 14 ++++++++ .../Update/UploadVersionRequest.cs | 10 ++---- .../Update/UploadVersionResponse.cs | 22 +++--------- 10 files changed, 105 insertions(+), 63 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs index 0047e311b..11911dd7e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs @@ -4,22 +4,18 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class CheckForUpdatesRequest + public class CheckForUpdatesRequest : WebRequestMessage { - [DataMember] public String Email { get; set; } - [DataMember] public String Password { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public bool AcceptBetaRelease { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs index f34f12d8f..b0577f40b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs @@ -4,37 +4,22 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class CheckForUpdatesResponse + public class CheckForUpdatesResponse : WebResponseMessage { - [DataMember] public bool IsUpdateAvailable { get; set; } - [DataMember] public bool IsStable { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public String Comments { get; set; } - [DataMember] - public String FtpHost { get; set; } - - [DataMember] - public String FilePath { get; set; } - - [DataMember] - public String UserName { get; set; } - - [DataMember] - public String Password { get; set; } - - [DataMember] public bool ForcedUpdate { get; set; } + + public String BlobAddress { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs index 53e49e52c..4a7df7caa 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs @@ -4,23 +4,19 @@ using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; +using System.Threading.Tasks; using Tango.MachineStudio.Common.Update; namespace Tango.MachineStudio.Common.Update { - [ServiceContract] public interface IMachineStudioUpdateService { - [OperationContract] - CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request); + Task CheckForUpdates(CheckForUpdatesRequest request); - [OperationContract] - UploadVersionResponse UploadVersion(UploadVersionRequest request); + Task UploadVersion(UploadVersionRequest request); - [OperationContract] - void NotifyUploadCompleted(UploadCompletedRequest request); + Task NotifyUploadCompleted(UploadCompletedRequest request); - [OperationContract] - String GetLatestVersion(); + Task GetLatestVersion(LatestVersionRequest request); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs new file mode 100644 index 000000000..b4e7bd975 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Update +{ + public class LatestVersionRequest : WebRequestMessage + { + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs new file mode 100644 index 000000000..b90cbf370 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Update +{ + public class LatestVersionResponse : WebResponseMessage + { + public String Version { get; set; } + } +} 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); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs index ce6096792..fc478db50 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs @@ -4,13 +4,12 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadCompletedRequest + public class UploadCompletedRequest : WebRequestMessage { - [DataMember] public String Token { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs new file mode 100644 index 000000000..89850e3e5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Update +{ + public class UploadCompletedResponse : WebResponseMessage + { + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs index 83739f615..c55cb9a22 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs @@ -4,28 +4,22 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadVersionRequest + public class UploadVersionRequest : WebRequestMessage { - [DataMember] public String Email { get; set; } - [DataMember] public String Password { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public String Comments { get; set; } - [DataMember] public bool ForcedUpdate { get; set; } - [DataMember] public bool IsStable { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs index 36dc3df30..4d13fc6ad 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs @@ -4,28 +4,14 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadVersionResponse + public class UploadVersionResponse : WebResponseMessage { - [DataMember] - public String FtpHost { get; set; } - - [DataMember] - public String FilePath { get; set; } - - [DataMember] - public String FileName { get; set; } - - [DataMember] - public String UserName { get; set; } - - [DataMember] - public String Password { get; set; } - - [DataMember] public String Token { get; set; } + + public String BlobAddress { get; set; } } } -- cgit v1.3.1 From 795444f234f6b45bc83d5c7b28725bd7ebc7ee89 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 24 Dec 2018 17:39:01 +0200 Subject: Working on machine service and machine studio. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 20578304 -> 20578304 bytes .../Authentication/IAuthenticationProvider.cs | 5 +++ .../Authentication/LoginResponse.cs | 1 + .../Update/CheckForUpdatesRequest.cs | 4 +- .../Update/CheckForUpdatesResponse.cs | 2 - .../DefaultAuthenticationProvider.cs | 7 ++++ .../ViewModels/LoadingViewVM.cs | 42 --------------------- .../ViewModels/MainViewVM.cs | 5 +-- .../ViewModels/UpdateViewVM.cs | 3 +- .../Tango.Web/Authentication/TokensManager.cs | 30 +++++++++++++++ .../Tango.Web/Controllers/JsonController.cs | 2 +- Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 1 + .../Controllers/MachineStudioController.cs | 22 ++++------- .../Web/Tango.MachineService/Web.config | 2 +- 15 files changed, 58 insertions(+), 68 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 978deab2f..3068c20a8 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 30de45e33..315369a3f 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/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs index 0c2aa3cb7..785dc1523 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs @@ -12,6 +12,11 @@ namespace Tango.MachineStudio.Common.Authentication /// public interface IAuthenticationProvider { + /// + /// Gets the access token that was retrieved at the last login. + /// + String AccessToken { get; } + /// /// Occurs when the current logged-in user has changed. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs index 075a5ec10..3da033b9f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs @@ -11,5 +11,6 @@ namespace Tango.MachineStudio.Common.Authentication public class LoginResponse : WebResponseMessage { public DataSource DataSource { get; set; } + public String Token { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs index 11911dd7e..cf06e678d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs @@ -10,9 +10,7 @@ namespace Tango.MachineStudio.Common.Update { public class CheckForUpdatesRequest : WebRequestMessage { - public String Email { get; set; } - - public String Password { get; set; } + public String Token { get; set; } public String Version { get; set; } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs index b0577f40b..ae1e958ab 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs @@ -18,8 +18,6 @@ namespace Tango.MachineStudio.Common.Update public String Comments { get; set; } - public bool ForcedUpdate { get; set; } - public String BlobAddress { get; set; } } } 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 450756705..4acc76c25 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -63,6 +63,8 @@ namespace Tango.MachineStudio.UI.Authentication }).Result; + AccessToken = response.Token; + ObservablesContext.OverrideSettingsDataSource(response.DataSource); ObservablesStaticCollections.Instance.Initialize(); @@ -107,5 +109,10 @@ namespace Tango.MachineStudio.UI.Authentication { CurrentUser = null; } + + /// + /// Gets the access token that was retrieved at the last login. + /// + public string AccessToken { get; private set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 6e8d0488b..283ea3637 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -89,48 +89,6 @@ namespace Tango.MachineStudio.UI.ViewModels { try { - try - { - Status = "Checking for critical updates..."; - - LogManager.Log("Checking for forced update..."); - - var client = new MachineStudioUpdateService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() - { - Email = "ForceUpdate", - Password = "ForceUpdate", - Version = ApplicationManager.Version.ToString(), - }).Result; - - if (response.IsUpdateAvailable && response.ForcedUpdate) - { - LogManager.Log("Forced update found, Navigating to update view!"); - - InvokeUI(() => - { - if (_notificationProvider.ShowQuestion("Machine Studio has detected a critical update which must be installed in order for the application to run properly. Do you wish to download and install this update?")) - { - TangoMessenger.Default.Send(new Messages.ForcedUpdateMessage() { UpdateResponse = response }); - _navigationManager.NavigateTo(NavigationView.UpdateView); - } - else - { - ApplicationManager.ShutDown(); - } - - IsLoading = false; - }); - - return; - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error checking for forced update!"); - } - try { Status = "Connecting to Team Foundation Services..."; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index befad162c..818d507ae 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -363,8 +363,7 @@ namespace Tango.MachineStudio.UI.ViewModels CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { - Email = _authenticationProvider.CurrentUser.Email, - Password = _authenticationProvider.CurrentUser.Password, + Token = _authenticationProvider.AccessToken, Version = _applicationManager.Version.ToString(), AcceptBetaRelease = _settings.AcceptBetaRelease, }).Result; @@ -455,7 +454,7 @@ namespace Tango.MachineStudio.UI.ViewModels //Check machine exist on my database first if (x.SelectedMachine.Machine == null) { - _notificationProvider.ShowError( $"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection."); + _notificationProvider.ShowError($"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection."); return; } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 3fec96629..e19dcdbe5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -196,8 +196,7 @@ namespace Tango.MachineStudio.UI.ViewModels CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { - Email = _authentication.CurrentUser.Email, - Password = _authentication.CurrentUser.Password, + Token = _authentication.AccessToken, Version = _application.Version.ToString(), AcceptBetaRelease = settings.AcceptBetaRelease, }).Result; diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs new file mode 100644 index 000000000..20fc8ab50 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web.Authentication +{ + public class TokensManager + { + private List _tokens; + + public TokensManager() + { + _tokens = new List(); + } + + public String CreateNew() + { + String token = Guid.NewGuid().ToString(); + _tokens.Add(token); + return token; + } + + public bool Exists(String token) + { + return _tokens.Contains(token); + } + } +} diff --git a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs index a581d9ec7..9d9016d5a 100644 --- a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs +++ b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs @@ -65,7 +65,7 @@ namespace Tango.Web.Controllers code = HttpStatusCode.Unauthorized; } - throw new HttpResponseException(Request.CreateErrorResponse(code, ex.Message)); + throw new HttpResponseException(Request.CreateErrorResponse(code, ex.ToString())); } } } diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 9d199a409..385b3bde8 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -228,6 +228,7 @@ GlobalVersionInfo.cs + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8d46ed7d9..18f8dbc0b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -18,15 +18,18 @@ using Tango.MachineStudio.Common.Update; using Tango.Web.Controllers; using Tango.Web.Helpers; using Tango.Web.Storage; +using Tango.Web.Authentication; namespace Tango.MachineService.Controllers { public class MachineStudioController : JsonController { + private static TokensManager _tokens_manager; private static List _pendingUploads; static MachineStudioController() { + _tokens_manager = new TokensManager(); _pendingUploads = new List(); } @@ -41,15 +44,7 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - //Load relation first... - db.Roles.ToList(); - db.Permissions.ToList(); - db.UsersRoles.ToList(); - db.RolesPermissions.ToList(); - - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); - - if (user != null && user.HasPermission(Permissions.RunMachineStudio) || (request.Email == "ForceUpdate")) + if (_tokens_manager.Exists(request.Token)) { var versions = db.MachineStudioVersions.ToList(); @@ -66,8 +61,6 @@ namespace Tango.MachineService.Controllers Version currentVersion = Version.Parse(request.Version); - bool isForcedUpdate = versions.Exists(x => x.ForceUpdate && Version.Parse(x.Version) > currentVersion); - String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments)); if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) @@ -81,13 +74,12 @@ namespace Tango.MachineService.Controllers response.IsUpdateAvailable = true; response.Version = latestVersion.Version; response.Comments = latestVersion.Comments; - response.ForcedUpdate = isForcedUpdate; response.IsStable = latestVersion.Stable; } } else { - throw new AuthenticationException("Invalid user credentials."); + throw new AuthenticationException("Invalid token."); } } @@ -245,7 +237,9 @@ namespace Tango.MachineService.Controllers IntegratedSecurity = false, UserName = request.Email, Password = request.Password, - } + }, + + Token = _tokens_manager.CreateNew() }; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 77d9a1bb3..097943016 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -19,7 +19,7 @@ - + -- 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') 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 @@ + + +