Trying to interpret LDAP attributes in stringOctetSyntax format
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Scott_Ashmore
Posted On:   Tuesday, March 19, 2002 08:23 AM

Hi, I've made a small LDAP client to retrieve user data from an LDAP server which then uses the data for authentication purposes elsewhere. All of the LDAP attributes except for one returns in plain text. The required attribute that does not convert to plain text is the userpassword. Please note that none of the data is encrypted on the LDAP server. Here is an excerpt of my code (which results in a seemingly encrypted password - i.e. the value of the password variable is '[B@4f2c80' which of course is not the password): DirContext ctx = new InitialDirContext(env); attrs = ctx.getAttributes(dn); String password = attrs.get("userpassword").   More>>

Hi,


I've made a small LDAP client to retrieve user data from an LDAP server which then uses the data for authentication purposes elsewhere. All of the LDAP attributes except for one returns in plain text. The required attribute that does not convert to plain text is the userpassword. Please note that none of the data is encrypted on the LDAP server.



Here is an excerpt of my code (which results in a seemingly encrypted password - i.e. the value of the password variable is '[B@4f2c80' which of course is not the password):



			
DirContext ctx = new InitialDirContext(env);

attrs = ctx.getAttributes(dn);


String password = attrs.get("userpassword").get().toString();




According to LDAP documentation, the userpassword is in octetStringSyntax. The LDAP documentation also states that values of octetStringSyntax Strings are the string values themselves. To me, that seems to imply that it should be in plain text but that is not the case. Casting the attribute as String instead of using toString() results in a "java.lang.ClassCastException: [B". Perhaps the '[B' is supposed to be of some significance?


If anyone knows of a solution to this problem, or can give me some insight as how to interpret octetStringSyntax or what specific class it needs to be casted as I'd greatly appreciate it.


Thanks in advance,

Scott

   <<Less

Re: Trying to interpret LDAP attributes in stringOctetSyntax format

Posted By:   Mahesh_Anantharaman  
Posted On:   Saturday, March 23, 2002 11:33 AM

Hi

Try this. I works.
thanks
mahesh


ctx2 = (DirContext)ctx.lookup(dn);
String[] passwords = {"userPassword"};
Attributes attrs = ctx2.getAttributes("",passwords);
Attribute passAttr = attrs.get("userPassword");
if (passAttr != null) {
Object password = (Object)passAttr.get();
if (password instanceof byte[]) {
String passwordStr =new String((byte[]) password);
cat.debug("Password :" + passwordStr);
empAttrs.put("userPassword",passwordStr);
}
}

Re: Trying to interpret LDAP attributes in stringOctetSyntax format

Posted By:   Christopher_Schultz  
Posted On:   Tuesday, March 19, 2002 08:30 AM

That sure looks like a byte array that you're getting back from the LDAP server.



When Java performs a toString on an array, you get a bracket character ("["), followed by the type of the array (that's the 'b' for byte), followed by the hashcode of the array.



Try casting the attribute to a byte[] and creating a new String(byte[]) out of it. I think you'll have better luck with that.



Good luck,

-chris
About | Sitemap | Contact