/// <summary> /// checks if the user has access to the navigation node /// </summary> public bool HasAccessPermission(XmlNode ANode, TPetraPrincipal AUserInfo, bool ACheckLedgerPermissions) { // TODO: if this is an action node, eg. opens a screen, check the static function that tells RequiredPermissions of the screen string PermissionsRequired = TXMLParser.GetAttributeRecursive(ANode, "PermissionsRequired", true); while (PermissionsRequired.Length > 0) { string PermissionRequired = StringHelper.GetNextCSV(ref PermissionsRequired); if (!AUserInfo.IsInModule(PermissionRequired)) { return(false); } } if (ACheckLedgerPermissions) { if (TXMLParser.GetAttributeRecursive(ANode, "DependsOnLedger", true).ToLower() == "true") { // check if the user has permissions for this ledger Int32 LedgerNumber = TXMLParser.GetIntAttribute(ANode, "LedgerNumber"); if (LedgerNumber != -1) { if (!AUserInfo.IsInModule(FormatLedgerNumberForModuleAccess(LedgerNumber))) { return(false); } } } } return(true); }
/// <summary> /// Tests whether the current user has access to a particular Partner. /// </summary> /// <remarks> /// <para>Corresponds to Progress 4GL Method 'CanAccessPartner' in /// common/sp_partn.p</para> /// <para>A server-side implementation of this Method exists that has only the /// <paramref name="APartnerRow" />parameter as an Argument. It /// looks up the Foundation Row on its own if this is needed.</para> /// </remarks> /// <param name="APartnerRow">Partner for which access should be checked for.</param> /// <param name="AIsFoundation">Set to true if Partner is a Foundation.</param> /// <param name="AFoundationRow">Foundation Row needs to be passed in /// if Partner is a Foundation.</param> /// <returns><see cref="TPartnerAccessLevelEnum.palGranted" /> if access /// to the Partner is granted, otherwise a different /// <see cref="TPartnerAccessLevelEnum" /> value.</returns> public static TPartnerAccessLevelEnum CanAccessPartner(PPartnerRow APartnerRow, bool AIsFoundation, PFoundationRow AFoundationRow) { TPetraPrincipal userinfo = UserInfo.GetUserInfo(); if ((APartnerRow.Restricted == PARTNER_RESTRICTED_TO_USER) && !((APartnerRow.UserId == userinfo.UserID) || userinfo.IsInModule("SYSMAN"))) { TLogging.LogAtLevel(6, "CanAccessPartner: Access DENIED - Partner " + APartnerRow.PartnerKey.ToString() + " is restriced to User " + APartnerRow.UserId + "!"); return(TPartnerAccessLevelEnum.palRestrictedToUser); } else if ((APartnerRow.Restricted == PARTNER_RESTRICTED_TO_GROUP) && !((userinfo.IsInGroup(APartnerRow.GroupId)) || userinfo.IsInModule("SYSMAN"))) { TLogging.LogAtLevel(6, "CanAccessPartner: Access DENIED - Partner " + APartnerRow.PartnerKey.ToString() + " is restriced to Group " + APartnerRow.GroupId + "!"); return(TPartnerAccessLevelEnum.palRestrictedToGroup); } if (APartnerRow.PartnerClass == SharedTypes.PartnerClassEnumToString(TPartnerClass.ORGANISATION)) { if (AIsFoundation) { if (AFoundationRow != null) { if (!CheckFoundationSecurity(AFoundationRow)) { TLogging.LogAtLevel(6, "CanAccessPartner: Access DENIED - Partner " + APartnerRow.PartnerKey.ToString() + " is restriced by Foundation Ownership!"); return(TPartnerAccessLevelEnum.palRestrictedByFoundationOwnership); } } else { throw new System.ArgumentException("AFoundationRow must not be null if AIsFoundation is true"); } } } TLogging.LogAtLevel(6, "CanAccessPartner: Access to Partner " + APartnerRow.PartnerKey.ToString() + " is GRANTED!"); return(TPartnerAccessLevelEnum.palGranted); }
/// <summary> /// Tests whether the current user has access to a particular Foundation. /// </summary> /// <remarks>Corresponds to Progress 4GL Method 'CheckFoundationSecurity' in /// common/sp_partn.p</remarks> /// <param name="AFoundationOwner1Key">PartnerKey of the first owner of the Foundation. /// Pass in 0 if there is no first owner.</param> /// <param name="AFoundationOwner2Key">PartnerKey of the second owner of the Foundation /// Pass in 0 if there is no second owner.</param> /// <returns>True if the current user has access to the passed in Foundation, /// otherwise false.</returns> public static bool CheckFoundationSecurity(Int64 AFoundationOwner1Key, Int64 AFoundationOwner2Key) { Boolean ReturnValue; TPetraPrincipal userinfo = UserInfo.GetUserInfo(); ReturnValue = false; if ((AFoundationOwner1Key == 0) && (AFoundationOwner2Key == 0)) { TLogging.Log("CheckFoundationSecurity: None of the Owners is set."); if (userinfo.IsInModule(SharedConstants.PETRAMODULE_DEVUSER) || (userinfo.IsInModule(SharedConstants.PETRAMODULE_DEVADMIN))) { TLogging.Log("CheckFoundationSecurity: User is member of DEVUSER or DEVADMIN Module"); ReturnValue = true; } } else { TLogging.Log("CheckFoundationSecurity: One of the Owners is set!"); if (userinfo.IsInModule(SharedConstants.PETRAMODULE_DEVADMIN)) { TLogging.Log("CheckFoundationSecurity: User is member of DEVADMIN Module"); ReturnValue = true; } else { TLogging.Log("CheckFoundationSecurity: User is NOT member of DEVADMIN Module"); if ((userinfo.PartnerKey == AFoundationOwner1Key) || (userinfo.PartnerKey == AFoundationOwner2Key)) { TLogging.Log("CheckFoundationSecurity: User is Owner1 or Owner2"); ReturnValue = true; } } } return(ReturnValue); }
/// <summary> /// checks if the user has access to the navigation node /// </summary> public bool HasAccessPermission(XmlNode ANode, TPetraPrincipal AUserInfo) { // TODO: if this is an action node, eg. opens a screen, check the static function that tells RequiredPermissions of the screen string PermissionsRequired = TXMLParser.GetAttributeRecursive(ANode, "PermissionsRequired", true); while (PermissionsRequired.Length > 0) { string PermissionRequired = StringHelper.GetNextCSV(ref PermissionsRequired); if (!AUserInfo.IsInModule(PermissionRequired)) { return(false); } } return(true); }
private void AddNavigationForEachLedger(XmlNode AMenuNode, ALedgerTable AAvailableLedgers, bool ADontUseDefaultLedger) { XmlNode childNode = AMenuNode.FirstChild; int PotentialCurrentLedger; ALedgerRow ProcessedLedger; XmlAttribute enabledAttribute; bool LedgersAvailableToUserCreatedInThisIteration = false; TPetraPrincipal userinfo = UserInfo.GetUserInfo(); //Iterate through all children nodes of the node while (childNode != null) { if (TXMLParser.GetAttribute(childNode, "DependsOnLedger").ToLower() == "true") { // If there is more than one Ledger in the system, show a 'Select Ledger' Collapsible Panel with a Task (=LinkLabel) // for each Ledger. if (false && (AAvailableLedgers.Rows.Count > 1)) { LedgersAvailableToUserCreatedInThisIteration = false; AAvailableLedgers.DefaultView.Sort = ALedgerTable.GetLedgerNumberDBName() + " ASC"; FMultiLedgerSite = true; // Create 'Select Ledger' Node XmlAttribute LabelAttributeLedger = childNode.OwnerDocument.CreateAttribute("Label"); XmlElement SelLedgerElmnt = childNode.OwnerDocument.CreateElement("SelectLedger"); XmlNode SelectLedgerNode = childNode.AppendChild(SelLedgerElmnt); SelectLedgerNode.Attributes.Append(LabelAttributeLedger); SelectLedgerNode.Attributes["Label"].Value = Catalog.GetString("Select Ledger"); // Create 1..n 'Ledger xyz' Nodes foreach (DataRowView Drv in AAvailableLedgers.DefaultView) { ProcessedLedger = (ALedgerRow)Drv.Row; XmlElement SpecificLedgerElmnt = childNode.OwnerDocument.CreateElement("Ledger" + ProcessedLedger.LedgerNumber); XmlNode SpecificLedgerNode = SelectLedgerNode.AppendChild(SpecificLedgerElmnt); XmlAttribute LabelAttributeSpecificLedger = childNode.OwnerDocument.CreateAttribute("Label"); SpecificLedgerNode.Attributes.Append(LabelAttributeSpecificLedger); XmlAttribute ledgerNumberAttribute = childNode.OwnerDocument.CreateAttribute("LedgerNumber"); ledgerNumberAttribute.Value = ProcessedLedger.LedgerNumber.ToString(); SpecificLedgerNode.Attributes.Append(ledgerNumberAttribute); XmlAttribute ledgerNameAttribute = childNode.OwnerDocument.CreateAttribute("LedgerName"); ledgerNameAttribute.Value = ProcessedLedger.LedgerName; SpecificLedgerNode.Attributes.Append(ledgerNameAttribute); if (ProcessedLedger.LedgerName != String.Empty) { SpecificLedgerNode.Attributes["Label"].Value = String.Format(Catalog.GetString( "Ledger {0} (#{1})"), ProcessedLedger.LedgerName, ProcessedLedger.LedgerNumber); } else { SpecificLedgerNode.Attributes["Label"].Value = String.Format(Catalog.GetString( "Ledger #{0}"), ProcessedLedger.LedgerNumber); } // Check access permission for Ledger if (!HasAccessPermission(SpecificLedgerNode, userinfo, true)) { enabledAttribute = childNode.OwnerDocument.CreateAttribute("Enabled"); enabledAttribute.Value = "false"; SpecificLedgerNode.Attributes.Append(enabledAttribute); } else { if (FLedgersAvailableToUser == null) { // (Re-)Calculate which Ledgers the user has access to FLedgersAvailableToUser = new List <string>(); LedgersAvailableToUserCreatedInThisIteration = true; } if (LedgersAvailableToUserCreatedInThisIteration) { // Add Ledger to the List of Ledgers that are available to the user if (!FLedgersAvailableToUser.Contains(FormatLedgerNumberForModuleAccess(ProcessedLedger.LedgerNumber))) { FLedgersAvailableToUser.Add(FormatLedgerNumberForModuleAccess(ProcessedLedger.LedgerNumber)); } } } } if ((LedgersAvailableToUserCreatedInThisIteration) || (FLedgersAvailableToUser == null)) { if (!ADontUseDefaultLedger) { // Set the 'Current Ledger' to the users' Default Ledger, or if he/she hasn't got one, to the first Ledger of the Site. PotentialCurrentLedger = TUserDefaults.GetInt32Default(TUserDefaults.FINANCE_DEFAULT_LEDGERNUMBER, ((ALedgerRow)AAvailableLedgers.DefaultView[0].Row).LedgerNumber); if ((FLedgersAvailableToUser != null) && (FLedgersAvailableToUser.Contains(FormatLedgerNumberForModuleAccess(PotentialCurrentLedger)))) { FCurrentLedger = PotentialCurrentLedger; } else { if (FLedgersAvailableToUser != null) { FCurrentLedger = Convert.ToInt32(FLedgersAvailableToUser[0].Substring(6)); // Skip "LEDGER" } else // = no Ledgers available to the user at all! { FCurrentLedger = LEDGERNUMBER_NO_ACCESS_TO_ANY_LEDGER; } } } } } else if (AAvailableLedgers.Rows.Count == 1) { // Check access permission for Ledger if (userinfo.IsInModule(FormatLedgerNumberForModuleAccess(AAvailableLedgers[0].LedgerNumber))) { // Set the 'Current Ledger' to the only Ledger of the Site. FCurrentLedger = AAvailableLedgers[0].LedgerNumber; } else // = no Ledgers available to the user at all! { FCurrentLedger = LEDGERNUMBER_NO_ACCESS_TO_ANY_LEDGER; } } else // = no Ledgers available to the user at all! { FCurrentLedger = LEDGERNUMBER_NO_ACCESS_TO_ANY_LEDGER; } childNode = childNode.NextSibling; } else { // Recurse into deeper levels! AddNavigationForEachLedger(childNode, AAvailableLedgers, ADontUseDefaultLedger); childNode = childNode.NextSibling; } } }
/// Load Petra Module DLLs into Clients AppDomain, initialise them and remote an Instantiator Object public override void LoadAssemblies(string AClientID, IPrincipal AUserInfo, ref Hashtable ARemotingURLs) { String RemotingURL_MCommon; String RemotingURL_MConference; String RemotingURL_MSysMan; String RemotingURL_MPartner; String RemotingURL_MPersonnel; String RemotingURL_MFinance; String RemotingURL_MReporting; TPetraPrincipal UserInfo = (TPetraPrincipal)AUserInfo; // Load SYSMAN Module assembly (always loaded) LoadPetraModuleAssembly(AClientID, MSYSMAN_DLLNAME, MSYSMAN_CLASSNAME, out RemotingURL_MSysMan); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MSYSMAN, RemotingURL_MSysMan); if (TLogging.DL >= 5) { Console.WriteLine(" TMSysMan instantiated. Remoting URL: " + RemotingURL_MSysMan); } // Load COMMON Module assembly (always loaded) LoadPetraModuleAssembly(AClientID, MCOMMON_DLLNAME, MCOMMON_CLASSNAME, out RemotingURL_MCommon); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MCOMMON, RemotingURL_MCommon); if (TLogging.DL >= 5) { Console.WriteLine(" TMCommon instantiated. Remoting URL: " + RemotingURL_MCommon); } // Load CONFERENCE Module assembly (always loaded) LoadPetraModuleAssembly(AClientID, MCONFERENCE_DLLNAME, MCONFERENCE_CLASSNAME, out RemotingURL_MConference); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MCONFERENCE, RemotingURL_MConference); if (TLogging.DL >= 5) { Console.WriteLine(" TMConference instantiated. Remoting URL: " + RemotingURL_MConference); } // Load PARTNER Module assembly (always loaded) LoadPetraModuleAssembly(AClientID, MPARTNER_DLLNAME, MPARTNER_CLASSNAME, out RemotingURL_MPartner); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MPARTNER, RemotingURL_MPartner); if (TLogging.DL >= 5) { Console.WriteLine(" TMPartner instantiated. Remoting URL: " + RemotingURL_MPartner); } // Load REPORTING Module assembly (always loaded) LoadPetraModuleAssembly(AClientID, MREPORTING_DLLNAME, MREPORTING_CLASSNAME, out RemotingURL_MReporting); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MREPORTING, RemotingURL_MReporting); if (TLogging.DL >= 5) { Console.WriteLine(" TMReporting instantiated. Remoting URL: " + RemotingURL_MReporting); } // Load PERSONNEL Module assembly (loaded only for users that have personnel privileges) if (UserInfo.IsInModule(SharedConstants.PETRAMODULE_PERSONNEL)) { LoadPetraModuleAssembly(AClientID, MPERSONNEL_DLLNAME, MPERSONNEL_CLASSNAME, out RemotingURL_MPersonnel); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MPERSONNEL, RemotingURL_MPersonnel); if (TLogging.DL >= 5) { Console.WriteLine(" TMPersonnel instantiated. Remoting URL: " + RemotingURL_MPersonnel); } } // Load FINANCE Module assembly (loaded only for users that have finance privileges) if ((UserInfo.IsInModule(SharedConstants.PETRAMODULE_FINANCE1)) || (UserInfo.IsInModule(SharedConstants.PETRAMODULE_FINANCE2)) || (UserInfo.IsInModule(SharedConstants.PETRAMODULE_FINANCE3))) { LoadPetraModuleAssembly(AClientID, MFINANCE_DLLNAME, MFINANCE_CLASSNAME, out RemotingURL_MFinance); ARemotingURLs.Add(SharedConstants.REMOTINGURL_IDENTIFIER_MFINANCE, RemotingURL_MFinance); if (TLogging.DL >= 5) { Console.WriteLine(" TMFinance instantiated. Remoting URL: " + RemotingURL_MFinance); } } }