{"id":4701,"date":"2012-05-24T12:25:54","date_gmt":"2012-05-24T17:25:54","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=4701"},"modified":"2012-05-25T08:35:24","modified_gmt":"2012-05-25T13:35:24","slug":"weblogic-logging-out-a-session","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=4701","title":{"rendered":"WebLogic: Session Management"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Overview\">Overview<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Session_Configuration\">Session Configuration<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#ExtendedSessionFormat\">ExtendedSessionFormat<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Session_Timeout\">Session Timeout<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Session_Cookies\">Session Cookies<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Session_Sharing\">Session Sharing<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Session_Persistence\">Session Persistence<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Five_Implementations\">Five Implementations<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Using_URL_Rewriting_Instead_of_Cookies\">Using URL Rewriting Instead of Cookies<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Coding_Guidelines_for_URL_Rewriting_\">Coding Guidelines for URL Rewriting <\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#Session_Logout\">Session Logout<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Log_Out_a_Single_Session\">Log Out a Single Session<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Log_Out_Multiple_Applications_such_as_in_SSO\">Log Out Multiple Applications such as in SSO<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<p>* Session is a series of related requests that come from the same client<br \/>\n* Session tracks requests from the same client during a certain period of time<br \/>\n* Session can also be persisted<\/p>\n<span id=\"Session_Configuration\"><h3>Session Configuration<\/h3><\/span>\n<p>* Configured in <em>weblogic.xml<\/em><br \/>\n* Configures:<br \/>\n&#8211; How many users you expect to hit the servlet (<em>max-in-memory-sessions<\/em>)<br \/>\n&#8211; How long each session lasts, i.e. session timeout (<em>timeout-secs<\/em>)<br \/>\n&#8211; How much data you expect to store for each user<br \/>\n&#8211; Heap size allocated to the WebLogic Server instance<\/p>\n<span id=\"ExtendedSessionFormat\"><h3>ExtendedSessionFormat<\/h3><\/span>\n<pre lang=\"bash\">\r\n-Dweblogic.servlet.useExtendedSessionFormat=true\r\n<\/pre>\n<p>* Retains the information that the load-balancing application needs for session stickiness.<br \/>\n* The extended session ID format will be part of the URL if URL rewriting is activated, and the startup flag is set to true. <\/p>\n<span id=\"Session_Timeout\"><h3>Session Timeout<\/h3><\/span>\n<p>* Can be set in both <em>web.xml<\/em> and <em>weblogic.xml<\/em><br \/>\n* <em>web.xml<\/em><\/p>\n<pre lang=\"xml\">\r\n  <session-config>\r\n    <session-timeout>120<\/session-timeout>\r\n  <\/session-config>\r\n<\/pre>\n<p>* <em>weblogic.xml<\/em><\/p>\n<pre lang=\"xml\">\r\n<session-descriptor>\r\n<timeout-secs>2400<\/timeout-secs>\r\n<\/session-descriptor> \r\n<\/pre>\n<p>* If both are set, <em>web.xml<\/em> take precedence.<\/p>\n<span id=\"Session_Cookies\"><h3>Session Cookies<\/h3><\/span>\n<p>* By default,<br \/>\n&#8211; Cookies are used for session management<br \/>\n&#8211; When browser quits, cookies are lost and session ends<br \/>\n* Cookie parameters can be set in <em>weblogic.xml<\/em>, e.g.<br \/>\n&#8211; <em>cookie-max-age-secs<\/em><\/p>\n<span id=\"Session_Sharing\"><h3>Session Sharing<\/h3><\/span>\n<p>* Sessions can be shared among multiple web applications<br \/>\n* All web apps need to be packed in the same ear file<br \/>\n* Enable session sharing in <em>weblogic-application.xml<\/em>, e.g.<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n<weblogic-application xmlns=\"http:\/\/www.bea.com\/ns\/weblogic\/90\";;>\r\n   ...\r\n <session-descriptor>\t\r\n     <persistent-store-type>memory<\/persistent-store-type>\r\n     <sharing-enabled>true<\/sharing-enabled>\r\n     ...\r\n <\/session-descriptor>\r\n...\r\n<\/weblogic-application>\r\n<\/pre>\n<span id=\"Session_Persistence\"><h2>Session Persistence<\/h2><\/span>\n<span id=\"Five_Implementations\"><h3>Five Implementations<\/h3><\/span>\n<p>* Memory (single server, non-replicated)<\/p>\n<pre lang=\"xml\">\r\n<persistent-store-type>memory<\/persistent-store-type>\r\n<\/pre>\n<p>* Cookies<\/p>\n<pre lang=\"xml\">\r\n<persistent-store-type>cookie<\/persistent-store-type>\r\n<persistent-store-cookie-name>WLCOOKIE<\/persistent-store-cookie-name>\r\n<\/pre>\n<p>* File system<\/p>\n<pre lang=\"xml\">\r\n<persistent-store-type>file<\/persistent-store-type>\r\n<persistent-store-dir>\/opt\/sessions<\/persistent-store-dir>\r\n<\/pre>\n<p>* JDBC<\/p>\n<pre lang=\"xml\">\r\n<persistent-store-type>jdbc<\/persistent-store-type>\r\n<persistent-store-pool>jdbc\/SessionDS<\/persistent-store-pool>\r\n<cache-size>2048<\/cache-size>\r\n<persistent-store-table>WL_SERVLET_SESSIONS<\/persistent-store-table>\r\n<jdbc-column-name-max-inactive-interval>jdbc<\/jdbc-column-name-max-inactive-interval>\r\n<jdbc-connection-timeout-secs>60<\/jdbc-connection-timeout-secs>\r\n<\/pre>\n<p>* In-memory replication (across a cluster)<\/p>\n<pre lang=\"xml\">\r\n<persistent-store-type>replicated<\/persistent-store-type>\r\nor\r\n<persistent-store-type>replicated_if_clustered<\/persistent-store-type>\r\n<\/pre>\n<span id=\"Using_URL_Rewriting_Instead_of_Cookies\"><h2>Using URL Rewriting Instead of Cookies<\/h2><\/span>\n<p>* By default, automatically enabled when accept cookie is disabled in client side.<br \/>\n* Can be disabled by setting <em>url-rewriting-enabled<\/em> to false<br \/>\n* e.g.<\/p>\n<pre lang=\"xml\">\r\n<session-descriptor>\r\n<timeout-secs>3600<\/timeout-secs>\r\n<invalidation-interval-secs>60<\/invalidation-interval-secs>\r\n<cookie-name>MyCookie<\/cookie-name>\r\n<cookie-max-age-secs>-1<\/cookie-max-age-secs>\r\n<url-rewriting-enabled>false<\/url-rewriting-enabled>\r\n<\/session-descriptor>\r\n<\/pre>\n<span id=\"Coding_Guidelines_for_URL_Rewriting_\"><h3>Coding Guidelines for URL Rewriting <\/h3><\/span>\n<p>* Encode URL before sending to an output stream:<\/p>\n<pre lang=\"java\">\r\n  response.sendRedirect(\r\n    httpResponse.encodeRedirectURL(welcomeURL));\r\n<\/pre>\n<p>* You can check if cookie is used:<\/p>\n<pre lang=\"java\">\r\nHttpServletRequest.isRequestedSessionIdFromCookie();\r\n<\/pre>\n<p>* You can check if an HttpSession is new:<\/p>\n<pre lang=\"java\">\r\nHttpSession session = request.getSession(true);\r\nif (session.isNew()) {\r\n  response.sendRedirect(\r\n    httpResponse.encodeRedirectURL(welcomeURL));\r\n}\r\n<\/pre>\n<span id=\"Session_Logout\"><h2>Session Logout<\/h2><\/span>\n<span id=\"Log_Out_a_Single_Session\"><h3>Log Out a Single Session<\/h3><\/span>\n<pre lang=\"java\">\r\nsession.invalidate();\r\n<\/pre>\n<span id=\"Log_Out_Multiple_Applications_such_as_in_SSO\"><h3>Log Out Multiple Applications such as in SSO<\/h3><\/span>\n<pre lang=\"java\">\r\n\/\/ Removes the authentication data from the users\u2019s session data, \r\n\/\/ which logs out a user but allows the session to remain alive.\r\nweblogic.servlet.security.ServletAuthentication.logout();\r\n\r\n\/\/ Invalidates all the sessions and removes the authentication data for the current user. \r\n\/\/ The cookie is also invalidated.\r\nweblogic.servlet.security.ServletAuthentication.invalidateAll();\r\n\r\n\/\/ Invalidates the current cookie by setting the cookie so that it expires immediately when the response is sent to the browser. \r\n\/\/ This method depends on a successful response reaching the user\u2019s browser. The session remains alive until it times out.\r\nweblogic.servlet.security.ServletAuthentication.killCookie();\r\n<\/pre>\n<p>* For example:<\/p>\n<pre lang=\"java\">\r\nString logout = httpRequest.getParameter(UIConstants.logout);\r\nif (logout != null && logout.equalsIgnoreCase(\"true\")){\r\n    ServletAuthentication.logout(httpRequest);\r\n    ServletAuthentication.invalidateAll(httpRequest);\r\n    ServletAuthentication.killCookie(httpRequest);\r\n    doRedirect(httpResponse, loggedOutPage);\r\n    return;\r\n}\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/docs.oracle.com\/cd\/E13222_01\/wls\/docs92\/webapp\/sessions.html\">Using Sessions and Session Persistence<\/a><br \/>\n* <a href=\"http:\/\/docs.oracle.com\/cd\/E13222_01\/wls\/docs92\/webapp\/weblogic_xml.html\">weblogic.xml Deployment Descriptor Elements<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview * Session is a series of related requests that come from the same client * Session tracks requests from the same client during a certain period of time * Session can also be persisted Session Configuration * Configured in &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=4701\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[91],"tags":[],"class_list":["post-4701","post","type-post","status-publish","format-standard","hentry","category-weblogic"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-1dP","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4701"}],"version-history":[{"count":9,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4701\/revisions"}],"predecessor-version":[{"id":4711,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4701\/revisions\/4711"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}