public ActionResult GetRoleBadges() { var userid = User.Identity.GetUserId(); var user = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(userid); var rolesHelper = new PermissionsHelper(); return(Content(user.GetRoleBadges().ToHtmlString())); }
private static IEnumerable <Dictionary <string, string> > GetAutoRunsWMIC() { var results = new List <Dictionary <string, string> >(); try { SelectQuery query = new SelectQuery("Win32_StartupCommand"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { using (ManagementObjectCollection win32_startup = searcher.Get()) { foreach (ManagementObject startup in win32_startup) { string command = startup["command"].ToString(); command = Environment.ExpandEnvironmentVariables(string.Format("{0}", command)); string filepath = MyUtils.GetExecutableFromPath(command); if (!string.IsNullOrEmpty(filepath)) { string filepathCleaned = filepath.Replace("'", "").Replace("\"", ""); try { string folder = Path.GetDirectoryName(filepathCleaned); results.Add(new Dictionary <string, string>() { { "Reg", "" }, { "RegKey", "From WMIC" }, { "RegPermissions", "" }, { "Folder", folder }, { "File", command }, { "isWritableReg", "" }, { "interestingFolderRights", string.Join(", ", PermissionsHelper.GetPermissionsFolder(folder, Checks.Checks.CurrentUserSiDs)) }, { "interestingFileRights", string.Join(", ", PermissionsHelper.GetPermissionsFile(filepath, Checks.Checks.CurrentUserSiDs)) }, { "isUnquotedSpaced", MyUtils.CheckQuoteAndSpace(command).ToString() } }); } catch (Exception) { } } } } } } catch (Exception e) { Beaprint.GrayPrint("Error getting autoruns from WMIC: " + e); } return(results); }
private void GetOwnerInfo() { try { if (PermissionsHelper.HasPermission(this, ConstantsAndTypes.AppPermission.ReadContacts) && PermissionsHelper.PermissionGranted(this, ConstantsAndTypes.AppPermission.ReadContacts)) { ContactsHelper contactHelper = new ContactsHelper(this); if (contactHelper.ReadProfile()) { string ownerUri = contactHelper.DeviceOwner.ThumbnailUri; string ownerFirstName = contactHelper.DeviceOwner.FirstName; string ownerSurname = contactHelper.DeviceOwner.Surname; if (_ownerThumb != null) { if (!string.IsNullOrEmpty(ownerUri)) { ImageryHelper imageHelper = new ImageryHelper(this, _ownerThumb); imageHelper.GetImageFromStringUri(contactHelper.DeviceOwner.ThumbnailUri); } else { _ownerThumb.SetImageResource(Resource.Drawable.ic_launcher); } } if (_ownerWelcome != null) { if (!(string.IsNullOrEmpty(ownerFirstName) || string.IsNullOrEmpty(ownerSurname))) { _ownerWelcome.Text = GetString(Resource.String.WelcomeMindYourMood) + " " + contactHelper.DeviceOwner.FirstName + " " + contactHelper.DeviceOwner.Surname; } else { _ownerWelcome.Text = GetString(Resource.String.WelcomeMindYourMoodNoContacts); } } } } else { if (_ownerWelcome != null) { _ownerWelcome.Text = GetString(Resource.String.WelcomeMindYourMoodNoContacts); } if (_ownerThumb != null) { _ownerThumb.SetImageResource(Resource.Drawable.ic_launcher); } } } catch (Exception e) { Log.Error(TAG, "GetOwnerInfo: Exception - " + e.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorMainGetOwnerInfo), "MainActivity.GetOwnerInfo"); } } }
public void ShouldBeAbleToCreateFirewallRule() { Skip.If(!PermissionsHelper.IsRunAsAdministrator(), "require administrator permissions"); var sut = new NetShHelper(); var result = sut.CreateFirewallRule(TestRuleName(nameof(ShouldBeAbleToCreateFirewallRule)), TestPorts + 1); result.Should().BeTrue(); }
private void UpdateEnabled() { base.Enabled = KeyImagePublisher.IsSupportedImage(base.SelectedPresentationImage) && WorkItemActivityMonitor.IsRunning && PermissionsHelper.IsInRole(AuthorityTokens.KeyImages); this.ShowEnabled = WorkItemActivityMonitor.IsRunning && PermissionsHelper.IsInRole(AuthorityTokens.KeyImages); }
private async void InitializeIfPermissionIsGranted() { // If the user has granted the location permission while the app was in background, Initialize if (await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { TryInitialize(); CoreApplication.Resuming -= CoreApplication_Resuming; } }
public void ShouldBeAbleToCreateUrlAcl() { Skip.If(!PermissionsHelper.IsRunAsAdministrator(), "require administrator permissions"); var sut = new NetShHelper(); var result = sut.CreateUrlAcl(TestUrls[0]); result.Should().BeTrue(); }
public static SortedDictionary <string, Dictionary <string, string> > GetInstalledAppsPerms() { //Get from Program Files SortedDictionary <string, Dictionary <string, string> > results = GetInstalledAppsPermsPath(Path.GetPathRoot(Environment.SystemDirectory) + "Program Files"); SortedDictionary <string, Dictionary <string, string> > results2 = GetInstalledAppsPermsPath(Path.GetPathRoot(Environment.SystemDirectory) + "Program Files (x86)"); results.Concat(results2).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); string[] registryPaths = new string[] { @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" }; foreach (var registryPath in registryPaths) { string[] subkeys = RegistryHelper.GetRegSubkeys("HKLM", registryPath); if (subkeys != null) { foreach (string app in subkeys) { string installLocation = RegistryHelper.GetRegValue("HKLM", string.Format(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0}", app), "InstallLocation"); if (string.IsNullOrEmpty(installLocation)) { continue; } installLocation = installLocation.Replace("\"", ""); if (installLocation.EndsWith(@"\")) { installLocation = installLocation.Substring(0, installLocation.Length - 1); } if (!results.ContainsKey(installLocation) && Directory.Exists(installLocation)) { bool already = false; foreach (string path in results.Keys) { if (installLocation.IndexOf(path) != -1) //Check for subfoldres of already found folders { already = true; break; } } if (!already) { results[installLocation] = PermissionsHelper.GetRecursivePrivs(installLocation); } } } } } return(results); }
/// <summary> /// Start new FFmpeg or FFprobe process. /// </summary> /// <param name="which">Which process to start (ffmpeg or ffprobe).</param> /// <param name="args">Arguments to send the process.</param> /// <param name="redirectOutput">Should redirect standard output.</param> /// <param name="redirectError">Should redirect standard error.</param> /// <returns>Nothing/output/error depending on redirectOutput & redirectError.</returns> public async Task <string> StartProcess(string args, string which = "ffmpeg", bool redirectOutput = false, bool redirectError = false) { // Get path to correct executable that is going to be used string ffPath; if (which.ToLower() == "ffprobe") { ffPath = await FindFFmpeg.GetPath("ffprobe"); } else { // Default to ffmpeg path ffPath = await FindFFmpeg.GetPath("ffmpeg"); } // Make sure we have exec rights PermissionsHelper.GetExecRights(ffPath); if (ffProcess != null) { ffProcess.StartInfo.FileName = ffPath; ffProcess.StartInfo.Arguments = args; ffProcess.StartInfo.CreateNoWindow = true; ffProcess.StartInfo.RedirectStandardOutput = redirectOutput; ffProcess.StartInfo.RedirectStandardError = redirectError; ffProcess.StartInfo.RedirectStandardInput = true; ffProcess.Start(); // return redirectOutput if set to if (redirectOutput) { var output = ffProcess.StandardOutput.ReadToEnd(); if (!string.IsNullOrEmpty(output)) { return(output); } } // return redirectError if set to if (redirectError) { var error = ffProcess.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(error)) { return(error); } } } else { throw new RecorderException($"Could not start {which}"); } return(""); }
public void ShouldFailIfPermissionsRequired() { Skip.If(PermissionsHelper.IsRunAsAdministrator(), "require non-administrator permissions"); var sut = new NetShHelper(); var result = sut.CreateUrlAcl(TestUrls[3]); result.Should().BeFalse(); }
private void HandleMicPermission() { if (!(PermissionsHelper.HasPermission(_context, ConstantsAndTypes.AppPermission.UseMicrophone) && PermissionsHelper.PermissionGranted(_context, ConstantsAndTypes.AppPermission.UseMicrophone))) { if (_speakSituationItem != null) { _speakSituationItem.Enabled = false; } } }
public IEnumerable <IConfigurationPage> GetPages() { List <IConfigurationPage> listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(AuthorityTokens.ViewerVisible)) { listPages.Add(new ConfigurationPage <PresetVoiLutConfigurationComponent>("TitleTools/TitleWindowLevel")); } return(listPages.AsReadOnly()); }
public IEnumerable <IConfigurationPage> GetPages() { List <IConfigurationPage> listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(ImageViewer.AuthorityTokens.ViewerVisible)) { listPages.Add(new ConfigurationPage <MonitorConfigurationApplicationComponent>("MonitorConfiguration")); } return(listPages.AsReadOnly()); }
internal static void VerifyNetworkStateAccess() { if (!PermissionsHelper.IsDeclaredInManifest(Manifest.Permission.AccessNetworkState)) { throw new UnauthorizedAccessException( "To access network information, please add " + "android.permission.ACCESS_NETWORK_STATE to application manifest " + "or the following attribute in the Android platform head: " + "[assembly: UsesPermission(\"android.permission.ACCESS_NETWORK_STATE\")]"); } }
public static async Task <GeolocationAccessStatus> RequestAccessAsync() { if (!await PermissionsHelper.CheckFineLocationPermission(CancellationToken.None)) { return(await PermissionsHelper.TryGetFineLocationPermission(CancellationToken.None) ? GeolocationAccessStatus.Allowed : GeolocationAccessStatus.Denied); } return(GeolocationAccessStatus.Allowed); }
public IEnumerable <IConfigurationPage> GetPages() { List <IConfigurationPage> listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(ClearCanvas.ImageViewer.AuthorityTokens.ViewerVisible)) { listPages.Add(new ConfigurationPage(AtsConfigurationComponent.Path, new AtsConfigurationComponent())); } return(listPages.AsReadOnly()); }
public IEnumerable <IConfigurationPage> GetPages() { List <IConfigurationPage> listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(AuthorityTokens.DicomExplorer)) { listPages.Add(new ConfigurationPage <DicomExplorerConfigurationComponent>("PathExplorer/PathDicom")); } return(listPages.AsReadOnly()); }
private void Play_Click(object sender, EventArgs e) { //if there is a current selection and it is not playing, then play it try { if (PermissionsHelper.PermissionGranted(this, ConstantsAndTypes.AppPermission.ReadExternalStorage)) { if (_mediaPlayer != null) { if (!_mediaPlayerConfigured) { Log.Info(TAG, "Play_Click: Player not configured - calling SetupMediaPlayer..."); SetupMediaPlayer(); } Log.Info(TAG, "Play_Click: currentlyPlayingTrack - " + _currentlyPlayingTrack.ToString()); Log.Info(TAG, "Play_Click: selectedItemIndex - " + _selectedListItemIndex.ToString()); if (_currentlyPlayingTrack != _selectedListItemIndex) { Log.Info(TAG, "Play_Click: isPlaying - " + (_isPlaying ? "True" : "False")); Log.Info(TAG, "Play_Click: isPaused - " + (_isPaused ? "True" : "False")); if (_mediaPlayer.IsPlaying || _isPaused) { if (_timerHandler != null) { _timerHandler.RemoveCallbacks(_timerRunnable); } else { Log.Info(TAG, "Play_Click: timerHandler is NULL!"); } _mediaPlayer.Stop(); _mediaPlayer.Reset(); if (_currentTrackPosition == -1) { _isPaused = false; _isPlaying = false; } } SetSelectedTrack(_selectedListItemIndex); _mediaPlayer.PrepareAsync(); } } } } catch (System.Exception ex) { Log.Error(TAG, "Play_Click: Exception - " + ex.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(this, ex, GetString(Resource.String.ErrorMusicPlayListTracksActivityPlay), "MusicPlayListTracksActivity.Play_Click"); } } }
public IEnumerable <IConfigurationPage> GetPages() { var listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(AuthorityTokens.ViewerVisible)) { listPages.Add(new ConfigurationPage(SegmentationConfigurationComponent.Path, new SegmentationConfigurationComponent())); } return(listPages.AsReadOnly()); }
public IEnumerable <IConfigurationPage> GetPages() { List <IConfigurationPage> listPages = new List <IConfigurationPage>(); if (PermissionsHelper.IsInRole(AuthorityTokens.ViewerVisible)) { listPages.Add(new ConfigurationPage <LayoutConfigurationComponent>(BasicLayoutConfigurationPath)); listPages.Add(new ConfigurationPage <DisplaySetCreationConfigurationComponent>(DisplaySetCreationConfigurationPath)); } return(listPages.AsReadOnly()); }
private async Task ValidateRequiredPermissions(CancellationToken ct) { if (!await PermissionsHelper.TryGetWriteExternalStoragePermission(ct)) { throw new UnauthorizedAccessException("Requires WRITE_EXTERNAL_STORAGE permission"); } if (!await PermissionsHelper.TryGetCameraPermission(ct)) { throw new UnauthorizedAccessException("Requires CAMERA permission"); } }
public void AlertPositiveButtonSelect(object sender, DialogClickEventArgs e, string instanceId) { if (instanceId == "useMic") { PermissionsHelper.RequestApplicationPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone); return; } var problem = GlobalData.ProblemSolvingItems.Find(prob => prob.ProblemID == _problemID); if (problem != null) { var step = problem.ProblemSteps.Find(stp => stp.ProblemStepID == _problemStepID); if (step != null) { var idea = step.ProblemStepIdeas.Find(ida => ida.ProblemIdeaID == _problemIdeaID); if (idea != null) { var proAndCon = idea.ProsAndCons[_selectedItemIndex]; if (proAndCon != null) { proAndCon.Remove(); idea.ProsAndCons.Remove(proAndCon); _selectedItemIndex = -1; UpdateAdapter(); } else { Log.Error(TAG, "AlertPositiveButtonSelect: proAndCon is NULL!"); } } else { Log.Error(TAG, "AlertPositiveButtonSelect: idea is NULL!"); } } else { Log.Error(TAG, "AlertPositiveButtonSelect: step is NULL!"); } } else { Log.Error(TAG, "AlertPositiveButtonSelect: problem is NULL!"); } }
public override void OnCreate() { base.OnCreate(); try { SetupDataFields(); ImageOptions = new DisplayImageOptions.Builder() .CacheInMemory(true) .CacheOnDisk(true) .ResetViewBeforeLoading() .ImageScaleType(UniversalImageLoader.Core.Assist.ImageScaleType.Exactly) .BitmapConfig(Android.Graphics.Bitmap.Config.Rgb565) .Build(); Log.Info(TAG, "OnCreate: Set up default options for Image Loader - cached in memory and cached on disk both true"); ImageLoaderConfig = new ImageLoaderConfiguration.Builder(Context) .DefaultDisplayImageOptions(ImageOptions) .Build(); ImageLoader.Instance.Init(ImageLoaderConfig); Log.Info(TAG, "OnCreate: Initialised Image Loader with default options set"); CurrentIsoLanguageCode = Locale.Default.ISO3Language; CurrentIsoCountryCode = Locale.Default.ISO3Country; Log.Info(TAG, "OnCreate: Determined Iso Language code - " + CurrentIsoLanguageCode); Log.Info(TAG, "OnCreate: Determined Iso Country code - " + CurrentIsoCountryCode); //grab current application permissions ApplicationPermissions = PermissionsHelper.SetupDefaultPermissionList(this); //******* thread task start Log.Info(TAG, "OnCreate: Initiating runnable thread..."); new Thread(new Runnable ( () => { Log.Info(TAG, "Runnable: Starting task ThreadTaskInitialisation"); ThreadTaskInitialisation(BaseContext); Log.Info(TAG, "Runnable: Finished runnable task"); } ) ).Start(); Log.Info(TAG, "OnCreate: In Main UI thread following initialisation of runnable task"); // thread task end } catch (System.Exception e) { Log.Error(TAG, "OnCreate: Error during GlobalData creation - " + e.Message); } }
public void AlertPositiveButtonSelect(object sender, DialogClickEventArgs e, string instanceId) { SQLiteDatabase sqlDatabase = null; try { if (instanceId == "useMic") { PermissionsHelper.RequestApplicationPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone); return; } if (instanceId == "remove") { var question = _appointment.Questions[_selectedItemIndex]; if (question != null) { Globals dbHelp = new Globals(); dbHelp.OpenDatabase(); sqlDatabase = dbHelp.GetSQLiteDatabase(); if (sqlDatabase != null && sqlDatabase.IsOpen) { question.Remove(sqlDatabase); _appointment.Questions.Remove(question); UpdateAdapter(); sqlDatabase.Close(); sqlDatabase = null; _selectedItemIndex = -1; } } } else { SaveAppointment(); SetResult(Result.Ok); Finish(); } } catch (Exception ex) { if (sqlDatabase != null && sqlDatabase.IsOpen) { sqlDatabase.Close(); sqlDatabase = null; } Log.Error(TAG, "AlertPositiveButtonSelect: Exception - " + ex.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(this, ex, GetString(Resource.String.AppointmentQuestionRemoveAlertTitle), "ResourcesAppointmentItemActivity.AlertPositiveButtonSelect"); } } }
public void SetupDefaultRolePermissions() { var permissionCommonService = Container.Resolve <IPermissionCommonService>(); var pageService = Container.Resolve <IPageService>(); var userService = Container.Resolve <IUserService>(); var permissionService = Container.Resolve <IPermissionService>(); var page = CreatePage(); pageService.Save(page); var operations = GetTestObjectOperations(); permissionCommonService.SetupDefaultRolePermissions(operations, typeof(Page), page.Id); //check guest var isAllowed = permissionCommonService.IsAllowed(1, null, typeof(Page), page.Id, PermissionOperationLevel.Object); Assert.IsFalse(isAllowed); //check user var user = CreateUserAndAssignToRole(null); userService.Save(user); isAllowed = permissionCommonService.IsAllowed(1, user, typeof(Page), page.Id, PermissionOperationLevel.Object); Assert.IsTrue(isAllowed); //check owner isAllowed = permissionCommonService.IsAllowed(1, user, typeof(Page), page.Id, true, PermissionOperationLevel.Object); Assert.IsTrue(isAllowed); userService.Delete(user); pageService.Delete(page); var query = from permission in permissionService.CreateQuery() where permission.EntityType.Name == PermissionsHelper.GetEntityType(typeof(Page)) && permission.EntityId == page.Id select permission; var result = query.ToList(); Assert.AreEqual(3, result.Count); foreach (var item in result) { permissionService.Delete(item); } result = query.ToList(); Assert.AreEqual(0, result.Count); }
/// <summary> /// Gets the resource operations. /// </summary> /// <param name="resource">The resource.</param> /// <param name="area">The area.</param> /// <returns></returns> public static IEnumerable <IPermissionOperation> GetResourceOperations(EntityType resource, PermissionArea area) { var permissibleObject = MvcApplication.PermissibleObjects.FirstOrDefault( perm => PermissionsHelper.GetEntityType(perm.GetType()) == resource.Name); if (permissibleObject != null) { return(permissibleObject.Operations.Where(operation => (area == PermissionArea.Plugin || operation.Area == area) && operation.OperationLevel != PermissionOperationLevel.Object)); } return(null); }
public void ShouldBeAbleToGetUrlAcl() { Skip.If(!PermissionsHelper.IsRunAsAdministrator(), "require administrator permissions"); var sut = new NetShHelper(); PrepareTestUrlAcl(sut, TestUrls[1]); var result = sut.GetUrlAcl(TestUrls[1]); result.Should().NotBeNull(); result.Reservations.First().Url.Should().Be(TestUrls[1]); result.Reservations.First().Data["User"].Should().Be($"{Environment.UserDomainName}\\{Environment.UserName}"); }
public void ShouldBeAbleToGetFirewallRule() { Skip.If(!PermissionsHelper.IsRunAsAdministrator(), "require administrator permissions"); var sut = new NetShHelper(); PrepareTestRule(sut, TestRuleName(nameof(ShouldBeAbleToGetFirewallRule)), TestPorts + 4); var result = sut.GetFirewallRule(TestRuleName(nameof(ShouldBeAbleToGetFirewallRule))); result.Should().NotBeNull(); result.Rules.First().RuleName.Should().Be(TestRuleName(nameof(ShouldBeAbleToGetFirewallRule))); result.Rules.First().LocalPort.Should().Be(TestPorts + 4); }
public async void GetLocationPermission() { var status = await PermissionsHelper.GetPermission(Permission.LocationWhenInUse); if (status == PermissionStatus.Granted) { await locationHelper.GetLocation(TimeSpan.FromMinutes(30), 500); } else { await App.Current.MainPage.DisplayAlert("Access to location denied", "We don't have access to your location", "Ok"); } }
private void thisPage_Loaded(object sender, RoutedEventArgs e) { try { App.MainWnd.ChangeTitle(Title); PermissionsHelper.PermissionsLicense(MainSettingTile, PersonalizationSettingTile, ChangePasswordTile, OpenSettingPlayer); PermissionsHelper.PermissionsAdmin(MainSettingTile, PersonalizationSettingTile, ChangePasswordTile, OpenSettingPlayer); } catch (Exception ex) { App.SendException(ex); } }