Help, there're commas and slashes in my DN!

Hi, I can authenticate my users against the active directory (AD) using Java. All is fine if the user's distinguishedName has no commas and slashes:

cn: Melvin H. Merana
distinguishedName: CN=Melvin H. Merana,OU=ESA OU,OU=Information Technology OU,OU=Smart Users OU,DC=smart,DC=LOCAL

But if the user has commas and slashes, for example,

cn: Floren V. Tamargo, IT/2209
distinguishedName: CN=Floren V. Tamargo\, IT/2209,OU=Information Technology OU,OU=Smart Users OU,DC=smart,DC=LOCAL

I get the following error:

javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-031006CC, problem 5012 (DIR_ERROR), data 0 ]; remaining name 'CN=Floren V. Tamargo\, IT/2209,OU=Information Technology OU,OU=Smart Users OU,DC=smart,DC=LOCAL'

Below is part of my code. The line that is giving the error is "ctx.getAttributes(logonUser.getDistinguishedname());".

May I know how to modify my code to handle names with commas and slashes? Thanks.
public User isAuthenticated(String userId, String password) throws CommunicationException {
	User logonUser = null;
	try {
		logonUser = getUserAdObject(userId);
		if (logonUser != null) {
		security_principal = "smart\\" + userId;
		security_credential = password;
		return logonUser;
	} catch (Exception e) {
		logonUser = null;
	return logonUser;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This applies to VBScript but I think would apply to you too.

According to the post you need to escape the "/" as well appearing in your name. try this and see it works.
CN=Floren V. Tamargo\, IT\/2209,OU=Information Technology OU,OU=Smart Users OU,DC=smart,DC=LOCAL


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You would need to escape the , correctly as it has special meaning to AD. Check out the link below on how to do it
killdurstAuthor Commented:
Hi guys, I've tried to escape the comma and slash characters but it didn't help. I think there's no solution to this so I've decided to implement a workaround. Which is to use the user's username and password to to to open the AD connection itself, i.e. creating the initialLdapContext itself. If it's able to be created, it means the username and password is correct. If it doesn't, it means the username and password is wrong.

To anyone else reading this, I'm giving these guys the points because of the time they spent participating in the question.
killdurstAuthor Commented:
Have decided to use a workaround instead.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.