Fórum

Login with Screen Name not working with JOSSO

raj kumar, modificado 12 Anos atrás.

Login with Screen Name not working with JOSSO

New Member Postagens: 3 Data de Entrada: 23/03/12 Postagens Recentes
Hi,

We have made JOSSO to handle the Liferay Login instead of the Sign In portlet. We have configured JOSSO and Liferay to point the same database (Liferay DataBase) to store the user credentials. Our requirement is to login through ScreenName of the user from JOSSO. The JOSSO authenticates the user by ScreenName perfectly, but later when redirecting the user to the Liferay page, it throws a com.liferay.portal.NoSuchUserException saying “no user exists with the primary key 0”  and ends up landing on a Blank page. This exception is thrown while invoking loginUser method from com.liferay.portal.servlet.MainServlet class. Please find the code for service() in MainServlet below which throws the exception:

*************************************************************************************************
long userId = getUserId(request);
String remoteUser = getRemoteUser(request, userId);

if (_log.isDebugEnabled()) {
_log.debug("Protect request");
}
request = protectRequest(request, remoteUser);
if (_log.isDebugEnabled()) {
_log.debug("Set principal");
}
setPrincipalName(userId, remoteUser);
try {
if (_log.isDebugEnabled()) {
_log.debug(
"Authenticate user id " + userId + " and remote user " + remoteUser);
}
userId = loginUser(request, response, userId, remoteUser);
if (_log.isDebugEnabled()) {
_log.debug("Authenticated user id " + userId);
}
}
catch (Exception e) {
_log.error(e, e);
}
************************************************************************************************
protected long loginUser(
HttpServletRequest request, HttpServletResponse response,
long userId, String remoteUser)
throws PortalException, SystemException {

if ((userId > 0) || (remoteUser == null)) {
return userId;
}

userId = GetterUtil.getLong(remoteUser); // throws NumberFormatException

EventsProcessorUtil.process(
PropsKeys.LOGIN_EVENTS_PRE, PropsValues.LOGIN_EVENTS_PRE, request,
response);
User user = UserLocalServiceUtil.getUserById(userId);
if (PropsValues.USERS_UPDATE_LAST_LOGIN) {
UserLocalServiceUtil.updateLastLogin(
userId, request.getRemoteAddr());
}
HttpSession session = request.getSession();
session.setAttribute(WebKeys.USER_ID, new Long(userId));
session.setAttribute(Globals.LOCALE_KEY, user.getLocale());

EventsProcessorUtil.process(
PropsKeys.LOGIN_EVENTS_POST, PropsValues.LOGIN_EVENTS_POST,
request, response);
return userId;
}
*****************************************************************************************************************
The problem is when JOSSO authenticates the user, request.getRemoteUser() returns the ScreenName and hence this code userId = GetterUtil.getLong(remoteUser) throws NumberFormatException and then followed by com.liferay.portal.NoSuchUserException saying “no user exists with the primary key 0”.

Please help me in resolving this issue. Thanks.
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Login with Screen Name not working with JOSSO

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes


long companyId =PortalUtil.getDefaultCompanyId();
userId = UserLocalServiceUtil.getUserByScreenName(remoteUser).getUserId();


Please try the above code

Regards,
Sandeep
raj kumar, modificado 12 Anos atrás.

RE: Login with Screen Name not working with JOSSO

New Member Postagens: 3 Data de Entrada: 23/03/12 Postagens Recentes
where should i add that code???

can i make changes to MainServlet.java???

what i mean is can i write my custom class for MainServlet and configure in web.xml???
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Login with Screen Name not working with JOSSO

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Are you having a custom AutoLogin Hook?
raj kumar, modificado 12 Anos atrás.

RE: Login with Screen Name not working with JOSSO

New Member Postagens: 3 Data de Entrada: 23/03/12 Postagens Recentes
Nope we dont have any custom auto login hook