You are viewing limited content. For full access, please sign in.

Question

Posted to Government

Question

Problem with a certificate, when I try to use a script

asked on April 29

Hello Community!

I am trIed to use a Script using C# code, the code take some data from Active Directory, but when I try to run the script I got this error message:

"The TLS/SSL host name does not match the host name in the X.509 certificate", as show the image below:

I don't what kind of certificate I must to install. When I tried to run the all workflow I found this other error message:

"The workflow service is not licensed. [0645-WF1]"

I dont know what is the license or certificate I missing, please any help in this is appreciate!

I left the workflow design and the code I am using:

and the c# code is inside in the script:

namespace WorkflowActivity.Scripting.Script
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.DirectoryServices;
    using System.DirectoryServices.AccountManagement;
    using System.DirectoryServices.ActiveDirectory;
    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : ScriptClass90
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            string userToFind= GetTokenValue("FindUserToModifyValues_Display_Name").ToString();
            List<Employee> employees = FindUsers(userToFind);
            if(employees.Count>0)
            {
                SetTokenValue("employeeName",employees[0].name);
            }else
            {
                SetTokenValue("employeeName","No employee founded");
            }

        }
        public static List<Employee> FindUsers(string userToFind)
        {
            string domainName = "TOHO_MAIN_HQ";
            var employees = new List<Employee>();
            Employee employee;
                // Get the current domain context
                Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, domainName));

                // Search for users with display names containing "John"
                using (DirectorySearcher searcher = new DirectorySearcher())
                {
                    // Set the search root to the domain's directory entry
                    searcher.SearchRoot = domain.GetDirectoryEntry();

                    // Set search filter for users with display names containing "John"
                    var instructionToRun= "(&(objectCategory=user)(displayName=*{" + userToFind + "}*))";
                    searcher.Filter = instructionToRun; // Use wildcard * to find all users with display names

                    // Specify the attributes to load
                    searcher.PropertiesToLoad.AddRange(new string[] { "samAccountName","givenName", "sn", "mail", "displayName", "department", "title", "manager" });

                    // Perform the search
                    SearchResultCollection results = searcher.FindAll();

                    // Display search results
                    if (results.Count > 0)
                    {
                        foreach (SearchResult result in results)
                        {
                            employee = new Employee();
                            // Retrieve and display user details
                            string displayName = result.Properties.Contains("displayname") ? result.Properties["displayName"][0].ToString() : "Not specified";

                            employee.name = displayName;
                            string email = result.Properties.Contains("mail") ? result.Properties["mail"][0].ToString() : "Not specified";

                            employee.email = email;
                            string jobTitle = result.Properties.Contains("title") ? result.Properties["title"][0].ToString() : "Not specified";

                            employee.jobTitle = jobTitle;
                            string department = result.Properties.Contains("department") ? result.Properties["department"][0].ToString() : "Not specified";

                            employee.department = department;
                            string managerDisplayName = result.Properties.Contains("manager") ? result.Properties["manager"][0].ToString() : "Not specified";

                            employee.manager = managerDisplayName=="Not specified"? "Not specified" : FindManagerName(managerDisplayName);
                            var employeeAccountName = result.Properties.Contains("samAccountName") ? result.Properties["samAccountName"][0].ToString() : "Not specified";
                            employee.staff = FindEmployeesBelowToManager(employeeAccountName, domain);
                            employees.Add( employee );
                        }
                    }
                }
                return employees;
        }
        public static List<string> FindEmployeesBelowToManager(string manager, Domain domain)
        {
            var staff = new List<string>();
            // Create a directory searcher for users
            using (DirectorySearcher searcher = new DirectorySearcher())
            {
                // Set the search root to the domain's directory entry
                searcher.SearchRoot = domain.GetDirectoryEntry();

                // Set search filter for the username
                var instructionToRun= "(&(objectCategory=user)(samAccountName={" + manager + "}))";
                searcher.Filter = instructionToRun;

                // Specify the attributes to load
                searcher.PropertiesToLoad.AddRange(new string[] { "distinguishedName" });

                // Perform the search
                SearchResult result = searcher.FindOne();

                if (result != null)
                {
                    // Retrieve the distinguished name of the user
                    string userDn = result.Properties["distinguishedName"][0].ToString();

                    // Create a directory searcher for direct reports
                    using (DirectorySearcher directReportsSearcher = new DirectorySearcher())
                    {
                        // Set the search root to the domain's directory entry
                        directReportsSearcher.SearchRoot = domain.GetDirectoryEntry();

                        // Set search filter for direct reports
                        instructionToRun= "(&(objectCategory=user)(manager={" + userDn + "}))";
                        directReportsSearcher.Filter = instructionToRun;

                        // Specify the attributes to load
                        directReportsSearcher.PropertiesToLoad.AddRange(new string[] { "displayName" });

                        // Perform the search
                        SearchResultCollection directReports = directReportsSearcher.FindAll();

                        // Display direct reports
                        if (directReports.Count > 0)
                        {
                            //Console.WriteLine("Direct Reports:");
                            foreach (SearchResult directReport in directReports)
                            {
                                string displayName = directReport.Properties.Contains("displayName") ? directReport.Properties["displayName"][0].ToString() : "Not specified";
                                //Console.WriteLine($"- {displayName}");
                                staff.Add(displayName);
                            }
                        }
                        else
                        {
                            //Console.WriteLine("No direct reports found.");
                        }
                    }
                }
                //else
                //{
                //    Console.WriteLine("User not found.");
                //}
            }
            return staff;
        }

        public static string FindManagerName(string managerNameWithComma)
        {
            string[] managerSeparatedByComma = managerNameWithComma.Split(',');
            string[] managerNameWithCN = managerSeparatedByComma[0].ToLower().Split('=');
            string[] managerName = managerNameWithCN[1].Split(' ');

            for (int i = 0; i < managerName.Length; i++)
            {
                if (string.IsNullOrEmpty(managerName[i]) == false)
                {
                    managerName[i] = char.ToUpper(managerName[i][0]) + managerName[i].Substring(1);
                }
            }
            return string.Join(" ", managerName);
        }
    }
        public class Employee
    {
        public string name { get; set; }
        public string email { get; set; }
        public string jobTitle { get; set; }
        public string department { get; set; }
        public string manager { get; set; }
        public List<string> staff {  get; set; }
    }
}

 

0 0

Replies

replied on April 30

Hi Fabian,

The reason you are receiving the certificate error is the site names do not match between what you are using in your script and the server the certificate is installed on.  For example, if you are running the script on a server with the SSL certificate for thecomputer.computers.com and your script references localhost (127.0.0.1), it doesn't match and you receive the error you are receiving.  On line 35 you have your domain listed, does that match the information on the SSL certificate?

For your second issue, you will want to check your licensing in LFDS and may need to do a renewal of your primary license.  If that doesn't fix the issue, check with your vendor about your licenses.

What version of Laserfiche are you running?  Your script on line 15 says ScriptClass90, this is for version 9.  If you are running version 10 it should be ScriptClass100 or ScriptClass110 for version 11.

1 0
replied on May 7

Hi Steven! sorry for the delay: I solved the problem of the licenses thank you for your help, the only problem I have is with the script version. I tried to install the version but it told me they does not recognize the script version, how can I get this version? 

Thanks in advanced!

0 0
replied on May 7

Hi Fabian!  In lines 3 - 11 in your script, do you have all the libraries listed that are being used?  The scripts I have, have two extra lines than what shows in yours.  They are:

using System.Threading;

using Laserfiche.RepositoryAccess

Add those two lines and let's see how it goes.

Steve

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.