Reputation: 751
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()
Upvotes: 0
Views: 1608
Reputation: 2242
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.
Upvotes: 1