public void GetEdgeHubConfig_AuthorizationValidatorReturnsError_ExpectedException() { var validator = new Mock <BrokerPropertiesValidator>(); validator .Setup(v => v.ValidateAuthorizationConfig(It.IsAny <AuthorizationProperties>())) .Returns(new List <string> { "Validation error has occurred" }); var routeFactory = new EdgeRouteFactory(new Mock <IEndpointFactory>().Object); var configParser = new EdgeHubConfigParser(routeFactory, validator.Object); var authzProperties = new AuthorizationProperties { new AuthorizationProperties.Statement( identities: new List <string> { "device_1", "device_3" }, allow: new List <AuthorizationProperties.Rule>(), deny: new List <AuthorizationProperties.Rule>()) }; var brokerProperties = new BrokerProperties(new BridgeConfig(), authzProperties); var properties = new EdgeHubDesiredProperties_1_2( "1.2.0", new Dictionary <string, RouteSpec>(), new StoreAndForwardConfiguration(100), brokerProperties); // assert Assert.Throws <InvalidOperationException>(() => configParser.GetEdgeHubConfig(properties)); }
public void GetEdgeHubConfig_BridgeValidatorReturnsError_ExpectedException() { var validator = new Mock <BrokerPropertiesValidator>(); validator .Setup(v => v.ValidateAuthorizationConfig(It.IsAny <AuthorizationProperties>())) .Returns(new List <string>()); validator .Setup(v => v.ValidateBridgeConfig(It.IsAny <BridgeConfig>())) .Returns(new List <string> { "Validation error has occurred" }); var routeFactory = new EdgeRouteFactory(new Mock <IEndpointFactory>().Object); var configParser = new EdgeHubConfigParser(routeFactory, validator.Object); var bridgeConfig = new BridgeConfig { new Bridge("floor2", new List <Settings> { }) }; var brokerProperties = new BrokerProperties(bridgeConfig, new AuthorizationProperties()); var properties = new EdgeHubDesiredProperties_1_2( "1.2.0", new Dictionary <string, RouteSpec>(), new StoreAndForwardConfiguration(100), brokerProperties); // assert Assert.Throws <InvalidOperationException>(() => configParser.GetEdgeHubConfig(properties)); }
} // Name public override void Execute() { var oValidator = new ValidateMobileCode(this.mobilePhoneNumber, this.confirmationCode); oValidator.Execute(); if (!oValidator.IsValidatedSuccessfully()) { throw new StrategyWarning(this, "Failed to validate mobile code."); } var sp = new SpBrokerLoadOwnProperties(DB, Log) { ContactMobile = this.mobilePhoneNumber, }; BrokerProperties props = sp.FillFirst <BrokerProperties>(); if ((props == null) || (props.BrokerID == 0)) { throw new StrategyWarning(this, string.Format( "No broker found with this phone number {0}.", this.mobilePhoneNumber )); } // if Log.Debug("Broker properties search result for mobile phone {0}:\n{1}", this.mobilePhoneNumber, props); new BrokerPasswordRestored(props.BrokerID).Execute(); } // Execute
public JsonResult Login(string LoginEmail, string LoginPassword) { ms_oLog.Debug("Broker login request: {0}", LoginEmail); if (User.Identity.IsAuthenticated) { ms_oLog.Warn( "Login request with contact email {0}: already authorized as {1}.", LoginEmail, User.Identity.Name ); return(new BrokerForJsonResult("You are already logged in.")); } // if BrokerProperties bp = this.m_oHelper.TryLogin(LoginEmail, LoginPassword, null, null); if (bp == null) { return(new BrokerForJsonResult("Failed to log in.")); } ms_oLog.Debug("Broker login succeeded for: {0}", LoginEmail); return(new PropertiesBrokerForJsonResult(oProperties: bp) { antiforgery_token = AntiForgery.GetHtml().ToString() }); } // Login
public PropertiesBrokerForJsonResult( string sErrorMsg = "", bool?bExplicitSuccess = null, BrokerProperties oProperties = null ) : base(sErrorMsg, bExplicitSuccess) { properties = oProperties ?? new BrokerProperties(); } // constructor
public BrokerLoadOwnProperties(string sContactEmail, CustomerOriginEnum origin) { m_oSp = new SpBrokerLoadOwnProperties(DB, Log) { ContactEmail = sContactEmail, Origin = (int)origin, BrokerID = 0, ContactMobile = null, }; Properties = new BrokerProperties(); } // constructor
} // constructor public BrokerLoadOwnProperties(int brokerID) { m_oSp = new SpBrokerLoadOwnProperties(DB, Log) { ContactEmail = null, Origin = 0, BrokerID = brokerID, ContactMobile = null, }; Properties = new BrokerProperties(); } // constructor
public BrokerSignup( string sFirmName, string sFirmRegNum, string sContactName, string sContactEmail, string sContactMobile, string sMobileCode, string sContactOtherPhone, DasKennwort password, DasKennwort passwordAgain, string sFirmWebSiteUrl, bool bIsCaptchaEnabled, int nBrokerTermsID, string sReferredBy, bool bFCARegistered, string sLicenseNumber, int uiOriginID ) { this.isCaptchaEnabled = bIsCaptchaEnabled; this.mobileCode = sMobileCode; this.sp = new SpBrokerSignUp(password.Decrypt(), passwordAgain.Decrypt(), DB, Log) { FirmName = sFirmName, FirmRegNum = sFirmRegNum, ContactName = sContactName, ContactEmail = (sContactEmail ?? string.Empty).Trim().ToLowerInvariant(), ContactMobile = sContactMobile, ContactOtherPhone = sContactOtherPhone, EstimatedMonthlyClientAmount = 0, FirmWebSiteUrl = sFirmWebSiteUrl, EstimatedMonthlyApplicationCount = 0, BrokerTermsID = nBrokerTermsID, ReferredBy = sReferredBy, Strategy = this, FCARegistered = bFCARegistered, LicenseNumber = sLicenseNumber, UiOriginID = uiOriginID, }; Properties = new BrokerProperties(); } // constructor
/// <summary> /// Build Service Bus Message /// </summary> /// <returns></returns> static ServiceBusMessage[] BuildServiceBusMessage() { var brokerProperties = new BrokerProperties() { Label = "TestLabel", TimeToLiveTimeSpan = TimeSpan.FromSeconds(120).ToString() }; var userProperties = new UserProperties() { CustomerName = "ABC", Priority = "Medium" }; var sbMessage = new ServiceBusMessage() { Body = "Test Message 1", BrokerProperties = brokerProperties, UserProperties = userProperties }; var messages = new List <ServiceBusMessage>(); messages.Add(sbMessage); return(messages.ToArray()); }
public BrokerLogin( string sEmail, DasKennwort sPassword, string promotionName, DateTime?promotionPageVisitTime, int uiOriginID ) { this.spLoadDataForLoginCheck = new BrokerLoadLoginData(DB, Log) { Email = sEmail, UiOriginID = uiOriginID, }; this.spOnSuccess = new BrokerLoginSucceeded(DB, Log) { LotteryCode = promotionName, PageVisitTime = promotionPageVisitTime, }; this.password = sPassword.Decrypt(); Properties = new BrokerProperties(); } // constructor
public static EdgeHubDesiredProperties_1_2 GetTestData() { var statement1 = new AuthorizationProperties.Statement( identities: new List <string> { "device_1", "device_3" }, allow: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish", "mqtt:subscribe" }, resources: new List <string> { "topic/a", "topic/b" }) }, deny: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish" }, resources: new List <string> { "system/alerts/+", "core/#" }) }); var statement2 = new AuthorizationProperties.Statement( identities: new List <string> { "device_2" }, allow: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish", "mqtt:subscribe" }, resources: new List <string> { "topic1", "topic2" }) }, deny: new List <AuthorizationProperties.Rule>()); var authzProperties = new AuthorizationProperties { statement1, statement2 }; var bridgeConfig = new BridgeConfig { new Bridge("$upstream", new List <Settings> { new Settings(Direction.In, "topic/a", "local/", "remote/") }), new Bridge("floor2", new List <Settings> { new Settings(Direction.Out, "/topic/b", "local", "remote") }) }; var brokerProperties = new BrokerProperties(bridgeConfig, authzProperties); var properties = new EdgeHubDesiredProperties_1_2( "1.2.0", new Dictionary <string, RouteSpec>(), new StoreAndForwardConfiguration(100), brokerProperties); return(properties); }
public JsonResult CustomerLogOn(LogOnModel model) { string customerIp = RemoteIp(); CustomerOriginEnum origin = UiCustomerOrigin.Get().GetOrigin(); if (!ModelState.IsValid) { log.Debug( "Customer log on attempt from remote IP {0} to origin '{1}': model state is invalid, list of errors:", customerIp, origin ); foreach (var val in ModelState.Values) { if (val.Errors.Count < 1) { continue; } foreach (var err in val.Errors) { log.Debug("Model value '{0}' with error '{1}'.", val.Value, err.ErrorMessage); } } // for each value log.Debug("End of list of errors."); return(Json(new { success = false, errorMessage = "User not found or incorrect password." }, JsonRequestBehavior.AllowGet)); } // if var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount); log.Debug( "Customer log on attempt from remote IP {0} received " + "with user name '{1}' and hash '{2}' (promotion: {3})...", customerIp, model.UserName, pu.Generate(model.UserName, model.Password), model.PromotionDisplayData ); try { if (this.brokerHelper.IsBroker(model.UserName)) { BrokerProperties bp = this.brokerHelper.TryLogin( model.UserName, model.Password, model.PromotionName, model.PromotionPageVisitTime ); if ((bp != null) && (bp.CurrentTermsID != bp.SignedTermsID)) { Session[Constant.Broker.Terms] = bp.CurrentTerms; Session[Constant.Broker.TermsID] = bp.CurrentTermsID; } // if return(Json(new { success = (bp != null), errorMessage = (bp == null) ? "User not found or incorrect password." : string.Empty, broker = true, })); } // if is broker } catch (Exception e) { log.Warn( e, "Failed to check whether '{0}' is a broker login at origin '{1}', continuing as a customer.", model.UserName, origin ); } // try var loginModel = new LoginCustomerMultiOriginModel { UserName = model.UserName, Origin = origin, Password = new DasKennwort(model.Password), PromotionName = model.PromotionName, PromotionPageVisitTime = model.PromotionPageVisitTime, RemoteIp = customerIp, }; UserLoginActionResult ular = this.serviceClient.Instance.LoginCustomerMutliOrigin(loginModel); if (MembershipCreateStatus.Success.ToString() == ular.Status) { model.SetCookie(LogOnModel.Roles.Customer); this.context.SetSessionOrigin(origin); return(Json(new { success = true, model, }, JsonRequestBehavior.AllowGet)); } // if // If we got this far, something failed, redisplay form return(Json(new { success = false, errorMessage = ular.ErrorMessage }, JsonRequestBehavior.AllowGet)); } // CustomerLogOn
public static EdgeHubDesiredProperties GetTestData() { var statement1 = new AuthorizationProperties.Statement( identities: new List <string> { "device_1", "device_3" }, allow: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish", "mqtt:subscribe" }, resources: new List <string> { "topic/a", "topic/b" }) }, deny: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish" }, resources: new List <string> { "system/alerts/+", "core/#" }) }); var statement2 = new AuthorizationProperties.Statement( identities: new List <string> { "device_2" }, allow: new List <AuthorizationProperties.Rule> { new AuthorizationProperties.Rule( operations: new List <string> { "mqtt:publish", "mqtt:subscribe" }, resources: new List <string> { "topic1", "topic2" }) }, deny: new List <AuthorizationProperties.Rule>()); var authzProperties = new AuthorizationProperties { statement1, statement2 }; var brokerProperties = new BrokerProperties(new BridgeConfig(), authzProperties); var properties = new EdgeHubDesiredProperties( "1.2.0", new Dictionary <string, RouteConfiguration>(), new StoreAndForwardConfiguration(100), brokerProperties); return(properties); }