public EntityAccessPolicy(AccessPolicyEntry originalPolicyEntry) { OriginalPolicyEntry = originalPolicyEntry; KeyPolicy = new KeyAccessPolicy() { AccessPermissionString = originalPolicyEntry.PermissionsToKeys }; SecretPolicy = new SecretAccessPolicy() { AccessPermissionString = originalPolicyEntry.PermissionsToSecrets }; }
private async void VaultSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (e.AddedItems.Count == 0) { return; } var item = (IKeyVault)e.AddedItems.Single(); await ShowProgressDialog("Getting items from vault..."); var vault = (IKeyVault)item; var keyVaultServiceToken = (await Authentication.Instance.GetKeyVaultApiToken(vault.TenantId.ToString("D"))).AsBearer(); var svc = Factory.GetKeyVaultService(vault, keyVaultServiceToken); var secrets = await svc.GetSecrets(); var keys = await svc.GetKeys(); var castSecrets = secrets.Select(s => (IKeyVaultSecureItem)s); var castKeys = keys.Select(k => (IKeyVaultSecureItem)k); var secretsAndKeys = castSecrets.Union(castKeys); SelectedVault = new KeyVaultViewModel(vault) { ShowAccessPermissions = new ActionCommand(() => ShowAccessPermissions(vault)), ShowDeleteConfirmation = new ActionCommand(() => ShowVaultDeleteConfirmation(vault)), ShowAddKey = new ActionCommand(() => ShowAddKey(vault)), ShowAddSecret = new ActionCommand(() => ShowAddSecret(vault)), }; OnPropertyChanged(nameof(VaultSelectedVisibility)); OnPropertyChanged(nameof(SelectedVault)); var currentUserPolicy = vault.Properties.AccessPolicies.FirstOrDefault(p => p.ObjectId == LoggedInOid); if (currentUserPolicy == null) { SelectedVaultKeyPermissions = new KeyAccessPolicy(); SelectedVaultSecretPermissions = new SecretAccessPolicy(); } else { SelectedVaultKeyPermissions = new KeyAccessPolicy() { AccessPermissionString = currentUserPolicy.Permissions.Keys.ToArray() }; SelectedVaultSecretPermissions = new SecretAccessPolicy() { AccessPermissionString = currentUserPolicy.Permissions.Secrets.ToArray() }; } UpdateSecrets(secretsAndKeys.Select(x => { if (x is IKeyVaultSecret) { var vm = new KeyVaultSecretViewModel((IKeyVaultSecret)x); vm.ShowSecret = new ActionCommand(async() => vm.Secret = await svc.GetSecretValue((IKeyVaultSecret)x)); vm.SetSecret = new ActionCommand(async() => vm.Secret = await svc.SetSecretValue((IKeyVaultSecret)x, vm.Secret)); vm.ShowDeleteConfirmation = new ActionCommand(() => ShowItemDeleteConfirmation(x)); return((IKeyVaultItemViewModel)vm); } else if (x is IKeyVaultKey) { var vm = new KeyVaultKeyViewModel((IKeyVaultKey)x); vm.ShowKey = new ActionCommand(async() => vm.Key = await svc.GetKeyValue((IKeyVaultKey)x)); vm.ShowDeleteConfirmation = new ActionCommand(() => ShowItemDeleteConfirmation(x)); vm.ShowEncryptDialog = new ActionCommand(() => ShowEncryptDialog((IKeyVaultKey)x)); vm.ShowSignDialog = new ActionCommand(() => ShowSignDialog((IKeyVaultKey)x)); vm.ShowWrapDialog = new ActionCommand(() => ShowWrapDialog((IKeyVaultKey)x)); return((IKeyVaultItemViewModel)vm); } return(null); })); } catch (Exception ex) { ShowErrorDialog(ex.ToString()); } await HideProgressDialog(); }