3

i want to get userPassword attribute from ldap using spring in java.

of course this not work:

context.getStringAttribute("userPassword");

If i try:

context.getObjectAttribute("userPassword");

i can get this attribute..but now from Object how i can get the hash password?

7
  • What kind of Object is it? It's not likely it's java.lang.Object. You should find out what kind of Object it really is and cast it to that type. Commented Jan 21, 2015 at 17:07
  • i don't know how i can get this attribute.. maybe the method getObjectAttribute is wrong..the userPassword attribute is like: userPassword: {MD5}AFxCqn99F5XK4RfSxu1Ldg== Commented Jan 21, 2015 at 17:10
  • You said getObjectAttribute("userPassword") returns you an Object, that sound's right. If you have a debugger see what kind of object it is, or if not, System.out.println(theObject.getClass().getName()) to find out what kind of Object it is. Once you know, just cast it to the right type. Commented Jan 21, 2015 at 17:12
  • if i try your code i have print this: [B Commented Jan 21, 2015 at 17:17
  • That sounds like a byte[] array, so try this: String pwHash = new String((byte[]) theObject);, this is casting the Object to a byte[] array and creating a new String from it (using the default encoding) Commented Jan 21, 2015 at 17:19

1 Answer 1

5

It sounds like context.getObjectAttribute("userPassword") returns an Object so you just need to identify what it is.

Based on the comments it was a byte[] array which was representing a String, so you can basically do this:

Object o = context.getObjectAttribute("userPassword");
byte[] bytes = (byte[]) o;
String hash = new String(bytes);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.