Change default Administrator and User roles names

StatusIDPriorityType
Closed31362MajorQuestion
ProfileReply
gabossoloClient

How to change default Administrator and User roles names.

Administartors and Users roles names?

Thank you!

Replies

UserDescriptionPosted On
MariyaVoytovichAgent

Hello gabossolo!

You can change the default Administrator and User roles names in the Model Editor.
Change the Value field in the Localization / Security / XafariSecuritySystem / AdministratorsRoleName node to change the administrator name.
Change the Value field in the Localization / Security / XafariSecuritySystem / UsersRoleNamenode to change the user name.

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,
Mariya
On behalf of Xafari Client Services Team

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,
Mariya
On behalf of Xafari Client Services Team

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!
Open the Model Editor and go to the Xafari/ArmDesign/Arms/YourArm node.
This node has the specific property:
Role is the role ID of the user who will be able to see this Arm. This property provides an important feature of the Arm to configure automatically in accordance with various user groups. A lookup list contains the roles from the Xafari|Roles node. These roles must be synchronized with the application Security System.

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,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya -- Thanks for your reply !

Coud you please tell me how to disable:
- Automatic Administartor and Users roles creation? I want to do it manaully.
- Automatic Windows User creation. Example: PC_NAME\USER.

Thanks!

Regards, GB

MariyaVoytovichAgent

Hi!

The answer to the first question is:
Administrator and user roles are created using the XafariSecurityManager in the Updater.
Xafari Security DC and Xpo Security implemented their own Updater and SecurityManager.
Therefore, to disable automatic creation of roles, you must create your own SecurityManager, which will implement XafariSecurityManager.
In your own SecurityManager, you need to override the methods: CreateAdministratorRole and CreateUsersRole.

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:
In directory authentication, always the user names are obtained through the WindowsIdentity object. So in the login window there will always be a name of the type COMPUTERNAME \ username or DOMAINNAME \ username.
But you cane disable create automatically user for the Windows account, see documentation:
Authentication
AuthenticationActiveDirectory.CreateUserAutomatically Property

Feel free to contact us if you need further assistance or have additional questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Thank you!

How and where to initialize my NewXafariSecurityManager ?

Concerning ActiveDirectory, I'm using Xafari.Security with AuthenticationStandard.

### My NewXafariSecurityManager code:
-----------------------------------------------------------------------------------------------------------------------
public class CargoAirXafariSecurityManager : XafariSecurityManager
{
private XafariSecurityManager _xafariSecurityManager;
private CargoAirXafariSecurityManager() { }

public static void InitializeXafariSecurityManager()
{
Instance = new CargoAirXafariSecurityManager();
}

public override void SetActionOperationPermission(ISecurityRole role, IObjectSpace objectSpace, string actionId, bool allowExecute)
{
_xafariSecurityManager.SetActionOperationPermission(role, objectSpace, actionId, allowExecute);
}

public override void SetActionOperationPermission(ISecurityRole role, IObjectSpace objectSpace, ActionBase action, bool allowExecute)
{
_xafariSecurityManager.SetActionOperationPermission(role, objectSpace, action, allowExecute);
}

public override ISecurityRole FindRole(IObjectSpace objectSpace, string roleName)
{
return _xafariSecurityManager.FindRole(objectSpace, roleName);
}

public override ISecurityRole CreateAdministratorRole(IObjectSpace objectSpace)
{
return null;
}

public override ISecurityRole CreateUsersRole(IObjectSpace objectSpace, string roleName = null)
{
return null;
}
-----------------------------------------------------------------------------------------------------------------------
Regards,

MariyaVoytovichAgent

Initialize SecurityManager in the project module
public sealed partial class MyApplicationModule : XafariModuleBase
{
public override void Setup(XafApplication application)
{

base.Setup(application);

application.SettingUp += (sender, args) =>

{
NewXafariSecurityManager.InitializeXafariSecurityManager();
};

}
}

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Thanks!

× This ticket is closed.

Write US