Status | ID | Priority | Type |
Closed | 31362 | Major | Question |
Profile | Reply |
gabossoloClient | How to change default Administrator and User roles names. Administartors and Users roles names? Thank you! |
User | Description | Posted On |
MariyaVoytovichAgent | Hello gabossolo! You can change the default Administrator and User roles names in the Model Editor. Then you must insert the string XafariSecuritySystem.SyncWithModel = true in the Main method that belongs to the Program class. internal static class Program { /// /// The main entry point for the application. ///[STAThread] private static void Main() { XafariSecuritySystem.SyncWithModel = true; } } Feel free to contact us if you need further assistance or have additional questions. Regards, | |
gabossoloClient | Noted! But how to add user in the Administrators group in Updater.cs file when doing initial update? Thanks! | |
MariyaVoytovichAgent | First you need to create a new user after adding the administrator role. public class Updater : XafariModuleUpdater { public override void SafeUpdateDatabaseAfterUpdateSchema() { base.SafeUpdateDatabaseAfterUpdateSchema(); CreateAdministratorUser(); this.ObjectSpace.CommitChanges(); } private void CreateAdministratorUser() { var strategy = SecuritySystem.Instance as SecurityStrategyComplex; if (strategy == null) return ; var usersCount = this.ObjectSpace.GetObjectsCount(strategy.UserType, null); if (usersCount>1) return; var administratorRole = (SecuritySystemRole)this.FindRole(this.ObjectSpace, XafariSecuritySystem.AdministratorsRoleName); if (administratorRole == null) { administratorRole = (SecuritySystemRole)this.ObjectSpace.Xafari().CreateObject(strategy.RoleType); administratorRole.Name = XafariSecuritySystem.AdministratorsRoleName; administratorRole.IsAdministrative = true; } var defaultAdminUserName = "TestUser"; var creator = (SecuritySystemUser)this.ObjectSpace.Xafari().CreateObject(strategy.UserType); creator.UserName = defaultAdminUserName; creator.ChangePasswordOnFirstLogon = true; creator.SetPassword("1"); creator.Roles.Add(administratorRole); }public ISecurityRole FindRole(IObjectSpace objectSpace, string roleName) { var strategy = SecuritySystem.Instance as SecurityStrategyComplex; if (strategy == null) return null;var role = (SecuritySystemRole)objectSpace.Xafari().FindObject(strategy.RoleType, new BinaryOperator("Name", roleName)); return role; The first time the application is started, the current user is assigned administrator privileges Regards, | |
gabossoloClient | Many thanks! | |
gabossoloClient | Hi ! Could you please tell me how to restrict Arm navigation item with other roles than predefined Administrator and Users? Thank you! Regards, | |
MariyaVoytovichAgent | Hi! Xafari|Roles node contains Administrator and Users roles, but if you renamed these roles in the Localization / Security / XafariSecuritySystem node, you must create new roles in the Xafari|Roles node with new names. Regards, | |
gabossoloClient | Hi Mariya -- Thanks for your reply ! Coud you please tell me how to disable: Thanks! Regards, GB | |
MariyaVoytovichAgent | Hi! The answer to the first question is: public class NewXafariSecurityManager : XafariSecurityManager { private NewXafariSecurityManager() { } public static void InitializeXafariSecurityManager() { Instance = new NewXafariSecurityManager(); } public override ISecurityRole CreateAdministratorRole(IObjectSpace objectSpace) { return null; } public override ISecurityRole CreateUsersRole(IObjectSpace objectSpace, string roleName = null) { return null; } } And initialize it in the project module public override void Setup(XafApplication application) { base.Setup(application); application.SettingUp += (sender, args) => { if (((XafApplication)sender).Xafari().IsSharedApplication()) return; NewXafariSecurityManager.InitializeXafariSecurityManager(); }; } The answer to the second question is: Feel free to contact us if you need further assistance or have additional questions. Regards, | |
gabossoloClient | Thank you! How and where to initialize my NewXafariSecurityManager ? Concerning ActiveDirectory, I'm using Xafari.Security with AuthenticationStandard. ### My NewXafariSecurityManager code: public static void InitializeXafariSecurityManager() public override void SetActionOperationPermission(ISecurityRole role, IObjectSpace objectSpace, string actionId, bool allowExecute) public override void SetActionOperationPermission(ISecurityRole role, IObjectSpace objectSpace, ActionBase action, bool allowExecute) public override ISecurityRole FindRole(IObjectSpace objectSpace, string roleName) public override ISecurityRole CreateAdministratorRole(IObjectSpace objectSpace) public override ISecurityRole CreateUsersRole(IObjectSpace objectSpace, string roleName = null) | |
MariyaVoytovichAgent | Initialize SecurityManager in the project module base.Setup(application); application.SettingUp += (sender, args) => { } Regards, | |
gabossoloClient | Thanks! |