{"id":3291,"date":"2012-05-04T08:06:09","date_gmt":"2012-05-04T12:06:09","guid":{"rendered":"http:\/\/onlineappsdba.com\/?p=3291"},"modified":"2012-05-10T22:21:53","modified_gmt":"2012-05-11T02:21:53","slug":"how-to-set-and-get-session-attributes-in-oam-11g","status":"publish","type":"post","link":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/","title":{"rendered":"How to set and get session attributes in OAM 11g"},"content":{"rendered":"<p>Session &amp; session attributes are newly introduced in OAM 11g. OAM 11g maintains a session at server side the sessionIds are managed by Session Management Engine SME. How to retrieve session IDs from OAM server are explained in <a href=\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-read-session-ids-of-a-user-from-oam-11g\/\">post<\/a>. So this post will give a sample code snippet to set and retrieve session attributes from session.<\/p>\n<p>OAM session ID is around 20 characters and will be of the format d331ab34-2e17-4c5c-8ba1-a7cdf695150c. Session IDs can also be seen in OAM database schema by using sql command select * from oam_session;<\/p>\n<p>The above sql command output will have results similar as shown below.<\/p>\n<p>SESSIONID<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nUSERID<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nIDENTITY_DOMAIN<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nSESSION_INDEX<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nCREATE_TIME<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nLAST_ACCESS_TIME<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nLAST_UPDATE_TIME<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nEXPIRY_TIME<br \/>\n4c2cdff7-0cbf-4723-aaab-489c06366d96<br \/>\nLN-Admin<br \/>\nNewOVDStore<br \/>\n-3226491390739477568<br \/>\n04-MAY-12 03.28.39.124000 AM<br \/>\n04-MAY-12 03.28.39.124000 AM<br \/>\n04-MAY-12 03.28.41.536000 AM<br \/>\n04-MAY-12 11.28.39.124000 AM<\/p>\n<p>So it is merely easy to identify the session ID associated with which user IDs. The same behavior can also be seen in OAM console in Session Management section.<\/p>\n<p>So the below snippet can be used to set and retrieve the session attributes from session.<\/p>\n<p>Hashtable credentials = new Hashtable ();<br \/>\ncredentials.put(\u201cuserid\u201d, user_login);<br \/>\ncredentials.put(\u201cpassword\u201d, user_passwd);<br \/>\ntry{<br \/>\nAccessClient ac=null;<br \/>\nResourceRequest req ;<br \/>\nac = AccessClient.createDefaultInstance(Location,AccessClient.CompatibilityMode.OAM_10G);<br \/>\nreq = new ResourceRequest(protocol, resource,method_way);<br \/>\nSystem.out.println(\u201cLocation\u2013&gt;\u201d+Location);<br \/>\nUserSession session = new UserSession(req,credentials);<br \/>\nString sessionToken=session.getSessionToken();<br \/>\nSystem.out.println(sessionToken);<br \/>\nSet set=session.getSessionIds(user_login);<\/p>\n<p>Iterator it = set.iterator();<\/p>\n<p>String sessionID = &#8220;&#8221;;<\/p>\n<p>while (it.hasNext()){<\/p>\n<p>sessionID = it.next();<\/p>\n<p>}<br \/>\nSystem.out.println(\u201cSessionattr\u2014&gt;\u201d+set);<\/p>\n<p>Hashtable sessionAttributes= new Hashtable ();<br \/>\nsessionAttributes.put(\u201cuserid\u201d, &#8220;mahendra&#8221;);<br \/>\nsessionAttributes.put(\u201cmobile\u201d, &#8220;999123412&#8221;);<\/p>\n<p>sessionAttributes.put(\u201cemail\u201d, &#8220;mahendra@abcd.com&#8221;);<\/p>\n<p>UserSession.setSessionAttributes(sessionID, sessionAttributes);<\/p>\n<p>Hashtable sessionAttrs = UserSession.getSessionAttributes(sessionID);<\/p>\n<p>System.out.println(&#8220;userid from session Attributes ===&gt;&#8221;+sessionAttrs.get(&#8220;userid&#8221;));<br \/>\nSystem.out.println(&#8220;mobile from session Attributes ===&gt;&#8221;+sessionAttrs.get(&#8220;mobile&#8221;));<br \/>\nSystem.out.println(&#8220;email from session Attributes ===&gt;&#8221;+sessionAttrs.get(&#8220;email&#8221;));<\/p>\n<p>}catch(Exception e){}<\/p>\n<p>In OAM 11g user can have multiple sessions and based on this, the attributes can be retrieved in a loop.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Session &amp; session attributes are newly introduced in OAM 11g. OAM 11g maintains a session at server side the sessionIds [&hellip;]<\/p>\n","protected":false},"author":115,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[51,40],"tags":[355,468],"class_list":["post-3291","post","type-post","status-publish","format-standard","hentry","category-session","category-sso","tag-oam-11g","tag-session"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to set and get session attributes in OAM 11g -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to set and get session attributes in OAM 11g -\" \/>\n<meta property=\"og:description\" content=\"Session &amp; session attributes are newly introduced in OAM 11g. OAM 11g maintains a session at server side the sessionIds [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-04T12:06:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-05-11T02:21:53+00:00\" \/>\n<meta name=\"author\" content=\"Masroof Ahmad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Masroof Ahmad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/\",\"url\":\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/\",\"name\":\"How to set and get session attributes in OAM 11g -\",\"isPartOf\":{\"@id\":\"https:\/\/onlineappsdba.com\/#website\"},\"datePublished\":\"2012-05-04T12:06:09+00:00\",\"dateModified\":\"2012-05-11T02:21:53+00:00\",\"author\":{\"@id\":\"https:\/\/onlineappsdba.com\/#\/schema\/person\/909a876ed58d400faf82caf81d61bfdb\"},\"breadcrumb\":{\"@id\":\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/onlineappsdba.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to set and get session attributes in OAM 11g\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/onlineappsdba.com\/#website\",\"url\":\"https:\/\/onlineappsdba.com\/\",\"name\":\"\",\"description\":\"Oracle Implementation &amp; Training Experts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/onlineappsdba.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/onlineappsdba.com\/#\/schema\/person\/909a876ed58d400faf82caf81d61bfdb\",\"name\":\"Masroof Ahmad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/onlineappsdba.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/10f9db7bdbbd7f9ccfbe9b2d208e5978fc28315e9c704383e639a926ea0fce5f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/10f9db7bdbbd7f9ccfbe9b2d208e5978fc28315e9c704383e639a926ea0fce5f?s=96&d=mm&r=g\",\"caption\":\"Masroof Ahmad\"},\"url\":\"https:\/\/onlineappsdba.com\/index.php\/author\/masroof\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to set and get session attributes in OAM 11g -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/","og_locale":"en_US","og_type":"article","og_title":"How to set and get session attributes in OAM 11g -","og_description":"Session &amp; session attributes are newly introduced in OAM 11g. OAM 11g maintains a session at server side the sessionIds [&hellip;]","og_url":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/","article_published_time":"2012-05-04T12:06:09+00:00","article_modified_time":"2012-05-11T02:21:53+00:00","author":"Masroof Ahmad","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Masroof Ahmad","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/","url":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/","name":"How to set and get session attributes in OAM 11g -","isPartOf":{"@id":"https:\/\/onlineappsdba.com\/#website"},"datePublished":"2012-05-04T12:06:09+00:00","dateModified":"2012-05-11T02:21:53+00:00","author":{"@id":"https:\/\/onlineappsdba.com\/#\/schema\/person\/909a876ed58d400faf82caf81d61bfdb"},"breadcrumb":{"@id":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/onlineappsdba.com\/index.php\/2012\/05\/04\/how-to-set-and-get-session-attributes-in-oam-11g\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/onlineappsdba.com\/"},{"@type":"ListItem","position":2,"name":"How to set and get session attributes in OAM 11g"}]},{"@type":"WebSite","@id":"https:\/\/onlineappsdba.com\/#website","url":"https:\/\/onlineappsdba.com\/","name":"","description":"Oracle Implementation &amp; Training Experts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/onlineappsdba.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/onlineappsdba.com\/#\/schema\/person\/909a876ed58d400faf82caf81d61bfdb","name":"Masroof Ahmad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/onlineappsdba.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/10f9db7bdbbd7f9ccfbe9b2d208e5978fc28315e9c704383e639a926ea0fce5f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10f9db7bdbbd7f9ccfbe9b2d208e5978fc28315e9c704383e639a926ea0fce5f?s=96&d=mm&r=g","caption":"Masroof Ahmad"},"url":"https:\/\/onlineappsdba.com\/index.php\/author\/masroof\/"}]}},"_links":{"self":[{"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/posts\/3291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/comments?post=3291"}],"version-history":[{"count":0,"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/posts\/3291\/revisions"}],"wp:attachment":[{"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/media?parent=3291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/categories?post=3291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/onlineappsdba.com\/index.php\/wp-json\/wp\/v2\/tags?post=3291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}