<?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>Problem with Pre Events, Login and Post Events</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110946472" />
  <subtitle>Problem with Pre Events, Login and Post Events</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110946472</id>
  <updated>2026-05-06T08:42:02Z</updated>
  <dc:date>2026-05-06T08:42:02Z</dc:date>
  <entry>
    <title>RE: Problem with Pre Events, Login and Post Events</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110991060" />
    <author>
      <name>Minhchau Dang</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110991060</id>
    <updated>2018-09-19T23:13:36Z</updated>
    <published>2018-09-19T23:13:36Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;blockquote&gt;
  &lt;div class="quote-title"&gt;Riccardo Saponi:&lt;/div&gt;
  &lt;div class="quote"&gt;
    &lt;div class="quote-content"&gt;
      &lt;p&gt;With a little debug we see that in Post Action the user have
        the old status (inactive). User is retrieved with &lt;strong&gt;
          &lt;code&gt;PortalUtil.getUser(httpservletrequest)&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
      &lt;p&gt;I think that this is the User in Liferay Session.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;Close. If you look at the source code for &lt;a href="https://github.com/liferay/liferay-portal/blob/6.2.4-ga5/portal-impl/src/com/liferay/portal/util/PortalImpl.java#L5356-L5420"&gt;PortalImpl.getUser()&lt;/a&gt;,
  you'll see that it's saved as an attribute on the request.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;div class="quote-title"&gt;Riccardo Saponi:&lt;/div&gt;
  &lt;div class="quote"&gt;
    &lt;div class="quote-content"&gt;
      &lt;p&gt;The Answer is: why during the login Liferay does not update the
        user in session? And why this happens only on the first attempt?&lt;/p&gt;
      &lt;p&gt;There is a way to avoid this behaviour?&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;Sure, after you've updated the user, just replace the request
  attribute with your updated user. As for why Liferay doesn't do this
  for you automatically, it's probably because Liferay developers are human.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Minhchau Dang</dc:creator>
    <dc:date>2018-09-19T23:13:36Z</dc:date>
  </entry>
  <entry>
    <title>Problem with Pre Events, Login and Post Events</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110946471" />
    <author>
      <name>Riccardo Saponi</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110946471</id>
    <updated>2018-09-13T14:50:42Z</updated>
    <published>2018-09-13T14:50:42Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi guys,&lt;/p&gt;
&lt;p&gt;a strange problem in one of our Liferay 6.2 ga4.&lt;/p&gt;
&lt;p&gt;We have a installation in a&lt;strong&gt; Centos Server&lt;/strong&gt;, with a
    &lt;strong&gt;Liferay 6.2 ga4&lt;/strong&gt; and an integration with another
  user&amp;nbsp;repository (external database).&lt;/p&gt;
&lt;p&gt;We have made a Pre-Login Action and a Post-Login Action.&lt;/p&gt;
&lt;p&gt;In the Pre-Login Action we read the external user repository and we
  create or update users in Liferay (with Groups and Roles associated).&lt;/p&gt;
&lt;p&gt;In the Post-Login Action we do some operation fo the landing page.&lt;/p&gt;
&lt;p&gt;In the Pre-Login Action we also set the Status of the User based on
  the external one. If we disable the external user, we set the status&amp;nbsp;&lt;strong&gt;
    &lt;code&gt;WorkflowConstants.STATUS_INACTIVE&lt;/code&gt;&lt;/strong&gt; in Liferay
  User, and when we re-enable this user we do the same in Liferay User.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now....&lt;/p&gt;
&lt;p&gt;During the process of re-activation, we set the status with the &lt;strong&gt;
    &lt;code&gt;UserLocalServiceUtil&lt;/code&gt;&lt;/strong&gt; API (&lt;strong&gt;
    &lt;code&gt;updateStatus&lt;/code&gt;&lt;/strong&gt;). We check the Liferay DB and we
  see the status updated.&lt;/p&gt;
&lt;p&gt;But...&lt;/p&gt;
&lt;p&gt;When this user login for the first time after the re-activation we
  have the Inactive Message&amp;nbsp; (see the attachment).&lt;/p&gt;
&lt;p&gt;With a little debug we see that in Post Action the user have the old
  status (inactive). User is retrieved with &lt;strong&gt;
    &lt;code&gt;PortalUtil.getUser(httpservletrequest)&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I think that this is the User in Liferay Session.&lt;/p&gt;
&lt;p&gt;So...in the Pre-Login we have the user's status with value &lt;strong&gt;
    &lt;code&gt;WorkflowConstants.STATUS_APPROVED&lt;/code&gt;&lt;/strong&gt;, and in the
  Post-Login we have the user's status with value&amp;nbsp;&lt;strong&gt;
    &lt;code&gt;WorkflowConstants.STATUS_INACTIVE.&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The next strange thing is that &lt;u&gt;after a reload of the page&lt;/u&gt; the
  user is logged and active.&lt;/p&gt;
&lt;p&gt;The Answer is: why during the login Liferay does not update the user
  in session? And why this happens only on the first attempt?&lt;/p&gt;
&lt;p&gt;There is a way to avoid this behaviour?&lt;/p&gt;
&lt;p&gt;We have already tried with some re-index operation but nothing
  change. Se the code below.&lt;/p&gt;
&lt;p&gt;
  &lt;code&gt;Indexer userIndexer =
    IndexerRegistryUtil.getIndexer(User.class.getName());&amp;lt;br&amp;gt;
    userIndexer.reindex(User.class.getName(), user.getUserId());&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Riccardo Saponi</dc:creator>
    <dc:date>2018-09-13T14:50:42Z</dc:date>
  </entry>
</feed>
