/// <summary> /// Used to check if one or all of the given features are enabled. /// </summary> /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param> /// <param name="requiresAll">True, to require that all the given features are enabled. False, to require one or more.</param> /// <param name="featureNames">Names of the features</param> public static bool IsEnabled(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) { if (featureNames.IsNullOrEmpty()) { return(true); } if (requiresAll) { foreach (var featureName in featureNames) { if (!featureChecker.IsEnabled(featureName)) { return(false); } } return(true); } foreach (var featureName in featureNames) { if (featureChecker.IsEnabled(featureName)) { return(true); } } return(false); }
/// <summary> /// Checks if one or all of the given features are enabled. Throws <see cref="AbpAuthorizationException"/> if not. /// </summary> /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param> /// <param name="requiresAll">True, to require that all the given features are enabled. False, to require one or more.</param> /// <param name="featureNames">Names of the features</param> public static void CheckEnabled(this IFeatureChecker featureChecker, bool requiresAll, params string[] featureNames) { if (featureNames.IsNullOrEmpty()) { return; } var localizedFeatureNames = LocalizeFeatureNames(featureChecker, featureNames); if (requiresAll) { foreach (var featureName in featureNames) { if (!featureChecker.IsEnabled(featureName)) { throw new AbpAuthorizationException( string.Format( L( featureChecker, "AllOfTheseFeaturesMustBeEnabled", "Required features are not enabled. All of these features must be enabled: {0}" ), string.Join(", ", localizedFeatureNames) ) ); } } } else { foreach (var featureName in featureNames) { if (featureChecker.IsEnabled(featureName)) { return; } } throw new AbpAuthorizationException( string.Format( L( featureChecker, "AtLeastOneOfTheseFeaturesMustBeEnabled", "Required features are not enabled. At least one of these features must be enabled: {0}" ), string.Join(", ", localizedFeatureNames) ) ); } }
/// <summary> /// Checks if given feature is enabled. Throws <see cref="AbpAuthorizationException"/> if not. /// </summary> /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param> /// <param name="featureName">Unique feature name</param> public static void CheckEnabled(this IFeatureChecker featureChecker, string featureName) { if (!featureChecker.IsEnabled(featureName)) { throw new AbpAuthorizationException("Feature is not enabled: " + featureName); } }
private void CheckChatFeaturesInternal(int?sourceTenantId, int?targetTenantId, ChatSide side) { var localizationPosfix = side == ChatSide.Sender ? "ForSender" : "ForReceiver"; if (sourceTenantId.HasValue) { if (!_featureChecker.IsEnabled(sourceTenantId.Value, AppFeatures.ChatFeature)) { throw new UserFriendlyException(L("ChatFeatureIsNotEnabled" + localizationPosfix)); } if (targetTenantId.HasValue) { if (sourceTenantId == targetTenantId) { return; } if (!_featureChecker.IsEnabled(sourceTenantId.Value, AppFeatures.TenantToTenantChatFeature)) { throw new UserFriendlyException(L("TenantToTenantChatFeatureIsNotEnabled" + localizationPosfix)); } } else { if (!_featureChecker.IsEnabled(sourceTenantId.Value, AppFeatures.TenantToHostChatFeature)) { throw new UserFriendlyException(L("TenantToHostChatFeatureIsNotEnabled" + localizationPosfix)); } } } else { if (targetTenantId.HasValue) { if (!_featureChecker.IsEnabled(targetTenantId.Value, AppFeatures.TenantToHostChatFeature)) { throw new UserFriendlyException(L("TenantToHostChatFeatureIsNotEnabled" + (side == ChatSide.Sender ? "ForReceiver" : "ForSender"))); } } } }
/// <summary> /// Checks if a given feature is enabled. Throws <see cref="AbpAuthorizationException"/> if not. /// </summary> /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param> /// <param name="featureName">Unique feature name</param> public static void CheckEnabled(this IFeatureChecker featureChecker, string featureName) { if (!featureChecker.IsEnabled(featureName)) { throw new AbpAuthorizationException(string.Format( L( featureChecker, "FeatureIsNotEnabled", "Feature is not enabled: {0}" ), featureName )); } }
void btnShareCenter_Click(object arg1, System.Windows.RoutedEventArgs arg2) { IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); if (!featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_ManageShares)) { Selected = false; return; } btnShareCenter.Selected = true; if (MenuButtonClick != null) { MenuButtonClick(this, arg2); } }
public bool ExecuteCommand(string command, Dictionary <string, object> parameters) { if (command == "ReloadSecureBrowser") { var model = content.DataContext as SecureBrowserViewModel; if (model != null && model.TabItemCollection != null) { var tmp = model.TabItemCollection.ToList(); foreach (var tab in tmp) { model.TabItemCollection.Single(p => p.TabId == tab.TabId).RemoveSelectedTabClick(null); } model.LoadSecureBrowserFavoriteList(); } } else { IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); if (!featureChecker.IsEnabled(DefaultProperties.Features_SecureBrowser_AccessSecureBrowser, showUIIfNotEnabled: false)) { BrowserHelper.OpenInDefaultBrowser(new Uri(parameters["url"].ToString(), UriKind.RelativeOrAbsolute)); } else { var model = content.DataContext as SecureBrowserViewModel; if (model.SelectedTabItem != null) { if (parameters.ContainsKey("TabIndex") && parameters["TabIndex"] is int && (int)parameters["TabIndex"] > -1 && (int)parameters["TabIndex"] < model.TabItemCollection.Count) { var currentTab = model.TabItemCollection[(int)parameters["TabIndex"]]; model.SelectedTabItem = currentTab; currentTab.SearchBar.Address = parameters["url"].ToString(); currentTab.SearchBar.Navigate(); } else { model.SelectedTabItem.AddNewTabForUrl(parameters["url"].ToString(), true); } return(true); } } } return(false); }
/// <summary> /// Checks if a given feature is enabled. Throws <see cref="AbpAuthorizationException"/> if not. /// </summary> /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param> /// <param name="featureName">Unique feature name</param> public static void CheckEnabled(this IFeatureChecker featureChecker, string featureName) { var localizedFeatureNames = LocalizeFeatureNames(featureChecker, new[] { featureName }); if (!featureChecker.IsEnabled(featureName)) { throw new AbpAuthorizationException(string.Format( L( featureChecker, "FeatureIsNotEnabled", "Feature is not enabled: {0}" ), localizedFeatureNames.First() )); } }
/// <summary> /// used to enable the alert popup and assign close and Open events /// </summary> /// <param name="obj"></param> private void AlertNotificationClick(object obj) { IFeatureChecker featureChecker = Resolver.GetInstanceOf <IFeatureChecker>(); if (!featureChecker.IsEnabled(DefaultProperties.Features_Miscellaneous_ShowNotificationAndAlerts)) { return; } alertPop = obj as Popup; if (alertPop != null) { alertPop.IsOpen = true; AlertButtonBackColor = DefaultProperties.AlertBackgroundcolor(); AlertBorderStrokeColor = DefaultProperties.AlertBorderStrokecolor(HiglightedBorderStrokecolor); alertPop.Closed += alertPop_Closed; Alert = BindingAlertData(false); AlertHistory = BindingAlertData(true); } }
void btnPasswordGenerator_Click(object arg1, System.Windows.RoutedEventArgs arg2) { IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); if (!featureChecker.IsEnabled(DefaultProperties.Features_PasswordGenerator_AccessPasswordGenerator)) { Selected = false; return; } btnPasswordGenerator.Selected = true; if (MenuButtonClick != null) { MenuButtonClick(this, arg2); if (content != null) { var _passwordGeneratorViewModel = content.DataContext as PasswordGeneratorViewModel; _passwordGeneratorViewModel.DefaultView(); } } }
public void Changing_Tenant_Feature_Should_Not_Effect_Other_Tenants() { //Create tenants var firstTenantId = UsingDbContext(context => { var firstTenant = new Tenant("Tenant1", "Tenant1"); context.Tenants.Add(firstTenant); context.SaveChanges(); return(firstTenant.Id); }); var secondTenantId = UsingDbContext(context => { var secondTenant = new Tenant("Tenant2", "Tenant2"); context.Tenants.Add(secondTenant); context.SaveChanges(); return(secondTenant.Id); }); _tenantManager.SetFeatureValue(firstTenantId, AppFeatureProvider.MyBoolFeature, "true"); _featureChecker.IsEnabled(secondTenantId, AppFeatureProvider.MyBoolFeature).ShouldBe(false); }
private bool IsValidForShowingMainWindow(bool isDeviceTrusted) { logger.Debug("IsValidForShowindMainWindow start. IsDeviceTrusted - {0}", isDeviceTrusted); //Debugger.Launch(); bool showMainWindow = true; //if(IsTwoStepVerificationPassed) //{ // return showMainWindow; //we already went with two step verification //} IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); if (!featureChecker.IsEnabled(DefaultProperties.Features_Miscellaneous_TwoStepAuthentication, showUIIfNotEnabled: false)) { logger.Debug("two step verification not enabled - show main window"); return(showMainWindow); } bool multiFactorAuthEnabled = false; bool isOnline = false; logger.Debug("Getting user info"); var userInfo = pbData.GetUserInfo(pbData.ActiveUser); if (userInfo != null) { logger.Debug("userInfo got - {0}", userInfo); isOnline = webApi.HasInetConn; if (userInfo.MultiFactorAuthentication) { logger.Debug("multifactor authentication!"); if (!isOnline) { logger.Debug("No internet - show main window"); ErrorMessage = "You have 2-step authentication enabled and must be online to do this"; showMainWindow = false; multiFactorAuthEnabled = true; return(showMainWindow); //we skip furter checking } } if (isOnline) { logger.Debug("have internet"); //retreive info from web if this is enabled anyway logger.Debug("GetAccount calling"); dynamic twoStepResp = webApi.GetAccount(pbData.ActiveUser + "|" + pbData.DeviceUUID, new WEBApiJSON.AccountRequest { }); logger.Debug("GetAccount calling"); string multiFactorAuth = null; if (twoStepResp.error == null) { logger.Debug("TwoStepResponse.error == null"); multiFactorAuth = twoStepResp.account.multi_factor_authentication; logger.Debug("MultiFactorAuth - {0}", multiFactorAuth); } else { logger.Debug("TwoStepResponse.error != null"); logger.Error(twoStepResp.error.ToString()); } if (!string.IsNullOrWhiteSpace(multiFactorAuth)) { bool.TryParse(multiFactorAuth, out multiFactorAuthEnabled); if (multiFactorAuthEnabled) { logger.Debug("multifactorAuthEnabled - true, dont show main window"); showMainWindow = false; //we will show two step dialog instead } if (userInfo.MultiFactorAuthentication != multiFactorAuthEnabled) //update DB only if it's different { logger.Debug("userInfo.MultiFactorAuthentication != multiFactorAuthEnabled"); pbData.UpdateMultiFactorAuthentication(multiFactorAuthEnabled); } } } } logger.Debug("multiFactorAuthEnabled - {0}, isDeviceTrusted - {1}", multiFactorAuthEnabled, isDeviceTrusted); if (multiFactorAuthEnabled && isDeviceTrusted) { logger.Debug("ShowMainWindow set true"); showMainWindow = true; } else if (multiFactorAuthEnabled && !isDeviceTrusted) { logger.Debug("ShowMainWindow set false"); showMainWindow = false; } logger.Debug("ShowMainWindow - {0}", showMainWindow); if (!showMainWindow) { logger.Debug("Close profile"); pbData.CloseProfile(); //two step needs to be passed } else { logger.Debug("UserPassword = string.Empty;"); UserPassword = string.Empty; } logger.Debug("IsValidForShowingMainWindow ended. result - {0}", showMainWindow); return(showMainWindow); }
public List <SecuerShareData> ShareItem(string receiver, string message, SecureItem secureItem, int expirationPeriodIndex, bool passwordVisibleToRecipient, DateTime?expirationDate) { Share share = new Share() { Receiver = receiver, Message = message, Visible = passwordVisibleToRecipient, ExpirationDate = expirationDate ?? DateTime.Now.AddYears(50).ToUniversalTime() }; Share shareItem = new Share(); logger.Info("Start ShareItem"); try { bool isShareAllowed = true; bool isShareTresholdReached = pbData.IsShareTresholdReached(false, true); IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UnlimitedShares, showUIIfNotEnabled: false); if (!isShareAllowed) { isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UpTo5Shares, showUIIfNotEnabled: false) && !isShareTresholdReached; } if (!isShareAllowed) { featureChecker.FireActionNotEnabledUI(); return(new List <SecuerShareData>()); } //validate emails List <string> receiverList = new List <string>(); share.Receiver = share.Receiver.Replace(" ", String.Empty); if (share.Receiver.Contains(',')) { receiverList.AddRange(share.Receiver.Replace(" ", String.Empty).Split(',')); } if (share.Receiver.Contains(';')) { receiverList.AddRange(share.Receiver.Replace(" ", String.Empty).Split(';')); } if (receiverList.Count == 0) { receiverList.Add(share.Receiver); } Common cm = new Common(); //Changed List <Share> shareList = pbData.GetShares(true, false, null, null); List <string> alreadyShared = shareList.Select(x => x.Receiver).ToList <string>(); foreach (var rec in receiverList) { if (!cm.IsEmailValid(rec)) { continue; } if (rec == pbData.ActiveUser) { continue; } if (alreadyShared.Contains(rec)) { continue; } else { alreadyShared.Add(rec); } ShareRequest reqData = new ShareRequest() { receiver = rec, secure_item_type = null, status = ShareStatus.Waiting, nickname = share.Nickname, expiration_date = share.ExpirationDateString, message = share.Message }; dynamic response = pbWebApi.RequestShare(reqData, String.Format("{0}|{1}", pbData.ActiveUser, pbData.DeviceUUID)); if (response.error != null) { MessageBox.Show(response.error.details.ToString(), response.error.message.ToString()); return(new List <SecuerShareData>()); } if (response.shares.sent != null) { if (response.shares.sent[0] != null) { dynamic sent = response.shares.sent[0]; if (!String.IsNullOrEmpty(sent.public_key.ToString())) { string receiverPublicKey = sent.public_key.ToString(); // Don't make recipient item as favorite. UATD-387 if (share.SharedItem == SharedItems.folder) { foreach (Folder folder in share.Folders) { foreach (SecureItem item in folder.SecureItems) { item.Favorite = false; } } } else { foreach (SecureItem item in share.SecureItems) { item.Favorite = false; } } reqData.data = EncriptItemForShare(share, Encoding.UTF8.GetString(Convert.FromBase64String(receiverPublicKey)));// JsonConvert.SerializeObject(new { key = encriptionKey, payload = payload }, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); reqData.status = ShareStatus.Pending; reqData.message = share.Message; if (!expirationDate.HasValue) { switch (expirationPeriodIndex) { case 0: share.ExpirationDate = DateTime.Now.AddYears(50).ToUniversalTime(); break; case 1: share.ExpirationDate = DateTime.Now.AddDays(1).ToUniversalTime(); break; case 2: share.ExpirationDate = DateTime.Now.AddDays(7).ToUniversalTime(); break; case 3: share.ExpirationDate = DateTime.Now.AddMonths(1).ToUniversalTime(); break; case 4: share.ExpirationDate = DateTime.Now.AddYears(1).ToUniversalTime(); break; default: share.ExpirationDate = DateTime.Now.AddYears(50).ToUniversalTime(); break; } } reqData.expiration_date = share.ExpirationDateString; reqData.order = "0"; reqData.uuid = sent.uuid.ToString(); reqData.visible = share.Visible; response = pbWebApi.RequestShare(reqData, String.Format("{0}|{1}", pbData.ActiveUser, pbData.DeviceUUID)); if (response.error != null) { MessageBox.Show(response.error.details.ToString(), response.error.message.ToString()); return(new List <SecuerShareData>()); } sent = response.shares.sent[0]; shareItem.Receiver = reqData.receiver; shareItem.Sender = pbData.ActiveUser; shareItem.ExpirationDate = expirationDate.Value; shareItem.Data = reqData.data; shareItem.Id = sent.uuid.ToString(); shareItem.UUID = sent.uuid.ToString(); shareItem.Status = sent.status; shareItem.Nickname = sent.nickname; shareItem.Message = reqData.message; shareItem.SecureItemType = reqData.secure_item_type; shareItem.ReceiverPrivateKey = receiverPublicKey; shareItem.Visible = reqData.visible; pbData.AddOrUpdateShare(shareItem); //return BindingSecureShareList(item.Id); //CASE #1 } else { sent = response.shares.sent[0]; shareItem.Receiver = reqData.receiver; shareItem.Sender = pbData.ActiveUser; shareItem.ExpirationDate = DateTime.Now.AddDays(1).ToUniversalTime(); shareItem.Data = reqData.data; shareItem.Id = sent.uuid.ToString(); shareItem.UUID = sent.uuid.ToString(); shareItem.Status = sent.status; shareItem.Nickname = sent.nickname; shareItem.Message = reqData.message; shareItem.SecureItemType = reqData.secure_item_type; shareItem.ReceiverPrivateKey = null; shareItem.Visible = reqData.visible; pbData.AddOrUpdateShare(shareItem); //return BindingSecureShareList(item.Id); //CASE #2 - user does not exist - no data encription } if (inAppAnalyitics != null) { doShareAnalytics(shareItem, ShareEventStatus.Shared); } } } } //((IAppCommand)System.Windows.Application.Current).ExecuteCommand("ReloadData", null); return(BindingSecureShareList(shareItem)); } catch (Exception ex) { logger.Error("Error in ShareItem -->" + ex.ToString()); MessageBox.Show("Error while saving share"); } return(new List <SecuerShareData>()); }
private void AcceptShare(object obj) { if (!AcceptMessageBoxVisibility) { if (obj == null) { return; } currentUUID = obj as string; AcceptMessageBoxVisibility = true; return; } AcceptMessageBoxVisibility = false; if (currentUUID == null) { return; } var uuid = currentUUID as string; currentUUID = null; if (String.IsNullOrWhiteSpace(uuid)) { return; } try { bool isShareAllowed = true; bool isShareTresholdReached = pbData.IsShareTresholdReached(true, false); IFeatureChecker featureChecker = resolver.GetInstanceOf <IFeatureChecker>(); isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UnlimitedShares, showUIIfNotEnabled: false); if (!isShareAllowed) { isShareAllowed = featureChecker.IsEnabled(DefaultProperties.Features_ShareCenter_UpTo5Shares, showUIIfNotEnabled: false) && !isShareTresholdReached; } if (!isShareAllowed) { featureChecker.FireActionNotEnabledUI(); return; } //TODO extract data and save secureItem Share item = pbData.GetSharesByUuid(uuid); if (item != null) { IPBWebAPI wepApi = resolver.GetInstanceOf <IPBWebAPI>(); dynamic share = wepApi.JsonStringToDynamic(item.Data); if (share != null) { string encriptionKey = share.key.ToString(); UserInfo ui = pbData.GetUserInfo(pbData.ActiveUser); encriptionKey = pbData.DecriptWithRSA(ui.RSAPrivateKey, encriptionKey); AESKeySet keySet = AESKeySet.KeysFromString(encriptionKey); string encriptedPayload = share.payload.ToString(); string data = pbData.DecryptAndVerifyWithAES(encriptedPayload, keySet);//.DecriptWithAES(encriptedPayload, encriptionKey); SecureItemShare sharedSecureItem = Newtonsoft.Json.JsonConvert.DeserializeObject <SecureItemShare>(data); sharedSecureItem.data.password_visible_recipient = item.Visible; string secureItemId = null; if (SaveSecureItem(sharedSecureItem, out secureItemId)) { if (shareCommon.UpdateShareStatus(uuid, ShareStatus.Shared, true, secureItemId)) { UpdateData(false, true); } ((IAppCommand)System.Windows.Application.Current).ExecuteCommand("ReloadData", null); } } } } catch (Exception ex) { logger.Error(String.Format("Error while Accepting share with uuid -> {0} with error-> {1}", uuid, ex.ToString())); } }