<div dir="ltr">Hi Antoine,<div><br></div><div>I guess the CmsSessionManager.switchUser method does not work because it requires the new user to have the workplace role.</div><div>It seems that it is really only intended for admins that are logged in to the workplace.</div>
<div><br></div><div>However, the method is a good starting point for implementing the SSO.</div><div><br></div><div>Here is what I did (note that I slightly improved the code while writing this without testing it ;)):</div>
<div><br></div><div> // you need a CmsObject with Admin rights. You can get it with a module action class</div><div> CmsUser newUser = adminCms.readUser("username");</div><div> </div>
<div> // req is the current HttpServletRequest</div><div> CmsSessionInfo info = OpenCms.getSessionManager().getSessionInfo(req);</div><div> // TODO: check for null</div><div><br>
// ctx is the CmsRequestContext of the current request<br> // project usually is the online project, siteRoot the root folder of the site<br> ctx.setSiteRoot(siteRoot);<br> ctx.setCurrentProject(project);<br>
ctx.setOuFqn(newUser.getOuFqn());<div> <br> // project usually is the online project, siteRoot the root folder of the site</div><div> CmsRequestContext context = new CmsRequestContext(newUser,<br>
project, null, siteRoot, null, null, null, 0, null,<br> null, newUser.getOuFqn());</div> <br> // create a new CmsSessionInfo<br> CmsSessionInfo sessionInfo = new CmsSessionInfo(<br>
context, info.getSessionId(), info.getMaxInactiveInterval());<br> </div><div> // here comes the tricky part (see below)<br> OpenCmsAccess.addSessionInfo(sessionInfo);<br>
<br></div><div>In the last line, you would need to call OpenCms.getSessionManager().addSessionInfo(CmsSessionInfo sessionInfo), however this method is protected, so you cannot call it directly from your code but only from code that is located in the org.opencms.main package. So I created this little class in that package:</div>
<div><br></div><div> package org.opencms.main;<br><br> import javax.servlet.http.HttpServletRequest;<br> import org.opencms.file.CmsRequestContext;<br><br> public class OpenCmsAccess {<br><br> public static void addSessionInfo(CmsSessionInfo sessionInfo) {<br>
OpenCms.getSessionManager().addSessionInfo(sessionInfo);<br> }<br> public static void updateSessionInfo(HttpServletRequest req, CmsRequestContext ctx) {<br> CmsSessionInfo info = OpenCms.getSessionManager().getSessionInfo(req);<br>
if (info != null) info.update(ctx);<br> }<br> }<br></div><div><br></div><div>HTH,</div><div>Stephan</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/19 Antoine PINEAU <span dir="ltr"><<a href="mailto:a.pineau@eurelis.com" target="_blank">a.pineau@eurelis.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="FR" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">Hello All,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">In order to implement an SSO mechanism, I wanted to know how to automatically log in a user in OpenCms without knowing his password.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">I tried to login as an Administrator (with user/password) and then performing a switchUser, but unfortunately it does not work.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">If somebody has already succeeding in performing this functionnality, it would be great to share the experience and piece of code.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif""><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">Thanks in advance.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif""><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">Best Regards<u></u><u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif"">--<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-family:"Trebuchet MS","sans-serif"">Antoine PINEAU</span></b><b><span style="font-size:12.0pt;font-family:"Trebuchet MS","sans-serif""><u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">Eurelis</span></b><b><span style="font-size:9.0pt;font-family:"Trebuchet MS","sans-serif";color:gray"><u></u><u></u></span></b></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>_______________________________________________<br>
This mail is sent to you from the opencms-dev mailing list<br>
To change your list options, or to unsubscribe from the list, please visit<br>
<a href="http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev</a><br>
<br>
<br>
<br>
<br></blockquote></div><br></div>