Skip to content

Commit

Permalink
*Roles assigment
Browse files Browse the repository at this point in the history
*Autologin in debug,release
  • Loading branch information
peterbarancek committed Jun 10, 2024
1 parent 214fe2f commit 99c4d5c
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<TcSmProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2012/07/TcSmProject" TcSmVersion="1.0" TcVersion="3.1.4024.42">
<TcSmProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2012/07/TcSmProject" TcSmVersion="1.0" TcVersion="3.1.4024.55">
<DataTypes>
<DataType>
<Name GUID="{132E66EA-9D48-518D-E919-C407F4B9DB22}" Namespace="TcoIo" AutoDeleteType="true">TcoAmsNetId</Name>
Expand Down Expand Up @@ -152,7 +152,6 @@
<Plc>
<Project GUID="{1F826822-78EF-46D2-B0C2-A803A090596D}" Name="x_template_xPlc" PrjFilePath="x_template_xPlc\x_template_xPlc.plcproj" TmcFilePath="x_template_xPlc\x_template_xPlc.tmc" ReloadTmc="true" AmsPort="851" FileArchiveSettings="#x000e" SymbolicMapping="true">
<Instance Id="#x08502000" TcSmClass="TComPlcObjDef" KeepUnrestoredLinks="2" TmcPath="x_template_xPlc\x_template_xPlc.tmc" TmcHash="{084F41A0-87AE-0BF0-6C92-DEFF9063B281}">

<Name>x_template_xPlc Instance</Name>
<CLSID ClassFactory="TcPlc30">{08500001-0000-0000-F000-000000000064}</CLSID>
<Vars VarGrpType="1">
Expand Down Expand Up @@ -834,7 +833,7 @@
</UnrestoredVarLinks>
<Contexts>
<Context>
<Id NeedCalleeCall="true">0</Id>
<Id>0</Id>
<Name>PlcTask</Name>
<ManualConfig>
<OTCID>#x02010030</OTCID>
Expand Down
27 changes: 6 additions & 21 deletions templates/mts-s-template/t/src/x_template_xHmi.Wpf/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public App()


const string SetId = "default";
Entry.LoadAppSettings(SetId, IsDebug);
Entry.LoadAppSettings(SetId, RepositoryEntry.IsDebug());

if (!IsDebug)
if (!RepositoryEntry.IsDebug())
DataExchangeActive = Entry.Settings.DataExchange;
else
DataExchangeActive = true; //should be true ,do exchange data are hanlded by this instance
Expand Down Expand Up @@ -163,6 +163,9 @@ public App()


// Authenticates default user, change this line if you need to authenticate different user.

Console.WriteLine(Entry.Settings.AutologinUserName.ToString());
Console.WriteLine(Entry.Settings.AutologinUserPassword);
SecurityManager.Manager.Service.AuthenticateUser(Entry.Settings.AutologinUserName, Entry.Settings.AutologinUserPassword);


Expand Down Expand Up @@ -433,25 +436,7 @@ private void GetProductionPlan(ProductionPlaner productionPlaner)

}

/// <summary>
/// Gets a value indicating whether the assembly was built in debug mode.
/// </summary>
public static bool IsDebug
{
get
{
bool isDebug = false;

#if (DEBUG)
isDebug = true;
#else
isDebug = false;
#endif

return isDebug;
}
}



/// <summary>
/// Gets the twin connector for this application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
if (App.IsDebug /*|| Entry.Settings.DepoyMode == DeployMode.Local*/ || Entry.Settings.DeployMode == DeployMode.Dummy)
if (RepositoryEntry.IsDebug() /*|| Entry.Settings.DepoyMode == DeployMode.Local*/ || Entry.Settings.DeployMode == DeployMode.Dummy)
{ this.WindowStyle = WindowStyle.SingleBorderWindow; }
else
this.WindowStyle = WindowStyle.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<value>Procesné data stanice</value>
</data>
<data name="StationTechnologyData" xml:space="preserve">
<value>Technologicke dáta stanicer</value>
<value>Technologicke dáta stanice</value>
</data>
<data name="ShowStationInWindow" xml:space="preserve">
<value>Zobraziť stanicu v novom okne.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<TabItem Header="{x:Static p:strings.StationProcessData}" DataContext="{Binding Component}">
<vortex:RenderableContentControl DataContext="{Binding _cuProcessDataDisplay}" PresentationType="ShadowDisplaySlim-ShadowDisplay"></vortex:RenderableContentControl>
</TabItem>
<TabItem Header="{x:Static p:strings.StationTechnologyData}" DataContext="{Binding Component}">
<vortex:RenderableContentControl DataContext="{Binding _cuTechnologicalDataDisplay}" PresentationType="ShadowDisplaySlim-ShadowDisplay"></vortex:RenderableContentControl>
</TabItem>

<TabItem Header="{x:Static p:strings.FullProcessData}">
<vortex:RenderableContentControl DataContext="{Binding OnlineData}" PresentationType="ShadowDisplaySlim-ShadowDisplay"></vortex:RenderableContentControl>

</TabItem>

<TabItem Header="{x:Static p:strings.StationTechnologyData}" DataContext="{Binding Component}">
<vortex:RenderableContentControl DataContext="{Binding _cuTechnologicalDataDisplay}" PresentationType="ShadowDisplaySlim-ShadowDisplay"></vortex:RenderableContentControl>
</TabItem>

</TabControl>
</Grid>
</UserControl>
40 changes: 20 additions & 20 deletions templates/mts-s-template/t/src/x_template_xOp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public App()



Entry.LoadAppSettings("defaultOP", IsDebug);
Entry.LoadAppSettings("defaultOP", RepositoryEntry.IsDebug());

if (!IsDebug)
if (!RepositoryEntry.IsDebug())
DataExchangeActive = Entry.Settings.DataExchange;
else
DataExchangeActive = false; //should be false ,do not exchange data due 'x_template_xHmi.Wpf' do it in debug otherwise it is defined 'LoadAppSettings' method above
Expand Down Expand Up @@ -431,24 +431,24 @@ private void GetProductionPlan(ProductionPlaner productionPlaner)

}

/// <summary>
/// Gets a value indicating whether the assembly was built in debug mode.
/// </summary>
public static bool IsDebug
{
get
{
bool isDebug = false;

#if (DEBUG)
isDebug = true;
#else
isDebug = false;
#endif

return isDebug;
}
}
// /// <summary>
// /// Gets a value indicating whether the assembly was built in debug mode.
// /// </summary>
// public static bool IsDebug
// {
// get
// {
// bool isDebug = false;

//#if (DEBUG)
// isDebug = true;
//#else
// isDebug = false;
//#endif

// return isDebug;
// }
// }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class ApplicationSettings
public long CappedMaxDocuments { get; set; } = 1000000;

// USER
public string AutologinUserName { get; set; } = "admin";
public string AutologinUserPassword { get; set; }= "admin";
public string AutologinUserName { get; set; } = RepositoryEntry.IsDebug() ? "MTSAdmin" : "operator";
public string AutologinUserPassword { get; set; }= RepositoryEntry.IsDebug() ? "MTSservis" : "";

public string GetConnectionString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace x_template_xPlcConnector
public class Entry
{




private static x_template_xPlcTwinController plc = new x_template_xPlcTwinController(Tc3ConnectorAdapter.Create(851,true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,19 @@ public static IAuthenticationService CreateSecurityManageUsingRavenDb(bool withD
if (withDefaultGroups)
{
// create only once
var con = groups.Count;
if (groups.Count <= 1)
{
DefaultGroups.Create();
DefaultRoles.Create();
var empty = groups.Count <= 1;

}
if (empty) DefaultGroups.Create();
DefaultRoles.Create();
if (empty) DefaultRoles.AssignRoles();

}

if (withDefaultUsers)
{
if (users.Count <= 1)
{
DefaultUsers.Create();
if (users.Count <= 1) DefaultUsers.Create();

}

}

return manager;
Expand All @@ -82,17 +79,23 @@ public static IAuthenticationService CreateSecurityManageUsingMongoDb(bool withD
var roleGroupManager = new RoleGroupManager(groups);

var manager = SecurityManager.Create(users, roleGroupManager);

if (withDefaultGroups)
{
// create only once
var con = groups.Count;
if (groups.Count <= 1)
{
DefaultGroups.Create();
DefaultRoles.Create();
var empty = groups.Count <= 1;

if (empty) DefaultGroups.Create();
DefaultRoles.Create();
if (empty) DefaultRoles.AssignRoles();

}

if (withDefaultUsers)
{
if (users.Count <= 1) DefaultUsers.Create();


}
}

if (withDefaultUsers)
Expand Down Expand Up @@ -147,5 +150,23 @@ public static void InitializeIndexProcessDataRepositoryMongoDb(MongoDbRepository

}
}
/// <summary>
/// Gets a value indicating whether the assembly was built in debug mode.
/// </summary>
public static bool IsDebug()
{

bool isDebug = false;

#if (DEBUG)
isDebug = true;
#else
isDebug = false;
#endif

return isDebug;

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ namespace x_template_xPlcConnector
public class DefaultRoles
{
private DefaultRoles()
{

{

SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Administrator,
new string[] { "Administrator",
process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
instructor_access,planer_access,statistic_access,
technology_automat_all,technology_ground_all,
ground_position_start,automat_start,manual_start,
station_details,sequencer_step,
can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});
SecurityManager.Manager.GetOrCreateRole(new Role(process_settings_access));
SecurityManager.Manager.GetOrCreateRole(new Role(process_settings_change));
SecurityManager.Manager.GetOrCreateRole(new Role(rework_settings_access));
SecurityManager.Manager.GetOrCreateRole(new Role(process_traceability_access));
SecurityManager.Manager.GetOrCreateRole(new Role(technology_settings_access));

SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Maintenance,
new string[] {
//process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
//instructor_access,planer_access,statistic_access,
technology_automat_all,technology_ground_all,
ground_position_start,automat_start,manual_start,
station_details,sequencer_step,
can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});
SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Operator,
new string[] {
//process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
//instructor_access,planer_access,statistic_access,
//technology_automat_all,technology_ground_all,
//ground_position_start,automat_start,manual_start,
//station_details,sequencer_step,
//can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});
SecurityManager.Manager.GetOrCreateRole(new Role(instructor_access));
SecurityManager.Manager.GetOrCreateRole(new Role(planer_access));
SecurityManager.Manager.GetOrCreateRole(new Role(statistic_access));

SecurityManager.Manager.GetOrCreateRole(new Role(technology_automat_all));
SecurityManager.Manager.GetOrCreateRole(new Role(technology_ground_all));

SecurityManager.Manager.GetOrCreateRole(new Role(ground_position_start));
SecurityManager.Manager.GetOrCreateRole(new Role(automat_start));
SecurityManager.Manager.GetOrCreateRole(new Role(manual_start));

SecurityManager.Manager.GetOrCreateRole(new Role(station_details));
SecurityManager.Manager.GetOrCreateRole(new Role(sequencer_step));

SecurityManager.Manager.GetOrCreateRole(new Role(can_override_inspection));
SecurityManager.Manager.GetOrCreateRole(new Role(can_change_hw_settings));

SecurityManager.Manager.GetOrCreateRole(new Role(can_user_close_application));
SecurityManager.Manager.GetOrCreateRole(new Role(can_user_change_localization));




}
public const string process_settings_access = nameof(process_settings_access);
public const string process_settings_change = nameof(process_settings_change);
Expand Down Expand Up @@ -74,6 +74,38 @@ public static void Create()
{
_roles = new DefaultRoles();
}

public static void AssignRoles()
{
SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Administrator,
new string[] { "Administrator",
process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
instructor_access,planer_access,statistic_access,
technology_automat_all,technology_ground_all,
ground_position_start,automat_start,manual_start,
station_details,sequencer_step,
can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});

SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Maintenance,
new string[] {
//process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
//instructor_access,planer_access,statistic_access,
technology_automat_all,technology_ground_all,
ground_position_start,automat_start,manual_start,
station_details,sequencer_step,
can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});
SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Operator,
new string[] {
//process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access,
//instructor_access,planer_access,statistic_access,
//technology_automat_all,technology_ground_all,
//ground_position_start,automat_start,manual_start,
//station_details,sequencer_step,
//can_override_inspection,can_change_hw_settings,
can_user_close_application,can_user_change_localization});
}

}
}
Loading

0 comments on commit 99c4d5c

Please sign in to comment.