Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to test LDAP-based authentication from forumsys?

I've not done any LDAP-based authentication before and also I've not worked with any LDAP server before. So I need a free online LDAP server to play with, I've found this https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

However my code is not working (or the info there has become invalid, I'm not sure), the result of authen is always false, here is my code:

path = "ldap.forumsys.com:389/dc=example,dc=com";
using (var pc = new PrincipalContext(ContextType.Domain, null, path))
{
  //this always returns false
  var ok = pc.ValidateCredentials("read-only-admin", "password");
}

Could you make it work on your side? Or at least please assert that the info there is invalid, in that case if possible please give me some other info (from other free LDAP servers for testing).

like image 448
Hopeless Avatar asked Aug 01 '18 03:08

Hopeless


People also ask

How do I test my local LDAP connection?

Open Group policy management console. Create a new GPO and edit it -> Computer configuration -> Policies -> Windows Settings -> Security Settings -> Local Policies -> Audit Policy: Audit Account Management -> Check the box for Success. Audit Directory Service Access -> Check the box for Success.


1 Answers

I figure it out too, and having no LDAP knowledge I´ve come up with this.

The problem in your solution may be first, you are using "ldap://" instead of "LDAP://", since it was something I came into when coding this. But I use System.DirectoryServices library.

I tested against this magnificent free to test LDAP server

var path = "LDAP://ldap.forumsys.com:389/dc=example,dc=com";
var user = $@"uid={username},dc=example,dc=com";
var pass = "password";

var directoryEntry = new DirectoryEntry(path, user, pass, AuthenticationTypes.None);

var searcher = new DirectorySearcher(directoryEntry);
searcher.PropertiesToLoad.Add("*");
var searchResult = searcher.FindOne();

I don´t understand exactly what all of this lines does, however, and lookign for a solution I found some recommendations.

on the path the "LDAP://" string should be on block mayus.

in the user, sometimes you need to use "cn=username-admin" for validating admins, be sure to also set Authentication type to ServerBind.

like image 185
Ricker Silva Avatar answered Oct 10 '22 22:10

Ricker Silva