Foren

No User exists with the primary key 0

Hubert Felber, geändert vor 13 Jahren.

No User exists with the primary key 0

Regular Member Beiträge: 157 Beitrittsdatum: 23.11.09 Neueste Beiträge
Hi,
I am testing with trunk revision 54478 from 2.6.2010
On some pages (like "My Account) I get
ERROR [IncludeTag] com.liferay.portal.NoSuchUserException: No User exists with the primary key 0

Reason:
We are using JAAS and are authenticating by screenname.
In this very case ("my account") Liferay internally stored the name in PrincipalBean as "administrator" which results in 0 when calling GetterUtil.getLong(name).

We defined an AutoLoginFilter where we overwrite getRemoteUser() to return the numerical userId from screenName to Liferay. But this seams to be not sufficient.
The filter has the following mappings:

<url-pattern>/c/portal/protected</url-pattern>
<url-pattern>/c/layout_management/update_page</url-pattern>

Questions:
  • Is AutoLoginFilter the correct method to ensure that Liferay gets the numerical UserId where ever it is needed? If not, what should I do?
  • Is there a rule on what url-pattern I have to map this autologin filter?
  • How would this work if the URL additionally contained the language like e.g. "/de/c/portal/proteced")? In the latter case I have to remove the language (de,en,it) programmatically from the URL in (overloaded) LoginAction to make Liferay display the page at all (only with JAAS enabled).

Thank you
Hubert
Hubert Felber, geändert vor 13 Jahren.

RE: No User exists with the primary key 0

Regular Member Beiträge: 157 Beitrittsdatum: 23.11.09 Neueste Beiträge
Hi
In com.liferay.portlet.login.util.login() the j_remoteUser attribute is set which has the correct value.
In com.liferay.portal.servlet.MainServlet.getRemoteUser() Liferay calls request.getRemoteUser() and then sometimes receives the screen name. But the j_remoteUser attribute would have the correct value, but is not used when JAAS is enabled. If this would be used, it would not be necessary to establish filter to map remote screen name to Liferay internal userID.
What is the reason for this?
Thank you
Hubert
thumbnail
Jorge Ferrer, geändert vor 13 Jahren.

RE: No User exists with the primary key 0

Liferay Legend Beiträge: 2871 Beitrittsdatum: 31.08.06 Neueste Beiträge
Hi Hubert,

Is this something new in 6.0 or also happened in 5.2. If it's the latter I'd recommend you to create a JIRA ticket for it.
Hubert Felber, geändert vor 13 Jahren.

RE: No User exists with the primary key 0

Regular Member Beiträge: 157 Beitrittsdatum: 23.11.09 Neueste Beiträge
Jorge Ferrer:
...create a JIRA ticket for it.
Hi Jorge, I did that, including a workaround that works for me.
Regards
Hubert
thumbnail
Jorge Ferrer, geändert vor 13 Jahren.

RE: No User exists with the primary key 0

Liferay Legend Beiträge: 2871 Beitrittsdatum: 31.08.06 Neueste Beiträge
Thanks Hubert,

Thanks for creating the tickets. We have many tickets open right now, many of which are not real issues so it's becoming very hard to distinguish those that are most worthy. We have a plan to fix this, but meanwhile, for this type of issues it's best if you also create a comment and (this is very important) link to the JIRA ticket.

I've taken a look at your proposed patch, but it seems all it does is log an error if the remoteUser is not a number. How does that fix the issue?
Hubert Felber, geändert vor 13 Jahren.

RE: No User exists with the primary key 0

Regular Member Beiträge: 157 Beitrittsdatum: 23.11.09 Neueste Beiträge
Jorge Ferrer:
How does that fix the issue?

Jorge,

If it is not a number it cannot be a valid Liferay user id which is numeric only.
This means that getRemoteUser() returned the screenname used by the user to sign in.
And it also means that I don't have a filter set for this URL (therefore the error message).
In this case I take the remoteuser from the "j_remoteuser" session attribute.
remoteUser = (String) request.getSession().getAttribute("j_remoteuser");

The "j_remoteuser" is set by com.liferay.portlet.login.util.LoginUtil.
If JAAS is enabled, this attribute remains in the session while it is removed if JAAS is not configured. This works for us because we don't have AllNumericUserNames.
Actually I don't see a reason why not to use always an attribute like this to get the Liferay internal user id.

Hubert
Michael Oliver, geändert vor 9 Jahren.

RE: No User exists with the primary key 0

Junior Member Beiträge: 66 Beitrittsdatum: 19.04.12 Neueste Beiträge
While this may not be related, I am getting the same exception when trying to update an organization via /api/jsonws/

http://localhost:8080/api/jsonws/organization/update-organization/organization-id/12501/parent-organization-id/0/name/abcnew2a/type/regular-organization/recursable/true/region-id/0/country-id/0/status-id/12017/comments/updated+Through+Jsonws+again/site/false
resultJson = {"exception":"No User exists with the primary key 0"}


I am logged in as the same admin user that I used to create the organization in the first place, and here I am updating the organization name by appending the 'a' and changing the comments.