001
014
015 package com.liferay.portal.struts;
016
017 import com.liferay.portal.LayoutPermissionException;
018 import com.liferay.portal.PortletActiveException;
019 import com.liferay.portal.UserActiveException;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
023 import com.liferay.portal.kernel.servlet.DynamicServletRequest;
024 import com.liferay.portal.kernel.servlet.HttpMethods;
025 import com.liferay.portal.kernel.servlet.SessionErrors;
026 import com.liferay.portal.kernel.struts.LastPath;
027 import com.liferay.portal.kernel.util.CharPool;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.HttpUtil;
030 import com.liferay.portal.kernel.util.JavaConstants;
031 import com.liferay.portal.kernel.util.ParamUtil;
032 import com.liferay.portal.kernel.util.PropsKeys;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.util.WebKeys;
038 import com.liferay.portal.liveusers.LiveUsers;
039 import com.liferay.portal.model.Layout;
040 import com.liferay.portal.model.LayoutConstants;
041 import com.liferay.portal.model.PasswordPolicy;
042 import com.liferay.portal.model.Portlet;
043 import com.liferay.portal.model.PortletPreferencesIds;
044 import com.liferay.portal.model.User;
045 import com.liferay.portal.model.UserTracker;
046 import com.liferay.portal.model.UserTrackerPath;
047 import com.liferay.portal.security.auth.InterruptedPortletRequestWhitelistUtil;
048 import com.liferay.portal.security.auth.PrincipalException;
049 import com.liferay.portal.security.permission.ActionKeys;
050 import com.liferay.portal.security.permission.PermissionChecker;
051 import com.liferay.portal.service.LayoutLocalServiceUtil;
052 import com.liferay.portal.service.PortletLocalServiceUtil;
053 import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
054 import com.liferay.portal.service.permission.PortletPermissionUtil;
055 import com.liferay.portal.service.persistence.UserTrackerPathUtil;
056 import com.liferay.portal.theme.ThemeDisplay;
057 import com.liferay.portal.util.PortalUtil;
058 import com.liferay.portal.util.PropsUtil;
059 import com.liferay.portal.util.PropsValues;
060 import com.liferay.portlet.InvokerPortlet;
061 import com.liferay.portlet.PortletConfigFactoryUtil;
062 import com.liferay.portlet.PortletInstanceFactoryUtil;
063 import com.liferay.portlet.PortletPreferencesFactoryUtil;
064 import com.liferay.portlet.PortletURLImpl;
065 import com.liferay.portlet.RenderRequestFactory;
066 import com.liferay.portlet.RenderRequestImpl;
067 import com.liferay.portlet.RenderResponseFactory;
068 import com.liferay.portlet.RenderResponseImpl;
069
070 import java.io.IOException;
071
072 import java.util.Date;
073 import java.util.HashSet;
074 import java.util.LinkedHashMap;
075 import java.util.Map;
076 import java.util.Set;
077 import java.util.regex.Matcher;
078 import java.util.regex.Pattern;
079
080 import javax.portlet.PortletConfig;
081 import javax.portlet.PortletContext;
082 import javax.portlet.PortletMode;
083 import javax.portlet.PortletPreferences;
084 import javax.portlet.PortletRequest;
085 import javax.portlet.WindowState;
086
087 import javax.servlet.ServletContext;
088 import javax.servlet.ServletException;
089 import javax.servlet.http.HttpServletRequest;
090 import javax.servlet.http.HttpServletResponse;
091 import javax.servlet.http.HttpSession;
092 import javax.servlet.jsp.PageContext;
093
094 import org.apache.struts.Globals;
095 import org.apache.struts.action.Action;
096 import org.apache.struts.action.ActionForm;
097 import org.apache.struts.action.ActionMapping;
098 import org.apache.struts.config.ActionConfig;
099 import org.apache.struts.config.ForwardConfig;
100 import org.apache.struts.tiles.TilesRequestProcessor;
101 import org.apache.struts.util.MessageResources;
102
103
109 public class PortalRequestProcessor extends TilesRequestProcessor {
110
111 public PortalRequestProcessor() {
112
113
114
115 _lastPaths = new HashSet<>();
116
117 _lastPaths.add(_PATH_PORTAL_LAYOUT);
118
119 addPaths(_lastPaths, PropsKeys.AUTH_FORWARD_LAST_PATHS);
120
121
122
123 _publicPaths = new HashSet<>();
124
125 _publicPaths.add(_PATH_C);
126 _publicPaths.add(_PATH_PORTAL_API_JSONWS);
127 _publicPaths.add(_PATH_PORTAL_FLASH);
128 _publicPaths.add(_PATH_PORTAL_J_LOGIN);
129 _publicPaths.add(_PATH_PORTAL_LAYOUT);
130 _publicPaths.add(_PATH_PORTAL_LICENSE);
131 _publicPaths.add(_PATH_PORTAL_LOGIN);
132 _publicPaths.add(_PATH_PORTAL_RENDER_PORTLET);
133 _publicPaths.add(_PATH_PORTAL_RESILIENCY);
134 _publicPaths.add(_PATH_PORTAL_TCK);
135 _publicPaths.add(_PATH_PORTAL_UPDATE_LANGUAGE);
136 _publicPaths.add(_PATH_PORTAL_UPDATE_PASSWORD);
137 _publicPaths.add(_PATH_PORTAL_VERIFY_EMAIL_ADDRESS);
138 _publicPaths.add(PropsValues.AUTH_LOGIN_DISABLED_PATH);
139
140 _trackerIgnorePaths = new HashSet<>();
141
142 addPaths(_trackerIgnorePaths, PropsKeys.SESSION_TRACKER_IGNORE_PATHS);
143 }
144
145 @Override
146 public void process(
147 HttpServletRequest request, HttpServletResponse response)
148 throws IOException, ServletException {
149
150 String path = super.processPath(request, response);
151
152 ActionMapping actionMapping =
153 (ActionMapping)moduleConfig.findActionConfig(path);
154
155 Action action = StrutsActionRegistryUtil.getAction(path);
156
157 if ((actionMapping == null) && (action == null)) {
158 String lastPath = getLastPath(request);
159
160 if (_log.isDebugEnabled()) {
161 _log.debug("Last path " + lastPath);
162 }
163
164 response.sendRedirect(lastPath);
165
166 return;
167 }
168
169 super.process(request, response);
170
171 try {
172 if (isPortletPath(path)) {
173 cleanUp(request);
174 }
175 }
176 catch (Exception e) {
177 _log.error(e, e);
178 }
179 }
180
181 protected void addPaths(Set<String> paths, String propsKey) {
182 String[] pathsArray = PropsUtil.getArray(propsKey);
183
184 for (String path : pathsArray) {
185 paths.add(path);
186 }
187 }
188
189 protected void callParentDoForward(
190 String uri, HttpServletRequest request,
191 HttpServletResponse response)
192 throws IOException, ServletException {
193
194 super.doForward(uri, request, response);
195 }
196
197 protected HttpServletRequest callParentProcessMultipart(
198 HttpServletRequest request) {
199
200 return super.processMultipart(request);
201 }
202
203 protected String callParentProcessPath(
204 HttpServletRequest request, HttpServletResponse response)
205 throws IOException {
206
207 return super.processPath(request, response);
208 }
209
210 protected boolean callParentProcessRoles(
211 HttpServletRequest request, HttpServletResponse response,
212 ActionMapping actionMapping)
213 throws IOException, ServletException {
214
215 return super.processRoles(request, response, actionMapping);
216 }
217
218 protected void cleanUp(HttpServletRequest request) throws Exception {
219
220
221
222
223 RenderRequestImpl renderRequestImpl =
224 (RenderRequestImpl)request.getAttribute(
225 JavaConstants.JAVAX_PORTLET_REQUEST);
226
227 if (renderRequestImpl != null) {
228 renderRequestImpl.cleanUp();
229 }
230 }
231
232 protected void defineObjects(
233 HttpServletRequest request, HttpServletResponse response,
234 Portlet portlet)
235 throws Exception {
236
237 String portletId = portlet.getPortletId();
238
239 ServletContext servletContext = (ServletContext)request.getAttribute(
240 WebKeys.CTX);
241
242 InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(
243 portlet, servletContext);
244
245 PortletPreferencesIds portletPreferencesIds =
246 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
247 request, portletId);
248
249 PortletPreferences portletPreferences =
250 PortletPreferencesLocalServiceUtil.getStrictPreferences(
251 portletPreferencesIds);
252
253 PortletConfig portletConfig = PortletConfigFactoryUtil.create(
254 portlet, servletContext);
255 PortletContext portletContext = portletConfig.getPortletContext();
256
257 RenderRequestImpl renderRequestImpl = RenderRequestFactory.create(
258 request, portlet, invokerPortlet, portletContext,
259 WindowState.MAXIMIZED, PortletMode.VIEW, portletPreferences);
260
261 RenderResponseImpl renderResponseImpl = RenderResponseFactory.create(
262 renderRequestImpl, response, portletId, portlet.getCompanyId());
263
264 renderRequestImpl.defineObjects(portletConfig, renderResponseImpl);
265
266 request.setAttribute(WebKeys.PORTLET_STRUTS_EXECUTE, Boolean.TRUE);
267 }
268
269 @Override
270 protected void doForward(
271 String uri, HttpServletRequest request,
272 HttpServletResponse response)
273 throws ServletException {
274
275 StrutsUtil.forward(uri, getServletContext(), request, response);
276 }
277
278 @Override
279 protected void doInclude(
280 String uri, HttpServletRequest request,
281 HttpServletResponse response)
282 throws ServletException {
283
284 StrutsUtil.include(uri, getServletContext(), request, response);
285 }
286
287 protected String getFriendlyTrackerPath(
288 String path, ThemeDisplay themeDisplay, HttpServletRequest request)
289 throws Exception {
290
291 if (!path.equals(_PATH_PORTAL_LAYOUT)) {
292 return null;
293 }
294
295 long plid = ParamUtil.getLong(request, "p_l_id");
296
297 if (plid == 0) {
298 return null;
299 }
300
301 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
302
303 String layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(
304 layout, themeDisplay);
305
306 String portletId = ParamUtil.getString(request, "p_p_id");
307
308 if (Validator.isNull(portletId)) {
309 return layoutFriendlyURL;
310 }
311
312 long companyId = PortalUtil.getCompanyId(request);
313
314 Portlet portlet = PortletLocalServiceUtil.getPortletById(
315 companyId, portletId);
316
317 if (portlet == null) {
318 String strutsPath = path.substring(
319 1, path.lastIndexOf(CharPool.SLASH));
320
321 portlet = PortletLocalServiceUtil.getPortletByStrutsPath(
322 companyId, strutsPath);
323 }
324
325 if ((portlet == null) || !portlet.isActive()) {
326 return layoutFriendlyURL.concat(StringPool.QUESTION).concat(
327 request.getQueryString());
328 }
329
330 String namespace = PortalUtil.getPortletNamespace(portletId);
331
332 FriendlyURLMapper friendlyURLMapper =
333 portlet.getFriendlyURLMapperInstance();
334
335 if (friendlyURLMapper == null) {
336 return layoutFriendlyURL.concat(StringPool.QUESTION).concat(
337 request.getQueryString());
338 }
339
340 PortletURLImpl portletURL = new PortletURLImpl(
341 request, portletId, plid, PortletRequest.RENDER_PHASE);
342
343 Map<String, String[]> parameterMap = request.getParameterMap();
344
345 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
346 String key = entry.getKey();
347
348 if (key.startsWith(namespace)) {
349 key = key.substring(namespace.length());
350
351 portletURL.setParameter(key, entry.getValue());
352 }
353 }
354
355 String portletFriendlyURL = friendlyURLMapper.buildPath(portletURL);
356
357 if (portletFriendlyURL != null) {
358 return layoutFriendlyURL.concat(portletFriendlyURL);
359 }
360 else {
361 return layoutFriendlyURL.concat(StringPool.QUESTION).concat(
362 request.getQueryString());
363 }
364 }
365
366 protected String getLastPath(HttpServletRequest request) {
367 HttpSession session = request.getSession();
368
369 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
370 WebKeys.THEME_DISPLAY);
371
372 Boolean httpsInitial = (Boolean)session.getAttribute(
373 WebKeys.HTTPS_INITIAL);
374
375 String portalURL = null;
376
377 if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS &&
378 !PropsValues.SESSION_ENABLE_PHISHING_PROTECTION &&
379 (httpsInitial != null) && !httpsInitial.booleanValue()) {
380
381 portalURL = PortalUtil.getPortalURL(request, false);
382 }
383 else {
384 portalURL = PortalUtil.getPortalURL(request);
385 }
386
387 StringBundler sb = new StringBundler(7);
388
389 sb.append(portalURL);
390 sb.append(themeDisplay.getPathMain());
391 sb.append(_PATH_PORTAL_LAYOUT);
392
393 if (!PropsValues.AUTH_FORWARD_BY_LAST_PATH) {
394 if (request.getRemoteUser() != null) {
395
396
397
398
399
400 sb.append(StringPool.QUESTION);
401 sb.append("p_l_id");
402 sb.append(StringPool.EQUAL);
403 sb.append(LayoutConstants.DEFAULT_PLID);
404 }
405
406 return sb.toString();
407 }
408
409 LastPath lastPath = (LastPath)session.getAttribute(WebKeys.LAST_PATH);
410
411 if (lastPath == null) {
412 return sb.toString();
413 }
414
415 Map<String, String[]> parameterMap = lastPath.getParameterMap();
416
417
418
419
420 if (lastPath.getContextPath().equals(themeDisplay.getPathMain())) {
421 ActionMapping actionMapping =
422 (ActionMapping)moduleConfig.findActionConfig(
423 lastPath.getPath());
424
425 if ((actionMapping == null) || (parameterMap == null)) {
426 return sb.toString();
427 }
428 }
429
430 StringBundler lastPathSB = new StringBundler(4);
431
432 lastPathSB.append(portalURL);
433 lastPathSB.append(lastPath.getContextPath());
434 lastPathSB.append(lastPath.getPath());
435 lastPathSB.append(HttpUtil.parameterMapToString(parameterMap));
436
437 return lastPathSB.toString();
438 }
439
440 protected boolean isPortletPath(String path) {
441 if ((path != null) && !path.equals(_PATH_C) &&
442 !path.startsWith(_PATH_COMMON) &&
443 !path.contains(_PATH_J_SECURITY_CHECK) &&
444 !path.startsWith(_PATH_PORTAL)) {
445
446 return true;
447 }
448 else {
449 return false;
450 }
451 }
452
453 protected boolean isPublicPath(String path) {
454 if ((path != null) &&
455 (_publicPaths.contains(path) || path.startsWith(_PATH_COMMON) ||
456 AuthPublicPathRegistry.contains(path))) {
457
458 return true;
459 }
460 else {
461 return false;
462 }
463 }
464
465 @Override
466 protected Action processActionCreate(
467 HttpServletRequest request, HttpServletResponse response,
468 ActionMapping actionMapping)
469 throws IOException {
470
471 ActionAdapter actionAdapter =
472 (ActionAdapter)StrutsActionRegistryUtil.getAction(
473 actionMapping.getPath());
474
475 if (actionAdapter != null) {
476 ActionConfig actionConfig = moduleConfig.findActionConfig(
477 actionMapping.getPath());
478
479 if (actionConfig != null) {
480 Action originalAction = super.processActionCreate(
481 request, response, actionMapping);
482
483 actionAdapter.setOriginalAction(originalAction);
484 }
485
486 return actionAdapter;
487 }
488
489 return super.processActionCreate(request, response, actionMapping);
490 }
491
492 @Override
493 protected ActionMapping processMapping(
494 HttpServletRequest request, HttpServletResponse response,
495 String path)
496 throws IOException {
497
498 if (path == null) {
499 return null;
500 }
501
502 Action action = StrutsActionRegistryUtil.getAction(path);
503
504 if (action != null) {
505 ActionMapping actionMapping =
506 (ActionMapping)moduleConfig.findActionConfig(path);
507
508 if (actionMapping == null) {
509 actionMapping = new ActionMapping();
510
511 actionMapping.setModuleConfig(moduleConfig);
512 actionMapping.setPath(path);
513
514 request.setAttribute(Globals.MAPPING_KEY, actionMapping);
515 }
516
517 return actionMapping;
518 }
519
520 ActionMapping actionMapping = super.processMapping(
521 request, response, path);
522
523 if (actionMapping == null) {
524 MessageResources messageResources = getInternal();
525
526 String msg = messageResources.getMessage("processInvalid");
527
528 _log.error("User ID " + request.getRemoteUser());
529 _log.error("Current URL " + PortalUtil.getCurrentURL(request));
530 _log.error("Referer " + request.getHeader("Referer"));
531 _log.error("Remote address " + request.getRemoteAddr());
532
533 _log.error(msg + " " + path);
534 }
535
536 return actionMapping;
537 }
538
539 @Override
540 protected HttpServletRequest processMultipart(HttpServletRequest request) {
541
542
543
544 return request;
545 }
546
547 @Override
548 protected String processPath(
549 HttpServletRequest request, HttpServletResponse response)
550 throws IOException {
551
552 String path = GetterUtil.getString(
553 super.processPath(request, response));
554
555 HttpSession session = request.getSession();
556
557 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
558 WebKeys.THEME_DISPLAY);
559
560
561
562 UserTracker userTracker = LiveUsers.getUserTracker(
563 themeDisplay.getCompanyId(), session.getId());
564
565 if ((userTracker != null) && !path.equals(_PATH_C) &&
566 !path.contains(_PATH_J_SECURITY_CHECK) &&
567 !path.contains(_PATH_PORTAL_PROTECTED) &&
568 !_trackerIgnorePaths.contains(path)) {
569
570 String fullPath = null;
571
572 try {
573 if (PropsValues.SESSION_TRACKER_FRIENDLY_PATHS_ENABLED) {
574 fullPath = getFriendlyTrackerPath(
575 path, themeDisplay, request);
576 }
577 }
578 catch (Exception e) {
579 _log.error(e, e);
580 }
581
582 String fullPathWithoutQueryString = fullPath;
583
584 if (Validator.isNull(fullPath)) {
585 String queryString = request.getQueryString();
586
587 fullPathWithoutQueryString = path;
588
589 if (Validator.isNotNull(queryString)) {
590 fullPath = path.concat(StringPool.QUESTION).concat(
591 queryString);
592 }
593 else {
594 fullPath = path;
595 }
596 }
597
598 int pos = fullPathWithoutQueryString.indexOf(StringPool.QUESTION);
599
600 if (pos != -1) {
601 fullPathWithoutQueryString =
602 fullPathWithoutQueryString.substring(0, pos);
603 }
604
605 if (!_trackerIgnorePaths.contains(fullPathWithoutQueryString)) {
606 UserTrackerPath userTrackerPath = UserTrackerPathUtil.create(0);
607
608 userTrackerPath.setUserTrackerId(
609 userTracker.getUserTrackerId());
610 userTrackerPath.setPath(fullPath);
611 userTrackerPath.setPathDate(new Date());
612
613 userTracker.addPath(userTrackerPath);
614 }
615 }
616
617 String remoteUser = request.getRemoteUser();
618
619 User user = null;
620
621 try {
622 user = PortalUtil.getUser(request);
623 }
624 catch (Exception e) {
625 }
626
627
628
629 if (_lastPaths.contains(path) && !_trackerIgnorePaths.contains(path)) {
630 boolean saveLastPath = ParamUtil.getBoolean(
631 request, "saveLastPath", true);
632
633 if (themeDisplay.isLifecycleResource() ||
634 themeDisplay.isStateExclusive() ||
635 themeDisplay.isStatePopUp() ||
636 !StringUtil.equalsIgnoreCase(
637 request.getMethod(), HttpMethods.GET)) {
638
639 saveLastPath = false;
640 }
641
642
643
644 if (saveLastPath) {
645
646
647
648
649 LastPath lastPath = (LastPath)request.getAttribute(
650 WebKeys.LAST_PATH);
651
652 if (lastPath == null) {
653 lastPath = new LastPath(
654 themeDisplay.getPathMain(), path,
655 request.getParameterMap());
656 }
657
658 session.setAttribute(WebKeys.LAST_PATH, lastPath);
659 }
660 }
661
662
663
664 if (PropsValues.SETUP_WIZARD_ENABLED) {
665 if (!path.equals(_PATH_PORTAL_LICENSE) &&
666 !path.equals(_PATH_PORTAL_STATUS)) {
667
668 return _PATH_PORTAL_SETUP_WIZARD;
669 }
670 }
671 else if (path.equals(_PATH_PORTAL_SETUP_WIZARD)) {
672 return _PATH_PORTAL_LAYOUT;
673 }
674
675
676
677 if (((remoteUser != null) || (user != null)) &&
678 path.equals(_PATH_PORTAL_LOGOUT)) {
679
680 return path;
681 }
682
683
684
685 if (((remoteUser != null) || (user != null)) &&
686 (path.equals(_PATH_PORTAL_EXPIRE_SESSION) ||
687 path.equals(_PATH_PORTAL_EXTEND_SESSION))) {
688
689 return path;
690 }
691
692
693
694 if (((remoteUser != null) || (user != null)) &&
695 path.equals(_PATH_PORTAL_UPDATE_TERMS_OF_USE)) {
696
697 return path;
698 }
699
700
701
702 if ((remoteUser != null) && (user == null)) {
703 return _PATH_PORTAL_LOGOUT;
704 }
705
706
707
708 if ((user != null) && !user.isActive()) {
709 SessionErrors.add(request, UserActiveException.class.getName());
710
711 return _PATH_PORTAL_ERROR;
712 }
713
714 long companyId = PortalUtil.getCompanyId(request);
715 String portletId = ParamUtil.getString(request, "p_p_id");
716
717 if (!path.equals(_PATH_PORTAL_JSON_SERVICE) &&
718 !path.equals(_PATH_PORTAL_RENDER_PORTLET) &&
719 !ParamUtil.getBoolean(request, "wsrp") &&
720 !themeDisplay.isImpersonated() &&
721 !InterruptedPortletRequestWhitelistUtil.
722 isPortletInvocationWhitelisted(
723 companyId, portletId,
724 PortalUtil.getStrutsAction(request))) {
725
726
727
728 if ((user != null) && !user.isTermsOfUseComplete()) {
729 return _PATH_PORTAL_TERMS_OF_USE;
730 }
731
732
733
734 if ((user != null) && !user.isEmailAddressVerificationComplete()) {
735 if (path.equals(_PATH_PORTAL_UPDATE_EMAIL_ADDRESS)) {
736 return _PATH_PORTAL_UPDATE_EMAIL_ADDRESS;
737 }
738
739 return _PATH_PORTAL_VERIFY_EMAIL_ADDRESS;
740 }
741
742
743
744 if ((user != null) && user.isPasswordReset()) {
745 try {
746 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
747
748 if ((passwordPolicy == null) ||
749 passwordPolicy.isChangeRequired()) {
750
751 return _PATH_PORTAL_UPDATE_PASSWORD;
752 }
753 }
754 catch (Exception e) {
755 _log.error(e, e);
756
757 return _PATH_PORTAL_UPDATE_PASSWORD;
758 }
759 }
760 else if ((user != null) && !user.isPasswordReset() &&
761 path.equals(_PATH_PORTAL_UPDATE_PASSWORD)) {
762
763 return null;
764 }
765
766
767
768 if ((user != null) && !user.isEmailAddressComplete()) {
769 return _PATH_PORTAL_UPDATE_EMAIL_ADDRESS;
770 }
771
772
773
774 if ((user != null) && !user.isDefaultUser() &&
775 !user.isReminderQueryComplete()) {
776
777 return _PATH_PORTAL_UPDATE_REMINDER_QUERY;
778 }
779 }
780
781
782
783 if (!isPublicPath(path)) {
784 if (user == null) {
785 SessionErrors.add(request, PrincipalException.class.getName());
786
787 return _PATH_PORTAL_LOGIN;
788 }
789 }
790
791 ActionMapping actionMapping =
792 (ActionMapping)moduleConfig.findActionConfig(path);
793
794 if (actionMapping == null) {
795 Action strutsAction = StrutsActionRegistryUtil.getAction(path);
796
797 if (strutsAction == null) {
798 return null;
799 }
800 }
801 else {
802 path = actionMapping.getPath();
803 }
804
805
806
807 if (isPortletPath(path)) {
808 try {
809 Portlet portlet = null;
810
811 if (Validator.isNotNull(portletId)) {
812 portlet = PortletLocalServiceUtil.getPortletById(
813 companyId, portletId);
814 }
815
816 if (portlet == null) {
817 String strutsPath = path.substring(
818 1, path.lastIndexOf(CharPool.SLASH));
819
820 portlet = PortletLocalServiceUtil.getPortletByStrutsPath(
821 companyId, strutsPath);
822 }
823
824 if ((portlet != null) && portlet.isActive()) {
825 defineObjects(request, response, portlet);
826 }
827 }
828 catch (Exception e) {
829 request.setAttribute(PageContext.EXCEPTION, e);
830
831 path = _PATH_COMMON_ERROR;
832 }
833 }
834
835
836
837 if (SessionErrors.contains(
838 request, LayoutPermissionException.class.getName())) {
839
840 return _PATH_PORTAL_ERROR;
841 }
842
843 return path;
844 }
845
846 @Override
847 protected void processPopulate(
848 HttpServletRequest request, HttpServletResponse response,
849 ActionForm actionForm, ActionMapping actionMapping)
850 throws ServletException {
851
852 if (actionForm == null) {
853 return;
854 }
855
856 boolean hasIgnoredParameter = false;
857
858 Map<String, String[]> oldParameterMap = request.getParameterMap();
859
860 Map<String, String[]> newParameterMap = new LinkedHashMap<>(
861 oldParameterMap.size());
862
863 for (Map.Entry<String, String[]> entry : oldParameterMap.entrySet()) {
864 String name = entry.getKey();
865
866 Matcher matcher = _strutsPortletIgnoredParamtersPattern.matcher(
867 name);
868
869 if (matcher.matches()) {
870 hasIgnoredParameter = true;
871 }
872 else {
873 newParameterMap.put(name, entry.getValue());
874 }
875 }
876
877 if (hasIgnoredParameter) {
878 request = new DynamicServletRequest(
879 request, newParameterMap, false);
880 }
881
882 super.processPopulate(request, response, actionForm, actionMapping);
883 }
884
885 @Override
886 protected boolean processRoles(
887 HttpServletRequest request, HttpServletResponse response,
888 ActionMapping actionMapping)
889 throws IOException, ServletException {
890
891 String path = actionMapping.getPath();
892
893 if (isPublicPath(path)) {
894 return true;
895 }
896
897 boolean authorized = true;
898
899 User user = null;
900
901 try {
902 user = PortalUtil.getUser(request);
903 }
904 catch (Exception e) {
905 }
906
907 if ((user != null) && isPortletPath(path)) {
908 try {
909
910
911
912 if (path.equals(_PATH_PORTAL_LOGOUT)) {
913 return true;
914 }
915
916 Portlet portlet = null;
917
918 String portletId = ParamUtil.getString(request, "p_p_id");
919
920 if (Validator.isNotNull(portletId)) {
921 portlet = PortletLocalServiceUtil.getPortletById(
922 user.getCompanyId(), portletId);
923 }
924
925 String strutsPath = path.substring(
926 1, path.lastIndexOf(CharPool.SLASH));
927
928 if (portlet != null) {
929 if (!strutsPath.equals(portlet.getStrutsPath())) {
930 throw new PrincipalException.MustBePortletStrutsPath(
931 strutsPath, portletId);
932 }
933 }
934 else {
935 portlet = PortletLocalServiceUtil.getPortletByStrutsPath(
936 user.getCompanyId(), strutsPath);
937 }
938
939 if ((portlet != null) && portlet.isActive() &&
940 !portlet.isSystem()) {
941
942 ThemeDisplay themeDisplay =
943 (ThemeDisplay)request.getAttribute(
944 WebKeys.THEME_DISPLAY);
945
946 Layout layout = themeDisplay.getLayout();
947 PermissionChecker permissionChecker =
948 themeDisplay.getPermissionChecker();
949
950 if (!PortletPermissionUtil.contains(
951 permissionChecker, layout, portlet,
952 ActionKeys.VIEW)) {
953
954 throw new PrincipalException.MustHavePermission(
955 permissionChecker, Portlet.class.getName(),
956 portlet.getPortletId(), ActionKeys.VIEW);
957 }
958 }
959 else if ((portlet != null) && !portlet.isActive()) {
960 SessionErrors.add(
961 request, PortletActiveException.class.getName());
962
963 authorized = false;
964 }
965 }
966 catch (Exception e) {
967 SessionErrors.add(request, PrincipalException.class.getName());
968
969 authorized = false;
970 }
971 }
972
973 if (!authorized) {
974 ForwardConfig forwardConfig = actionMapping.findForward(
975 _PATH_PORTAL_ERROR);
976
977 processForwardConfig(request, response, forwardConfig);
978
979 return false;
980 }
981 else {
982 return true;
983 }
984 }
985
986 private static final String _PATH_C = "/c";
987
988 private static final String _PATH_COMMON = "/common";
989
990 private static final String _PATH_COMMON_ERROR = "/common/error";
991
992 private static final String _PATH_J_SECURITY_CHECK = "/j_security_check";
993
994 private static final String _PATH_PORTAL = "/portal";
995
996 private static final String _PATH_PORTAL_API_JSONWS = "/portal/api/jsonws";
997
998 private static final String _PATH_PORTAL_ERROR = "/portal/error";
999
1000 private static final String _PATH_PORTAL_EXPIRE_SESSION =
1001 "/portal/expire_session";
1002
1003 private static final String _PATH_PORTAL_EXTEND_SESSION =
1004 "/portal/extend_session";
1005
1006 private static final String _PATH_PORTAL_FLASH = "/portal/flash";
1007
1008 private static final String _PATH_PORTAL_J_LOGIN = "/portal/j_login";
1009
1010 private static final String _PATH_PORTAL_JSON_SERVICE =
1011 "/portal/json_service";
1012
1013 private static final String _PATH_PORTAL_LAYOUT = "/portal/layout";
1014
1015 private static final String _PATH_PORTAL_LICENSE = "/portal/license";
1016
1017 private static final String _PATH_PORTAL_LOGIN = "/portal/login";
1018
1019 private static final String _PATH_PORTAL_LOGOUT = "/portal/logout";
1020
1021 private static final String _PATH_PORTAL_PROTECTED = "/portal/protected";
1022
1023 private static final String _PATH_PORTAL_RENDER_PORTLET =
1024 "/portal/render_portlet";
1025
1026 private static final String _PATH_PORTAL_RESILIENCY = "/portal/resiliency";
1027
1028 private static final String _PATH_PORTAL_SETUP_WIZARD =
1029 "/portal/setup_wizard";
1030
1031 private static final String _PATH_PORTAL_STATUS = "/portal/status";
1032
1033 private static final String _PATH_PORTAL_TCK = "/portal/tck";
1034
1035 private static final String _PATH_PORTAL_TERMS_OF_USE =
1036 "/portal/terms_of_use";
1037
1038 private static final String _PATH_PORTAL_UPDATE_EMAIL_ADDRESS =
1039 "/portal/update_email_address";
1040
1041 private static final String _PATH_PORTAL_UPDATE_LANGUAGE =
1042 "/portal/update_language";
1043
1044 private static final String _PATH_PORTAL_UPDATE_PASSWORD =
1045 "/portal/update_password";
1046
1047 private static final String _PATH_PORTAL_UPDATE_REMINDER_QUERY =
1048 "/portal/update_reminder_query";
1049
1050 private static final String _PATH_PORTAL_UPDATE_TERMS_OF_USE =
1051 "/portal/update_terms_of_use";
1052
1053 private static final String _PATH_PORTAL_VERIFY_EMAIL_ADDRESS =
1054 "/portal/verify_email_address";
1055
1056 private static final Log _log = LogFactoryUtil.getLog(
1057 PortalRequestProcessor.class);
1058
1059 private static final Pattern _strutsPortletIgnoredParamtersPattern =
1060 Pattern.compile(PropsValues.STRUTS_PORTLET_IGNORED_PARAMETERS_REGEXP);
1061
1062 private final Set<String> _lastPaths;
1063 private final Set<String> _publicPaths;
1064 private final Set<String> _trackerIgnorePaths;
1065
1066 }