public List<SystemUserGroupRoleRelation> GetSystemUserGroupRoleRelationByUserGroup(SystemUserGroup systemUserGroup) { List<ICriterion> criterions = new List<ICriterion>(); criterions.Add(SystemUserGroupRoleRelationDao.PROPERTY_USERGROUPID.Eq(systemUserGroup)); return this.FindAll(criterions.ToArray()); }
public JsonResult AddOrUpdateUserGroup(SystemUserGroup systemUserGroupObj) { try { _UserDetailsBusinessLogic = new UserDetailsBusinessLogic(); bool isSuccess = false; if (_UserDetailsBusinessLogic.IsUserGroupAvailable(systemUserGroupObj.UserGroupName) == true) { isSuccess = _UserDetailsBusinessLogic.UpdateUserGroup(systemUserGroupObj); } else { isSuccess = _UserDetailsBusinessLogic.SaveUserGroup(systemUserGroupObj); } return(Json(isSuccess)); } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, "UName", ex); return(Json(false)); } }
public static void SetupPermissions() { SystemUserGroup adminGroup = GetAdminGroup(); AssureUriPermission("/signin/settings", adminGroup); AssureUriPermission("/signin/user/authentication/settings/{?}", adminGroup); }
static public bool IsAdmin() { SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; SystemUser user = Helper.GetCurrentSystemUser(); return(Helper.IsMemberOfGroup(user, adminGroup)); }
/// <summary> /// Remove System User as a Member of a SystemUserGroup /// </summary> /// <param name="user"></param> /// <param name="group"></param> public static void RemoveSystemUserFromSystemUserGroup(SystemUser user, SystemUserGroup group) { var removeGroup = Db.SQL <SystemUserGroupMember>("SELECT o FROM Simplified.Ring3.SystemUserGroupMember o WHERE o.WhatIs=? AND o.ToWhat=?", user, group).First; removeGroup?.Delete(); //group.RemoveMember(user); }
public List<int> GetUserGroupAssignedroleIDList(SystemUserGroup userGroup) { List<SystemRole> list = this.DaosContainerIocID.SystemUserGroupRoleRelationDaoInstance.GetUserGroupAssignedRole(userGroup); List<int> roleList = new List<int>(); foreach (SystemRole role in list) { roleList.Add(role.RoleID); } return roleList; }
/// <summary> /// Add System User as a Member of a SystemUserGroup /// </summary> /// <param name="user"></param> /// <param name="group"></param> public static void AddSystemUserToSystemUserGroup(SystemUser user, SystemUserGroup group) { SystemUserGroupMember systemUserGroupMember = new SystemUserGroupMember(); systemUserGroupMember.WhatIs = user; systemUserGroupMember.ToWhat = group; //systemUserGroupMember.SetSystemUser(user); //systemUserGroupMember.SetToWhat(group); //group.AddMember(systemUser); }
public List <int> GetUserGroupAssignedroleIDList(SystemUserGroup userGroup) { List <SystemRole> list = systemUserGroupRoleRelationDaoInstance.GetUserGroupAssignedRole(userGroup); List <int> roleList = new List <int>(); foreach (SystemRole role in list) { roleList.Add(role.RoleID); } return(roleList); }
private static UriPermission GetPermissionFromGroup(SystemUserGroup group, string url) { if (group == null) { return(null); } UriPermission permission = Db.SQL <UriPermission>("SELECT o.Permission FROM Simplified.Ring5.SystemUserGroupUriPermission o WHERE o.Permission.Uri=? AND o.SystemUserGroup=?", url, group).First ?? GetPermissionFromGroup(group.Parent, url); return(permission); }
public List<SystemRole> GetUserGroupAssignedRole(SystemUserGroup systemUserGroup) { List<SystemUserGroupRoleRelation> listSystemUserGroupRoleRelation = GetSystemUserGroupRoleRelationByUserGroup(systemUserGroup); List<SystemRole> assignRoles = new List<SystemRole>(); foreach (SystemUserGroupRoleRelation relation in listSystemUserGroupRoleRelation) { assignRoles.Add(relation.RoleID); } return assignRoles; }
/// <summary> /// Set up Uri permissions /// TODO: This is hardcoded, we need a gui!! /// TODO: Automate this /// </summary> static private void SetupPermissions() { SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; Helper.AssureUriPermission("/UserAdmin/admin/users", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/users/{?}", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/createuser", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/usergroups", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/usergroups/{?}", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/createusergroup", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/settings", adminGroup); }
/// <summary> /// Creates Admin User if missing and adds it to the admin group. /// </summary> private void CreateAdminSystemUserIfMissing(string adminPassword, out string message, out bool isAlert) { message = string.Empty; isAlert = false; SystemUser user = GetAdminUser(); SystemUserGroup group = GetAdminUserGroup(); if (IsInGroup(user, group)) { message = "There is already an Admin user created"; isAlert = true; return;//Do nothing if there's already an admin user } // There is no system user belonging to the admin group Db.Transact(() => { if (group == null) { group = new SystemUserGroup { Name = AdminGroupName, Description = AdminGroupDescription }; } if (user == null) { var person = new Person() { FirstName = AdminUsername, LastName = AdminUsername }; user = SystemUser.RegisterSystemUser(AdminUsername, AdminEmail, adminPassword); user.WhatIs = person; } // Add the admin group to the system admin user var member = new SystemUserGroupMember { WhatIs = user, ToWhat = group }; }); message = $"Admin user with username = '******' was created"; }
private static SystemUserGroup GetAdminGroup() { SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", AuthorizationHelper.AdminGroupName).First; if (adminGroup == null) { Db.Transact(() => { adminGroup = new SystemUserGroup { Name = AdminGroupName, Description = AdminGroupDescription }; }); } return(adminGroup); }
public static void AssureUriPermission(string uri, SystemUserGroup group) { UriPermission permission = Db.SQL <UriPermission>("SELECT o.Permission FROM Simplified.Ring5.SystemUserGroupUriPermission o WHERE o.Permission.Uri=? AND o.SystemUserGroup=?", uri, group).First; if (permission == null) { Db.Transact(() => { UriPermission p1 = new UriPermission { Uri = uri, CanGet = true }; new SystemUserGroupUriPermission { ToWhat = p1, WhatIs = group }; }); } }
public virtual void SaveUserGroupAssignedRoleIDList(List<int> roleIDList, SystemUserGroup userGroup) { List<SystemUserGroupRoleRelation> systemUserGroupRoleRelation = this.DaosContainerIocID.SystemUserGroupRoleRelationDaoInstance.GetSystemUserGroupRoleRelationByUserGroup(userGroup); foreach (SystemUserGroupRoleRelation userGroupRoleRelation in systemUserGroupRoleRelation) { this.DaosContainerIocID.SystemUserGroupRoleRelationDaoInstance.Delete(userGroupRoleRelation); } foreach (int id in roleIDList) { SystemRole assignedRole = this.DaosContainerIocID.SystemRoleDaoInstance.Load(id); SystemUserGroupRoleRelation userGroupRoleRelation = new SystemUserGroupRoleRelation(); userGroupRoleRelation.RoleID = assignedRole; userGroupRoleRelation.UserGroupID = userGroup; this.DaosContainerIocID.SystemUserGroupRoleRelationDaoInstance.Save(userGroupRoleRelation); } }
protected void btnSave_Click(object sender, EventArgs e) { //验证不通过返回 if (!this.Page.IsValid) { return; } SystemUserGroup obj = new SystemUserGroup(); obj.GroupNameCn = this.txtGroupNameCn.Text.Trim(); obj.GroupNameEn = this.txtGroupNameEn.Text.Trim(); obj.GroupDescription = this.txtGroupDescription.Text.Trim(); //添加数据 this.SaveCurrentData(obj); }
public virtual void SaveUserGroupAssignedRoleIDList(List <int> roleIDList, SystemUserGroup userGroup) { List <SystemUserGroupRoleRelation> systemUserGroupRoleRelation = systemUserGroupRoleRelationDaoInstance.GetSystemUserGroupRoleRelationByUserGroup(userGroup); foreach (SystemUserGroupRoleRelation userGroupRoleRelation in systemUserGroupRoleRelation) { systemUserGroupRoleRelationDaoInstance.Delete(userGroupRoleRelation); } foreach (int id in roleIDList) { SystemRole assignedRole = systemRoleDaoInstance.Load(id); SystemUserGroupRoleRelation userGroupRoleRelation = new SystemUserGroupRoleRelation(); userGroupRoleRelation.RoleID = assignedRole; userGroupRoleRelation.UserGroupID = userGroup; systemUserGroupRoleRelationDaoInstance.Save(userGroupRoleRelation); } }
void Handle(Input.AddUserToGroup action) { this.Message = null; if (string.IsNullOrEmpty(this.SelectedSystemUserGroupID_)) { action.Cancel(); this.Message = "None of the System Groups is selected!"; return; } SystemUserGroup group = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.ObjectID=?", this.SelectedSystemUserGroupID_).First; SystemUserGroupMember systemUserGroupMember = new SystemUserGroupMember(); systemUserGroupMember.WhatIs = this.Data; systemUserGroupMember.ToWhat = group; this.SelectedSystemUserGroupID_ = null; }
/// <summary> /// Assure that there is at least one system user beloning to the admin group /// </summary> internal static void AssureAdminSystemUser() { SystemUserGroup group = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", AdminGroupName).First; SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.Username = ?", AdminUsername) .First; if (group != null && user != null && SystemUser.IsMemberOfGroup(user, group)) { return; } // There is no system user beloning to the admin group Db.Transact(() => { if (group == null) { group = new SystemUserGroup(); group.Name = AdminGroupName; group.Description = AdminGroupDescription; } if (user == null) { Person person = new Person() { FirstName = AdminUsername, LastName = AdminUsername }; user = SystemUser.RegisterSystemUser(AdminUsername, AdminEmail, AdminPassword); user.WhatIs = person; } // Add the admin group to the system admin user SystemUserGroupMember member = new Simplified.Ring3.SystemUserGroupMember(); member.WhatIs = user; member.ToWhat = group; }); }
/// <summary> /// TODO: Avoid circular references!! /// </summary> /// <param name="group"></param> /// <param name="basedOnGroup"></param> /// <returns></returns> private static bool IsBasedOnGroup(SystemUserGroup group, SystemUserGroup basedOnGroup) { if (group == null) { return(false); } // NOTE: To compare to objects queried from database we need to use .Equals(), "==" wont work!!. if (group.Equals(basedOnGroup)) { return(true); } if (IsBasedOnGroup(group.Parent, basedOnGroup)) { return(true); } return(false); }
public static bool IsMemberOfGroup(SystemUser user, SystemUserGroup basedOnGroup) { if (user == null || basedOnGroup == null) { return(false); } var groups = Db.SQL <SystemUserGroup>( "SELECT o.SystemUserGroup FROM Simplified.Ring3.SystemUserGroupMember o " + "WHERE o.SystemUser=?", user); foreach (var groupItem in groups) { if (IsBasedOnGroup(groupItem, basedOnGroup)) { return(true); } } return(false); }
/// <summary> /// Set up Uri permissions /// TODO: This is hardcoded, we need a gui!! /// TODO: Automate this /// </summary> static private void SetupPermissions() { SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; if (adminGroup == null) { Db.Transact(() => { adminGroup = new SystemUserGroup(); adminGroup.Name = AdminGroupName; adminGroup.Description = AdminGroupDescription; }); } Helper.AssureUriPermission("/UserAdmin/admin/users", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/users/{?}", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/createuser", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/usergroups", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/usergroups/{?}", adminGroup); Helper.AssureUriPermission("/UserAdmin/admin/createusergroup", adminGroup); }
public static void Register() { string redirectPageHtml = "/useradmin/viewmodels/RedirectPage.html"; Handle.GET("/useradmin/accessdenied", () => { return(new AccessDeniedPage()); }); Handle.GET("/useradmin/unauthenticated?return_uri={?}", (string returnUri) => { MasterPage master = MainHandlers.GetMasterPageFromSession(); master.CurrentPage = Self.GET <UnauthenticatedPage>("/useradmin/partial/unauthenticated?return_uri=" + returnUri); return(master); }); Handle.GET("/useradmin/partial/unauthenticated?return_uri={?}", (string returnUri) => { return(new UnauthenticatedPage()); }); // Create System user Handle.GET("/useradmin/admin/createuser", (Request request) => { MasterPage master = MainHandlers.GetMasterPageFromSession(); Json page; if (!Helper.TryNavigateTo("/UserAdmin/admin/createuser", request, redirectPageHtml, out page)) { master.CurrentPage = page; } else { master.CurrentPage = Db.Scope(() => { var user = new SystemUser(); return(new CreateUserPage { Html = "/UserAdmin/viewmodels/partials/administrator/CreateUserPage.html", Uri = request.Uri, Data = user, SystemUserPasswordPage = Self.GET("/useradmin/user/authentication/password/" + user.GetObjectID()) }); }); } return(master); }); // Get System users Handle.GET("/useradmin/admin/users", (Request request) => { MasterPage master = MainHandlers.GetMasterPageFromSession(); Json page; if (!Helper.TryNavigateTo("/useradmin/admin/users", request, redirectPageHtml, out page)) { master.CurrentPage = page; } else { master.CurrentPage = new ListUsersPage() { Html = "/UserAdmin/viewmodels/partials/administrator/ListUsersPage.html", Uri = request.Uri }; } return(master); }); Handle.GET("/UserAdmin/persons/{?}", (string userid) => { return(Self.GET("/UserAdmin/admin/users/" + userid)); }); Handle.GET("/UserAdmin/admin/users/{?}", (string userid, Request request) => { Json page; MasterPage master = MainHandlers.GetMasterPageFromSession(); if (!Helper.TryNavigateTo("/UserAdmin/admin/users/{?}", request, redirectPageHtml, out page)) { master.CurrentPage = page; return(master); } // Get system user SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).First; if (user == null) { // TODO: Return a "User not found" page return(master); } SystemUser systemUser = Helper.GetCurrentSystemUser(); SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; // Check if current user has permission to get this user instance if (Helper.IsMemberOfGroup(systemUser, adminGroup)) { if (user.WhoIs is Person) { master.CurrentPage = Db.Scope(() => new EditPersonPage { Html = "/UserAdmin/viewmodels/partials/administrator/EditPersonPage.html", Uri = request.Uri, Data = user, SystemUserAuthenticationSettingsPage = Self.GET("/useradmin/user/authentication/settings/" + user.GetObjectID()) }); return(master); } } else if (user == systemUser) { // User can edit it's self } else { // No rights // User trying to view another's users data // User has no permission, redirect to app's root page master.CurrentPage = new RedirectPage() { Html = redirectPageHtml, RedirectUrl = "/useradmin" }; return(master); } return(master); }); // User authentication settings Handle.GET("/useradmin/user/authentication/settings/{?}", (string userId) => new Json(), new HandlerOptions { SelfOnly = true }); // User password settings Handle.GET("/useradmin/user/authentication/password/{?}", (string userId) => new Json(), new HandlerOptions { SelfOnly = true }); }
/// <summary> /// 默认构造函数 /// </summary> public SystemUserGroupUserRelationBase() { _usergroupuserid = 0; _userid = null; _usergroupid = null; }
/// <summary> /// 默认构造函数 /// </summary> public SystemUserGroupRoleRelationBase() { _usergrouprole_id = 0; _role_id = null; _usergroup_id = null; }
public static void Register() { string redirectPageHtml = "/useradmin/viewmodels/RedirectPage.html"; Handle.GET("/useradmin/accessdenied", () => { return(new AccessDeniedPage()); }); // Create System user Handle.GET("/useradmin/admin/createuser", (Request request) => { MasterPage master = LauncherHooks.GetMaster(); Json page; if (!Helper.TryNavigateTo("/UserAdmin/admin/createuser", request, redirectPageHtml, out page)) { master.CurrentPage = page; } else { master.CurrentPage = new CreateUserPage() { Html = "/UserAdmin/viewmodels/partials/administrator/CreateUserPage.html", Uri = request.Uri }; } return(master); }); // Get System users Handle.GET("/useradmin/admin/users", (Request request) => { MasterPage master = LauncherHooks.GetMaster(); Json page; if (!Helper.TryNavigateTo("/useradmin/admin/users", request, redirectPageHtml, out page)) { master.CurrentPage = page; } else { master.CurrentPage = new ListUsersPage() { Html = "/UserAdmin/viewmodels/partials/administrator/ListUsersPage.html", Uri = request.Uri }; } return(master); }); Handle.GET("/UserAdmin/admin/users/{?}", (string userid, Request request) => { //return Db.Scope<Json>(() => { Json page; MasterPage master = LauncherHooks.GetMaster(); if (!Helper.TryNavigateTo("/UserAdmin/admin/users/{?}", request, redirectPageHtml, out page)) { master.CurrentPage = page; return(master); } // Get system user Simplified.Ring3.SystemUser user = Db.SQL <Simplified.Ring3.SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).First; if (user == null) { // TODO: Return a "User not found" page return(master); //return (ushort)System.Net.HttpStatusCode.NotFound; } SystemUser systemUser = Helper.GetCurrentSystemUser(); SystemUserGroup adminGroup = Db.SQL <Simplified.Ring3.SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; // Check if current user has permission to get this user instance if (Helper.IsMemberOfGroup(systemUser, adminGroup)) { if (user.WhoIs is Person) { master.CurrentPage = Db.Scope <string, Simplified.Ring3.SystemUser, Json>((uri, personUser) => { return(new EditPersonPage() { Html = "/UserAdmin/viewmodels/partials/administrator/EditPersonPage.html", Uri = uri, Data = personUser }); }, request.Uri, user); return(master); } else if (user.WhoIs is Organization) { Db.Scope <string, Simplified.Ring3.SystemUser, Json>((uri, companyUser) => { return(new EditCompanyPage() { Html = "/UserAdmin/viewmodels/partials/administrator/EditCompanyPage.html", Uri = uri, Data = companyUser }); }, request.Uri, user); } } else if (user == systemUser) { // User can edit it's self } else { // No rights // User trying to view another's users data // User has no permission, redirect to app's root page master.CurrentPage = new RedirectPage() { Html = redirectPageHtml, RedirectUrl = "/useradmin" }; return(master); } return(master); }); // Get System user //Handle.GET("/useradmin/admin/_users/{?}", (string userid, Request request) => { // Json page; // MasterPage master = LauncherHooks.GetMaster(); // if (!Helper.TryNavigateTo("/UserAdmin/admin/users/{?}", request, redirectPageHtml, out page)) { // master.CurrentPage = page; // return master; // } // // Get system user // Simplified.Ring3.SystemUser user = Db.SQL<Simplified.Ring3.SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).First; // if (user == null) { // // TODO: Return a "User not found" page // return master; // //return (ushort)System.Net.HttpStatusCode.NotFound; // } // SystemUser systemUser = Helper.GetCurrentSystemUser(); // SystemUserGroup adminGroup = Db.SQL<Simplified.Ring3.SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First; // // Check if current user has permission to get this user instance // if (Helper.IsMemberOfGroup(systemUser, adminGroup)) { // if (user.WhoIs is Person) { // master.CurrentPage = Db.Scope<string, Simplified.Ring3.SystemUser, Json>((uri, personUser) => { // return new EditPersonPage() { // Html = "/UserAdmin/viewmodels/partials/administrator/EditPersonPage.html", // Uri = uri, // Data = personUser // }; // }, request.Uri, user); // return master; // } // else if (user.WhoIs is Organization) { // Db.Scope<string, Simplified.Ring3.SystemUser, Json>((uri, companyUser) => { // return new EditCompanyPage() { // Html = "/UserAdmin/viewmodels/partials/administrator/EditCompanyPage.html", // Uri = uri, // Data = companyUser // }; // }, // request.Uri, user); // } // } // else if (user == systemUser) { // // User can edit it's self // } // else { // // No rights // // User trying to view another's users data // // User has no permission, redirect to app's root page // master.CurrentPage = new RedirectPage() { // Html = redirectPageHtml, // RedirectUrl = "/useradmin" // }; // return master; // } // return (ushort)System.Net.HttpStatusCode.NotFound; //}); // Reset password Handle.GET("/useradmin/user/resetpassword?{?}", (string query, Request request) => { NameValueCollection queryCollection = HttpUtility.ParseQueryString(query); string token = queryCollection.Get("token"); MasterPage master = LauncherHooks.GetMaster(); if (token == null) { // TODO: master.CurrentPage = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } // Retrive the resetPassword instance ResetPassword resetPassword = Db.SQL <Simplified.Ring6.ResetPassword>("SELECT o FROM Simplified.Ring6.ResetPassword o WHERE o.Token=? AND o.Expire>?", token, DateTime.UtcNow).First; if (resetPassword == null) { // TODO: Show message "Reset token already used or expired" master.CurrentPage = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } if (resetPassword.User == null) { // TODO: Show message "User deleted" master.CurrentPage = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } Simplified.Ring3.SystemUser systemUser = resetPassword.User; ResetPasswordPage page = new ResetPasswordPage() { Html = "/UserAdmin/viewmodels/partials/user/ResetPasswordPage.html", Uri = "/useradmin/user/resetpassword" //Uri = request.Uri // TODO: }; page.resetPassword = resetPassword; if (systemUser.WhoIs != null) { page.FullName = systemUser.WhoIs.FullName; } else { page.FullName = systemUser.Username; } master.CurrentPage = page; return(master); }); }
public void Register() { Application.Current.Use(new HtmlFromJsonProvider()); Application.Current.Use(new PartialToStandaloneHtmlProvider()); //Testing JWT /*Handle.GET("/signin/jwt/{?}/{?}", (string Username, string Password) => { * string message; * SystemUserSession session = SignInOut.SignInSystemUser(Username, Password, null, out message); * * if (session != null) { * string jwt = JWT.JsonWebToken.Encode(new { Username = Username, Issuer = "Polyjuice.SignIn" }, session.Token.User.Password, JWT.JwtHashAlgorithm.HS256); * Handle.AddOutgoingHeader("x-jwt", jwt); * } * * return 200; * });*/ Application.Current.Use((Request req) => { Cookie cookie = GetSignInCookie(); if (cookie != null) { if (Session.Current == null) { Session.Current = new Session(SessionOptions.PatchVersioning); } SystemUserSession session = SystemUser.SignInSystemUser(cookie.Value); if (session != null) { RefreshAuthCookie(session); } } return(null); }); Handle.GET("/signin/user", () => { MasterPage master = this.GetMaster(); if (master.SignInPage != null) { return(master.SignInPage); } Cookie cookie = GetSignInCookie(); SignInPage page = new SignInPage() { Data = null }; master.SignInPage = page; if (cookie != null) { SystemUser.SignInSystemUser(cookie.Value); master.RefreshSignInState(); } //Testing JWT /*if (Handle.IncomingRequest.HeadersDictionary.ContainsKey("x-jwt")) { * System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); * string jwt = Handle.IncomingRequest.HeadersDictionary["x-jwt"]; * Dictionary<string, string> payload = JWT.JsonWebToken.DecodeToObject<Dictionary<string, string>>(jwt, string.Empty, false); * string username = payload["Username"]; * SystemUser user = Db.SQL<SystemUser>("SELECT su FROM Simplified.Ring3.SystemUser su WHERE su.Username = ?", username).First; * * try { * JWT.JsonWebToken.DecodeToObject<Dictionary<string, string>>(jwt, user.Password, true); * page.SetAuthorizedState(SignInOut.SignInSystemUser(user)); * } catch (JWT.SignatureVerificationException) { * } * }*/ return(page); }); Handle.GET("/signin/partial/signout", HandleSignOut, new HandlerOptions() { SkipRequestFilters = true }); Handle.GET("/signin/signinuser", HandleSignInForm); Handle.GET <string>("/signin/signinuser?{?}", HandleSignInForm); Handle.GET("/signin/profile", () => { MasterPage master = this.GetMaster(); master.RequireSignIn = true; master.Open("/signin/partial/profile-form"); return(master); }); Handle.GET("/signin/partial/signin-form", () => new SignInFormPage() { Data = null }, new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/alreadyin-form", () => new AlreadyInPage() { Data = null }, new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/restore-form", () => new RestorePasswordFormPage(), new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/profile-form", () => new ProfileFormPage() { Data = null }, new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/accessdenied-form", () => new AccessDeniedPage(), new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/main-form", () => new MainFormPage() { Data = null }, new HandlerOptions() { SelfOnly = true }); Handle.GET("/signin/partial/user/image", () => new UserImagePage()); Handle.GET("/signin/partial/user/image/{?}", (string objectId) => new Json(), new HandlerOptions { SelfOnly = true }); Handle.GET("/signin/generateadminuser", (Request request) => { if (Db.SQL("SELECT o FROM Simplified.Ring3.SystemUser o").First != null) { Handle.SetOutgoingStatusCode(403); return("Unable to generate admin user: database is not empty!"); } string ip = request.ClientIpAddress.ToString(); if (ip == "127.0.0.1" || ip == "localhost") { SignInOut.AssureAdminSystemUser(); return("Default admin user has been successfully generated."); } Handle.SetOutgoingStatusCode(403); return("Access denied."); }, new HandlerOptions() { SkipRequestFilters = true }); Handle.POST("/signin/partial/signin", (Request request) => { NameValueCollection values = HttpUtility.ParseQueryString(request.Body); string username = values["username"]; string password = values["password"]; string rememberMe = values["rememberMe"]; HandleSignIn(username, password, rememberMe); Session.Current.CalculatePatchAndPushOnWebSocket(); return(200); }, new HandlerOptions() { SkipRequestFilters = true }); Handle.GET("/signin/admin/settings", (Request request) => { Json page; if (!AuthorizationHelper.TryNavigateTo("/signin/admin/settings", request, out page)) { return(page); } return(Db.Scope(() => { var settingsPage = new SettingsPage { Html = "/SignIn/viewmodels/SettingsPage.html", Uri = request.Uri, Data = MailSettingsHelper.GetSettings() }; return settingsPage; })); }); // Reset password Handle.GET("/signin/user/resetpassword?{?}", (string query, Request request) => { NameValueCollection queryCollection = HttpUtility.ParseQueryString(query); string token = queryCollection.Get("token"); MasterPage master = this.GetMaster(); if (token == null) { // TODO: master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } // Retrive the resetPassword instance ResetPassword resetPassword = Db.SQL <ResetPassword>("SELECT o FROM Simplified.Ring6.ResetPassword o WHERE o.Token=? AND o.Expire>?", token, DateTime.UtcNow).First; if (resetPassword == null) { // TODO: Show message "Reset token already used or expired" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } if (resetPassword.User == null) { // TODO: Show message "User deleted" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } SystemUser systemUser = resetPassword.User; ResetPasswordPage page = new ResetPasswordPage() { Html = "/SignIn/viewmodels/ResetPasswordPage.html", Uri = "/signin/user/resetpassword" //Uri = request.Uri // TODO: }; page.ResetPassword = resetPassword; if (systemUser.WhoIs != null) { page.FullName = systemUser.WhoIs.FullName; } else { page.FullName = systemUser.Username; } master.Partial = page; return(master); }); Handle.GET("/signin/user/authentication/settings/{?}", (string userid, Request request) => { Json page; if (!AuthorizationHelper.TryNavigateTo("/signin/user/authentication/settings/{?}", request, out page)) { return(new Json()); } // Get system user SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).FirstOrDefault(); if (user == null) { // TODO: Return a "User not found" page return(new Json()); //return (ushort)System.Net.HttpStatusCode.NotFound; } SystemUser systemUser = SystemUser.GetCurrentSystemUser(); SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", AuthorizationHelper.AdminGroupName).FirstOrDefault(); // Check if current user has permission to get this user instance if (AuthorizationHelper.IsMemberOfGroup(systemUser, adminGroup)) { if (user.WhoIs is Person) { page = Db.Scope(() => new SystemUserAuthenticationSettings { Html = "/SignIn/viewmodels/SystemUserAuthenticationSettings.html", Uri = request.Uri, Data = user, UserPassword = Self.GET("/signin/user/authentication/password/" + user.GetObjectID()) }); return(page); } } return(new Json()); }, new HandlerOptions { SelfOnly = true }); Handle.GET("/signin/user/authentication/password/{?}", (string userid, Request request) => { // Get system user SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).FirstOrDefault(); if (user == null) { return(new Json()); } Json page = Db.Scope(() => new SetPasswordPage { Html = "/SignIn/viewmodels/SetPasswordPage.html", Data = user }); return(page); }, new HandlerOptions { SelfOnly = true }); Blender.MapUri("/signin/user", "user"); //expandable icon; used in Launcher Blender.MapUri("/signin/signinuser", "userform"); //inline form; used in RSE Launcher Blender.MapUri("/signin/signinuser?{?}", "userform-return"); //inline form; used in UserAdmin Blender.MapUri("/signin/admin/settings", "settings"); Blender.MapUri("/signin/user/authentication/password/{?}", "authentication-password"); Blender.MapUri("/signin/user/authentication/settings/{?}", "authentication-settings"); Blender.MapUri("/signin/partial/user/image", "userimage-default"); // default user image }
private static bool IsInGroup(SystemUser user, SystemUserGroup group) { return(group != null && user != null && SystemUser.IsMemberOfGroup(user, group)); }
public void Register() { Handle.GET("/signin/app-name", () => new AppName()); Handle.GET("/signin", () => { return(Self.GET("/signin/signinuser")); }); Handle.GET("/signin/user", () => { MasterPage master = this.GetMaster(); if (master.SignInPage != null) { return(master.SignInPage); } Cookie cookie = cookieHelpers.GetSignInCookie(); SignInPage page = new SignInPage() { Data = null }; Session.Current.Store[nameof(SignInPage)] = page; if (cookie != null) { SystemUser.SignInSystemUser(cookie.Value); master.RefreshSignInState(); } return(page); }); Handle.GET("/signin/signinuser", HandleSignInForm); Handle.GET <string>("/signin/signinuser?{?}", HandleSignInForm); Handle.GET("/signin/profile", () => { MasterPage master = this.GetMaster(); master.RequireSignIn = true; master.Open("/signin/partial/profile-form"); return(master); }); Handle.GET("/signin/generateadminuser", (Request request) => { return(new Response() { Body = "Create the admin user by going to '/signin/signinuser' and pressing the 'Create Admin' button.", }); }, new HandlerOptions() { SkipRequestFilters = true }); Handle.GET("/signin/createadminuser", () => { MasterPage master = this.GetMaster(); master.RequireSignIn = false; master.Open("/signin/partial/createadminuser"); return(master); }); Handle.GET("/signin/settings", (Request request) => { Json page; if (!AuthorizationHelper.TryNavigateTo("/signin/settings", request, out page)) { return(page); } return(Db.Scope(() => { var settingsPage = new SettingsPage { Html = "/SignIn/viewmodels/SettingsPage.html", Uri = request.Uri, Data = MailSettingsHelper.GetSettings() }; return settingsPage; })); }); // Reset password Handle.GET("/signin/user/resetpassword?{?}", (string query, Request request) => { NameValueCollection queryCollection = HttpUtility.ParseQueryString(query); string token = queryCollection.Get("token"); MasterPage master = this.GetMaster(); if (token == null) { // TODO: master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } // Retrive the resetPassword instance ResetPassword resetPassword = Db.SQL <ResetPassword>("SELECT o FROM Simplified.Ring6.ResetPassword o WHERE o.Token=? AND o.Expire>?", token, DateTime.UtcNow).First; if (resetPassword == null) { // TODO: Show message "Reset token already used or expired" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } if (resetPassword.User == null) { // TODO: Show message "User deleted" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } SystemUser systemUser = resetPassword.User; ResetPasswordPage page = new ResetPasswordPage() { Html = "/SignIn/viewmodels/ResetPasswordPage.html", Uri = "/signin/user/resetpassword" //Uri = request.Uri // TODO: }; page.ResetPassword = resetPassword; if (systemUser.WhoIs != null) { page.FullName = systemUser.WhoIs.FullName; } else { page.FullName = systemUser.Username; } master.Partial = page; return(master); }); Handle.GET("/signin/user/authentication/settings/{?}", (string userid, Request request) => { Json page; if (!AuthorizationHelper.TryNavigateTo("/signin/user/authentication/settings/{?}", request, out page)) { return(new Json()); } // Get system user SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).FirstOrDefault(); if (user == null) { // TODO: Return a "User not found" page return(new Json()); //return (ushort)System.Net.HttpStatusCode.NotFound; } SystemUser systemUser = SystemUser.GetCurrentSystemUser(); SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", AuthorizationHelper.AdminGroupName).FirstOrDefault(); // Check if current user has permission to get this user instance if (AuthorizationHelper.IsMemberOfGroup(systemUser, adminGroup)) { if (user.WhoIs is Person) { page = Db.Scope(() => new SystemUserAuthenticationSettings { Html = "/SignIn/viewmodels/SystemUserAuthenticationSettings.html", Uri = request.Uri, Data = user, UserPassword = Self.GET("/signin/user/authentication/password/" + user.GetObjectID()) }); return(page); } } return(new Json()); }, new HandlerOptions { SelfOnly = true }); Handle.GET("/signin/user/authentication/password/{?}", (string userid, Request request) => { // Get system user SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).FirstOrDefault(); if (user == null) { return(new Json()); } Json page = Db.Scope(() => new SetPasswordPage { Html = "/SignIn/viewmodels/SetPasswordPage.html", Data = user }); return(page); }, new HandlerOptions { SelfOnly = true }); }
/// <summary> /// Delete System User Group and it's relationships /// </summary> /// <param name="group"></param> public static void DeleteSystemUserGroup(SystemUserGroup group) { // Remove System user member's Db.SlowSQL("DELETE FROM Simplified.Ring3.SystemUserGroupMember WHERE SystemUserGroup=?", group); group.Delete(); }