How to enable SSL for Active Directry in Radzen

I was faced with a IT department moving to SSL/ldap, currently Radzen does not support this.

Microsoft LDAP Signing

In your Radzen application add

server\Authentication\ApplicationUserManager.cs to the Code generation ignore list in settings

image

You will need to make the following changes in a code editor to ApplicationUserManager.cs

In the function

private LdapEntry FindUser(string userName)

Under

var connection = new LdapConnection();

Add the following lines

connection.SecureSocketLayer = true;
connection.UserDefinedServerCertValidationDelegate += (sender, cert, chain, sslPolicyErrors) => { return true; };

Change the following line

connection.Connect(options.Server, LdapConnection.DefaultPort);

to

connection.Connect(options.Server, LdapConnection.DefaultSslPort);

The final code should look like this

private LdapEntry FindUser(string userName)
    {
        var baseDN = String.Join(",", this.Domain.Split('.').Select(dc => $"dc={dc.ToLower()}"));

        var connection = new LdapConnection();

        connection.SecureSocketLayer = true;

        connection.UserDefinedServerCertValidationDelegate +=   (sender, cert, chain, sslPolicyErrors) => { return true; };



        try
        {
            connection.Connect(options.Server, LdapConnection.DefaultSslPort);
            connection.Bind(options.User, options.Password);
            var cons = new LdapSearchConstraints();
            cons.ReferralFollowing = true;

            var searchResults = connection.Search(baseDN, LdapConnection.ScopeSub,
                $"(sAMAccountName={userName.ToLower()})", null, false, cons);

            while (searchResults.HasMore())
            {
                try
                {
                    return searchResults.Next();
                }
                catch (LdapException)
                {
                }

            }
        }
        catch (LdapException)
        {

        }
        finally
        {
            connection.Disconnect();
        }

        return null;
    }
3 Likes