• Post Reply Bookmark Topic Watch Topic
  • New Topic

Authentication error 401 REST WebService  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am calling a web service which needs authentication, this is the code:




This is the error:


Someone knows how could I autenticate, please?

Regards, Isaac



 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this by calling java.net.Authenticator.setDefault() with an instance of java.net.Authenticator. Create a subclass that overrides getPasswordAuthentication(). A proper implementation at least checks that the scheme and protocol are HTTPS, and that the host name is exactly the expected one, otherwise you will be giving out passwords to random people.

If you decide to hardcode the password in your application, don't put it in String form anywhere. Return a character array that's been initialized with each separate character of the password.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have the next code:



I get this error:


I left the original credentials it is not problem

Any idea, please?
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:I left the original credentials it is not problem

It is. I just logged in and changed it. I will PM you your new password in an hour. NEVER SHARE PASSWORDS.
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't listen to a thing I said. Check the scheme and protocol. Check the host name. Don't use String for passwords.

Finally, you just print the error code and don't do anything else with the response you get from the server. Why don't you check the response for an error message?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!