Logout Logged in User

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Logout Logged in User

Aaron Spike
I think I understand the separation between Orbeon and container based authentication a little better now. And though I think it would be handy, I think this separation must be why Orbeon doesn't have built in capabilities of displaying the logged in user and enabling logout. I'm attempting to implement these things now. I would love some feedback on my method. This is what I'm doing:

First, I created a logout.jsp file in the root of the Orbeon war directory. For simplicity of testing I have hardcoded a redirect URL. After accessing this page, and then attempting to access a protected page, I am prompted to authenticate. Is this sufficient? Would someone with better knowledge of best practices do this differently?

<%@ page session="true"%>
<%
session
.invalidate();
response
.sendRedirect("/orbeon/");
%>

Next I have overridden the apps/fr/theme.xsl file and appended the following template. This provides a working logout link on the navbar which I have styled in a custom css file (added with the oxf.fr.css.custom.uri property). I would love to have a better match rule. I had trouble distinguishing between the two navbars in form builder, thus 'navbar-inverse'. I'd love to hear XSL improvements too.

    <xsl:template match="xh:div[contains(@class,'navbar-inverse')]/xh:div[contains(@class,'navbar-inner')]/xh:div[contains(@class,'container')]">
       
<xsl:copy>
           
<xsl:apply-templates select="@*|node()"/>
           
<xsl:variable name="current-user" select="' '" />
           
<xsl:if test="$current-user != ''">
               
<xh:span class="pull-right logout-link">
                   
<xh:a href="/logout.jsp">logout <xsl:value-of select="$current-user"/></xh:a>
               
</xh:span>
           
</xsl:if>
       
</xsl:copy>
   
</xsl:template>

I would like to make the logout link created by the above template serve double duty and display the user name of the currently logged in user. I found the following solution on StackOverflow (http://stackoverflow.com/questions/13613661/orbeon-how-to-display-username-on-page-banner-using-epilogue) but I can't crack the syntax needed to accomplish the chained calls to get from NetUtils all the way to getRemoteUser. A single level call works fine. org.orbeon.oxf.util.NetUtils.getExternalContext().getRequest().getRemoteUser()

Aaron Spike


This electronic communication, including any attached documents, may contain confidential and/or legally privileged information that is intended only for use by the recipient(s) named above. If you have received this communication in error, please notify the sender immediately and delete the communication and any attachments. Views expressed by the author do not necessarily represent those of Martin Luther College.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Logout Logged in User

Alessandro  Vernet
Administrator
Hi Aaron,

The way you're doing the logout looks good to me. And based on the discussion on Twitter, which I imagine happened after this post, using p:get-remote-user() is working for you, correct?

Alex

On Tue, Mar 24, 2015 at 1:02 PM Aaron Spike <[hidden email]> wrote:
I think I understand the separation between Orbeon and container based authentication a little better now. And though I think it would be handy, I think this separation must be why Orbeon doesn't have built in capabilities of displaying the logged in user and enabling logout. I'm attempting to implement these things now. I would love some feedback on my method. This is what I'm doing:

First, I created a logout.jsp file in the root of the Orbeon war directory. For simplicity of testing I have hardcoded a redirect URL. After accessing this page, and then attempting to access a protected page, I am prompted to authenticate. Is this sufficient? Would someone with better knowledge of best practices do this differently?

<%@ page session="true"%>
<%
session
.invalidate();
response
.sendRedirect("/orbeon/");
%>

Next I have overridden the apps/fr/theme.xsl file and appended the following template. This provides a working logout link on the navbar which I have styled in a custom css file (added with the oxf.fr.css.custom.uri property). I would love to have a better match rule. I had trouble distinguishing between the two navbars in form builder, thus 'navbar-inverse'. I'd love to hear XSL improvements too.

    <xsl:template match="xh:div[contains(@class,'navbar-inverse')]/xh:div[contains(@class,'navbar-inner')]/xh:div[contains(@class,'container')]">
       
<xsl:copy>
           
<xsl:apply-templates select="@*|node()"/>
           
<xsl:variable name="current-user" select="' '" />
           
<xsl:if test="$current-user != ''">
               
<xh:span class="pull-right logout-link">
                   
<xh:a href="/logout.jsp">logout <xsl:value-of select="$current-user"/></xh:a>
               
</xh:span>
           
</xsl:if>
       
</xsl:copy>
   
</xsl:template>

I would like to make the logout link created by the above template serve double duty and display the user name of the currently logged in user. I found the following solution on StackOverflow (http://stackoverflow.com/questions/13613661/orbeon-how-to-display-username-on-page-banner-using-epilogue) but I can't crack the syntax needed to accomplish the chained calls to get from NetUtils all the way to getRemoteUser. A single level call works fine. org.orbeon.oxf.util.NetUtils.getExternalContext().getRequest().getRemoteUser()

Aaron Spike


This electronic communication, including any attached documents, may contain confidential and/or legally privileged information that is intended only for use by the recipient(s) named above. If you have received this communication in error, please notify the sender immediately and delete the communication and any attachments. Views expressed by the author do not necessarily represent those of Martin Luther College.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Logout Logged in User

Aaron Spike
Yes, p:get-remote-user() works fabulously. 

Can you comment on the syntax for making calls to Java from XSL? I know I can do:

<xsl:value-of xmlns:utils="java:org.orbeon.oxf.util.NetUtils" select="utils:getExternalContext()"/>

But I don't see how it is possible to follow this with getRequest() and then getRemoteUser()? Is is possible or must anything requiring a chain of calls like this be rolled into a helper method on a Java class somewhere to call as a unit?

Aaron Spike



This electronic communication, including any attached documents, may contain confidential and/or legally privileged information that is intended only for use by the recipient(s) named above. If you have received this communication in error, please notify the sender immediately and delete the communication and any attachments. Views expressed by the author do not necessarily represent those of Martin Luther College.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Logout Logged in User

Alessandro  Vernet
Administrator
Hi Aaron,

Yes, it is possible, with code along the lines of:

<xsl:variable name="externalContext" xmlns:utils="java:org.orbeon.oxf.util.NetUtils" select="utils:getExternalContext()"/>
<xsl:variable name="username" xmlns:ec="java:org.orbeon.oxf.pipeline.api.ExternalContext" select="ec:getUsername(externalContext)"/>

But as you can see, it is a pain to write: the code is extremely verbose, you have no indication on whether your code is correct until you run it, and errors can be cryptic. So you'll find pretty quickly that you're better off writing a static method somewhere that does all the calls you need, so you can call it directly.

Alex

On Fri, Mar 27, 2015 at 5:34 AM Aaron Spike <[hidden email]> wrote:
Yes, p:get-remote-user() works fabulously. 

Can you comment on the syntax for making calls to Java from XSL? I know I can do:

<xsl:value-of xmlns:utils="java:org.orbeon.oxf.util.NetUtils" select="utils:getExternalContext()"/>

But I don't see how it is possible to follow this with getRequest() and then getRemoteUser()? Is is possible or must anything requiring a chain of calls like this be rolled into a helper method on a Java class somewhere to call as a unit?

Aaron Spike



This electronic communication, including any attached documents, may contain confidential and/or legally privileged information that is intended only for use by the recipient(s) named above. If you have received this communication in error, please notify the sender immediately and delete the communication and any attachments. Views expressed by the author do not necessarily represent those of Martin Luther College.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Logout Logged in User

Aaron Spike
Thanks for the very helpful example.

Aaron Spike

This electronic communication, including any attached documents, may contain confidential and/or legally privileged information that is intended only for use by the recipient(s) named above. If you have received this communication in error, please notify the sender immediately and delete the communication and any attachments. Views expressed by the author do not necessarily represent those of Martin Luther College.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].