From 4e496467dcc8549605917a44263d78cef40f71bb Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 23 Dec 2018 12:44:08 +0200 Subject: Implemented machine studio active directory secure login. --- .../MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') 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 545d51ef2..6e8d0488b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -144,9 +144,8 @@ namespace Tango.MachineStudio.UI.ViewModels Status = "Loading, please wait..."; - ObservablesStaticCollections.Instance.Initialize(); - - _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); + //ObservablesStaticCollections.Instance.Initialize(); + //_eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); Status = "Starting application..."; -- 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.UI/ViewModels/LoadingViewVM.cs') 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