private void PropertyPage_Save(object sender, ResultEventArgs <bool> e) { if (this.generalPropPage.IsValid() == false || this.accountsPropPage.IsValid() == false) { MsgBoxUtil.Show(this.generalPropPage.ParentSheet, "Some information is missing or incorrect. Please review and correct the information entered on each page."); e.Result = false; } else { if (this.generalPropPage.IsDirty() == true || this.accountsPropPage.IsDirty() == true) { // load app info from SSO this.appInfo = SSOManager.GetApplicationInfo(this.appInfo.Name); // update it with new information from property pages this.generalPropPage.Update(this.appInfo); this.accountsPropPage.Update(this.appInfo); // save changes into SSO SSOManager.UpdateApplicationInfo(this.appInfo); // notify subscribers the application has been saved this.OnSaved(EventArgs.Empty); } e.Result = true; } }
private static bool Export(string[] args) { // validate arguments if (args.Length < 3) { Console.WriteLine("ERROR - Invalid number of arguments."); Console.WriteLine(); return(false); } // get export parameters string appName = args[1]; string fileName = args[2]; // export the SSO application configuration file try { SSOManager.ExportApplication(appName, fileName); Console.WriteLine("SSO application successfully exported."); return(true); } catch (Exception ex) { Console.WriteLine("ERROR - An error has occurred exporting the SSO application."); Console.WriteLine(""); Console.WriteLine(ex); return(false); } }
public void CreatesSSOManager() { // Arrange var targetSettings = new SSOSettings(); targetSettings.Apps.Add(new SSOTargetSettings { AppName = "App1", AuthenticationUrlTemplate = "Url1", ExpireInSeconds = 1, TokenProviderSettings = new TokenProviderSettings() }); targetSettings.Apps.Add(new SSOTargetSettings { AppName = "App2", AuthenticationUrlTemplate = "Url2", ExpireInSeconds = 2, TokenProviderSettings = new TokenProviderSettings() }); var factoryMock = new Mock <ITokenProviderFactory>(); var optionsMock = new Mock <IOptions <SSOSettings> >(); optionsMock.Setup(x => x.Value).Returns(targetSettings); // Act var target = new SSOManager(factoryMock.Object, optionsMock.Object); // Assert factoryMock.Verify(x => x.Create(It.IsAny <TokenProviderSettings>()), Times.Exactly(targetSettings.Apps.Count)); }
public void RejectsIfTokenIsExpired() { var settings = CreateSSOSettings(); var providerMock = new Mock <ITokenProvider>(); var mocks = CreateMocks(settings); var testPayload = new { id = 1 }.ToExpandoObject(); providerMock .Setup(x => x.TryVerify(It.IsAny <string>(), out It.Ref <AccessToken> .IsAny)) .Returns(new TryVerifyReturns((string s, out AccessToken token) => { token = new AccessToken { ExpireOn = DateTime.UtcNow.AddMilliseconds(-1), Payload = testPayload }; return(true); })); mocks.factoryMock .Setup(x => x.Create(It.IsAny <TokenProviderSettings>())) .Returns(providerMock.Object); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var actual = target.TryVerifyToken("App1", "TestToken", out ExpandoObject payload); Assert.False(actual); Assert.Null(payload); }
public void RejectsIfTokenIsInvalid() { var settings = CreateSSOSettings(); var providerMock = new Mock <ITokenProvider>(); var mocks = CreateMocks(settings); providerMock .Setup(x => x.TryVerify(It.IsAny <string>(), out It.Ref <AccessToken> .IsAny)) .Returns(new TryVerifyReturns((string s, out AccessToken token) => { token = null; return(false); })); mocks.factoryMock .Setup(x => x.Create(It.IsAny <TokenProviderSettings>())) .Returns(providerMock.Object); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var actual = target.TryVerifyToken("App1", "TestToken", out ExpandoObject payload); Assert.False(actual); Assert.Null(payload); }
public void VerifiesToken() { var settings = CreateSSOSettings(); var mocks = CreateMocks(settings); var providerMock = new Mock <ITokenProvider>(); var expectedPayload = new { id = 1 }.ToExpandoObject(); providerMock .Setup(x => x.TryVerify(It.IsAny <string>(), out It.Ref <AccessToken> .IsAny)) .Returns(new TryVerifyReturns((string s, out AccessToken token) => { token = new AccessToken { ExpireOn = DateTime.UtcNow.AddMonths(1), Payload = expectedPayload }; return(true); })); mocks.factoryMock .Setup(x => x.Create(It.IsAny <TokenProviderSettings>())) .Returns(providerMock.Object); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var actual = target.TryVerifyToken("App2", "TestToken", out ExpandoObject actualPayload); Assert.True(actual); Assert.Equal(expectedPayload, actualPayload); providerMock.Verify(x => x.TryVerify(It.IsAny <string>(), out It.Ref <AccessToken> .IsAny), Times.Once()); }
protected override void OnDelete(SyncStatus status) { try { if (MsgBoxUtil.Confirm(this.SnapIn, Properties.Resources.DeleteFieldMessage) == true) { // get SSO application fields SSOAppFieldCollection appFields = SSOManager.GetApplicationFields(this.ScopeNode.DisplayName); // delete selected ones foreach (ResultNode resultNode in this.SelectedNodes) { appFields.Remove(resultNode.DisplayName); this.ResultNodes.Remove(resultNode); } // save fields SSOManager.UpdateApplicationFields(this.ScopeNode.DisplayName, appFields, true); // refresh view this.RefreshFields(); } } catch (Exception ex) { MsgBoxUtil.Show(this.SnapIn, ex); } }
public void RefreshApps() { try { // load apps List <SSOAppInfo> applications = SSOManager.GetApplications(); this.ResultNodes.Clear(); foreach (SSOAppInfo app in applications) { ResultNode resultNode = new ResultNode(); resultNode.DisplayName = app.Name; resultNode.SubItemDisplayNames.AddRange(new string[5] { app.Status, app.Description, app.AdminAccounts, app.UserAccounts, app.Contact }); this.ResultNodes.Add(resultNode); } } catch (Exception ex) { MsgBoxUtil.Show(this.SnapIn, ex); } }
public ActionResult Login() { //if (IsAuthorised("154211")) //{ // return Redirect("~/" + SessionHelper.DefaultPage); //} //SessionHelper.UserName = "******"; //SessionHelper.UserId = 3; //SessionHelper.UnitId = 1; //SessionHelper.DateFormat = "dd MMM, yyyy"; //return Redirect("~/Main"); var encriptData = string.Empty; if (Request.QueryString[SsoUtility.SsoToken] != null) { encriptData = HttpUtility.HtmlDecode(Request.QueryString[SsoUtility.SsoToken]); //Process for normal authentication var objSsoManager = new SSOManager(); var objSso = objSsoManager.GetSSO(encriptData); //SMSC.Models.SMSCContext _contex = new Models.SMSCContext(); if (objSso.authenticated == true) { userLoginLogService.Add(new UserLoginLog { PIN = objSso.name , Name = objSso.fullname , LoginTime = DateTime.Now }); unitOfWork.Commit(); SessionHelper.IsGuest = false; if (IsAuthorised(objSso.name)) { return(Redirect("~/" + SessionHelper.DefaultPage)); } else { SessionHelper.UserName = objSso.fullname; SessionHelper.UserId = 0; SessionHelper.UnitId = 1; //SessionHelper.DateFormat = "dd MMM, yyyy"; return(Redirect("~/Main")); } } else if (objSso.name != null) { ModelState.AddModelError("", ""); } } return(View("Index")); }
private void PropertyPage_Save(object sender, ResultEventArgs <bool> e) { if (this.IsValid() == false) { MsgBoxUtil.Show(this.ParentSheet, "Some information is missing or incorrect. Please review and correct the information entered on the page."); e.Result = false; } else { if (this.IsDirty() == true) { // get the new field information entered on the page this.Update(this.appField); // get the SSO application fields SSOAppFieldCollection appFields = SSOManager.GetApplicationFields(this.appName); // flag to indicate whether the application must be recreated bool recreate = false; // check if the field is new or was renamed if (string.IsNullOrEmpty(this.originalFieldName) == true || this.propertyControl.FieldName.Equals(this.originalFieldName, StringComparison.InvariantCultureIgnoreCase) == false) { // the field is new or was renamed, ensure the new field name does not exist if (appFields.Contains(this.propertyControl.FieldName) == true) { MsgBoxUtil.Show(this.ParentSheet, string.Format("The field name {0} already exists.", this.propertyControl.FieldName)); e.Result = false; return; } // need to recreate the application recreate = true; // remove the field before writing it using the new name (it will cause to add it) if (appFields.Contains(this.propertyControl.FieldName) == true) { appFields.Remove(this.propertyControl.FieldName); } } // write the field value (if the field was renamed, a new one will be added) appFields.Write(this.propertyControl.FieldName, this.propertyControl.FieldValue); // update the sso application SSOManager.UpdateApplicationFields(this.appName, appFields, recreate); // update the result node ResultNode resultNode = (ResultNode)this.ParentSheet.SelectionObject; this.OnSaved(new EventArgs <SSOAppField>(this.appField)); } e.Result = true; } }
public void ThrowsIfArgumentsAreInvalid(string app, ExpandoObject payload, Type exceptionType, string expectedParamName) { var settings = CreateSSOSettings(); var mocks = CreateMocks(settings); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var ex = Assert.Throws(exceptionType, () => target.IssueToken(app, payload)); Assert.Equal(expectedParamName, ((ArgumentException)ex).ParamName); }
public ActionResult LogOut() { SSOManager sSOManager = new SSOManager(); //string token = HttpContext.Session["User"].ToString(); //清楚session sSOManager.SSO_Token_Clear(); HttpContext.Session.Remove("token"); //清楚redis用户权限信息 return(Redirect("~/Home/Index")); }
public AppPropertyPageManager(string appName) { // load app info from SSO this.appInfo = SSOManager.GetApplicationInfo(appName); // initialize property pages // general this.generalPropPage = new AppGeneralPropertyPage(); this.generalPropPage.Load += PropertyPage_Load; this.generalPropPage.Save += PropertyPage_Save; // accounts this.accountsPropPage = new AppAccountsPropertyPage(); }
public void ThrowsIfRequestedAppNotRegistered() { var settings = CreateSSOSettings(); var mocks = CreateMocks(settings); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var ex = Assert.Throws <AppNotRegisteredException>(() => target.IssueToken("InvalidApp", new { }.ToExpandoObject())); Assert.Equal("InvalidApp", ex.AppName); Assert.Equal($"Requested application was not registered.{Environment.NewLine}Application name: InvalidApp", ex.Message); }
public ResultPakage <bool> CreateCourse(Dal.Course course) { Db db = new Db(); //var imageName = Util.SaveImage("UploadCourseImagePath", HttpContext.Current); //if (imageName != null && imageName.Length > 0) { // course.PicUrl = imageName; //} var user = SSOManager.GetUserInfoFromHeader(); course.CreatePerson = user.Id; course.CreateTime = DateTime.Now; db.Courses.Add(course); db.SaveChanges(); return(Util.ReturnOkResult(true)); }
protected void Export(string appName) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = "SSO Application Config files (*.xml)|*.xml|All files (*.*)|*.*"; saveFileDialog.DefaultExt = "*.xml"; saveFileDialog.FileName = appName + ".xml"; saveFileDialog.Title = "Export SSO Application Configuration"; if (this.SnapIn.Console.ShowDialog(saveFileDialog) == DialogResult.OK) { SSOManager.ExportApplication(appName, saveFileDialog.FileName); } } }
public JsonResult SS0Login(string Username, string Password, string ReturnUrl) { Response <List <MainMenu> > rsp = new Response <List <MainMenu> >(); Response <UserSSOInfo> usi = new Response <UserSSOInfo>(); //获取用户信息 UserSSOInfo ssoinfo = new UserSSOInfo(); string redirect_url = ReturnUrl; if (string.IsNullOrEmpty(ReturnUrl)) { redirect_url = "/Home/Index"; //rsp.isSSO = true; } //db查询; usi = UserLogin.Login(Username, Md5Helpers.CreateMD5Hash(Password)); if (usi.status == 0) { rsp.redirect_url = redirect_url; rsp.status = 0; rsp.msg = usi.msg; return(Json(rsp)); } ssoinfo = usi.entity; List <Role> rolelist = ssoinfo.RoleList; List <Menu> menuelist = new List <Menu>(); //foreach (var item in rolelist) //{ // //取父菜单 // List<Menu> tempmenue = item.MenuList.Where(x => x.ParentId == 0 && x.Menu_Type == 1).ToList(); // //取并集 // menuelist = menuelist.Union(tempmenue).ToList(); //} SSOManager sSOManager = new SSOManager(); string token = sSOManager.SSO_Token(ssoinfo); //附加token ViewBag.token = token; ViewBag.User = Username; HttpContext.Session["token"] = token; HttpContext.Session["User"] = ssoinfo.User.UserName; rsp.entity = ssoinfo.Mainlist; rsp.token = token; rsp.redirect_url = redirect_url; return(Json(rsp)); }
protected void Import() { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "SSO Application Config files (*.xml)|*.xml|All files (*.*)|*.*"; openFileDialog.DefaultExt = "*.xml"; openFileDialog.Title = "Import SSO Application Configuration"; if (this.SnapIn.Console.ShowDialog(openFileDialog) == DialogResult.OK) { // import the app configuration from the file SSOManager.ImportApplication(openFileDialog.FileName, true); } } }
protected override void OnDelete(SyncStatus status) { GT.BizTalk.SSO.AdminMMC.UI.MsgBoxUtil.Show("Notification from AppScopeNode.OnDelete"); try { if (MsgBoxUtil.Confirm(this.SnapIn, Properties.Resources.DeleteApplicationMessge) == true) { SSOManager.DeleteApplication(this.DisplayName); ((AppRootScopeNode)this.Parent).RefreshApps(); } base.OnDelete(status); } catch (Exception ex) { MsgBoxUtil.Show(this.SnapIn, ex); } }
public void IssuesToken() { var settings = CreateSSOSettings(); var mocks = CreateMocks(settings); var providerMock = new Mock <ITokenProvider>(); providerMock.Setup(x => x.Issue(It.IsAny <AccessToken>())).Returns("TestToken"); mocks.factoryMock.Setup(x => x.Create(It.IsAny <TokenProviderSettings>())).Returns(providerMock.Object); var payload = new ExpandoObject(); var target = new SSOManager(mocks.factoryMock.Object, mocks.optionsMock.Object); var actual = target.IssueToken("App2", payload); providerMock.Verify(x => x.Issue(It.IsAny <AccessToken>()), Times.Once()); Assert.Equal("Url2-TestToken", actual); }
public void RefreshApps() { try { // load apps List <SSOAppInfo> applications = SSOManager.GetApplications(); this.Children.Clear(); foreach (SSOAppInfo appInfo in applications) { AppScopeNode appScopeNode = new AppScopeNode(appInfo.Name); this.Children.Add(appScopeNode); } } catch (Exception ex) { MsgBoxUtil.Show(this.SnapIn, ex); } }
private void RefreshFields() { // get current config settings SSOAppFieldCollection appFields = SSOManager.GetApplicationFields(this.ScopeNode.DisplayName); this.ResultNodes.Clear(); foreach (SSOAppField field in appFields) { if (string.IsNullOrEmpty(field.Name) == false) { ResultNode resultNode = new ResultNode(); resultNode.DisplayName = field.Name; resultNode.SubItemDisplayNames.Add(field.Value); resultNode.SubItemDisplayNames.Add(field.Identifier); this.ResultNodes.Add(resultNode); } } }
private static void WaitCallbackProcessApps(object objData) { ProcessAppsData processAppsData = (ProcessAppsData)objData; try { foreach (Node node in processAppsData.SelectedNodes) { if (AppListView.cancelProcessMultipleApps) { break; } string displayName = node.DisplayName; switch (processAppsData.Action) { case "Enable": SSOManager.EnableApplication(displayName, true); break; case "Disable": SSOManager.EnableApplication(displayName, false); break; case "Delete": SSOManager.DeleteApplication(displayName); break; case "PurgeCache": SSOManager.PurgeApplicationCache(displayName); break; } ++processAppsData.WaitDialog.WorkProcessed; } } catch (Exception ex) { MsgBoxUtil.Show(processAppsData.SnapIn, ex); } finally { processAppsData.WaitDialog.CompleteDialog(); } }
private void btnCreate_Click(object sender, System.EventArgs e) { try { // create a new instance of an application configuration SSOAppConfig appConfig = new SSOAppConfig(); appConfig.AppInfo.Enabled = true; // update the application metadata information with the data entered by the user foreach (AppWizardStep step in this.steps) { step.Update(appConfig.AppInfo); } // create the application SSOManager.CreateApplication(appConfig); } catch (Exception ex) { MsgBoxUtil.Show(this, ex); } }
public SSOTicketMessageEvent() { SSOManager = DependencyFactory.Resolve <SSOManager>(); }
private static bool Import(string[] args) { // validate arguments string suppressConfirm = string.Empty; string fileName = string.Empty; if (args.Length == 2) { fileName = args[1]; } else if (args.Length == 3) { suppressConfirm = args[1]; fileName = args[2]; } else { Console.WriteLine("ERROR - Invalid number of arguments."); Console.WriteLine(); return(false); } // validate suppress confirm if (string.IsNullOrEmpty(suppressConfirm) == false && suppressConfirm.ToLower() != "/y") { Console.WriteLine("ERROR - Invalid option."); Console.WriteLine(); return(false); } // validate file name if (File.Exists(fileName) == false) { Console.WriteLine("ERROR - The specified SSO application configuration file does not exist."); Console.WriteLine(); return(false); } // import the SSO application configuration file try { // load the app configuration from the file SSOAppConfig appConfig = XmlSerializationUtil.LoadXml <SSOAppConfig>(fileName); // check if the application already exists if (SSOManager.ApplicationExists(appConfig.AppInfo.Name) == true) { bool overrideApp = true; // the application exists, ask the user for confirmation to override // if confirmation was not suppressed if (string.IsNullOrEmpty(suppressConfirm) == true) { Console.WriteLine("SSO application already exists. Override (Y/N)?"); int key = Console.Read(); char ch = Convert.ToChar(key); overrideApp = (ch == 'y' || ch == 'Y'); } if (overrideApp == true) { // update/recreate the application SSOManager.UpdateApplication(appConfig, true); Console.WriteLine("SSO application successfully imported."); } } else { // create a new application SSOManager.CreateApplication(appConfig); Console.WriteLine("SSO application successfully imported."); } return(true); } catch (Exception ex) { Console.WriteLine("ERROR - An error has occurred importing the SSO application."); Console.WriteLine(""); Console.WriteLine(ex); return(false); } }
public HomeController() { _SSOManager = new SSOManager(); }