sagi_kiran
Apr 15th, 2010, 04:26 AM
Hi,
I am trying to retrieve the password of the user from the SecurityContext using the below code, but I always seem to get null. Can you please let me know if I am doing something wrong
-----------------------------------------
public UserDetails getUser() {
SecurityContext ctx = SecurityContextHolder.getContext();
UserDetails user = null;
if (ctx != null) {
Authentication auth = ctx.getAuthentication();
if (auth != null) {
Object obj = auth.getPrincipal();
if (obj != null) {
if (UserDetails.class.isAssignableFrom(obj.getClass() )) {
user = (UserDetails) auth.getPrincipal();
}
System.out.println(user.getPassword());
}
}
}
return user;
}
Regards,
Kiran C Sagi.
I am trying to retrieve the password of the user from the SecurityContext using the below code, but I always seem to get null. Can you please let me know if I am doing something wrong
-----------------------------------------
public UserDetails getUser() {
SecurityContext ctx = SecurityContextHolder.getContext();
UserDetails user = null;
if (ctx != null) {
Authentication auth = ctx.getAuthentication();
if (auth != null) {
Object obj = auth.getPrincipal();
if (obj != null) {
if (UserDetails.class.isAssignableFrom(obj.getClass() )) {
user = (UserDetails) auth.getPrincipal();
}
System.out.println(user.getPassword());
}
}
}
return user;
}
Regards,
Kiran C Sagi.