BusinessMgr

This commit is contained in:
Andy Howard
2025-01-09 16:31:16 +00:00
parent 4005870236
commit 4f91faae8b
30 changed files with 475 additions and 265 deletions
@@ -43,11 +43,16 @@ namespace Sarand.Net.Standard.Base.Bus
//-------------------------------------------------------------------
// Properties.
/// <summary>OK - No error state message.</summary>
public bool OK { get { return !HasErrorState(); } }
//-------------------------------------------------------------------
// E r r o r S t a t e
// Error State.
//-------------------------------------------------------------------
private SacsErrorState errorState = null;
public bool HasErrorState ()
public bool HasErrorState()
{
return errorState != null;
}
+7
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -111,6 +112,12 @@ namespace Sarand.Net.Standard.Base.Bus
return (IsValid(sysId) ? sysId.id.ToString() : invalidValue);
}
// From String.
public static SysId ToSysId(String value)
{
return new SysId(StringUtil.ToLong(value));
}
//-------------------------------------------------------------------
/// <summary>
/// JSON Converter to serialise/deserialise SysId to/from simple integer value.
@@ -1,9 +0,0 @@
namespace Sarand.Net.Standard.Base.Dbas
{
//=======================================================================
public interface IDbDataTable
{
}
//=======================================================================
}
+27 -15
View File
@@ -68,27 +68,39 @@ namespace Sarand.Net.Standard.Base.Dbas
//-------------------------------------------------------------------
// Database schema.
List<String> GetTableNames (bool refresh = false);
List<DbDfnTable> GetTableDfns (bool refresh = false);
DbDfnTable GetTableDfn (String name, bool refresh = false);
bool TableExists (String tableName);
bool ColumnExists (String tableName, String columnName);
bool IndexExists (String tableName, String indexName);
List<String> GetTableNames(bool refresh = false);
List<DbDfnTable> GetTableDfns(bool refresh = false);
DbDfnTable GetTableDfn(String name, bool refresh = false);
bool TableExists(String tableName);
bool ColumnExists(String tableName, String columnName);
bool IndexExists(String tableName, String indexName);
// Database info - schema summary.
IDatabaseInfo CreateDbInfo();
//-------------------------------------------------------------------
// Password utilities.
public enum PasswordHashMethod { MsSql }
/// <summary>Generate password hash using the specified method.</summary>
String EncodePassword_Hex(String password, PasswordHashMethod method = PasswordHashMethod.MsSql);
/// <summary>Compare password to hashed value using the specified method.</summary>
bool ComparePassword_Hex(String password, String passwordHashHex, ISacsDatabase.PasswordHashMethod method = ISacsDatabase.PasswordHashMethod.MsSql);
//-------------------------------------------------------------------
// Query records.
String GetSelectQueryPrefix ();
IDbDataTable ExecuteQuery (String query);
int ExecuteNonQuery (String query);
int ExecuteInsert (String tableName, List<StringPair> columnNameValues);
int ExecuteUpdate (String tableName, List<StringPair> columnNameValues, String filter);
int ExecuteDelete (String tableName, String filter);
String GetSelectQueryPrefix();
/// <summary>
/// Execute query directly against database.
/// <para>- NB Check for null response and error state.</para>
/// </summary>
DbResultSet ExecuteQuery(String query);
int ExecuteNonQuery(String query);
int ExecuteInsert(String tableName, List<StringPair> columnNameValues);
int ExecuteUpdate(String tableName, List<StringPair> columnNameValues, String filter);
int ExecuteDelete(String tableName, String filter);
// Specific queries.
long GetRowCount (String tableName, String filter);
DataValue GetRowValue (String tableName, String columnName, String filter);
DataValue GetRowValue (String tableName, String columnName, String filter, DbGetValueType getValueType);
long GetRowCount(String tableName, String filter);
DataValue GetRowValue(String tableName, String columnName, String filter);
DataValue GetRowValue(String tableName, String columnName, String filter, DbGetValueType getValueType);
//-------------------------------------------------------------------
}
@@ -1,6 +1,7 @@
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@@ -52,19 +53,27 @@ namespace Sarand.Net.Standard.Base.Helpers
}
//-------------------------------------------------------------------
public static String getRandomLengthNumber(ushort maxLength=4)
public static String GetRandomLengthNumber(ushort maxLength = 4)
{
String fn = "getRandomLengthNumber";
String value = "";
int len = GetInt32(1, maxLength + 1);
for (int i = 0; i < len; i++)
value += GetInt32(0,10);
if (StringUtil.IsEmpty(value))
throw new NotSupportedException("getRandomLengthNumber Generated blank value");
value += GetInt32(0, 10);
if (StringUtil.IsBlank(value))
throw new NotSupportedException($"{fn} Generated blank value");
if (value.Length > maxLength)
throw new NotSupportedException("getRandomLengthNumber Generated excess length value");
throw new NotSupportedException($"{fn} Generated excess length value");
return value;
}
//-------------------------------------------------------------------
/// <summary>Returns filename in 8.3 format.</summary>
public static String GetRandomFileName()
{
return Path.GetRandomFileName();
}
//-------------------------------------------------------------------
}
//=======================================================================
@@ -21,6 +21,12 @@ namespace Sarand.Net.Standard.Base.Security
Group = 3,
Right = 4,
}
// Password storage methods - must be kept up to date with legacy application.
public enum PasswordMethod
{
Legacy = 0,
MsSql = 10,
}
public enum FilterAttrType
{
Code, // Partial code.
@@ -29,14 +35,6 @@ namespace Sarand.Net.Standard.Base.Security
Group_Exclude, // Item doesn't belong to group.
};
}
// Password configuration.
public class PasswordConfig
{
/// <summary>Minimum password length. < 1 = no limit.</summary>
public int MinimumLength { get; protected set; } = 6;
/// <summary>Maximum password length. < 1 = no limit.</summary>
public int MaximumLength { get; protected set; } = 6;
}
//=======================================================================
public abstract class SaSecurityConsole : SaErrorStateItem
@@ -58,8 +56,8 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Data members.
protected static String GroupSuperCode = "SUPER";
protected static String AdminUserCode = "admin";
public static String GroupCode_Super = "SUPER";
public static String UserCode_Admin = "admin";
private static List<TypeCodeDesc> securityItemTypes = new List<TypeCodeDesc>();
//-------------------------------------------------------------------
@@ -116,6 +114,12 @@ namespace Sarand.Net.Standard.Base.Security
return userIdDefault;
}
protected void ClearRegisteredSecurityRights()
{
RegisteredRights.Clear();
DataItemDfns.Clear();
}
//-------------------------------------------------------------------
// L o g i n
//-------------------------------------------------------------------
@@ -140,9 +144,28 @@ namespace Sarand.Net.Standard.Base.Security
/// <summary>Security Group modified event.</summary>
public abstract bool OnSecurityGroupModified(SysId userId);
//-------------------------------------------------------------------
// Password utilities.
//-------------------------------------------------------------------
// Password configuration.
public PasswordConfig PasswordConfig { get; protected set; } = new PasswordConfig();
public class SaPasswordConfig
{
/// <summary>Minimum password length. < 1 = no limit.</summary>
public int MinimumLength { get; protected set; } = 6;
/// <summary>Maximum password length. < 1 = no limit.</summary>
public int MaximumLength { get; protected set; } = 6;
}
public SaPasswordConfig PasswordConfig { get; protected set; } = new SaPasswordConfig();
/// <summary>Store the password against against the user.</summary>
public abstract bool SetPassword(SaSecurityItem securityItemUser, String password);
/// <summary>Does the password match that currently defined against the user.</summary>
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password);
/// <summary>Is the password currently defined against the user blank.</summary>
public abstract bool PasswordIsBlank(SaSecurityItem securityItemUser);
/// <summary>Show form to change password for currently logged in user.</summary>
/// <returns>Flag to indicate password changed</returns>
public abstract bool ShowChangePasswordForm(DbUpdateInfo dbUpdateInfo);
@@ -12,6 +12,11 @@ namespace Sarand.Net.Standard.Base.Security
//=======================================================================
public abstract class SaSecurityItem : SacsHierarchyItem
{
//-------------------------------------------------------------------
// Definitions.
// Password Salt constants - must be kept up to date with legacy application.
private static String PasswordSalt_MsSql = "MsSql";
//-------------------------------------------------------------------
// Columns.
public enum Column
@@ -67,7 +72,7 @@ namespace Sarand.Net.Standard.Base.Security
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data ()
public Data()
{
Status = DefaultStatus;
}
@@ -161,7 +166,7 @@ namespace Sarand.Net.Standard.Base.Security
set { SetFlag(Flag_AuthenticatedUser, value); }
}
// Population.
internal void PopulateFrom (Data data)
internal void PopulateFrom(Data data)
{
ItemType = data.ItemType;
Code = data.Code;
@@ -182,7 +187,7 @@ namespace Sarand.Net.Standard.Base.Security
InvalidLoginCount = data.InvalidLoginCount;
base.PopulateFrom(data);
}
public Data Clone ()
public Data Clone()
{
Data data = new Data();
data.PopulateFrom(this);
@@ -219,7 +224,7 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Construction.
public SaSecurityItem (SysId id, SaSecurity.ItemType securityItemType) :
public SaSecurityItem(SysId id, SaSecurity.ItemType securityItemType) :
base(id)
{
base.SetData(data);
@@ -238,7 +243,7 @@ namespace Sarand.Net.Standard.Base.Security
public static SaStatus EnabledStatus { get { return SaStatus.Enabled; } }
public static SaStatus DisabledStatus { get { return SaStatus.Disabled; } }
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(securityItemStatuses); } }
public static DataValue.TriStateType GetStatusTriState (SaStatus status)
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
{
switch (status)
{
@@ -254,8 +259,8 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Data properties.
public Data GetData () { return data.Clone(); }
public void SetData (Data data)
public Data GetData() { return data.Clone(); }
public void SetData(Data data)
{
// Properties that cannot be changed if previously specified.
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
@@ -359,68 +364,31 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Password utilities.
private static readonly Encoding Encoding_Ansi1252 = Encoding.GetEncoding(1252);
public bool IsPasswordBlank ()
{
return EncryptPassword("").Equals(PasswordEncrypted);
}
public bool PasswordMatches (String password)
{
return PasswordEncrypted.Equals(EncryptPassword(password));
}
public static String EncryptPassword (String password)
{
// We know this is not very water-tight, but it at least
// hides the contents of the password from prying eyes.
String toBeEncrypted = password;
// Password length goes in as first character:
toBeEncrypted = ByteToString((byte)(128 - password.Length)) + toBeEncrypted;
toBeEncrypted = string.Concat(toBeEncrypted.Reverse());
// Pad out to fixed length (minimum 16, multiples of 8):
int fixedLength = 16;
if (password.Length / 8 > 2) fixedLength = 8 * (int)(password.Length / 8);
while (toBeEncrypted.Length < fixedLength)
{
char charToAdd = (char)(password.Length > 0 ? password[(toBeEncrypted.Length % password.Length)] : 'A' + (toBeEncrypted.Length * 13) % 23);
if (toBeEncrypted.Length % 2 != 0)
toBeEncrypted += charToAdd;
else toBeEncrypted = charToAdd + toBeEncrypted;
}
// Now perform a simple algorythm on each character to hide its true value:
byte[] encryptedChars = new byte[toBeEncrypted.Length];
for (int i = 0; i < toBeEncrypted.Length; i++)
{
int iData = toBeEncrypted[i];
iData += 17 + i;
if (iData > 255) iData -= (255 + 32);
encryptedChars[i] = (byte)iData;
}
String result = Encoding_Ansi1252.GetString(encryptedChars);
#if DEBUG
// Password: mgbgt
// To encrypt: tbmggtgbgm{btggm
// Encrypted: 133, 116, 128, 123, 124, 138, 126, 122, 128, 135, 150, 126, 145, 133, 134, 141
//Logger.Info(fn + "\n\tPassword: " + password + "\n\tTo encrypt: " + toBeEncrypted + "\n\tEncrypted: " + encryptedChars.Select(i => i.ToString()).ToList().Concat(", "));
//Logger.Debug(password + ": " + result);
#endif
return result;
}
private byte[] PasswordStringToBytes (String value)
/// <summary>Extract password storage method from data.</summary>
public SaSecurity.PasswordMethod GetPasswordMethod()
{
byte[] values = new byte[value.Length];
for (int idx = 0; idx < value.Length; idx++)
{
char c = value[idx];
UInt32 ui = Convert.ToUInt32(c);
SaLogger.Info(idx + ". " + ui.ToString("x8"));
values[idx] = (byte)(c);
}
return values;
return SaSecurity.PasswordMethod.Legacy;
}
private static String ByteToString (byte value)
public void SetEncodedPassword(SaSecurity.PasswordMethod method, String encodedPassword)
{
return Encoding_Ansi1252.GetString(new[] { value });
if (method == SaSecurity.PasswordMethod.MsSql)
{
#pragma warning disable CS0618 // Deprecated property
PasswordEncrypted = "";
#pragma warning restore CS0618 // Deprecated property
PasswordSalt = PasswordSalt_MsSql;
PasswordHash = encodedPassword;
}
else
{
#pragma warning disable CS0618 // Deprecated property
PasswordEncrypted = encodedPassword;
#pragma warning restore CS0618 // Deprecated property
PasswordSalt = "";
PasswordHash = "";
}
}
//-------------------------------------------------------------------
@@ -455,7 +423,7 @@ namespace Sarand.Net.Standard.Base.Security
//=======================================================================
public static class SaSecurityItemList
{
public static SaSecurityItem GetSecItemById (this List<SaSecurityItem> secItems, SysId secItemId)
public static SaSecurityItem GetSecItemById(this List<SaSecurityItem> secItems, SysId secItemId)
{
if (!SysId.IsValid(secItemId)) return null;
foreach (SaSecurityItem secItem in secItems)
@@ -31,10 +31,19 @@ namespace Sarand.Net.Standard.Base.Security
// Database properties.
public abstract bool DatabaseIsValid { get; }
public abstract bool CanUpdateDatabase { get; }
public abstract bool ColumnExists (SaSecurityDbDfn.ColumnIdx columnIdx);
//-------------------------------------------------------------------
// Utilities.
public abstract bool ColumnExists (SaSecurityDbDfn.ColumnIdx columnIdx);
// Password utilities.
/// <summary>Store the password against against the user.</summary>
public abstract bool SetPassword(SaSecurityItem securityItemUser, String password);
/// <summary>Does the password match that currently defined against the user.</summary>
public abstract bool PasswordMatches(SaSecurityItem securityItemUser, String password);
/// <summary>Is the password currently defined against the user blank.</summary>
public abstract bool PasswordIsBlank(SaSecurityItem securityItemUser);
//-------------------------------------------------------------------
}
@@ -10,40 +10,52 @@ namespace Sarand.Net.Standard.Base.Security
public class SaSecurityProfile
{
//-------------------------------------------------------------------
/// <summary>Security Group definition.</summary>
public class GroupData
{
public readonly List<SaSecurityProfile.RightData> rights = new List<RightData>();
public GroupData (SaSecurityItem secGroup, List<SaSecurityProfile.RightData> groupRights)
private readonly List<SaSecurityProfile.RightData> rights = new List<RightData>();
public GroupData(SaSecurityItem secGroup, List<SaSecurityProfile.RightData> groupRights)
{
if (secGroup.ItemType != SaSecurity.ItemType.Group) throw new NotSupportedException("SaSecurityProfile.GroupData - Invalid security item type: "+ secGroup.ItemType.ToString());
GroupId = secGroup.Id;
GroupCode = secGroup.Code;
GroupDesc = secGroup.Description;
if (secGroup.ItemType != SaSecurity.ItemType.Group) throw new NotSupportedException("SaSecurityProfile.GroupData - Invalid security item type: " + secGroup.ItemType.ToString());
Id = secGroup.Id;
Code = secGroup.Code;
Desc = secGroup.Description;
rights.AddRange(groupRights);
}
protected GroupData () { }
public SysId GroupId { get; protected set; }
public String GroupCode { get; protected set; }
public String GroupDesc { get; protected set; }
protected GroupData() { }
public SysId Id { get; }
public String Code { get; }
public String Desc { get; }
// Security rights.
public List<SaSecurityProfile.RightData> Rights { get { return new List<RightData>(rights); } }
/// <summary>
/// Retrieve the list of data items for which the user is explicitly granted the
/// specified security right, or where the right is explicitly denied if the flag is false.
/// </summary>
public List<SysId> GetDataItemsForRight(String rightCode, bool granted = true) { return rights.GetDataItemsForRight(rightCode, granted); }
/// <summary>Is the Security Right code granted access for the Data item (if specified).</summary>
public bool IsSecurityRightGranted(String rightCode, SysId dataItemId = null) { return rights.IsSecurityRightGranted(rightCode, dataItemId); }
/// <summary>Is the Security Right code denined access for the Data item (if specified).</summary>
public bool IsSecurityRightDenied(String rightCode, SysId dataItemId = null) { return rights.IsSecurityRightDenied(rightCode, dataItemId); }
}
/// <summary>Security Right definition.</summary>
public class RightData
{
public RightData (SaSecurityItem secRight, SaSecurityLink secRightLink)
public RightData(SaSecurityItem secRight, SaSecurityLink secRightLink)
{
if (secRight.ItemType != SaSecurity.ItemType.Right) throw new NotSupportedException("SaSecurityProfile.RightData - Invalid security item type: " + secRight.ItemType.ToString());
RightId = secRight.Id;
RightCode = secRight.Code;
RightDesc = secRight.Description;
Id = secRight.Id;
Code = secRight.Code;
Desc = secRight.Description;
DataItemId = secRightLink.ItemIdContext;
Granted = (secRightLink.Status == SaStatus.Granted);
}
protected RightData () { }
public SysId RightId { get; protected set; }
public String RightCode { get; protected set; }
public String RightDesc { get; protected set; }
public SysId DataItemId { get; protected set; }
public bool Granted { get; protected set; }
protected RightData() { }
public SysId Id { get; }
public String Code { get; }
public String Desc { get; }
public SysId DataItemId { get; }
public bool Granted { get; }
}
//-------------------------------------------------------------------
@@ -53,7 +65,7 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Construction.
internal SaSecurityProfile (SaSecurityItem secItem, List<SaSecurityProfile.GroupData> profileGroups, List<SaSecurityProfile.RightData> profileRights, bool systemAdmin)
internal SaSecurityProfile(SaSecurityItem secItem, List<SaSecurityProfile.GroupData> profileGroups, List<SaSecurityProfile.RightData> profileRights, bool systemAdmin)
{
Clear();
if (secItem != null)
@@ -115,9 +127,9 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
// Utilities.
public bool IsMemberOfSecurityGroup (SysId secGroupId)
public bool IsMemberOfSecurityGroup(SysId secGroupId)
{
return securityGroups.Exists(item => item.GroupId.Equals(secGroupId));
return securityGroups.Exists(item => item.Id.Equals(secGroupId));
}
//-------------------------------------------------------------------
@@ -125,14 +137,14 @@ namespace Sarand.Net.Standard.Base.Security
/// Retrieve the list of data items for which the user is explicitly granted the
/// specified security right, or where the right is explicitly denied if the flag is false.
/// </summary>
public List<SysId> GetDataItemsForRight (String rightCode, bool granted = true)
public List<SysId> GetDataItemsForRight(String rightCode, bool granted = true)
{
return securityGroups.GetDataItemsForRight(rightCode, granted);
}
//-------------------------------------------------------------------
/// <summary>Is the Security Right code granted access for the Data item (if specified).</summary>
public bool IsSecurityRightGranted (String rightCode, SysId dataItemId = null)
public bool IsSecurityRightGranted(String rightCode, SysId dataItemId = null)
{
if (SystemAdmin) return true;
return (securityGroups.IsSecurityRightGranted(rightCode, dataItemId) || securityRights.IsSecurityRightGranted(rightCode, dataItemId));
@@ -140,7 +152,7 @@ namespace Sarand.Net.Standard.Base.Security
//-------------------------------------------------------------------
/// <summary>Is the Security Right code denined access for the Data item (if specified).</summary>
public bool IsSecurityRightDenied (String rightCode, SysId dataItemId = null)
public bool IsSecurityRightDenied(String rightCode, SysId dataItemId = null)
{
if (SystemAdmin) return false;
return (securityGroups.IsSecurityRightDenied(rightCode, dataItemId) || securityRights.IsSecurityRightDenied(rightCode, dataItemId));
@@ -156,22 +168,22 @@ namespace Sarand.Net.Standard.Base.Security
/// Retrieve the list of data items for which the user is explicitly granted the
/// specified security right, or where the right is explicitly denied if the flag is false.
/// </summary>
public static List<SysId> GetDataItemsForRight (this List<SaSecurityProfile.GroupData> groups, String rightCode, bool granted = true)
public static List<SysId> GetDataItemsForRight(this List<SaSecurityProfile.GroupData> groups, String rightCode, bool granted = true)
{
List<SysId> dataItemIds = new List<SysId>();
HashSet<SysId> dataItemIds = new HashSet<SysId>();
foreach (var securityGroup in groups)
dataItemIds.AddIds(securityGroup.rights.GetDataItemsForRight(rightCode,granted));
return dataItemIds;
dataItemIds.AddIds(securityGroup.GetDataItemsForRight(rightCode, granted));
return new List<SysId>(dataItemIds);
}
/// <summary>Is the Security Right code granted access for the Data item (if specified).</summary>
public static bool IsSecurityRightGranted (this List<SaSecurityProfile.GroupData> groups, String rightCode, SysId dataItemId = null)
public static bool IsSecurityRightGranted(this List<SaSecurityProfile.GroupData> groups, String rightCode, SysId dataItemId = null)
{
return groups.Exists(item => item.rights.IsSecurityRightGranted(rightCode, dataItemId));
return groups.Exists(group => group.IsSecurityRightGranted(rightCode, dataItemId));
}
/// <summary>Is the Security Right code denined access for the Data item (if specified).</summary>
public static bool IsSecurityRightDenied (this List<SaSecurityProfile.GroupData> groups, String rightCode, SysId dataItemId = null)
public static bool IsSecurityRightDenied(this List<SaSecurityProfile.GroupData> groups, String rightCode, SysId dataItemId = null)
{
return groups.Exists(item => item.rights.IsSecurityRightDenied(rightCode, dataItemId));
return groups.Exists(group => group.IsSecurityRightDenied(rightCode, dataItemId));
}
}
@@ -182,17 +194,17 @@ namespace Sarand.Net.Standard.Base.Security
/// Retrieve the list of data items for which the user is explicitly granted the
/// specified security right, or where the right is explicitly denied if the flag is false.
/// </summary>
public static List<SysId> GetDataItemsForRight (this List<SaSecurityProfile.RightData> rights, String rightCode, bool granted = true)
public static List<SysId> GetDataItemsForRight(this List<SaSecurityProfile.RightData> rights, String rightCode, bool granted = true)
{
List<SysId> dataItemIds = new List<SysId>();
foreach (var securityRight in rights.FindAll(x => x.RightCode.EqualsCI(rightCode) && x.Granted == granted))
HashSet<SysId> dataItemIds = new HashSet<SysId>();
foreach (var securityRight in rights.FindAll(x => x.Code.EqualsCI(rightCode) && x.Granted == granted))
dataItemIds.AddId(securityRight.DataItemId);
return dataItemIds;
return new List<SysId>(dataItemIds);
}
/// <summary>Is the Security Right code granted access for the Data item (if specified).</summary>
public static bool IsSecurityRightGranted (this List<SaSecurityProfile.RightData> rights, String rightCode, SysId dataItemId = null)
public static bool IsSecurityRightGranted(this List<SaSecurityProfile.RightData> rights, String rightCode, SysId dataItemId = null)
{
foreach (var userSecurityRight in rights.FindAll(item => item.RightCode.EqualsCI(rightCode)))
foreach (var userSecurityRight in rights.FindAll(item => item.Code.EqualsCI(rightCode)))
{
if (SysId.ToInt(dataItemId) != SysId.ToInt(userSecurityRight.DataItemId)) continue;
return userSecurityRight.Granted;
@@ -200,9 +212,9 @@ namespace Sarand.Net.Standard.Base.Security
return false;
}
/// <summary>Is the Security Right code denined access for the Data item (if specified).</summary>
public static bool IsSecurityRightDenied (this List<SaSecurityProfile.RightData> rights, String rightCode, SysId dataItemId = null)
public static bool IsSecurityRightDenied(this List<SaSecurityProfile.RightData> rights, String rightCode, SysId dataItemId = null)
{
foreach (var userSecurityRight in rights.FindAll(item => item.RightCode.EqualsCI(rightCode)))
foreach (var userSecurityRight in rights.FindAll(item => item.Code.EqualsCI(rightCode)))
{
if (SysId.ToInt(dataItemId) != SysId.ToInt(userSecurityRight.DataItemId)) continue;
return !userSecurityRight.Granted;
+14 -17
View File
@@ -474,14 +474,16 @@ namespace Sarand.Net.Standard.Base.Utils
}
public static long ToLong(this string value, long defaultValue = 0)
{
if (String.IsNullOrEmpty(value)) return defaultValue;
try
if (!String.IsNullOrEmpty(value))
{
Double returnValue = defaultValue;
if (Double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out returnValue))
return (Int64)returnValue;
try
{
Double returnValue = defaultValue;
if (Double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out returnValue))
return (Int64)returnValue;
}
catch (Exception) { }
}
catch (Exception) { }
return defaultValue;
}
public static short ToShort(Object value, short defaultValue = 0)
@@ -494,22 +496,17 @@ namespace Sarand.Net.Standard.Base.Utils
}
public static long ToLong(Object value, long defaultValue = 0)
{
if (value == null) return defaultValue;
try
if (value != null)
{
return ToLong(value.ToString());
try
{
return ToLong(value.ToString(), defaultValue);
}
catch (Exception) { }
}
catch (Exception) { }
return defaultValue;
}
//---------------------------------------------------------------------------
// SysId.
public static SysId ToSysId(this String value)
{
return new SysId(StringUtil.ToLong(value));
}
//---------------------------------------------------------------------------
// Hex values to integer.
/// <summary>Convert hex character to integer value.</summary>
+2 -2
View File
@@ -7,11 +7,11 @@
<ItemGroup>
<PackageReference Include="CsvHelper" Version="19.0.0" />
<PackageReference Include="MailKit" Version="4.8.0" />
<PackageReference Include="MailKit" Version="4.9.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
<PackageReference Include="ZstdNet" Version="1.4.5" />
</ItemGroup>