List of usage examples for com.liferay.portal.kernel.util WebKeys USER_ID
String USER_ID
To view the source code for com.liferay.portal.kernel.util WebKeys USER_ID.
Click Source Link
From source file:com.liferay.chat.hook.events.SessionDestroyAction.java
License:Open Source License
@Override public void run(HttpSession session) { Long userId = (Long) session.getAttribute(WebKeys.USER_ID); JabberUtil.disconnect(userId); }
From source file:com.marcelmika.lims.portal.domain.Buddy.java
License:Open Source License
/** * Factory method which creates new Buddy object from HttpSession * * @param session HttpSession/*from w w w .j a v a2 s. c o m*/ * @return Buddy */ public static Buddy fromHttpSession(HttpSession session) { // Create new buddy Buddy buddy = new Buddy(); // Get user ID from http session buddy.buddyId = (Long) session.getAttribute(WebKeys.USER_ID); return buddy; }
From source file:com.siemens.sw360.portal.users.LoginAction.java
License:Open Source License
private static long getLiferayUserId(HttpServletRequest request) { long userId = -1; Object fromWebKey = request.getAttribute(WebKeys.USER_ID); if (fromWebKey != null && fromWebKey instanceof Long) { userId = (Long) fromWebKey; }//from w w w. j a v a 2s .c om if (userId <= 0) { userId = CommonUtils.toUnsignedInt(request.getRemoteUser()); } return userId; }
From source file:com.vportal.portal.servlet.PortalSessionListener.java
License:Open Source License
public void sessionDestroyed(HttpSessionEvent event) { /*if (PropsValues.SESSION_DISABLED) { return;/*from w w w .jav a 2 s .co m*/ }*/ //hoan if (GetterUtil.getBoolean(PropsUtil.get("SESSION_DISABLED"))) { return; } //hoan HttpSession ses = event.getSession(); MethodKey method = new MethodKey("com.liferay.portal.kernel.util.Validator.PortalSessionContext", "remove", String.class); Object[] args = new Object[] { ses.getId() }; try { PortalClassInvoker.invoke(false, method, args); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //PortalSessionContext.remove(ses.getId()); try { Long userIdObj = (Long) ses.getAttribute(WebKeys.USER_ID); if (userIdObj == null) { _log.warn("User id is not in the session"); } else { long userId = userIdObj.longValue(); if (CompanyThreadLocal.getCompanyId() == 0) { setCompanyId(userId); } //MailSessionLock.cleanUp(ses); MethodKey methodSignOut = new MethodKey("com.liferay.portal.liveusers.LiveUsers", "signOut", long.class, String.class, String.class); Object[] argsSignOut = new Object[] { CompanyThreadLocal.getCompanyId(), userId, ses.getId() }; PortalClassInvoker.invoke(false, methodSignOut, argsSignOut); //LiveUsers.signOut(CompanyThreadLocal.getCompanyId(), userId, ses.getId()); } } catch (IllegalStateException ise) { _log.warn("Please upgrade to a servlet 2.4 compliant container"); } catch (Exception e) { _log.error(e, e); } //ses.removeAttribute(WebKeys.PORTLET_SESSION_TRACKER); //ses.removeAttribute(WebKeys.REVERSE_AJAX); //MessagingUtil.closeXMPPConnection(ses); // Process session destroyed events try { /*EventsProcessor.process( PropsKeys.SERVLET_SESSION_DESTROY_EVENTS, PropsValues.SERVLET_SESSION_DESTROY_EVENTS, ses);*/ //hoan MethodKey methodProcess = new MethodKey("com.liferay.portal.events.EventsProcessorUtil", "process", String.class, String.class, HttpSession.class); Object[] argsProcess = new Object[] { PropsKeys.SERVLET_SESSION_DESTROY_EVENTS, PropsUtil.getArray(PropsKeys.SERVLET_SESSION_DESTROY_EVENTS), ses }; PortalClassInvoker.invoke(false, methodProcess, argsProcess); /*EventsProcessorUtil.process( PropsKeys.SERVLET_SESSION_DESTROY_EVENTS, PropsValues.SERVLET_SESSION_DESTROY_EVENTS, ses);*/ //hoan } catch (ActionException ae) { _log.error(ae, ae); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:it.publisys.liferay.hook.shibboleth.ShibbolethAutoLogin.java
License:Open Source License
@SuppressWarnings("unchecked") public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException { if (_log.isDebugEnabled()) { _log.debug(" - start"); }// ww w . j a v a 2 s.c om String[] credentials = null; // boolean _isNew = false; long companyId = 0; // String _ltype = request.getParameter(LTYPE_PARAM); String _login = null; User _user = null; try { // verifico se il request path e' quello di login if (request.getRequestURI().contains(LOGIN_PATH)) { if (_log.isDebugEnabled()) { _log.debug(LTYPE_PARAM + ": " + _ltype); } // verifico che il parametro 'ltype' sia 'shibb' if (Validator.isNotNull(_ltype) && LTYPE_VALUE.equals(_ltype)) { if (_log.isDebugEnabled()) { Enumeration<Object> _ens = request.getHeaderNames(); while (_ens.hasMoreElements()) { Object _o = _ens.nextElement(); if (_o.toString().startsWith(SHIB_PREFIX)) { _log.debug("*=*=* " + _o + ": " + request.getHeader(_o.toString())); } } } String authType = getAuthType(companyId); // Parametro trasmesso dallo ShibbolethSP assunto come default _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_EMAIL); if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) { _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_FISCAL_NUMBER); } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) { _login = request.getHeader(ShibbolethPropsValues.SHIBBOLETH_EMAIL); } if (Validator.isNotNull(_login)) { _login = _login.toUpperCase(); companyId = PortalUtil.getCompany(request).getCompanyId(); if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) { _log.info("Login by ScreenName: " + _login); _user = loginByScreenName(companyId, _login); } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) { _log.info("Login by Email: " + _login); _user = loginByEmail(companyId, _login); } if (_user == null) { _log.warn( String.format("Utente non presente in archivio Liferay. [_login:%s]", _login)); throw new NoSuchUserException("Utente non presente in archivio Liferay."); } credentials = new String[] { String.valueOf(_user.getUserId()), _user.getPassword(), String.valueOf(_user.isPasswordEncrypted()) }; request.getSession().setAttribute(WebKeys.USER_ID, _user.getUserId()); } else { SessionMessages.add(request, "shibbError", "Parametri per la login non ricevuti."); throw new AutoLoginException("Parametri per la login non ricevuti."); } } } } catch (NoSuchUserException e) { _log.warn("No Such User with login: " + _login + ". Insert new User."); _isNew = true; } catch (Exception e) { _log.error("Generic Error.", e); SessionMessages.add(request, "shibbError", "Si è verificato un errore. Riprovare più tardi."); throw new AutoLoginException(e); } // creare nuovo utente se _isNew if (_isNew) { _user = _createNewUser(companyId, request); if (_user != null) { credentials = new String[] { String.valueOf(_user.getUserId()), _user.getPassword(), String.valueOf(_user.isPasswordEncrypted()) }; request.getSession().setAttribute(WebKeys.USER_ID, _user.getUserId()); } } if (_user != null) { _updateUser(_user, request); // aggiorno la data di ultimo accesso try { UserLocalServiceUtil.updateLastLogin(_user.getUserId(), request.getRemoteAddr()); } catch (PortalException e) { _log.warn( "Impossibile aggiornare la data di ultimo accesso dell'utente [" + _user.getUserId() + "]", e); } catch (SystemException e) { _log.warn( "Impossibile aggiornare la data di ultimo accesso dell'utente [" + _user.getUserId() + "]", e); } } String _redirecturl = request.getParameter("redirecturl"); if (_redirecturl != null && "true".equals(_redirecturl)) { _log.info("============================================"); _log.info("[Redirect URL] " + _redirecturl); _log.info("Effettuo la redirect"); String _sname = request.getParameter("sname"); _log.info("[sname] " + _sname); String _path = request.getParameter("path"); _log.info("[path] " + _path); Map<String, String[]> params = new HashMap<String, String[]>(); params.put("sname", new String[] { _sname }); LastPath lastPath = new LastPath("/", _path, params); request.getSession().setAttribute(WebKeys.LAST_PATH, lastPath); _log.info("[LastPath] " + lastPath); _log.info("============================================"); } return credentials; }