<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay 7.1: get the logged-in user in a @ManagedBean</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110902019" />
  <subtitle>Liferay 7.1: get the logged-in user in a @ManagedBean</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110902019</id>
  <updated>2026-04-05T01:49:54Z</updated>
  <dc:date>2026-04-05T01:49:54Z</dc:date>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110948213" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110948213</id>
    <updated>2018-09-13T17:21:29Z</updated>
    <published>2018-09-13T17:21:29Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi Claus,&lt;br&gt; Can you try using &lt;a href="https://docs.liferay.com/ce/portal/7.1-latest/javadocs/portal-kernel/com/liferay/portal/kernel/util/PortalUtil.html#getUser-javax.portlet.PortletRequest-"&gt;&lt;code&gt;PortalUtil.getUser()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code class="hljs avrasm"&gt;FacesContext facesContext = FacesContext&amp;lt;span class="hljs-preprocessor"&amp;gt;.getCurrentInstance&amp;lt;/span&amp;gt;()&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;
ExternalContext externalContext = facesContext&amp;lt;span class="hljs-preprocessor"&amp;gt;.getExternalContext&amp;lt;/span&amp;gt;()&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;
PortletRequest portletRequest = (PortletRequest) externalContext&amp;lt;span class="hljs-preprocessor"&amp;gt;.getRequest&amp;lt;/span&amp;gt;()&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;
User user = &amp;lt;span class="hljs-keyword"&amp;gt;com&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.liferay&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.portal&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.kernel&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.util&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.PortalUtil&amp;lt;/span&amp;gt;&amp;lt;span class="hljs-preprocessor"&amp;gt;.getUser&amp;lt;/span&amp;gt;(portletRequest)&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also, make sure that your Liferay Portal dependencies are marked
  &lt;code&gt;&amp;amp;lt;scope&amp;amp;gt;provided&amp;amp;lt;/scope&amp;amp;gt;&lt;/code&gt; (for Maven) or
  &lt;code&gt;providedCompile&lt;/code&gt; (for Gradle) so that they are not
  included in your WAR’s &lt;strong&gt;
    &lt;code&gt;WEB-INF/lib&lt;/code&gt;&lt;/strong&gt; folder. Otherwise you may have
  duplicate Liferay Portal classes on the classpath which can cause the
  WAR to fail to deploy.&lt;/p&gt;
&lt;p&gt;If that doesn’t work, please provide the &lt;a href="http://sscce.org"&gt;shortest, simplest portlet that reproduces
    the issue&lt;/a&gt;&amp;nbsp;and attach it to your post.&lt;/p&gt;
&lt;p&gt;- Kyle&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-13T17:21:29Z</dc:date>
  </entry>
  <entry>
    <title>Moved to the Liferay Faces - English category.</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110948181" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110948181</id>
    <updated>2018-09-13T17:03:15Z</updated>
    <published>2018-09-13T17:03:15Z</published>
    <summary type="html">Moved to the Liferay Faces - English category.</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-13T17:03:15Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110932384" />
    <author>
      <name>Claus Lüthje</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110932384</id>
    <updated>2018-09-12T06:14:59Z</updated>
    <published>2018-09-12T06:14:59Z</published>
    <summary type="html">&lt;p&gt;Hi Christoph,&lt;/p&gt;
&lt;p&gt;thanks for the hint. My portlet is in active state and no unresolved
  dependencies (or versions) are shown when using diag.&lt;/p&gt;
&lt;p&gt;While this widget is visible with 'lb' and 'diag' it can't be found
  to be added to the page.&lt;/p&gt;
&lt;p&gt;Deployment went by without problems (apart from &lt;a
  href="https://issues.liferay.com/browse/LPS-84485"&gt;https://issues.liferay.com/browse/LPS-84485&lt;/a&gt;
  , which doesn't seem to matter in this context)&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Claus&lt;/p&gt;</summary>
    <dc:creator>Claus Lüthje</dc:creator>
    <dc:date>2018-09-12T06:14:59Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110928836" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110928836</id>
    <updated>2018-09-11T16:08:48Z</updated>
    <published>2018-09-11T16:08:48Z</published>
    <summary type="html">&lt;p&gt;Look into the gogo shell, it's available from the control panel in 7.1&lt;/p&gt;

&lt;p&gt;https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/using-the-felix-gogo-shell&lt;br /&gt;  &lt;/p&gt;
&lt;p&gt;Enter &amp;quot;lb &amp;lt;yourmodule&amp;gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;(or only &amp;quot;lb&amp;quot; if you are not sure about the name and skim
  the list to find your module)&lt;/p&gt;
&lt;p&gt;I guess, it will be in resolved state. Try &amp;quot;diag&amp;quot; and it
  probably will show you that it is missing at least one dependency. My
  best guess is that you have a dependency on a 7.0 version of some
  module instead of a 7.1 version. In that case, you probably just need
  to increase the version number in gradle. But that's just guesswork.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2018-09-11T16:08:48Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110924405" />
    <author>
      <name>Claus Lüthje</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110924405</id>
    <updated>2018-09-11T11:15:10Z</updated>
    <published>2018-09-11T11:15:10Z</published>
    <summary type="html">&lt;p&gt;I added LiferayPortletHelperUtil.getUser(); to get the user, but when
  I add the corresponding Maven dependencies, the portlet isn't deployed anymore.&lt;/p&gt;
&lt;p&gt;My code looks like this:&lt;/p&gt;
&lt;pre&gt;
User user = LiferayPortletHelperUtil.getScopeGroupUser();

if (user != null) { 
	try {
		System.out.println(&amp;quot;*** Login: &amp;quot;+user.getLogin());
		System.out.println(&amp;quot;*** Full Name: &amp;quot;+user.getFullName());
	} catch (PortalException ex) {
		// log error
	}
}												}&lt;/pre&gt;
&lt;p&gt;I don't get any errors in the log. The portlet just isn't available
  for selection in the UI.&lt;/p&gt;
&lt;p&gt;As the JARs don't seem to be provided, I tried to include them into
  the war. This didn't help&lt;/p&gt;</summary>
    <dc:creator>Claus Lüthje</dc:creator>
    <dc:date>2018-09-11T11:15:10Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110921480" />
    <author>
      <name>Claus Lüthje</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110921480</id>
    <updated>2018-09-11T06:37:45Z</updated>
    <published>2018-09-11T06:37:45Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;I try to be more specific, which may be a little hard as I'm not at
  liberty to share the code in its interity.&lt;/p&gt;
&lt;p&gt;I use Liveray 7.1 GA 1 CE on Java 8.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Let's give it a try:&lt;/p&gt;
&lt;p&gt;I have a ManagedBean declared like this:&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;
  &lt;code&gt;&amp;amp;nbsp;&amp;amp;nbsp;&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;
@ManagedBean(name = "mybean")
@ViewScoped
public class MyBean implements Serializable {

// ...

	public void startWork(){

		// here I need the currently logged-in used

	}

//…
}&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;Accessing the managed bean, I have a JSF-based XHTML with PrimeFaces:&lt;/p&gt;
&lt;pre&gt;
&amp;lt;h:body&amp;gt;

	&amp;lt;h:form&amp;gt;
		...
		&amp;lt;p:ajax event="rowDblselect" listener="#{mybean.startWork()}" /&amp;gt;
		…
	&amp;lt;/h:form&amp;gt;
&amp;lt;/h:body&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;This basically works fine. The only&amp;nbsp;thing I don't&amp;nbsp;know how to
  &amp;nbsp;achieve is a reference to the currently logged-in&amp;nbsp;user.&lt;/p&gt;
&lt;p&gt;I hope this clarifies things a Little...&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Claus&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Claus Lüthje</dc:creator>
    <dc:date>2018-09-11T06:37:45Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110917933" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110917933</id>
    <updated>2018-09-10T14:44:09Z</updated>
    <published>2018-09-10T14:44:09Z</published>
    <summary type="html">&lt;blockquote&gt;
  &lt;div class="quote-title"&gt;Claus Lüthje:&lt;/div&gt;
  &lt;div class="quote"&gt;
    &lt;div class="quote-content"&gt;
      &lt;p&gt;Is this possible or am I approaching the issue wrongly?&lt;br /&gt;
        Any help or comment is very welcome.&lt;/p&gt;
      &lt;p&gt;Regards,&lt;/p&gt;
      &lt;p&gt;Claus&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;When nobody reacts, it often helps to get more specific. Post code, a
  minimal sample. What do you have, how do you use it - e.g. is it on
  the HTTP-touching layer? On the business layer?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Quite often, identity should be explicit part of the API, but I have
  no clue if this would be good here, as I'm not sure what you're doing
  where, why and how.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2018-09-10T14:44:09Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110913973" />
    <author>
      <name>Claus Lüthje</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110913973</id>
    <updated>2018-09-10T09:28:33Z</updated>
    <published>2018-09-10T09:28:33Z</published>
    <summary type="html">&lt;p&gt;Is this possible or am I approaching the issue wrongly?&lt;br /&gt; Any
  help or comment is very welcome.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Claus&lt;/p&gt;</summary>
    <dc:creator>Claus Lüthje</dc:creator>
    <dc:date>2018-09-10T09:28:33Z</dc:date>
  </entry>
  <entry>
    <title>Liferay 7.1: get the logged-in user in a @ManagedBean</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110902018" />
    <author>
      <name>Claus Lüthje</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110902018</id>
    <updated>2018-09-07T08:35:11Z</updated>
    <published>2018-09-07T08:35:11Z</published>
    <summary type="html">&lt;p&gt;I use Liferay 7.1 GA-1. I want to access the currently logged-in user Information.&lt;/p&gt;
&lt;p&gt;How is this done?&lt;/p&gt;</summary>
    <dc:creator>Claus Lüthje</dc:creator>
    <dc:date>2018-09-07T08:35:11Z</dc:date>
  </entry>
</feed>
