Goldbones
Goldbones

Reputation: 1457

Get Password Credentials by WebServiceContext using basic authentication

I want to know username and password of a HTTP request using basic authentication.

I´m using WebServiceContext.

  @Resource
  private WebServiceContext context;

I can know the username by using context.getUserPrincipal().toString()

But I still want to know the password.By making debug I am allowed to see my password, which is password.

enter image description here

How can I retrieve the submitted password accessing only the WebServiceContext?

I can see it on debug, can´t I access it directly from code?

Upvotes: 1

Views: 454

Answers (1)

Jean-François Savard
Jean-François Savard

Reputation: 21004

password is a char array, if you use toString() you will return the memory address of the array.

instead, use String.valueOf(passwordAsCharArray);

Assuming you have the correct getters,

String.valueOf(( new ArrayList<PasswordCredential>((((Subject)context.getMessageContex‌​t().get("‌​CLIENT_SUBJECT")).get‌‌​‌​‌​‌​​PrivCredentials‌​())).get(0)).getPassword());

Upvotes: 1

Related Questions