RequiredGroupMembership: Users.Grp.GID --> Users.Grp.GID[] (initial version), ver. 2.18.1006
This commit is contained in:
parent
438374532f
commit
cd246e89c8
@ -24,7 +24,7 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
readonly ulong mask; /// derived from bitPosition in the constructor
|
||||
readonly ulong target;
|
||||
readonly string message;
|
||||
readonly Users.Grp.GID bypassLevel;
|
||||
readonly Users.Grp.GID[] bypassLevel;
|
||||
|
||||
public CoverTest()
|
||||
{
|
||||
|
||||
@ -22,7 +22,7 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
public int BitPosition;
|
||||
public bool Invert;
|
||||
public string Message;
|
||||
public Users.Grp.GID BypassLevel;
|
||||
public Users.Grp.GID[] BypassLevel;
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
CoverTestCfg()
|
||||
@ -35,7 +35,7 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
Invert = false;
|
||||
Message = Strings.Close_the_cover;
|
||||
|
||||
BypassLevel = Users.Grp.GID.TestingSpecialists;
|
||||
BypassLevel = new Users.Grp.GID[] { Users.Grp.GID.TestingSpecialists };
|
||||
}
|
||||
|
||||
public CoverTestCfg(IComponentFactory factory)
|
||||
|
||||
@ -68,7 +68,7 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
bitPositionTextBox.Text = config.BitPosition.ToString();
|
||||
invertCheckBox.Checked = config.Invert;
|
||||
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()
|
||||
@ -93,11 +93,12 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
config.Invert = invertCheckBox.Checked;
|
||||
config.Message = messageTextBox.Text;
|
||||
|
||||
config.BypassLevel = null;
|
||||
for (Users.Grp.GID gid = 0; gid < Users.Grp.GID.NrOfGroups; gid++)
|
||||
{
|
||||
if (bypassLevelComboBox.Text == gid.ToString())
|
||||
{
|
||||
config.BypassLevel = gid;
|
||||
config.BypassLevel = new Users.Grp.GID[] { gid };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,9 +18,9 @@ namespace TBF.BenchControl.Elde.CoverTest
|
||||
public bool Completed { get { return 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();
|
||||
ControlBox = false;
|
||||
|
||||
@ -46,7 +46,7 @@ namespace TBF.BenchControl.TestMethods.Endurance
|
||||
InitializeComponent();
|
||||
|
||||
/// 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 |
|
||||
TBF.UiControls.SharedButtons.Buttons.Remove |
|
||||
TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
|
||||
@ -42,7 +42,7 @@ namespace TBF
|
||||
Flags = CfgUpdateFlags.None;
|
||||
|
||||
/// 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.OptionalButtons = SharedButtons.Buttons.None;
|
||||
sharedButtons.Unlocked += Unlock;
|
||||
|
||||
@ -69,7 +69,7 @@ namespace TBF
|
||||
selectComponentTypeDlg = new SelectComponentClassDlg();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Administrators;
|
||||
sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
|
||||
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add |
|
||||
SharedButtons.Buttons.Remove |
|
||||
|
||||
@ -15,7 +15,7 @@ namespace TBF.Forms
|
||||
/// <summary>
|
||||
/// Required access rights to make changes with this form
|
||||
/// </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
|
||||
|
||||
|
||||
@ -806,7 +806,13 @@ namespace TBF
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// 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.Unlocked += unlockButton_Click;
|
||||
sharedButtons.OKClicked += okButton_Click;
|
||||
|
||||
@ -51,7 +51,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// 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.Buttons.Up | SharedButtons.Buttons.Down;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
|
||||
@ -62,7 +62,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// 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.Buttons.Up | SharedButtons.Buttons.Down;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
@ -102,7 +102,8 @@ namespace TBF
|
||||
|
||||
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
|
||||
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
|
||||
|
||||
@ -26,7 +26,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// 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.Buttons.Up | SharedButtons.Buttons.Down |
|
||||
SharedButtons.Buttons.Edit | SharedButtons.Buttons.Copy |
|
||||
|
||||
@ -221,15 +221,22 @@ namespace TBF
|
||||
Users.Entities.User loadedUser = null;
|
||||
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;
|
||||
|
||||
if (Users.Entities.User.IsPowerUser(loginDlgBench.Alias, loginDlgBench.Password))
|
||||
{
|
||||
loadedUser = new Users.Entities.User(loginDlgBench.Alias, 6, true);
|
||||
authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password);
|
||||
if (authorized)
|
||||
GlobalData.AuthorizedAs = Users.Entities.AuthorizedAs.PowerUser;
|
||||
authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership);
|
||||
if (authorized)
|
||||
{
|
||||
GlobalData.AuthorizedAs = Users.Entities.AuthorizedAs.PowerUser;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
@ -246,14 +253,10 @@ namespace TBF
|
||||
/// Load and authorise user from the UsersDB database
|
||||
try
|
||||
{
|
||||
Grp.GID requiredGroupMembership = Grp.GID.None;
|
||||
#if TURA_IPERL || TURA_SPECIAL
|
||||
requiredGroupMembership = Grp.GID.Testers;
|
||||
#endif
|
||||
if (loginDlgBench.Password == LoginDlgWithBenchSelection.UseTheTagPassword)
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -262,17 +265,17 @@ namespace TBF
|
||||
default:
|
||||
case Users.Entities.LoginMethod.UserName:
|
||||
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;
|
||||
case Users.Entities.LoginMethod.FullName:
|
||||
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;
|
||||
case Users.Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(loginDlgBench.Alias, out number)) break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.1005.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.1005.0")]
|
||||
[assembly: AssemblyVersion("2.18.1006.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.1006.0")]
|
||||
|
||||
@ -65,7 +65,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// 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.Buttons.Up | SharedButtons.Buttons.Down |
|
||||
SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab |
|
||||
|
||||
@ -252,7 +252,7 @@ namespace TBF.UiControls
|
||||
/// Prevent 'Stop draining' by password
|
||||
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;
|
||||
|
||||
if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
|
||||
@ -269,7 +269,7 @@ namespace TBF.UiControls
|
||||
/// Prevent 'Stop draining' by password
|
||||
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;
|
||||
|
||||
if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
|
||||
@ -286,7 +286,7 @@ namespace TBF.UiControls
|
||||
/// Prevent 'Stop draining' by password
|
||||
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;
|
||||
|
||||
if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
|
||||
|
||||
@ -63,7 +63,7 @@ namespace TBF.UiControls
|
||||
Middle,
|
||||
}
|
||||
|
||||
public Users.Grp.GID RequiredGroupMembership;
|
||||
public Users.Grp.GID[] RequiredGroupMembership;
|
||||
|
||||
Users.Entities.User originalUser;
|
||||
|
||||
@ -76,7 +76,7 @@ namespace TBF.UiControls
|
||||
lockState = LockState.Locked;
|
||||
MoreActive = false;
|
||||
OptionalButtons = Buttons.None;
|
||||
RequiredGroupMembership = Users.Grp.GID.None;
|
||||
RequiredGroupMembership = null;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
||||
/// Copyright (c) 2016-2018 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
||||
/// Copyright (c) 2016-2018 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
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>
|
||||
/// Sets users password. It then will be encrypted.
|
||||
/// </summary>
|
||||
@ -129,17 +161,17 @@ namespace Users.Entities
|
||||
|
||||
|
||||
/// <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().
|
||||
/// Authorization method: 'requiredGroupMembership' contains a list of required groups.
|
||||
/// Valid name and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
|
||||
/// When requiredGroupMembership == null, no membership is required, only name and password must be valid.
|
||||
/// 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().
|
||||
/// </summary>
|
||||
/// <param name="userName">User name</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <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))
|
||||
{
|
||||
@ -167,26 +199,17 @@ namespace Users.Entities
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The SECOND of TWO possible user authorization method to be used when
|
||||
/// no specific group membership is required.
|
||||
/// </summary>
|
||||
public virtual bool Authorize(string userName, string password)
|
||||
{
|
||||
return Authorize(userName, password, Grp.GID.None);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Authorization method: 'requiredGroupMembership' contains a list of required groups.
|
||||
/// Valid number and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
|
||||
/// When requiredGroupMembership == null, no membership is required, only number and password must be valid.
|
||||
/// 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().
|
||||
/// </summary>
|
||||
/// <param name="number">User ID number</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <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)
|
||||
{
|
||||
@ -206,26 +229,17 @@ namespace Users.Entities
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The SECOND of TWO possible user authorization method to be used when
|
||||
/// no specific group membership is required.
|
||||
/// </summary>
|
||||
public virtual bool AuthorizeNumber(int number, string password)
|
||||
{
|
||||
return AuthorizeNumber(number, password, Grp.GID.None);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Authorization method: 'requiredGroupMembership' contains a list of required groups.
|
||||
/// Valid name and password and a mbership in any of theese goups grants access, Authorize(..) returns true.
|
||||
/// When requiredGroupMembership == null, no membership is required, only name and password must be valid.
|
||||
/// 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().
|
||||
/// </summary>
|
||||
/// <param name="fullName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <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())
|
||||
{
|
||||
@ -244,26 +258,17 @@ namespace Users.Entities
|
||||
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>
|
||||
/// 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().
|
||||
/// Authorization method: 'requiredGroupMembership' contains a list of required groups.
|
||||
/// Valid TAG and a mbership in any of theese goups grants access, Authorize(..) returns true.
|
||||
/// When requiredGroupMembership == null, no membership is required, only the TAG must be valid.
|
||||
/// 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().
|
||||
/// </summary>
|
||||
/// <param name="tag">Tag (RFID, NFC, ... s/n)</param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <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)
|
||||
{
|
||||
@ -282,16 +287,6 @@ namespace Users.Entities
|
||||
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>
|
||||
/// Returns a 'User' with a given username from a database.
|
||||
/// </summary>
|
||||
|
||||
@ -18,8 +18,9 @@ namespace Users.Forms
|
||||
// Private fields
|
||||
string user;
|
||||
string password;
|
||||
Grp.GID requiredGroupMembership = Grp.GID.Invalid;
|
||||
Grp.GID[] requiredGroupMembership;
|
||||
bool noDatabase;
|
||||
Color oriBackColor;
|
||||
|
||||
/// Smart card support, card S/N is used as user.Tag
|
||||
GemCard.CardNative card;
|
||||
@ -35,6 +36,8 @@ namespace Users.Forms
|
||||
public LoginDlg()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
oriBackColor = BackColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,16 +62,21 @@ namespace Users.Forms
|
||||
/// <summary>
|
||||
/// Constructor when a specific group membership is required.
|
||||
/// </summary>
|
||||
public LoginDlg(Grp.GID requiredGroupMembership)
|
||||
public LoginDlg(Grp.GID[] requiredGroupMembership)
|
||||
: this()
|
||||
{
|
||||
this.requiredGroupMembership = requiredGroupMembership;
|
||||
#if DEBUG
|
||||
user = "MHA";
|
||||
userNameTextBox.Text = "MHA";
|
||||
passwordTextBox.Text = "kremik";
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with a predefined user when a specific group membership is required.
|
||||
/// </summary>
|
||||
public LoginDlg(string predefinedUser, Grp.GID requiredGroupMembership)
|
||||
public LoginDlg(string predefinedUser, Grp.GID[] requiredGroupMembership)
|
||||
: this()
|
||||
{
|
||||
user = predefinedUser;
|
||||
@ -85,6 +93,9 @@ namespace Users.Forms
|
||||
else
|
||||
passwordTextBox.Select();
|
||||
|
||||
///
|
||||
/// Smart card reader detection
|
||||
///
|
||||
smartCardReader = null; /// null = No smart card reader detected
|
||||
|
||||
#if TURA_IPERL || TURA_SPECIAL
|
||||
@ -183,15 +194,15 @@ namespace Users.Forms
|
||||
{
|
||||
default:
|
||||
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;
|
||||
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;
|
||||
case Entities.LoginMethod.Number:
|
||||
int number;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -222,7 +233,7 @@ namespace Users.Forms
|
||||
/// </summary>
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (requiredGroupMembership == Grp.GID.Invalid)
|
||||
if (requiredGroupMembership == null)
|
||||
{
|
||||
Entities.User.Unauthorize();
|
||||
}
|
||||
@ -278,7 +289,7 @@ namespace Users.Forms
|
||||
Users.Entities.User loadedUser = Users.Entities.User.LoadUserByTag(tag, db);
|
||||
if (loadedUser != null)
|
||||
{
|
||||
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeTag(tag) : loadedUser.AuthorizeTag(tag, requiredGroupMembership);
|
||||
authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership);
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
@ -304,7 +315,7 @@ namespace Users.Forms
|
||||
|
||||
void OnCardRemoved(object sender, CardRemovedEventArgs args)
|
||||
{
|
||||
BackColor = SystemColors.Control;
|
||||
BackColor = oriBackColor;
|
||||
}
|
||||
|
||||
private void LoginDlg_FormClosing(object sender, FormClosingEventArgs e)
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.18.982.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.982.0")]
|
||||
[assembly: AssemblyVersion("2.18.1006.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.1006.0")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user