0

I'm using a Apache CXF with WebClient and I want to send my credentials to the server

    WebClient client = WebClient.create("http://localhost:8084", "username", "password", null)

The problem is that I can't get the password value.

The following method is not working

    SecurityContextHolder.getContext().getAuthentication().getCredentials()
nunofmendes
  • 3,731
  • 2
  • 32
  • 42
Ihar Sadounikau
  • 741
  • 6
  • 20
  • follow this link may be helpful for you http://stackoverflow.com/questions/9498461/retrieve-password-of-current-user-from-spring-security – Irfan Nasim Nov 27 '14 at 17:33
  • The password is generally cleared after authentication. Perhaps you could explain why you want to read it after the user has logged in? – Shaun the Sheep Nov 27 '14 at 19:16
  • 1
    You shouldn't be able to get a password from any well-designed security environment. – user207421 Nov 27 '14 at 19:52

1 Answers1

1

Lets say that you been login and you need to get company name that you been retrieve from database. First you will need to object that implement UserDetails that will save in UserDetailsService and add any variable that you need (company, etc).

public class CustomUserDetails implements UserDetails{      
    private String password;
    private String username;
    private String companyName;
}

than at typecast with your custom Userdetails implementation.

CustomUserDetails customDetails (CustomUserDetails)SecurityContextHolder.getContext().getAuthentication().getCredentials();

getCredentials will return Object of what you saved to the credential. Whatever it type you can always return it to the class you been save.

Irfan Nasim
  • 1,952
  • 2
  • 19
  • 29