Why is full name used for DN in Active Directory? - active-directory

[Rewriting my question based on comments]
My DN in Active Directory is "CN=Jesse Barnum,cn=users,dc=360works,dc=com".
I'm writing a web application which attempts to bind to the LDAP server, using the username and password of the active user. When doing the bind, I use the format "CN=$loginName$,cn=users,dc=360works,dc=com". Therefore, my users need to type in their full name (ie. 'Jesse Barnum'), rather than their shorter UID ('jbarnum').
Since users logging in typically expect to type a short name (like 'jbarnum', rather than 'Jesse Barnum'), I'd like for my DN to use my short name, like this: "CN=jbarnum,cn=users,dc=360works,dc=com". Doesn't it seem like that should be the default behavior (Windows Server 2012)?
So my question is: Can I change how the DN is constructed in Active Directory to use the short name instead of the full name?

You can change that behaviour but why should you? As you want to create a login there are much more elegant and more flexible solutions available.
When creating an LDAP based login I'm always doing the following:
bind to the server with a special account that can search the LDAP. Often that can also be done with a so called "anonymous bind".
search the LDAP for the given username in any attribute you like. A filter of (|(uid=username)(mail=username)(cn=username)) would allow your user to either use the uid, mail or cn to log in.
get the dn from the retrieved result and use that DN whic should be the DN of the users record) for a second bind - this time with the provided Password
That way the DN is completely irrellevant for your login as i is retrieved using the provided information based on attributes.
For an example in PHP have a look at https://gist.github.com/heiglandreas/5689592

The CN can be based on anything, really. It comes down to how you provision your users in the directory. If you use the out-of-box AD Users and Computers or AD Administrative Center tools to create users, they default to the full name format. You can change the CN after the fact, or if you are using something programmatic to create users, then you can create them however you like initially.

Related

user principal name issues and LDAP

So... this question is maybe not solely a programming question but I hope one of you can shed some light on my issue:
The base need we have in our software is to query the groups a user is associated too with
LDAP. For this task we actually use parts of LDAP Admin to query the user. Actually we want to query for the UserPrincipalName which at least to my knowledge is the most common way right?
So.. our problem is that the AD is setup such that the user has an UPN like foo#HUS
but the user actually is bound to the domain HUS.adomain.com (aka LDAP base: dc=HUS,dc=adomain,dc=com) and searching using an UPN like foo#HUS.adomain.com does not work - only foo#HUS works. So... the question is:
Is this common?
And is there a name/resource for that?
(sorry I'm quite new to that all...)
The goal would be to use as less parameters in the administration tool as possible
aka only the base (and form from the base the UPN username).
Update: I found at least one resource (in German) that states that this is possible but not recommended by Microsoft for Azure AD. (aka having a different mail address than UPN )
When you initiate a LDAP search using a UPN like foo#HUS.adomain.com it wont work because this value is not present in the userPrincipalName value. When you search for a user by building its UPN using all the domain suffix available in the forest, then you would not consider searching the userPrincipalName attribute.
It is very difficult to build every constructed attribute from base for querying because every Active directory environment would be different. As you have mentioned that you would like to build the attribute from base, it may work if this is the only AD infra that you are targeting. Every AD infra would have its own ways in which it will be setup.
However if you would want your tool to work in any AD environment you would have to consider some other parameters.
UPN is a editable attribute . An organization can set it up or can create a user without a UPN value. Below is example of user created programmatically by using old ADSI libraries. You can repro the same by removing any users userprincipalName attribute value and the user logon account name as shown in the pictures below.
UPN is an optional attribute and a user account can be present in AD without it as well. Coming back to your specific environment in this environment only foo#HUS works because "HUS" might be setup as a valid domain suffix within the Active directory. You can check this by opening the domain.msc console on any domain controller or a machine with Remote Server Administration Tools installed. You would find the UPN suffix as shown below . I changed it in my environment as shown below.
The value you will add will now show up in the . If you remove HUS from here for example any existing user who have user#HUS userPrincipalName populated will get removed because this is a optional constructed attribute in AD. And you will have to setup this for all the users in the environment . For example check below after I changed the username to dh # HUS .
The userprincipalName value also got populated with the same.
Hope this helps clarify your query and understand more on how to use the native Active directory tools to understand more while you develop your custom LDAP search functionality/tool.

What are the steps to implement single sign on against Active Directory using LDAP?

I need to authenticate users against Active Directory in my C++ application. I know I need to bind to something and authenticate using the user's distinguished name and password. This distinguished name is often long with commas and contains the username.
Say the user enters something in my application's username and password box. How do I find the distinguished name to bind to? Do I have to write a search query for it?
You need to:
Search the AD for the user's DN based on what he entered into your form, typically an email address or a user ID or something else that is unique. Unless the AD supports anonymous searching you will need to bind to it using an adminstrative account/password that has permission to do this search. THis is done via an LDAP filter expression, a topic which you need to look up.
When/if you've found it, rebind to AD using the DN of that entry and the password from the form.
If either step fails, the login fails, and don't tell the user which step it was, i.e. don't tell him 'no such user' or 'wrong password', just tell him 'bad credentials' or similar in both cases. Otherwise you are leaking information to the attacker.

Whats is the LDAP Authentication best practice?

I want to know the best practice for authenticating users using OpenLDAP. I could perform a search using the cn.
But then what if I got multiple hits with similar cn (under different ancestors of course) and they all use the same password?
I tried to use uids but then I got some types of accounts that do not use uids (like mail accounts and the admin cn). Also, when I added some users under the admin cn (which has no uid) I could not login with the admin cn.
What is the unique key that identifies a user?
Note: I am using phpldapadmin to manage the active directory, and openldap for the c++ code.
You can configure your OpenLDAP server to perform the uniqueness check on your chosen attribute. CN is not the most favorable attribute to choose for uniqueness I would choose UID attribute and have a policy in place for username generation.

Finding CN of users in Active Directory

I'm trying to find the Base DN of the user that can access or controls all the users in Active Directory so I can put it in my LDAP.
Usually someone will give me this, and it looks like DC=domain,DC=company,DC=com
But the admin is not available, so I don't know how to find this in Active Directory.
I'm looking for a step by step to find this info. Which tree and tabs to open and how to construct it.
My user is: admin, the server is: controller-16.domain.company.com
But I don't know if they added OU or groups or something else
I know that this:
CN=admin,DC=domain,DC=company,DC=com
does not work. Nor does:
DC=domain,DC=company,DC=com
If the Base DN works on Gawor's LDAP Browser, then it will work for my LDAP.
You could try my Beavertail ADSI browser - it should show you the current AD tree, and from it, you should be able to figure out the path and all.
Or if you're on .NET 3.5, using the System.DirectoryServices.AccountManagement namespace, you could also do it programmatically:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
This would create a basic, default domain context and you should be able to peek at its properties and find a lot of stuff from it.
Or:
UserPrincipal myself = UserPrincipal.Current;
This will give you a UserPrincipal object for yourself, again, with a ton of properties to inspect. I'm not 100% sure what you're looking for - but you most likely will be able to find it on the context or the user principal somewhere!
Most common AD default design is to have a container, cn=users just after the root of the domain. Thus a DN might be:
cn=admin,cn=users,DC=domain,DC=company,DC=com
Also, you might have sufficient rights in an LDAP bind to connect anonymously, and query for (cn=admin). If so, you should get the full DN back in that query.
CN refers to class name, so put in your LDAP query CN=Users. Should work.

LDAP Active Directory path

I am trying to add a user to Active Directory through an MPS Web Service. I've been trying a long time to find the correct LDAP-url to use to tell it to add the new user to the Users group. I've tried things like:
LDAP://XXXX.YYY/OU=Users,DC=XXXX,DC=YYY
LDAP://XXXX.YYY/CN=Users,DC=XXXX,DC=YYY
LDAP://XXXX.YYY/DN=Users,DC=XXXX,DC=YYY
It seems the "farthest" I've gotten is an error that says I have given it an invalid Customer.
I really don't have a lot of experience with LDAP (pretty much none at all), so even just a good LDAP and Active Directory tutorial would be extremely useful (even that is eluding me right now). Thanks!
I've since lookup up the actual distinguished name in ADSI Edit, which was LDAP://XXXX.YYY/CN=Users,DC=XXXX,DC=YYY, but still have no luck.
You have error in your LDAP string.
Let's have examle:
user with account name User1 in organization unit Office1 where contoso.com is domain.
Object:
contoso.com/Users/Office1/User1
LDAP Path is:
LDAP://CN=User1,OU=Office1,OU=Users,DC=contoso,DC=com
Note that there is no slash in path itself
CN = Common Name
OU = Organizational Unit
DC = Domain Component
You can start with:
LDAP Query Basics
Creating a list of Users and their e-mail addresses in Exchange 2000
How Can I Get a List of All the Users Whose Passwords Never Expire?
if your domain is xxxx.yyyy.zzzz and you are search for all users; your path is:
LDAP://CN=Users,DC=xxxx,DC=yyyy,DC=zzzz
means every dot in domain replace with dc=
More directly, the default Users container (not a group) in a default Active Directory install would be CN=Users,dc=domain,dc=com
You are not clear if you are having trouble adding a user to a group, or if you are having trouble creating a user in a specific location.

Resources