RequiredGroupMembership: Users.Grp.GID --> Users.Grp.GID[] (initial version), ver. 2.18.1006

This commit is contained in:
Milan Hanajik
2018-09-25 09:05:51 +02:00
parent 438374532f
commit cd246e89c8
22 changed files with 130 additions and 113 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace TBF.BenchControl.Elde.CoverTest
readonly ulong mask; /// derived from bitPosition in the constructor readonly ulong mask; /// derived from bitPosition in the constructor
readonly ulong target; readonly ulong target;
readonly string message; readonly string message;
readonly Users.Grp.GID bypassLevel; readonly Users.Grp.GID[] bypassLevel;
public CoverTest() public CoverTest()
{ {
@@ -22,7 +22,7 @@ namespace TBF.BenchControl.Elde.CoverTest
public int BitPosition; public int BitPosition;
public bool Invert; public bool Invert;
public string Message; public string Message;
public Users.Grp.GID BypassLevel; public Users.Grp.GID[] BypassLevel;
/// Private parameterless constructor invoked by all other (public) constructors /// Private parameterless constructor invoked by all other (public) constructors
CoverTestCfg() CoverTestCfg()
@@ -35,7 +35,7 @@ namespace TBF.BenchControl.Elde.CoverTest
Invert = false; Invert = false;
Message = Strings.Close_the_cover; Message = Strings.Close_the_cover;
BypassLevel = Users.Grp.GID.TestingSpecialists; BypassLevel = new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists };
} }
public CoverTestCfg(IComponentFactory factory) public CoverTestCfg(IComponentFactory factory)
@@ -68,7 +68,7 @@ namespace TBF.BenchControl.Elde.CoverTest
bitPositionTextBox.Text = config.BitPosition.ToString(); bitPositionTextBox.Text = config.BitPosition.ToString();
invertCheckBox.Checked = config.Invert; invertCheckBox.Checked = config.Invert;
messageTextBox.Text = config.Message; messageTextBox.Text = config.Message;
bypassLevelComboBox.Text = config.BypassLevel.ToString(); bypassLevelComboBox.Text = config.BypassLevel == null ? "---" : ((config.BypassLevel.Length > 0) ? config.BypassLevel[0].ToString() : "---");
} }
public void Unlock() public void Unlock()
@@ -93,11 +93,12 @@ namespace TBF.BenchControl.Elde.CoverTest
config.Invert = invertCheckBox.Checked; config.Invert = invertCheckBox.Checked;
config.Message = messageTextBox.Text; config.Message = messageTextBox.Text;
config.BypassLevel = null;
for (Users.Grp.GID gid = 0; gid < Users.Grp.GID.NrOfGroups; gid++) for (Users.Grp.GID gid = 0; gid < Users.Grp.GID.NrOfGroups; gid++)
{ {
if (bypassLevelComboBox.Text == gid.ToString()) if (bypassLevelComboBox.Text == gid.ToString())
{ {
config.BypassLevel = gid; config.BypassLevel = new Users.Grp.GID[] { gid };
break; break;
} }
} }
@@ -18,9 +18,9 @@ namespace TBF.BenchControl.Elde.CoverTest
public bool Completed { get { return completed; } } public bool Completed { get { return completed; } }
bool completed; bool completed;
Users.Grp.GID bypassLevel; Users.Grp.GID[] bypassLevel;
public CoverTestForm(string message, Users.Grp.GID bypassLevel, ILog bypassLog) public CoverTestForm(string message, Users.Grp.GID[] bypassLevel, ILog bypassLog)
{ {
InitializeComponent(); InitializeComponent();
ControlBox = false; ControlBox = false;
@@ -46,7 +46,7 @@ namespace TBF.BenchControl.TestMethods.Endurance
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = TBF.UiControls.SharedButtons.Buttons.Add | sharedButtons.OptionalButtons = TBF.UiControls.SharedButtons.Buttons.Add |
TBF.UiControls.SharedButtons.Buttons.Remove | TBF.UiControls.SharedButtons.Buttons.Remove |
TBF.UiControls.SharedButtons.Buttons.Up | TBF.UiControls.SharedButtons.Buttons.Up |
+1 -1
View File
@@ -42,7 +42,7 @@ namespace TBF
Flags = CfgUpdateFlags.None; Flags = CfgUpdateFlags.None;
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = global::Users.Grp.GID.Metrologists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { global::Users.Grp.GID.Metrologists };
sharedButtons.MoreButtonTop = ComponentCfgCtrlHeight - 45; sharedButtons.MoreButtonTop = ComponentCfgCtrlHeight - 45;
sharedButtons.OptionalButtons = SharedButtons.Buttons.None; sharedButtons.OptionalButtons = SharedButtons.Buttons.None;
sharedButtons.Unlocked += Unlock; sharedButtons.Unlocked += Unlock;
+1 -1
View File
@@ -69,7 +69,7 @@ namespace TBF
selectComponentTypeDlg = new SelectComponentClassDlg(); selectComponentTypeDlg = new SelectComponentClassDlg();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Administrators; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | sharedButtons.OptionalButtons = SharedButtons.Buttons.Add |
SharedButtons.Buttons.Remove | SharedButtons.Buttons.Remove |
+1 -1
View File
@@ -15,7 +15,7 @@ namespace TBF.Forms
/// <summary> /// <summary>
/// Required access rights to make changes with this form /// Required access rights to make changes with this form
/// </summary> /// </summary>
const Users.Grp.GID RequiredGroupMembership = Users.Grp.GID.Metrologists; static readonly Users.Grp.GID[] RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists, Users.Grp.GID.Metrologists };
public bool Unlocked; /// true = changes enabled public bool Unlocked; /// true = changes enabled
+7 -1
View File
@@ -806,7 +806,13 @@ namespace TBF
private void statusStrip1_DoubleClick(object sender, EventArgs e) private void statusStrip1_DoubleClick(object sender, EventArgs e)
{ {
if (new Users.Forms.LoginDlg(Users.Grp.GID.Testers).ShowDialog() == DialogResult.OK) #if TURA_IPERL || TURA_SPECIAL
Users.Grp.GID[] reqGrpMembership = new Users.Grp.GID[] { Users.Grp.GID.Testers, Users.Grp.GID.TestingSpecialists, Users.Grp.GID.Metrologists, Users.Grp.GID.HeadOfLab };
#else
Users.Grp.GID[] reqGrpMembership = null;
#endif
if (new Users.Forms.LoginDlg(reqGrpMembership).ShowDialog() == DialogResult.OK)
{ {
UpdateUser(); UpdateUser();
} }
+1 -1
View File
@@ -26,7 +26,7 @@ namespace TBF
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove;
sharedButtons.Unlocked += unlockButton_Click; sharedButtons.Unlocked += unlockButton_Click;
sharedButtons.OKClicked += okButton_Click; sharedButtons.OKClicked += okButton_Click;
+1 -1
View File
@@ -51,7 +51,7 @@ namespace TBF
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down; SharedButtons.Buttons.Up | SharedButtons.Buttons.Down;
sharedButtons.Unlocked += Unlocked; sharedButtons.Unlocked += Unlocked;
+3 -2
View File
@@ -62,7 +62,7 @@ namespace TBF
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.TestingSpecialists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists, Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down; SharedButtons.Buttons.Up | SharedButtons.Buttons.Down;
sharedButtons.Unlocked += Unlocked; sharedButtons.Unlocked += Unlocked;
@@ -102,7 +102,8 @@ namespace TBF
this.usedNames = usedNames; this.usedNames = usedNames;
sharedButtons.RequiredGroupMembership = procedure.Protected ? Users.Grp.GID.Metrologists : Users.Grp.GID.TestingSpecialists; sharedButtons.RequiredGroupMembership = procedure.Protected ? new Users.Grp.GID[] { Users.Grp.GID.Metrologists }
: new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists, Users.Grp.GID.Metrologists };
/// Prepare a list of components and a list of all valves in the test bench /// Prepare a list of components and a list of all valves in the test bench
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)) using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
+1 -1
View File
@@ -26,7 +26,7 @@ namespace TBF
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.TestingSpecialists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists, Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
SharedButtons.Buttons.Edit | SharedButtons.Buttons.Copy | SharedButtons.Buttons.Edit | SharedButtons.Buttons.Copy |
+15 -12
View File
@@ -221,15 +221,22 @@ namespace TBF
Users.Entities.User loadedUser = null; Users.Entities.User loadedUser = null;
try try
{ {
bool authorized = false; #if TURA_IPERL || TURA_SPECIAL
Grp.GID[] reqGrpMembership = new Grp.GID[] { Grp.GID.Testers, Grp.GID.TestingSpecialists, Grp.GID.Metrologists, Grp.GID.HeadOfLab };
#else
Grp.GID[] reqGrpMembership = null;
#endif
bool authorized = false;
Users.Entities.AuthorizedAs authorizedAs = Users.Entities.AuthorizedAs.PowerUser; Users.Entities.AuthorizedAs authorizedAs = Users.Entities.AuthorizedAs.PowerUser;
if (Users.Entities.User.IsPowerUser(loginDlgBench.Alias, loginDlgBench.Password)) if (Users.Entities.User.IsPowerUser(loginDlgBench.Alias, loginDlgBench.Password))
{ {
loadedUser = new Users.Entities.User(loginDlgBench.Alias, 6, true); loadedUser = new Users.Entities.User(loginDlgBench.Alias, 6, true);
authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password); authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership);
if (authorized) if (authorized)
GlobalData.AuthorizedAs = Users.Entities.AuthorizedAs.PowerUser; {
GlobalData.AuthorizedAs = Users.Entities.AuthorizedAs.PowerUser;
}
} }
/// ///
@@ -246,14 +253,10 @@ namespace TBF
/// Load and authorise user from the UsersDB database /// Load and authorise user from the UsersDB database
try try
{ {
Grp.GID requiredGroupMembership = Grp.GID.None;
#if TURA_IPERL || TURA_SPECIAL
requiredGroupMembership = Grp.GID.Testers;
#endif
if (loginDlgBench.Password == LoginDlgWithBenchSelection.UseTheTagPassword) if (loginDlgBench.Password == LoginDlgWithBenchSelection.UseTheTagPassword)
{ {
loadedUser = Users.Entities.User.LoadUserByTag(loginDlgBench.Alias, db); loadedUser = Users.Entities.User.LoadUserByTag(loginDlgBench.Alias, db);
if (loadedUser != null) authorized = loadedUser.AuthorizeTag(loginDlgBench.Alias, requiredGroupMembership); if (loadedUser != null) authorized = loadedUser.AuthorizeTag(loginDlgBench.Alias, reqGrpMembership);
} }
else else
{ {
@@ -262,17 +265,17 @@ namespace TBF
default: default:
case Users.Entities.LoginMethod.UserName: case Users.Entities.LoginMethod.UserName:
loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.Alias, db); loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.Alias, db);
if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, requiredGroupMembership); if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership);
break; break;
case Users.Entities.LoginMethod.FullName: case Users.Entities.LoginMethod.FullName:
loadedUser = Users.Entities.User.LoadUserByFullName(loginDlgBench.Alias, db); loadedUser = Users.Entities.User.LoadUserByFullName(loginDlgBench.Alias, db);
if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password, requiredGroupMembership); if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership);
break; break;
case Users.Entities.LoginMethod.Number: case Users.Entities.LoginMethod.Number:
int number; int number;
if (!int.TryParse(loginDlgBench.Alias, out number)) break; if (!int.TryParse(loginDlgBench.Alias, out number)) break;
loadedUser = Users.Entities.User.LoadUserByNumber(number, db); loadedUser = Users.Entities.User.LoadUserByNumber(number, db);
if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password, requiredGroupMembership); if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password, reqGrpMembership);
break; break;
} }
} }
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.18.1005.0")] [assembly: AssemblyVersion("2.18.1006.0")]
[assembly: AssemblyFileVersion("2.18.1005.0")] [assembly: AssemblyFileVersion("2.18.1006.0")]
+1 -1
View File
@@ -65,7 +65,7 @@ namespace TBF
InitializeComponent(); InitializeComponent();
/// SharedDlgButtons configuration /// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists; sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab | SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab |
+3 -3
View File
@@ -252,7 +252,7 @@ namespace TBF.UiControls
/// Prevent 'Stop draining' by password /// Prevent 'Stop draining' by password
if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists)) if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists))
{ {
if ((new Users.Forms.LoginDlg(Users.Grp.GID.TestingSpecialists)).ShowDialog() != DialogResult.OK) if ((new Users.Forms.LoginDlg(new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists })).ShowDialog() != DialogResult.OK)
return; return;
if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
@@ -269,7 +269,7 @@ namespace TBF.UiControls
/// Prevent 'Stop draining' by password /// Prevent 'Stop draining' by password
if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists)) if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists))
{ {
if ((new Users.Forms.LoginDlg(Users.Grp.GID.TestingSpecialists)).ShowDialog() != DialogResult.OK) if ((new Users.Forms.LoginDlg(new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists })).ShowDialog() != DialogResult.OK)
return; return;
if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
@@ -286,7 +286,7 @@ namespace TBF.UiControls
/// Prevent 'Stop draining' by password /// Prevent 'Stop draining' by password
if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists)) if (drain1Highlighted && !Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.TestingSpecialists))
{ {
if ((new Users.Forms.LoginDlg(Users.Grp.GID.TestingSpecialists)).ShowDialog() != DialogResult.OK) if ((new Users.Forms.LoginDlg(new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists })).ShowDialog() != DialogResult.OK)
return; return;
if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
+2 -2
View File
@@ -63,7 +63,7 @@ namespace TBF.UiControls
Middle, Middle,
} }
public Users.Grp.GID RequiredGroupMembership; public Users.Grp.GID[] RequiredGroupMembership;
Users.Entities.User originalUser; Users.Entities.User originalUser;
@@ -76,7 +76,7 @@ namespace TBF.UiControls
lockState = LockState.Locked; lockState = LockState.Locked;
MoreActive = false; MoreActive = false;
OptionalButtons = Buttons.None; OptionalButtons = Buttons.None;
RequiredGroupMembership = Users.Grp.GID.None; RequiredGroupMembership = null;
InitializeComponent(); InitializeComponent();
} }
+1 -1
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2016-2017 Sensus Metering Systems /// Copyright (c) 2016-2018 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
+59 -64
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2016-2017 Sensus Metering Systems /// Copyright (c) 2016-2018 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -101,6 +101,38 @@ namespace Users.Entities
} }
} }
/// <summary>
/// Check whether user is a member of any of specified groups.
/// Returns true also when no groups are defined (groupIds = null).
/// </summary>
/// <param name="groupIds">An array of group GID-s or null (no membership required)</param>
/// <returns>true if user is a member of any of specified groups</returns>
public virtual bool IsMemberOf(Grp.GID[] groupIds)
{
if (groupIds == null || powerUser)
{
return true;
}
foreach (var groupId in groupIds)
{
if (groupId >= 0 && (int)groupId < Grp.Count)
{
// for all group elements in User.groups
for (int i = 0; i < Groups.Count; ++i)
{
// element GID = parameter GroupId ?
if (((Group)Groups[i]).Gid == (int)groupId)
{
return true;
}
}
}
}
return false;
}
/// <summary> /// <summary>
/// Sets users password. It then will be encrypted. /// Sets users password. It then will be encrypted.
/// </summary> /// </summary>
@@ -129,17 +161,17 @@ namespace Users.Entities
/// <summary> /// <summary>
/// The FIRST of TWO possible user authorization method to be used /// Authorization method: 'requiredGroupMembership' contains a list of required groups.
/// when a specific group membership is required (you can use Grp.GID.None). /// Valid name and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
/// If the user is not authorized, the current user remains to be a current user /// When requiredGroupMembership == null, no membership is required, only name and password must be valid.
/// (i.e. the access rights were not risen to a higher level). /// If the user is not authorized, the current user remains to be a current user and access rights were not
/// If you require different behavior, use Unauthorize() before calling Authorize(). /// risen to a higher level. If you require different behavior, use Unauthorize() before calling Authorize().
/// </summary> /// </summary>
/// <param name="userName">User name</param> /// <param name="userName">User name</param>
/// <param name="password">Password</param> /// <param name="password">Password</param>
/// <param name="requiredGrupMembership"></param> /// <param name="requiredGrupMembership"></param>
/// <returns>true = authorized</returns> /// <returns>true = authorized</returns>
public virtual bool Authorize(string userName, string password, Grp.GID requiredGroupMembership) public virtual bool Authorize(string userName, string password, Grp.GID[] requiredGroupMembership)
{ {
if (IsPowerUser(userName, password)) if (IsPowerUser(userName, password))
{ {
@@ -167,26 +199,17 @@ namespace Users.Entities
} }
/// <summary> /// <summary>
/// The SECOND of TWO possible user authorization method to be used when /// Authorization method: 'requiredGroupMembership' contains a list of required groups.
/// no specific group membership is required. /// Valid number and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
/// </summary> /// When requiredGroupMembership == null, no membership is required, only number and password must be valid.
public virtual bool Authorize(string userName, string password) /// If the user is not authorized, the current user remains to be a current user and access rights were not
{ /// risen to a higher level. If you require different behavior, use Unauthorize() before calling Authorize().
return Authorize(userName, password, Grp.GID.None); /// </summary>
}
/// <summary>
/// The FIRST of TWO possible user authorization method to be used
/// when a specific group membership is required (you can use Grp.GID.None).
/// If the user is not authorized, the current user remains to be a current user
/// (i.e. the access rights were not risen to a higher level).
/// If you require different behavior, use Unauthorize() before calling Authorize().
/// </summary>
/// <param name="number">User ID number</param> /// <param name="number">User ID number</param>
/// <param name="password">Password</param> /// <param name="password">Password</param>
/// <param name="requiredGrupMembership"></param> /// <param name="requiredGrupMembership"></param>
/// <returns>true = authorized</returns> /// <returns>true = authorized</returns>
public virtual bool AuthorizeNumber(int number, string password, Grp.GID requiredGroupMembership) public virtual bool AuthorizeNumber(int number, string password, Grp.GID[] requiredGroupMembership)
{ {
if (Number == number) if (Number == number)
{ {
@@ -206,26 +229,17 @@ namespace Users.Entities
} }
/// <summary> /// <summary>
/// The SECOND of TWO possible user authorization method to be used when /// Authorization method: 'requiredGroupMembership' contains a list of required groups.
/// no specific group membership is required. /// Valid name and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
/// </summary> /// When requiredGroupMembership == null, no membership is required, only name and password must be valid.
public virtual bool AuthorizeNumber(int number, string password) /// If the user is not authorized, the current user remains to be a current user and access rights were not
{ /// risen to a higher level. If you require different behavior, use Unauthorize() before calling Authorize().
return AuthorizeNumber(number, password, Grp.GID.None); /// </summary>
}
/// <summary>
/// The FIRST of TWO possible user authorization method to be used
/// when a specific group membership is required (you can use Grp.GID.None).
/// If the user is not authorized, the current user remains to be a current user
/// (i.e. the access rights were not risen to a higher level).
/// If you require different behavior, use Unauthorize() before calling Authorize().
/// </summary>
/// <param name="fullName"></param> /// <param name="fullName"></param>
/// <param name="password"></param> /// <param name="password"></param>
/// <param name="requiredGrupMembership"></param> /// <param name="requiredGrupMembership"></param>
/// <returns>true = authorized</returns> /// <returns>true = authorized</returns>
public virtual bool AuthorizeFullName(string fullName, string password, Grp.GID requiredGroupMembership) public virtual bool AuthorizeFullName(string fullName, string password, Grp.GID[] requiredGroupMembership)
{ {
if (FullName.ToLower() == fullName.ToLower()) if (FullName.ToLower() == fullName.ToLower())
{ {
@@ -244,26 +258,17 @@ namespace Users.Entities
return false; return false;
} }
/// <summary>
/// The SECOND of TWO possible user authorization method to be used when
/// no specific group membership is required.
/// </summary>
public virtual bool AuthorizeFullName(string fullName, string password)
{
return AuthorizeFullName(fullName, password, Grp.GID.None);
}
/// <summary> /// <summary>
/// The FIRST of TWO possible user authorization method to be used /// Authorization method: 'requiredGroupMembership' contains a list of required groups.
/// when a specific group membership is required (you can use Grp.GID.None). /// Valid TAG and a mbership in any of theese goups grants access, Authorize(..) returns true.
/// If the user is not authorized, the current user remains to be a current user /// When requiredGroupMembership == null, no membership is required, only the TAG must be valid.
/// (i.e. the access rights were not risen to a higher level). /// If the user is not authorized, the current user remains to be a current user and access rights were not
/// If you require different behavior, use Unauthorize() before calling Authorize(). /// risen to a higher level. If you require different behavior, use Unauthorize() before calling Authorize().
/// </summary> /// </summary>
/// <param name="tag">Tag (RFID, NFC, ... s/n)</param> /// <param name="tag">Tag (RFID, NFC, ... s/n)</param>
/// <param name="requiredGrupMembership"></param> /// <param name="requiredGrupMembership"></param>
/// <returns>true = authorized</returns> /// <returns>true = authorized</returns>
public virtual bool AuthorizeTag(string tag, Grp.GID requiredGroupMembership) public virtual bool AuthorizeTag(string tag, Grp.GID[] requiredGroupMembership)
{ {
if (Tag == tag) if (Tag == tag)
{ {
@@ -282,16 +287,6 @@ namespace Users.Entities
return false; return false;
} }
/// <summary>
/// The SECOND of TWO possible user authorization method to be used when
/// no specific group membership is required.
/// </summary>
public virtual bool AuthorizeTag(string tag)
{
return AuthorizeTag(tag, Grp.GID.None);
}
/// <summary> /// <summary>
/// Returns a 'User' with a given username from a database. /// Returns a 'User' with a given username from a database.
/// </summary> /// </summary>
+20 -9
View File
@@ -18,8 +18,9 @@ namespace Users.Forms
// Private fields // Private fields
string user; string user;
string password; string password;
Grp.GID requiredGroupMembership = Grp.GID.Invalid; Grp.GID[] requiredGroupMembership;
bool noDatabase; bool noDatabase;
Color oriBackColor;
/// Smart card support, card S/N is used as user.Tag /// Smart card support, card S/N is used as user.Tag
GemCard.CardNative card; GemCard.CardNative card;
@@ -35,6 +36,8 @@ namespace Users.Forms
public LoginDlg() public LoginDlg()
{ {
InitializeComponent(); InitializeComponent();
oriBackColor = BackColor;
} }
/// <summary> /// <summary>
@@ -59,16 +62,21 @@ namespace Users.Forms
/// <summary> /// <summary>
/// Constructor when a specific group membership is required. /// Constructor when a specific group membership is required.
/// </summary> /// </summary>
public LoginDlg(Grp.GID requiredGroupMembership) public LoginDlg(Grp.GID[] requiredGroupMembership)
: this() : this()
{ {
this.requiredGroupMembership = requiredGroupMembership; this.requiredGroupMembership = requiredGroupMembership;
#if DEBUG
user = "MHA";
userNameTextBox.Text = "MHA";
passwordTextBox.Text = "kremik";
#endif
} }
/// <summary> /// <summary>
/// Constructor with a predefined user when a specific group membership is required. /// Constructor with a predefined user when a specific group membership is required.
/// </summary> /// </summary>
public LoginDlg(string predefinedUser, Grp.GID requiredGroupMembership) public LoginDlg(string predefinedUser, Grp.GID[] requiredGroupMembership)
: this() : this()
{ {
user = predefinedUser; user = predefinedUser;
@@ -85,6 +93,9 @@ namespace Users.Forms
else else
passwordTextBox.Select(); passwordTextBox.Select();
///
/// Smart card reader detection
///
smartCardReader = null; /// null = No smart card reader detected smartCardReader = null; /// null = No smart card reader detected
#if TURA_IPERL || TURA_SPECIAL #if TURA_IPERL || TURA_SPECIAL
@@ -183,15 +194,15 @@ namespace Users.Forms
{ {
default: default:
case Entities.LoginMethod.UserName: case Entities.LoginMethod.UserName:
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.Authorize(user, password) : loadedUser.Authorize(user, password, requiredGroupMembership); authorized = loadedUser.Authorize(user, password, requiredGroupMembership);
break; break;
case Entities.LoginMethod.FullName: case Entities.LoginMethod.FullName:
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeFullName(user, password) : loadedUser.AuthorizeFullName(user, password, requiredGroupMembership); authorized = loadedUser.AuthorizeFullName(user, password, requiredGroupMembership);
break; break;
case Entities.LoginMethod.Number: case Entities.LoginMethod.Number:
int number; int number;
if (!int.TryParse(user, out number)) break; if (!int.TryParse(user, out number)) break;
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeNumber(number, password) : loadedUser.AuthorizeNumber(number, password, requiredGroupMembership); authorized = loadedUser.AuthorizeNumber(number, password, requiredGroupMembership);
break; break;
} }
} }
@@ -222,7 +233,7 @@ namespace Users.Forms
/// </summary> /// </summary>
private void cancelButton_Click(object sender, EventArgs e) private void cancelButton_Click(object sender, EventArgs e)
{ {
if (requiredGroupMembership == Grp.GID.Invalid) if (requiredGroupMembership == null)
{ {
Entities.User.Unauthorize(); Entities.User.Unauthorize();
} }
@@ -278,7 +289,7 @@ namespace Users.Forms
Users.Entities.User loadedUser = Users.Entities.User.LoadUserByTag(tag, db); Users.Entities.User loadedUser = Users.Entities.User.LoadUserByTag(tag, db);
if (loadedUser != null) if (loadedUser != null)
{ {
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeTag(tag) : loadedUser.AuthorizeTag(tag, requiredGroupMembership); authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership);
} }
} }
catch (Exception) { } catch (Exception) { }
@@ -304,7 +315,7 @@ namespace Users.Forms
void OnCardRemoved(object sender, CardRemovedEventArgs args) void OnCardRemoved(object sender, CardRemovedEventArgs args)
{ {
BackColor = SystemColors.Control; BackColor = oriBackColor;
} }
private void LoginDlg_FormClosing(object sender, FormClosingEventArgs e) private void LoginDlg_FormClosing(object sender, FormClosingEventArgs e)
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.18.982.0")] [assembly: AssemblyVersion("2.18.1006.0")]
[assembly: AssemblyFileVersion("2.18.982.0")] [assembly: AssemblyFileVersion("2.18.1006.0")]