Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

http basic auth by java code

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have a web application which expose the rest service, i want to set the url as basic auth in server side by JAVA CODE, not the configuration file. how to do that? thanks.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would check for an HTTP header called "Authorization". It contains the username and the base-64 encoded password. (See this for the mechanics of how that header is put together.) That gets you the username and password to authenticate.

If the header is missing, or the username/password combination is invalid, you would respond with an HTTP 304 status, somewhat like this:

If you're using a REST library it may have provisions for this.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slight nit: HttpServletResponse.SC_UNAUTHORIZED is 401.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!