{"id":193,"date":"2006-08-27T13:25:35","date_gmt":"2006-08-27T17:25:35","guid":{"rendered":"http:\/\/www.dr-chuck.com\/wordpress\/?p=193"},"modified":"2011-12-17T12:20:25","modified_gmt":"2011-12-17T16:20:25","slug":"make-sure-and-come-back-and-fix-usagesessionservice","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2006\/08\/make-sure-and-come-back-and-fix-usagesessionservice\/","title":{"rendered":"Make sure and come back and fix UsageSessionService"},"content":{"rendered":"<p>UsageSessionSerivce needs a new method that does not demand an Authorization not a httprequest as a parameter.<br \/>\nFor now the code is living in SakaiPortalLogin.jws and SakaiLogin.jws so these can be used in older versions of Sakai.<br \/>\nNeed to add the method the the BASE API, test it out, then commit it &#8211; then sometime later &#8211; likey *after* 2.3 &#8211; remove the code from the two web service calls.<\/p>\n<p><!--more--><br \/>\nvi .\/event-impl\/impl\/src\/java\/org\/sakaiproject\/event\/impl\/UsageSessionServiceAdaptor.java<br \/>\npublic boolean login(Authentication authn, HttpServletRequest req)<br \/>\n{<br \/>\n\/\/ establish the user&#8217;s session &#8211; this has been known to fail<br \/>\nUsageSession session = startSession(authn.getUid(), req.getRemoteAddr(), req.getHeader(&#8220;user-agent&#8221;));<br \/>\nif (session == null)<br \/>\n{<br \/>\nreturn false;<br \/>\n}<br \/>\n\/\/ set the user information into the current session<br \/>\nSession sakaiSession = sessionManager().getCurrentSession();<br \/>\nsakaiSession.setUserId(authn.getUid());<br \/>\nsakaiSession.setUserEid(authn.getEid());<br \/>\n\/\/ update the user&#8217;s externally provided realm definitions<br \/>\nauthzGroupService().refreshUser(authn.getUid());<br \/>\n\/\/ post the login event<br \/>\neventTrackingService().post(eventTrackingService().newEvent(EVENT_LOGIN, null, true));<br \/>\nreturn true;<br \/>\n}<br \/>\npublic UsageSession startSession(String userId, String remoteAddress, String userAgent)<br \/>\n{<br \/>\n\/\/ do we have a current session?<br \/>\nSession s = sessionManager().getCurrentSession();<br \/>\nif (s != null)<br \/>\n{<br \/>\nUsageSession session = (UsageSession) s.getAttribute(USAGE_SESSION_KEY);<br \/>\nif (session != null)<br \/>\n{<br \/>\n\/\/ If we have a session for this user, simply reuse<br \/>\nif (userId != null &#038;&#038; userId.equals(session.getUserId()))<br \/>\n{<br \/>\nreturn session;<br \/>\n}<br \/>\n\/\/ if it is for another user, we will create a new session, log a warning, and unbound\/close the existing one<br \/>\ns.setAttribute(USAGE_SESSION_KEY, null);<br \/>\nM_log.warn(&#8220;startSession: replacing existing UsageSession: &#8221; + session.getId() + &#8221; user: &#8221; + session.getUserId()<br \/>\n+ &#8221; for new user: &#8221; + userId);<br \/>\n}<br \/>\n\/\/ create the usage session and bind it to the session<br \/>\nsession = new BaseUsageSession(idManager().createUuid(), serverConfigurationService().getServerIdInstance(), userId,<br \/>\nremoteAddress, userAgent, null, null);<br \/>\n\/\/ store<br \/>\nif (m_storage.addSession(session))<br \/>\n{<br \/>\n\/\/ set as the current session<br \/>\ns.setAttribute(USAGE_SESSION_KEY, session);<br \/>\nreturn session;<br \/>\n}<br \/>\n}<br \/>\nreturn null;<br \/>\n}<br \/>\nSakaiLogin.jws:<br \/>\nUsageSessionService_loginDirect(user.getId(), id, ipAddress, &#8220;SakaiLogin.jws&#8221;);<br \/>\n\/\/ This code is adapted from the file:<br \/>\n\/\/ .\/event-impl\/impl\/src\/java\/org\/sakaiproject\/event\/impl\/UsageSessionServiceAdaptor.java<br \/>\n\/\/ Method<br \/>\n\/\/ public boolean login(Authentication authn, HttpServletRequest req)<br \/>\n\/\/ We want to do exactly what this routine *does* but we do not have an HttpServletRequest<br \/>\n\/\/ to hand it<br \/>\npublic boolean UsageSessionService_loginDirect(String userId, String userEid, String ipAddress, String userAgent)<br \/>\n{<br \/>\n\/\/ establish the user&#8217;s session &#8211; this has been known to fail<br \/>\nUsageSession session = UsageSessionService.startSession(userId,ipAddress,userAgent);<br \/>\nif (session == null)<br \/>\n{<br \/>\nreturn false;<br \/>\n}<br \/>\n\/\/ set the user information into the current session<br \/>\nSession sakaiSession = SessionManager.getCurrentSession();<br \/>\nsakaiSession.setUserId(userId);<br \/>\nsakaiSession.setUserEid(userEid);<br \/>\n\/\/ update the user&#8217;s externally provided realm definitions<br \/>\nAuthzGroupService.refreshUser(userId);<br \/>\nString EVENT_LOGIN = &#8220;user.login&#8221;;<br \/>\n\/\/ post the login event<br \/>\nEventTrackingService.post(EventTrackingService.newEvent(EVENT_LOGIN, null, true));<br \/>\nreturn true;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UsageSessionSerivce needs a new method that does not demand an Authorization not a httprequest as a parameter. For now the code is living in SakaiPortalLogin.jws and SakaiLogin.jws so these can be used in older versions of Sakai. Need to add the method the the BASE API, test it out, then commit it &#8211; then sometime [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-193","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=193"}],"version-history":[{"count":1,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":2292,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/193\/revisions\/2292"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}