Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old September 12th, 2002, 10:37 AM
namNASA namNASA is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 namNASA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Create a logout feature

I want to create a logout button. Below is my situation:

The first time the user click on my website, he/she is required to enter password. I use this:

response.setStatus(response.SC_UNAUTHORIZED); // Ie 401
response.setHeader("WWW-Authenticate",
"BASIC realm=\"privileged-few\"");

During the use of the site on the already-logged-in browser, the user doesn't have to login again. I use:

String authorization = request.getHeader("Authorization");

to get the login ID and password.

Now, I want to create the logout button. I want to reset the "Authorization" parameter in the Header to empty. What should I do?

Thanks a lot,

Nam.

Reply With Quote
  #2  
Old September 17th, 2002, 09:56 AM
namNASA namNASA is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 namNASA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help please

Hi all,

I really appreciate if you lead me to some directions. I've tested so many ways but still stuck.

Thanks a ton.

Nam.

Reply With Quote
  #3  
Old September 17th, 2002, 12:17 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Have you tried response.setHeader("Authorization", ""); ?

Reply With Quote
  #4  
Old September 18th, 2002, 01:33 PM
namNASA namNASA is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 namNASA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Please help

No, response.setHeader("Authorization","") does not work. I've been searching for the solution for months. It seems that it's impossible. If you guys have any ideas, I just can't say enough thanks.

I already describe the problem that I can't create a logout button. I have the same issue when I want to force the user to relogin using the same browser that's idle for 30 minutes.
==========
I use
response.setHeader("WWW-Authenticate",
"BASIC realm=\"privileged-few\"");

for users to login their accounts. If the user's browser is idle for 30 min, I want to invalidate the user's session and force him/her to login again.

Now, when the login dialog appear, if the user click Cancel, and then refresh the page, he/she can get into the site again without having to login. It is because the request.getHeader("Authorization") returns the same pair of login and password.

I have tried response.setHeader("Authorization","") before set the WWW-Authenticate..., it doesn't work. How can I achieve this?

Reply With Quote
  #5  
Old September 18th, 2002, 08:34 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
From the php manual
Quote:
Both Netscape Navigator and Internet Explorer will clear the local browser window's authentication cache for the realm upon receiving a server response of 401. This can effectively "log out" a user, forcing them to re-enter their username and password. Some people use this to "time out" logins, or provide a "log-out" button. This behavior is not required by the HTTP Basic authentication standard, so you should never depend on this. Testing with Lynx has shown that Lynx does not clear the authentication credentials with a 401 server response, so pressing back and then forward again will open the resource as long as the credential requirements haven't changed. The user can press the '_' key to clear their authentication information, however.


another option
Quote:
Someone gave me a simple solution to the 'logout' problem: add some sort of timestamp to the basic realm you send in the WWW_Authenticate header. Mine now is: $realm="RealmName ( ".strftime("%c",time())." )";. (btw: the problem was: 1) IE4 asks for the page one more time after a 401, defeating sending a 401 once to force a user to log on again. and 2) IE4 remembers the password, and puts it default in the logon window. Changing the realm solves these problems, not the 'logon failed' message of NS though).

Reply With Quote
  #6  
Old September 20th, 2002, 11:28 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
For a more reliable way to do this, you may want to "Roll your own" Authentication instead of using the WWW_Authenticate header to get the user and pw.

I assume since you are manually sending the Authenticate header instead of having the HTTP server do it for you, you are also manually retrieving the username and pw and comparing them yourself to a database or flat file? If so, you might be better off looking for a bean in the session and if it is not there redirecting the user to a login page. The login page submits to a servlet (could be the same one) and if they check out ok, it creates a bean of some sort and stores it in the session. At the same time you use setMaxInactiveInterval(int interval) to set the session to time out in 30 minutes or whatever.

I don't believe there is a reliable way to keep the browser from returning a previously entered username and pw to a domain it has already authenticated to. Changing the realm is a hack at best. And sending a 401 header may be ignored in the next browser release for all you know.

Hope this helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Create a logout feature


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway