List of usage examples for com.liferay.portal.kernel.util WebKeys LAST_PATH
String LAST_PATH
To view the source code for com.liferay.portal.kernel.util WebKeys LAST_PATH.
Click Source Link
From source file:com.liferay.so.hook.events.SOUserDefaultLandingPageAction.java
License:Open Source License
protected void doRun(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = PortletPropsValues.SO_USER_DEFAULT_LANDING_PAGE_PATH; if (Validator.isNull(path)) { return;/*from w ww . j a v a 2s.c o m*/ } HttpSession session = request.getSession(); User user = (User) session.getAttribute(WebKeys.USER); if ((user == null) || !SocialOfficeServiceUtil.isSocialOfficeGroup(user.getGroupId())) { return; } if (path.contains("${liferay:screenName}") || path.contains("${liferay:userId}")) { path = StringUtil.replace(path, new String[] { "${liferay:screenName}", "${liferay:userId}" }, new String[] { HtmlUtil.escapeURL(user.getScreenName()), String.valueOf(user.getUserId()) }); } LastPath lastPath = new LastPath(StringPool.BLANK, path); session.setAttribute(WebKeys.LAST_PATH, lastPath); }
From source file:com.stoxx.logout.post.action.LogoutPostAction.java
License:Open Source License
@Override public void run(HttpServletRequest request, HttpServletResponse response) { HttpSession session = null;/*from ww w .jav a2 s . c om*/ LastPath lastPathnew = null; try { session = request.getSession(); String contextPath = "/web"; lastPathnew = new LastPath(contextPath, "/stoxxcom/home"); User _user = PortalUtil.getUser(request); if (Validator.isNotNull(_user)) { List<UserGroup> userGroups = UserGroupLocalServiceUtil.getUserUserGroups(_user.getUserId()); _log.info( ">>>>>>>>> logout url " + request.getRequestURL() + " user is " + _user.getEmailAddress()); String lastPathAction = (String) request.getSession().getAttribute("lasPathString"); _log.info("custom last path" + lastPathAction); Object lastPath = request.getSession().getAttribute("LAST_PATH"); if (Validator.isNotNull(lastPath)) { _log.info("The last path is " + lastPath.toString()); } else { _log.info("Last Path is null"); } for (UserGroup userGroup : userGroups) { _log.info("the usergroup names is " + userGroup.getName()); if (userGroup.getName() .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.customer"))) { lastPathnew = new LastPath(contextPath, "/stoxxcom/home"); break; } else if (userGroup.getName() .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.translator")) || userGroup.getName() .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.staff.user"))) { lastPathnew = new LastPath(contextPath, "/stoxxnet/login"); break; } else if (userGroup.getName() .equalsIgnoreCase(PrefsPropsUtil.getString("dax.usergroup.user"))) { lastPathnew = new LastPath(contextPath, "/dax/login"); break; } else { lastPathnew = new LastPath(contextPath, "/stoxxcom/home"); } } } session.setAttribute(WebKeys.LAST_PATH, lastPathnew); } catch (Exception e) { _log.info(e.getMessage(), e); } }
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"); }//from w ww .ja 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; }
From source file:it.webscience.kpeople.event.login.KpeoplePrivatePageRedirectAction.java
License:Open Source License
protected void doRun(HttpServletRequest request, HttpServletResponse response) throws Exception { long companyId = PortalUtil.getCompanyId(request); String path = PrefsPropsUtil.getString(companyId, PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING); path = path + "/" + PortalUtil.getUser(request).getScreenName(); path = path + PrefsPropsUtil.getString(companyId, PropsKeys.DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL); _log.info(String.format("PrivatePageRedirectAction, path=%s...", path)); if (_log.isInfoEnabled()) { _log.info("Private page path: " + StringPool.EQUAL + path); }/*from ww w.j a v a2 s. c o m*/ if (Validator.isNotNull(path)) { LastPath lastPath = new LastPath(StringPool.BLANK, path, new HashMap<String, String[]>()); HttpSession session = request.getSession(); request.setAttribute(WebKeys.LAST_PATH, lastPath); session.setAttribute(WebKeys.LAST_PATH, lastPath); } }
From source file:org.corak.liferay.portal.events.CustomLoginPostAction.java
License:Open Source License
/** * Will be fired for each Login Event and redirects the user to her or his landing page. */// w w w . java 2s . c o m public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException { try { debug("CustomLoginPostAction for User: " + request.getRemoteUser()); HttpSession session = request.getSession(); User user = UserLocalServiceUtil.getUser(PortalUtil.getUserId(request)); LastPath lastPath = null; Group firstUserGroup = null; Long companyId = PortalUtil.getCompanyId(request); //Role roleUser = RoleLocalServiceUtil.getRole(companyId, "User"); Role rolePowerUser = RoleLocalServiceUtil.getRole(companyId, "Power User"); Role roleAdministrator = RoleLocalServiceUtil.getRole(companyId, "Administrator"); // First look for User's Private Pages if (!(UserLocalServiceUtil.hasRoleUser(rolePowerUser.getRoleId(), user.getUserId()) || UserLocalServiceUtil.hasRoleUser(roleAdministrator.getRoleId(), user.getUserId()))) { // Redirect to User's Private Pages lastPath = new LastPath(request.getContextPath(), "/web/guest/registration"); } else { lastPath = null; if (lastPath == null) { // Look for Organizations debug("Looking for associated Organizations"); List<Organization> organizations = user.getOrganizations(); for (Organization organization : organizations) { Group group = organization.getGroup(); debug("Organization: " + group.getName() + ", friendlyUrl: " + group.getFriendlyURL()); if (firstUserGroup == null) firstUserGroup = group; if (group.hasPrivateLayouts()) lastPath = new LastPath(request.getContextPath(), PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING) + group.getFriendlyURL()); if (lastPath != null) break; } } if (lastPath == null) { // Look for Communities debug("Looking for associated Communities"); List<Group> groups = user.getGroups(); for (Group group : groups) { debug("Community: " + group.getName() + ", friendlyUrl: " + group.getFriendlyURL()); //if(group.getName().equals("Guest")){ //lastPath = new LastPath(request.getContextPath(), "/web/guest/workflow"); // break; //} //if(firstUserGroup == null) firstUserGroup = group; if (group.hasPrivateLayouts() && (!group.getName().equals("Guest"))) lastPath = new LastPath(request.getContextPath(), PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING) + group.getFriendlyURL()); if (lastPath != null) break; } if (firstUserGroup.getName().equals("Guest")) { lastPath = new LastPath(request.getContextPath(), "/web/guest/workflow"); } } if (lastPath == null && firstUserGroup != null) { // Redirect to the Public Pages of the first found // Community/Organization lastPath = new LastPath(request.getContextPath(), PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING) + firstUserGroup.getFriendlyURL()); } /*if((lastPath == null)&&(UserLocalServiceUtil.hasRoleUser(rolePowerUser.getRoleId(), user.getUserId()) || UserLocalServiceUtil.hasRoleUser(roleAdministrator.getRoleId(), user.getUserId()))) { // Redirect to User's Private Pages lastPath = new LastPath(request.getContextPath(), "/web/guest/workflow"); }*/ } if (lastPath != null) { debug("lastPath = " + lastPath.toString()); session.setAttribute(WebKeys.LAST_PATH, lastPath); } } catch (Exception e) { throw new ActionException(e); } }
From source file:org.lsp.liferay.portlet.advertising.events.AdvertisingLandingPageAction.java
License:Open Source License
public void run(HttpServletRequest request, HttpServletResponse response) { long userId = PortalUtil.getUserId(request); long companyId = PortalUtil.getCompanyId(request); String path;/*from w ww. ja v a 2 s . c o m*/ try { path = PrefsPropsUtil.getString(companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH); if (_log.isDebugEnabled()) { _log.debug(PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL + path); } long campaignIdToDisplay = CampaignLocalServiceUtil.getCampaignIdToDisplay(companyId, userId); _log.debug("Redirecting User to: " + path); LastPath lastPath = new LastPath(request.getContextPath(), path); if (_log.isDebugEnabled()) { _log.debug("lastPath = " + lastPath.toString()); } HttpSession session = request.getSession(); session.setAttribute(WebKeys.LAST_PATH, lastPath); if (campaignIdToDisplay > 0) { session.setAttribute(CampaignConstants.CAMPAIGN_HEADER, CampaignLocalServiceUtil.getCampaign(campaignIdToDisplay).getJournalArticlePrimaryKey()); CampaignLogLocalServiceUtil.markDisplayed(campaignIdToDisplay, userId); } } catch (SystemException e) { _log.error(e.getMessage(), e); } catch (PortalException e) { _log.error(e.getMessage(), e); } }
From source file:se.vgregion.userassociations.hook.UserCommunityAction.java
License:Open Source License
/** * The action is run by Liferay when the user log in. * Uses configured matchers that associate the user with community/organization, * and redirect the user to its community. * * @param request the HttpRequest//from w w w .ja va2s. c om * @param response the HttpResponse is not used, needed for the method signature. * @throws ActionException wrap all exceptions in an ActionException. */ @Override public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException { LOGGER.info("user login action"); try { HttpSession session = request.getSession(); User user = null; user = getUserLocalService().getUser(getPortal().getUserId(request)); resolveAssociations(user); LastPath lastPath = (LastPath) session.getAttribute(WebKeys.LAST_PATH); LOGGER.info("before: " + (lastPath == null ? "null" : lastPath.getPath())); if (lastPath == null || lastPath.getPath() == null || lastPaths.contains(lastPath.getPath())) { // Look for Communities - No path form initial call lastPath = computeLastPath(request.getContextPath(), user); } LOGGER.info("after: " + (lastPath == null ? "null" : lastPath.getPath())); if (lastPath != null) { session.setAttribute(WebKeys.LAST_PATH, lastPath); } } catch (SystemException e) { throw new ActionException(e); } catch (PortalException e) { throw new ActionException(e); } }
From source file:se.vgregion.userassociations.hook.UserCommunityActionTest.java
License:Open Source License
@Test public void testRun() throws Exception { UserCommunityAction action = new UserCommunityAction(); UserLocalService userLocalService = mock(UserLocalService.class); ReflectionTestUtils.setField(action, "userLocalService", userLocalService); Portal portal = mock(Portal.class); ReflectionTestUtils.setField(action, "portal", portal); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse res = mock(HttpServletResponse.class); HttpSession session = mock(HttpSession.class); when(req.getSession()).thenReturn(session); when(req.getContextPath()).thenReturn("/"); User user = getUser(0l, 12345l, "mockUser", new long[] {}); Group vgr = mock(Group.class); when(vgr.getName()).thenReturn("VGRegion"); when(vgr.hasPrivateLayouts()).thenReturn(true); when(user.getGroups()).thenReturn(Arrays.asList(vgr)); when(portal.getUserId(req)).thenReturn(123l); when(userLocalService.getUser(123l)).thenReturn(user); action.run(req, res);//ww w . ja v a 2 s . c om verify(session).setAttribute(eq(WebKeys.LAST_PATH), anyString()); }
From source file:se.vgregion.userassociations.hook.UserCommunityActionTest.java
License:Open Source License
@Test public void testRun2() throws Exception { UserCommunityAction action = new UserCommunityAction(); UserLocalService userLocalService = mock(UserLocalService.class); ReflectionTestUtils.setField(action, "userLocalService", userLocalService); Portal portal = mock(Portal.class); ReflectionTestUtils.setField(action, "portal", portal); HttpServletRequest req = mock(HttpServletRequest.class); HttpServletResponse res = mock(HttpServletResponse.class); HttpSession session = mock(HttpSession.class); when(req.getSession()).thenReturn(session); when(req.getContextPath()).thenReturn("/"); User user = getUser(0l, 12345l, "mockUser", new long[] {}); Group extern = mock(Group.class); when(extern.getName()).thenReturn("Extern"); when(extern.hasPrivateLayouts()).thenReturn(true); when(user.getGroups()).thenReturn(Arrays.asList(extern)); when(portal.getUserId(req)).thenReturn(123l); when(userLocalService.getUser(123l)).thenReturn(user); action.run(req, res);// www . j av a 2 s. c o m verify(session).setAttribute(eq(WebKeys.LAST_PATH), anyString()); }