public void WhenAllClaimsArePresent_AccountIsFilledWithAllProperties()
        {
            var claims = new Dictionary <string, string>
            {
                { "oid", "dd89e54b-3c19-4db3-a234-3855d7428ef4" },
                { "name", "Jane Doe" },
                { "streetAddress", "Long Road 10029" },
                { "city", "Big City" },
                { "postalCode", "O-773382" },
                { "country", "Germany" },
                { "extension_Role", "8" },
                { "emails", "[\"[email protected]\"]" }
            };
            var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims.Select(c => new Claim(c.Key, c.Value))));
            var account         = new RemoteAccount();
            var sut             = CreateSut();

            sut.Convert(claimsPrincipal, account, ResolutionContextNotUsed);

            account.ObjectId.Should().Be(new Guid("dd89e54b-3c19-4db3-a234-3855d7428ef4"));
            account.DisplayName.Should().Be("Jane Doe");
            account.Country.Should().Be("Germany");
            account.Postalcode.Should().Be("O-773382");
            account.City.Should().Be("Big City");
            account.Street.Should().Be("Long Road 10029");
            account.Email.Should().Be("*****@*****.**");
        }
Example #2
0
        public async Task WhenConnected_UpdatesExistingUserDetails()
        {
            var user          = new ClaimsPrincipal();
            var sut           = CreateSut(user, out var repository, out var mapper, out _);
            var mappedAccount = new RemoteAccount {
                DisplayName = "Jane Doe", Street = "Long Road 1000233", ObjectId = Guid.NewGuid()
            };
            var existingAccount = new RemoteAccount {
                Id = 123, DisplayName = "Jane Doe"
            };

            mapper.Map <RemoteAccount>(user).Returns(mappedAccount);
            repository.FirstOrDefaultAsync(Arg.Is <RemoteAccountByObjectIdSpecification>(s => s.ObjectId == mappedAccount.ObjectId)).Returns(existingAccount);
            mapper.When(m => m.Map(user, existingAccount)).Do(info => info.Arg <RemoteAccount>().Street = "Long Road 1000233");

            var action = await sut.HandleAsync().ConfigureAwait(true);

            mapper.Received(1).Map(user, existingAccount);
            await repository.Received(1).UpdateAsync(existingAccount).ConfigureAwait(true);

            var connectedAccount = action.Value.Should().BeOfType <ConnectedAccount>().Subject;

            connectedAccount.Account.Should().Be(existingAccount);
            connectedAccount.IsGuest.Should().BeTrue();
        }
Example #3
0
    private async Task GetRoleViaGraphApi(RemoteAccount remoteAccount)
    {
        var role = Role.Guest;

        try
        {
            var user = await _graphClient.Users[remoteAccount.ObjectId.ToString()]
                       .Request().Select($"id,displayName,{RoleAttributeName}")
                       .GetAsync().ConfigureAwait(false);

            role = TryToGetRoleFromCustomAttribute(user);
        }
        catch (ServiceException e)
        {
            if (e.StatusCode == HttpStatusCode.NotFound)
            {
                _logger.LogWarning("User with ID {remoteAccount} was not found in AADB2C, assigning guest role",
                                   remoteAccount.ObjectId);
            }
            else
            {
                _logger.LogError(e, "Failed to query user with ID {remoteAccount} from AADB2C, assigning guest role",
                                 remoteAccount.ObjectId);
            }
        }

        remoteAccount.Role = role;
    }
Example #4
0
 public EditRemoteAccountDlg(RemoteAccount remoteAccount, IEnumerable <RemoteAccount> existing)
 {
     InitializeComponent();
     _existing        = ImmutableList.ValueOf(existing);
     _originalAccount = remoteAccount;
     comboAccountType.Items.AddRange(RemoteAccountType.ALL.ToArray());
     SetRemoteAccount(UnifiAccount.DEFAULT);
     SetRemoteAccount(remoteAccount);
 }
        public void WhenFullObjectIdentifierType_ObjectIdIsParsedCorrectly()
        {
            var claims = new Dictionary <string, string>
            {
                { "http://schemas.microsoft.com/identity/claims/objectidentifier", "dd89e54b-3c19-4db3-a234-3855d7428ef4" }
            };
            var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims.Select(c => new Claim(c.Key, c.Value))));
            var account         = new RemoteAccount();
            var sut             = CreateSut();

            sut.Convert(claimsPrincipal, account, ResolutionContextNotUsed);

            account.ObjectId.Should().Be("dd89e54b-3c19-4db3-a234-3855d7428ef4");
        }
        public void WhenSingleEmail_AddressIsParsedCorrectly()
        {
            var claims = new Dictionary <string, string>
            {
                { "emails", "*****@*****.**" },
            };
            var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims.Select(c => new Claim(c.Key, c.Value))));
            var account         = new RemoteAccount();
            var sut             = CreateSut();

            sut.Convert(claimsPrincipal, account, ResolutionContextNotUsed);

            account.Email.Should().Be("*****@*****.**");
        }
Example #7
0
        public void SetRemoteAccount(RemoteAccount remoteAccount)
        {
            comboAccountType.SelectedIndex = RemoteAccountType.ALL.IndexOf(remoteAccount.AccountType);
            textUsername.Text  = remoteAccount.Username;
            textPassword.Text  = remoteAccount.Password;
            textServerURL.Text = remoteAccount.ServerUrl;
            var unifiAccount = remoteAccount as UnifiAccount;

            if (unifiAccount != null)
            {
                tbxIdentityServer.Text = unifiAccount.IdentityServer;
                tbxClientScope.Text    = unifiAccount.ClientScope;
                tbxClientSecret.Text   = unifiAccount.ClientSecret;
            }
        }
Example #8
0
        public async Task WhenConnectedWithoutAssignedOrganization_SendsEmailNotification()
        {
            var user          = new ClaimsPrincipal();
            var sut           = CreateSut(user, out var repository, out var mapper, out var emailNotificationService);
            var mappedAccount = new RemoteAccount {
                DisplayName = "Jane Doe", City = "New York", Email = "*****@*****.**"
            };
            var storedAccount = new RemoteAccount {
                Id = 123, DisplayName = "Jane Doe", City = "New York", Email = "*****@*****.**"
            };

            mapper.Map <RemoteAccount>(user).Returns(mappedAccount);
            repository.AddAsync(mappedAccount).Returns(storedAccount);

            await sut.HandleAsync().ConfigureAwait(true);

            await emailNotificationService.Received(1)
            .NotifyNewUserRegistered("Jane Doe", "*****@*****.**", "New York");
        }
Example #9
0
        public async Task WhenConnectedWithAssignedOrganization_ReturnsNewAuthenticatedUserAsUser()
        {
            var user          = new ClaimsPrincipal();
            var sut           = CreateSut(user, out var repository, out var mapper, out _);
            var mappedAccount = new RemoteAccount {
                DisplayName = "Jane Doe"
            };
            var storedAccount = new RemoteAccount {
                Id = 123, DisplayName = "Jane Doe", OrganizationId = 12
            };

            mapper.Map <RemoteAccount>(user).Returns(mappedAccount);
            repository.AddAsync(mappedAccount).Returns(storedAccount);

            var action = await sut.HandleAsync().ConfigureAwait(true);

            mapper.Received(1).Map <RemoteAccount>(user);
            await repository.Received(1).AddAsync(mappedAccount).ConfigureAwait(true);

            var connectedAccount = action.Value.Should().BeOfType <ConnectedAccount>().Subject;

            connectedAccount.Account.Should().Be(storedAccount);
            connectedAccount.IsGuest.Should().BeFalse();
        }
Example #10
0
        private void populateListViewFromDirectory(MsDataFileUri directory)
        {
            _abortPopulateList = false;
            listView.Cursor    = Cursors.Default;
            _waitingForData    = false;
            listView.Items.Clear();

            var listSourceInfo = new List <SourceInfo>();

            if (null == directory || directory is MsDataFilePath && string.IsNullOrEmpty(((MsDataFilePath)directory).FilePath))
            {
                foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
                {
                    string     label      = string.Empty;
                    string     sublabel   = driveInfo.Name;
                    ImageIndex imageIndex = ImageIndex.Folder;
                    _driveReadiness[sublabel] = false;
                    try
                    {
                        switch (driveInfo.DriveType)
                        {
                        case DriveType.Fixed:
                            imageIndex = ImageIndex.LocalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Local_Drive;
                            if (driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.CDRom:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Optical_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Removable:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Removable_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Network:
                            label = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Network_Share;
                            break;
                        }
                        _driveReadiness[sublabel] = IsDriveReady(driveInfo);
                    }
                    catch (Exception)
                    {
                        label += string.Format(@" ({0})", Resources.OpenDataSourceDialog_populateListViewFromDirectory_access_failure);
                    }

                    string name = driveInfo.Name;
                    if (label != string.Empty)
                    {
                        name = string.Format(@"{0} ({1})", label, name);
                    }

                    listSourceInfo.Add(new SourceInfo(new MsDataFilePath(driveInfo.RootDirectory.FullName))
                    {
                        type         = DataSourceUtil.FOLDER_TYPE,
                        imageIndex   = imageIndex,
                        name         = name,
                        dateModified = GetDriveModifiedTime(driveInfo)
                    });
                }
            }
            else if (directory is RemoteUrl)
            {
                RemoteUrl remoteUrl = directory as RemoteUrl;
                if (string.IsNullOrEmpty(remoteUrl.ServerUrl))
                {
                    foreach (var remoteAccount in _remoteAccounts)
                    {
                        listSourceInfo.Add(new SourceInfo(remoteAccount.GetRootUrl())
                        {
                            name       = remoteAccount.GetKey(),
                            type       = DataSourceUtil.FOLDER_TYPE,
                            imageIndex = ImageIndex.MyNetworkPlaces,
                        });
                    }
                }
                else
                {
                    RemoteAccount remoteAccount = GetRemoteAccount(remoteUrl);
                    if (RemoteSession == null || !Equals(remoteAccount, RemoteSession.Account))
                    {
                        RemoteSession = RemoteSession.CreateSession(remoteAccount);
                    }
                    RemoteServerException exception;
                    bool isComplete = _remoteSession.AsyncFetchContents(remoteUrl, out exception);
                    foreach (var item in _remoteSession.ListContents(remoteUrl))
                    {
                        var imageIndex = DataSourceUtil.IsFolderType(item.Type)
                            ? ImageIndex.Folder
                            : ImageIndex.MassSpecFile;
                        listSourceInfo.Add(new SourceInfo(item.MsDataFileUri)
                        {
                            name         = item.Label,
                            type         = item.Type,
                            imageIndex   = imageIndex,
                            dateModified = item.LastModified,
                            size         = item.FileSize
                        });
                    }
                    if (null != exception)
                    {
                        if (MultiButtonMsgDlg.Show(this, exception.Message, Resources.OpenDataSourceDialog_populateListViewFromDirectory_Retry) != DialogResult.Cancel)
                        {
                            RemoteSession.RetryFetchContents(remoteUrl);
                            isComplete = false;
                        }
                    }
                    if (!isComplete)
                    {
                        listView.Cursor = Cursors.WaitCursor;
                        _waitingForData = true;
                    }
                }
            }
            else if (directory is MsDataFilePath)
            {
                MsDataFilePath msDataFilePath = (MsDataFilePath)directory;
                DirectoryInfo  dirInfo        = new DirectoryInfo(msDataFilePath.FilePath);

                try
                {
                    // subitems: Name, Type, Spectra, Size, Date Modified
                    var arraySubDirInfo = dirInfo.GetDirectories();
                    Array.Sort(arraySubDirInfo, (d1, d2) => string.Compare(d1.Name, d2.Name, StringComparison.CurrentCultureIgnoreCase));
                    var arrayFileInfo = dirInfo.GetFiles();
                    Array.Sort(arrayFileInfo, (f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.CurrentCultureIgnoreCase));

                    // Calculate information about the files, allowing the user to cancel
                    foreach (var info in arraySubDirInfo)
                    {
                        listSourceInfo.Add(getSourceInfo(info));
                        Application.DoEvents();
                        if (_abortPopulateList)
                        {
                            //MessageBox.Show( "abort" );
                            break;
                        }
                    }

                    if (!_abortPopulateList)
                    {
                        foreach (var info in arrayFileInfo)
                        {
                            listSourceInfo.Add(getSourceInfo(info));
                            Application.DoEvents();
                            if (_abortPopulateList)
                            {
                                //MessageBox.Show( "abort" );
                                break;
                            }
                        }
                    }
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(
                        Resources.OpenDataSourceDialog_populateListViewFromDirectory_An_error_occurred_attempting_to_retrieve_the_contents_of_this_directory,
                        x.Message);
                    // Might throw access violation.
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
            }

            // Populate the list
            var items = new List <ListViewItem>();

            foreach (var sourceInfo in listSourceInfo)
            {
                if (sourceInfo != null &&
                    (sourceTypeComboBox.SelectedIndex == 0 ||
                     sourceTypeComboBox.SelectedItem.ToString() == sourceInfo.type ||
                     // Always show folders
                     sourceInfo.isFolder))
                {
                    ListViewItem item = new ListViewItem(sourceInfo.ToArray(), (int)sourceInfo.imageIndex)
                    {
                        Tag = sourceInfo,
                    };
                    item.SubItems[2].Tag = sourceInfo.size;
                    item.SubItems[3].Tag = sourceInfo.dateModified;

                    items.Add(item);
                }
            }
            listView.Items.AddRange(items.ToArray());
        }