Why session not timeout

Why session not timeout

###Useful links Timeout settings in WAS

Java Session invalidate and timeout does not work

JSP login page session timeout

REST services basic auth session timeout

###Basic auth Steps

Briefly the basic authentication (rfc 2617) works like this:

  1. Client requests some resource.

  2. Server recognizes that the resource has a security constraint, in web.xml. Therefore it sends a HTTP 401 "Authorization required" response. The header contains something like...

    WWW-Authenticate: Basic realm="Protected"

  3. The client resends its request, but this time with the credentials (base64-encoded) in the header, e.g. ...

    Authorization: Basic dG9tY2F0OnMzY3JIdA==

  4. The server authenticates the request based on the given credentials and sends the requested resource.

In order to make web browsing convenient for humans virtually every browser caches the credentials until the browser is closed. Every time you reload the page in the browser the "Authorization" entry is sent with the header of the request. Therefore you are not asked for your credentials again while testing your web service with a browser.

###Cyper's attempt

  1. Input user/pass from the dialog, browser will add below request header +Authorization Basic bGdpbG1vcmVAYXUxLmlibS5bG1vcS5jb20=

  2. If you request the page for 2nd time(browser will add JSESSIONID in Cookie header) Authorization Basic bGdpbG1vcmVAYXUxLmlibS5jb206cmVAYXUxLmlibS5jb20= + JSESSIONID=00009RNA9pcLQSi1OHhiWQOmwLx:-1; + CookieChecker=set; + CMAVID=none; + cmTPSet=Y; + 51040000_clogin=l=1425356444&v=1&e=1425358246064

    Note this JSESSIONID is generated and sent from server in response header like this Set-Cookie:JSESSIONID=00009RNA9pcLQSi1OHhiWQOmwLx:-1; Path=/; HttpOnly

    Also note that for Basic auth, browser will send credential information in the header for each and every request.

  3. When timeout, server execute request.getRemoteUser() and re-login this user automatically, and sent a New JESSIONID to user browser by including below header. Set-Cookie JSESSIONID=0000O0OB4W_4sxtn6elSmolMxI9:-1; Path=/; HttpOnly

  4. Browser updates the JESSIONID in its cookie and will send back this cookie each time in the consequent request.

  5. If you want to expire the Basic auth, you need to remove Authorization header from browser request, here is the method:

In Firefox you can choose Clear Recent History from the History menu (Ctrl + Shift + Del). You can then select to just clear Active Logins from the details to just clear those sessions.

###Login directly in the browser without the popup dialog. We can use blow url:

https://user:pass@www.example.com/mygroups.wss

see superuser

###How request.getRemoteUser() works See stackoverflow

In cyper's opinion, what it does in the Clear Active Logins, is to remove Authorization header from user browser, the JSESSIONID is not removed from Cookie actually.

###Final Solution:###

  1. Check session object from SecurityInterceptor.java

    if session object is null, it either means it's a request from a new client or it may be a request from an existing client but expired(session timeout)

  2. Identify it's new client or expired

    Request from a new client does not include JSESSIONID in its cookie.

    1. If system can't find JSESSIONID from user's cookie, we take it as new client and check request.getRemoteUser() further, if the latter returns null: You are not logged in, please login first. Otherwise, login this user and do authentication further.

    2. If JSESSIONID from Cookie header exists but session is null: Your session is expired, please relogin.

  3. If session object is not null, go check authentication directly.

转载于:https://my.oschina.net/uniquejava/blog/382191

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值