001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.ccpp.PortalProfileFactory;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
021    import com.liferay.portal.kernel.portlet.LiferayPortletContext;
022    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
023    import com.liferay.portal.kernel.portlet.LiferayPortletSession;
024    import com.liferay.portal.kernel.portlet.LiferayWindowState;
025    import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
026    import com.liferay.portal.kernel.servlet.DynamicServletRequest;
027    import com.liferay.portal.kernel.servlet.ProtectedPrincipal;
028    import com.liferay.portal.kernel.servlet.ServletContextPool;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.ContentTypes;
031    import com.liferay.portal.kernel.util.ContextPathUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.JavaConstants;
034    import com.liferay.portal.kernel.util.LocaleUtil;
035    import com.liferay.portal.kernel.util.ParamUtil;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.xml.QName;
039    import com.liferay.portal.model.Portlet;
040    import com.liferay.portal.model.PortletApp;
041    import com.liferay.portal.model.PortletConstants;
042    import com.liferay.portal.model.PublicRenderParameter;
043    import com.liferay.portal.model.User;
044    import com.liferay.portal.security.lang.DoPrivilegedBean;
045    import com.liferay.portal.security.lang.DoPrivilegedUtil;
046    import com.liferay.portal.service.RoleLocalServiceUtil;
047    import com.liferay.portal.servlet.NamespaceServletRequest;
048    import com.liferay.portal.servlet.SharedSessionServletRequest;
049    import com.liferay.portal.theme.ThemeDisplay;
050    import com.liferay.portal.util.PortalUtil;
051    import com.liferay.portal.util.WebKeys;
052    import com.liferay.portlet.portletconfiguration.util.PublicRenderParameterConfiguration;
053    
054    import java.security.Principal;
055    import java.security.PrivilegedAction;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.Enumeration;
060    import java.util.HashMap;
061    import java.util.LinkedHashMap;
062    import java.util.List;
063    import java.util.Locale;
064    import java.util.Map;
065    
066    import javax.ccpp.Profile;
067    
068    import javax.portlet.PortalContext;
069    import javax.portlet.PortletConfig;
070    import javax.portlet.PortletContext;
071    import javax.portlet.PortletMode;
072    import javax.portlet.PortletPreferences;
073    import javax.portlet.PortletRequest;
074    import javax.portlet.PortletResponse;
075    import javax.portlet.PortletSession;
076    import javax.portlet.WindowState;
077    import javax.portlet.filter.PortletRequestWrapper;
078    
079    import javax.servlet.ServletContext;
080    import javax.servlet.http.Cookie;
081    import javax.servlet.http.HttpServletRequest;
082    import javax.servlet.http.HttpSession;
083    
084    /**
085     * @author Brian Wing Shun Chan
086     * @author Brian Myunghun Kim
087     * @author Sergey Ponomarev
088     * @author Raymond Aug??
089     */
090    public abstract class PortletRequestImpl implements LiferayPortletRequest {
091    
092            public static PortletRequestImpl getPortletRequestImpl(
093                    PortletRequest portletRequest) {
094    
095                    while (!(portletRequest instanceof PortletRequestImpl)) {
096                            if (portletRequest instanceof DoPrivilegedBean) {
097                                    DoPrivilegedBean doPrivilegedBean =
098                                            (DoPrivilegedBean)portletRequest;
099    
100                                    portletRequest =
101                                            (PortletRequest)doPrivilegedBean.getActualBean();
102                            }
103                            else if (portletRequest instanceof PortletRequestWrapper) {
104                                    PortletRequestWrapper portletRequestWrapper =
105                                            (PortletRequestWrapper)portletRequest;
106    
107                                    portletRequest = portletRequestWrapper.getRequest();
108                            }
109                            else {
110                                    throw new RuntimeException(
111                                            "Unable to unwrap the portlet request from " +
112                                                    portletRequest.getClass());
113                            }
114                    }
115    
116                    return (PortletRequestImpl)portletRequest;
117            }
118    
119            public void cleanUp() {
120                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
121                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
122                    _request.removeAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
123                    _request.removeAttribute(PortletRequest.LIFECYCLE_PHASE);
124            }
125    
126            public void defineObjects(
127                    PortletConfig portletConfig, PortletResponse portletResponse) {
128    
129                    LiferayPortletConfig liferayPortletConfig =
130                            (LiferayPortletConfig)portletConfig;
131    
132                    setAttribute(WebKeys.PORTLET_ID, liferayPortletConfig.getPortletId());
133                    setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, portletConfig);
134                    setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, this);
135                    setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse);
136                    setAttribute(PortletRequest.LIFECYCLE_PHASE, getLifecycle());
137            }
138    
139            @Override
140            public Object getAttribute(String name) {
141                    if (name == null) {
142                            throw new IllegalArgumentException();
143                    }
144    
145                    if (name.equals(PortletRequest.CCPP_PROFILE)) {
146                            return getCCPPProfile();
147                    }
148                    else if (name.equals(PortletRequest.USER_INFO)) {
149                            Object value = getUserInfo();
150    
151                            if (value != null) {
152                                    return value;
153                            }
154                    }
155    
156                    return _request.getAttribute(name);
157            }
158    
159            @Override
160            public Enumeration<String> getAttributeNames() {
161                    List<String> names = new ArrayList<String>();
162    
163                    Enumeration<String> enu = _request.getAttributeNames();
164    
165                    while (enu.hasMoreElements()) {
166                            String name = enu.nextElement();
167    
168                            if (!name.equals(JavaConstants.JAVAX_SERVLET_INCLUDE_PATH_INFO)) {
169                                    names.add(name);
170                            }
171                    }
172    
173                    return Collections.enumeration(names);
174            }
175    
176            @Override
177            public String getAuthType() {
178                    return _request.getAuthType();
179            }
180    
181            public Profile getCCPPProfile() {
182                    if (_profile == null) {
183                            _profile = PortalProfileFactory.getCCPPProfile(_request);
184                    }
185    
186                    return _profile;
187            }
188    
189            @Override
190            public String getContextPath() {
191                    LiferayPortletContext liferayPortletContext =
192                            (LiferayPortletContext)_portletContext;
193    
194                    ServletContext servletContext =
195                            liferayPortletContext.getServletContext();
196    
197                    String servletContextName = servletContext.getServletContextName();
198    
199                    if (ServletContextPool.containsKey(servletContextName)) {
200                            servletContext = ServletContextPool.get(servletContextName);
201    
202                            return ContextPathUtil.getContextPath(servletContext);
203                    }
204    
205                    return StringPool.SLASH.concat(_portletContext.getPortletContextName());
206            }
207    
208            @Override
209            public Cookie[] getCookies() {
210                    return _request.getCookies();
211            }
212    
213            public String getETag() {
214                    return null;
215            }
216    
217            @Override
218            public HttpServletRequest getHttpServletRequest() {
219                    return _request;
220            }
221    
222            public abstract String getLifecycle();
223    
224            @Override
225            public Locale getLocale() {
226                    Locale locale = _locale;
227    
228                    if (locale == null) {
229                            locale = _request.getLocale();
230                    }
231    
232                    if (locale == null) {
233                            locale = LocaleUtil.getDefault();
234                    }
235    
236                    return locale;
237            }
238    
239            @Override
240            public Enumeration<Locale> getLocales() {
241                    return _request.getLocales();
242            }
243    
244            public String getMethod() {
245                    return _request.getMethod();
246            }
247    
248            public HttpServletRequest getOriginalHttpServletRequest() {
249                    return _originalRequest;
250            }
251    
252            @Override
253            public String getParameter(String name) {
254                    if (name == null) {
255                            throw new IllegalArgumentException();
256                    }
257    
258                    if (_portletRequestDispatcherRequest != null) {
259                            return _portletRequestDispatcherRequest.getParameter(name);
260                    }
261    
262                    return _request.getParameter(name);
263            }
264    
265            @Override
266            public Map<String, String[]> getParameterMap() {
267                    if (_portletRequestDispatcherRequest != null) {
268                            return Collections.unmodifiableMap(
269                                    _portletRequestDispatcherRequest.getParameterMap());
270                    }
271    
272                    return Collections.unmodifiableMap(_request.getParameterMap());
273            }
274    
275            @Override
276            public Enumeration<String> getParameterNames() {
277                    if (_portletRequestDispatcherRequest != null) {
278                            return _portletRequestDispatcherRequest.getParameterNames();
279                    }
280    
281                    return _request.getParameterNames();
282            }
283    
284            @Override
285            public String[] getParameterValues(String name) {
286                    if (name == null) {
287                            throw new IllegalArgumentException();
288                    }
289    
290                    if (_portletRequestDispatcherRequest != null) {
291                            return _portletRequestDispatcherRequest.getParameterValues(name);
292                    }
293    
294                    return _request.getParameterValues(name);
295            }
296    
297            @Override
298            public PortalContext getPortalContext() {
299                    return _portalContext;
300            }
301    
302            public Portlet getPortlet() {
303                    return _portlet;
304            }
305    
306            public PortletContext getPortletContext() {
307                    return _portletContext;
308            }
309    
310            @Override
311            public PortletMode getPortletMode() {
312                    return _portletMode;
313            }
314    
315            public String getPortletName() {
316                    return _portletName;
317            }
318    
319            @Override
320            public PortletSession getPortletSession() {
321                    return _session;
322            }
323    
324            @Override
325            public PortletSession getPortletSession(boolean create) {
326                    /*HttpSession httpSes = _req.getSession(create);
327    
328                    if (httpSes == null) {
329                            return null;
330                    }
331                    else {
332                            if (create) {
333                                    _session = new PortletSessionImpl(
334                                            _req.getSession(), _portletContext, _portletName, _plid);
335                            }
336    
337                            return _ses;
338                    }*/
339    
340                    /*if ((_session == null) && create) {
341                            _req.getSession(create);
342    
343                            _session = new PortletSessionImpl(
344                                    _req.getSession(), _portletContext, _portletName, _plid);
345                    }*/
346    
347                    if (!create && _invalidSession) {
348                            return null;
349                    }
350    
351                    return _session;
352            }
353    
354            @Override
355            public PortletPreferences getPreferences() {
356                    return DoPrivilegedUtil.wrap(new PortletPreferencesPrivilegedAction());
357            }
358    
359            public PortletPreferencesImpl getPreferencesImpl() {
360                    return (PortletPreferencesImpl)_preferences;
361            }
362    
363            @Override
364            public Map<String, String[]> getPrivateParameterMap() {
365                    Map<String, String[]> parameterMap = null;
366    
367                    if (_portletRequestDispatcherRequest != null) {
368                            parameterMap = _portletRequestDispatcherRequest.getParameterMap();
369                    }
370                    else {
371                            parameterMap = _request.getParameterMap();
372                    }
373    
374                    Map<String, String[]> privateParameterMap = null;
375    
376                    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
377                            String name = entry.getKey();
378    
379                            if (_portlet.getPublicRenderParameter(name) != null) {
380                                    continue;
381                            }
382    
383                            if (privateParameterMap == null) {
384                                    privateParameterMap = new HashMap<String, String[]>(
385                                            parameterMap.size(), 1);
386                            }
387    
388                            privateParameterMap.put(name, entry.getValue());
389                    }
390    
391                    if (privateParameterMap == null) {
392                            return Collections.emptyMap();
393                    }
394    
395                    return Collections.unmodifiableMap(privateParameterMap);
396            }
397    
398            @Override
399            public Enumeration<String> getProperties(String name) {
400                    List<String> values = new ArrayList<String>();
401    
402                    String value = _portalContext.getProperty(name);
403    
404                    if (value != null) {
405                            values.add(value);
406                    }
407    
408                    return Collections.enumeration(values);
409            }
410    
411            @Override
412            public String getProperty(String name) {
413                    return _portalContext.getProperty(name);
414            }
415    
416            @Override
417            public Enumeration<String> getPropertyNames() {
418                    return _portalContext.getPropertyNames();
419            }
420    
421            @Override
422            public Map<String, String[]> getPublicParameterMap() {
423                    Map<String, String[]> parameterMap = null;
424    
425                    if (_portletRequestDispatcherRequest != null) {
426                            parameterMap = _portletRequestDispatcherRequest.getParameterMap();
427                    }
428                    else {
429                            parameterMap = _request.getParameterMap();
430                    }
431    
432                    Map<String, String[]> publicParameterMap = null;
433    
434                    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
435                            String name = entry.getKey();
436    
437                            if (_portlet.getPublicRenderParameter(name) != null) {
438                                    if (publicParameterMap == null) {
439                                            publicParameterMap = new HashMap<String, String[]>(
440                                                    parameterMap.size(), 1);
441                                    }
442    
443                                    publicParameterMap.put(name, entry.getValue());
444                            }
445                    }
446    
447                    if (publicParameterMap == null) {
448                            return Collections.emptyMap();
449                    }
450                    else {
451                            return Collections.unmodifiableMap(publicParameterMap);
452                    }
453            }
454    
455            @Override
456            public String getRemoteUser() {
457                    return _remoteUser;
458            }
459    
460            @Override
461            public Map<String, String[]> getRenderParameters() {
462                    return RenderParametersPool.get(_request, _plid, _portletName);
463            }
464    
465            @Override
466            public String getRequestedSessionId() {
467                    if (_session != null) {
468                            return _session.getId();
469                    }
470                    else {
471                            HttpSession session = _request.getSession(false);
472    
473                            if (session == null) {
474                                    return StringPool.BLANK;
475                            }
476                            else {
477                                    return session.getId();
478                            }
479                    }
480            }
481    
482            @Override
483            public String getResponseContentType() {
484                    if (_wapTheme) {
485                            return ContentTypes.XHTML_MP;
486                    }
487                    else {
488                            return ContentTypes.TEXT_HTML;
489                    }
490            }
491    
492            @Override
493            public Enumeration<String> getResponseContentTypes() {
494                    List<String> responseContentTypes = new ArrayList<String>();
495    
496                    responseContentTypes.add(getResponseContentType());
497    
498                    return Collections.enumeration(responseContentTypes);
499            }
500    
501            @Override
502            public String getScheme() {
503                    return _request.getScheme();
504            }
505    
506            @Override
507            public String getServerName() {
508                    return _request.getServerName();
509            }
510    
511            @Override
512            public int getServerPort() {
513                    return _request.getServerPort();
514            }
515    
516            public LinkedHashMap<String, String> getUserInfo() {
517                    return UserInfoFactory.getUserInfo(_remoteUserId, _portlet);
518            }
519    
520            @Override
521            public Principal getUserPrincipal() {
522                    return _userPrincipal;
523            }
524    
525            @Override
526            public String getWindowID() {
527                    return _portletName.concat(
528                            LiferayPortletSession.LAYOUT_SEPARATOR).concat(
529                                    String.valueOf(_plid));
530            }
531    
532            @Override
533            public WindowState getWindowState() {
534                    return _windowState;
535            }
536    
537            public void invalidateSession() {
538                    _invalidSession = true;
539            }
540    
541            public boolean isInvalidParameter(String name) {
542                    if (Validator.isNull(name) ||
543                            name.startsWith(PortletQName.PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
544                            name.startsWith(
545                                    PortletQName.REMOVE_PUBLIC_RENDER_PARAMETER_NAMESPACE) ||
546                            PortalUtil.isReservedParameter(name)) {
547    
548                            return true;
549                    }
550                    else {
551                            return false;
552                    }
553            }
554    
555            @Override
556            public boolean isPortletModeAllowed(PortletMode portletMode) {
557                    if ((portletMode == null) || Validator.isNull(portletMode.toString())) {
558                            return true;
559                    }
560                    else {
561                            return _portlet.hasPortletMode(
562                                    getResponseContentType(), portletMode);
563                    }
564            }
565    
566            public boolean isPrivateRequestAttributes() {
567                    return _portlet.isPrivateRequestAttributes();
568            }
569    
570            @Override
571            public boolean isRequestedSessionIdValid() {
572                    return _request.isRequestedSessionIdValid();
573            }
574    
575            @Override
576            public boolean isSecure() {
577                    return _request.isSecure();
578            }
579    
580            public boolean isTriggeredByActionURL() {
581                    return _triggeredByActionURL;
582            }
583    
584            @Override
585            public boolean isUserInRole(String role) {
586                    if (_remoteUserId <= 0) {
587                            return false;
588                    }
589                    else {
590                            try {
591                                    long companyId = PortalUtil.getCompanyId(_request);
592    
593                                    String roleLink = _portlet.getRoleMappers().get(role);
594    
595                                    if (Validator.isNotNull(roleLink)) {
596                                            return RoleLocalServiceUtil.hasUserRole(
597                                                    _remoteUserId, companyId, roleLink, true);
598                                    }
599                                    else {
600                                            return RoleLocalServiceUtil.hasUserRole(
601                                                    _remoteUserId, companyId, role, true);
602                                    }
603                            }
604                            catch (Exception e) {
605                                    _log.error(e);
606                            }
607    
608                            return _request.isUserInRole(role);
609                    }
610            }
611    
612            @Override
613            public boolean isWindowStateAllowed(WindowState windowState) {
614                    return PortalContextImpl.isSupportedWindowState(windowState);
615            }
616    
617            @Override
618            public void removeAttribute(String name) {
619                    if (name == null) {
620                            throw new IllegalArgumentException();
621                    }
622    
623                    _request.removeAttribute(name);
624            }
625    
626            @Override
627            public void setAttribute(String name, Object obj) {
628                    if (name == null) {
629                            throw new IllegalArgumentException();
630                    }
631    
632                    if (obj == null) {
633                            removeAttribute(name);
634                    }
635                    else {
636                            _request.setAttribute(name, obj);
637                    }
638            }
639    
640            public void setPortletMode(PortletMode portletMode) {
641                    _portletMode = portletMode;
642            }
643    
644            public void setPortletRequestDispatcherRequest(HttpServletRequest request) {
645                    _portletRequestDispatcherRequest = request;
646            }
647    
648            public void setWindowState(WindowState windowState) {
649                    _windowState = windowState;
650            }
651    
652            protected void init(
653                    HttpServletRequest request, Portlet portlet,
654                    InvokerPortlet invokerPortlet, PortletContext portletContext,
655                    WindowState windowState, PortletMode portletMode,
656                    PortletPreferences preferences, long plid) {
657    
658                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
659                            WebKeys.THEME_DISPLAY);
660    
661                    _portlet = portlet;
662                    _portletName = portlet.getPortletId();
663                    _publicRenderParameters = PublicRenderParametersPool.get(request, plid);
664    
665                    String portletNamespace = PortalUtil.getPortletNamespace(_portletName);
666    
667                    boolean portalSessionShared = false;
668    
669                    PortletApp portletApp = portlet.getPortletApp();
670    
671                    if (portletApp.isWARFile() && !portlet.isPrivateSessionAttributes()) {
672                            portalSessionShared = true;
673                    }
674    
675                    request = new SharedSessionServletRequest(request, portalSessionShared);
676    
677                    DynamicServletRequest dynamicRequest = null;
678    
679                    if (portlet.isPrivateRequestAttributes()) {
680                            dynamicRequest = new NamespaceServletRequest(
681                                    request, portletNamespace, portletNamespace, false);
682                    }
683                    else {
684                            dynamicRequest = new DynamicServletRequest(request, false);
685                    }
686    
687                    boolean portletFocus = false;
688    
689                    String ppid = ParamUtil.getString(request, "p_p_id");
690    
691                    boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(
692                            request, "p_p_state_rcv");
693    
694                    if (_portletName.equals(ppid) &&
695                            !(windowStateRestoreCurrentView &&
696                              portlet.isRestoreCurrentView())) {
697    
698                            // Request was targeted to this portlet
699    
700                            if (themeDisplay.isLifecycleRender() ||
701                                    themeDisplay.isLifecycleResource()) {
702    
703                                    // Request was triggered by a render or resource URL
704    
705                                    portletFocus = true;
706                            }
707                            else if (themeDisplay.isLifecycleAction()) {
708                                    _triggeredByActionURL = true;
709    
710                                    if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) {
711    
712                                            // Request was triggered by an action URL and is being
713                                            // processed by com.liferay.portlet.ActionRequestImpl
714    
715                                            portletFocus = true;
716                                    }
717                            }
718                    }
719    
720                    if (portletFocus) {
721                            Map<String, String[]> renderParameters =
722                                    new HashMap<String, String[]>();
723    
724                            if (getLifecycle().equals(PortletRequest.RENDER_PHASE) &&
725                                    !LiferayWindowState.isExclusive(request) &&
726                                    !LiferayWindowState.isPopUp(request)) {
727    
728                                    RenderParametersPool.put(
729                                            request, plid, _portletName, renderParameters);
730                            }
731    
732                            Map<String, String[]> parameters = request.getParameterMap();
733    
734                            for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
735                                    String name = entry.getKey();
736    
737                                    if (isInvalidParameter(name)) {
738                                            continue;
739                                    }
740    
741                                    String[] values = entry.getValue();
742    
743                                    if (themeDisplay.isLifecycleRender()) {
744                                            renderParameters.put(name, values);
745                                    }
746    
747                                    if (values == null) {
748                                            continue;
749                                    }
750    
751                                    name = removePortletNamespace(
752                                            invokerPortlet, portletNamespace, name);
753    
754                                    dynamicRequest.setParameterValues(name, values);
755                            }
756                    }
757                    else {
758                            Map<String, String[]> renderParameters = RenderParametersPool.get(
759                                    request, plid, _portletName);
760    
761                            for (Map.Entry<String, String[]> entry :
762                                            renderParameters.entrySet()) {
763    
764                                    String name = entry.getKey();
765                                    String[] values = entry.getValue();
766    
767                                    name = removePortletNamespace(
768                                            invokerPortlet, portletNamespace, name);
769    
770                                    dynamicRequest.setParameterValues(name, values);
771                            }
772                    }
773    
774                    mergePublicRenderParameters(dynamicRequest, preferences, plid);
775    
776                    _request = dynamicRequest;
777                    _originalRequest = request;
778                    _wapTheme = BrowserSnifferUtil.isWap(_request);
779                    _portlet = portlet;
780                    _portalContext = new PortalContextImpl();
781                    _portletContext = portletContext;
782                    _windowState = windowState;
783                    _portletMode = portletMode;
784                    _preferences = preferences;
785                    _session = new PortletSessionImpl(
786                            _request.getSession(), _portletContext, _portletName, plid);
787    
788                    String remoteUser = request.getRemoteUser();
789    
790                    String userPrincipalStrategy = portlet.getUserPrincipalStrategy();
791    
792                    if (userPrincipalStrategy.equals(
793                                    PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) {
794    
795                            try {
796                                    User user = PortalUtil.getUser(request);
797    
798                                    if (user != null) {
799                                            _remoteUser = user.getScreenName();
800                                            _remoteUserId = user.getUserId();
801                                            _userPrincipal = new ProtectedPrincipal(_remoteUser);
802                                    }
803                            }
804                            catch (Exception e) {
805                                    _log.error(e);
806                            }
807                    }
808                    else {
809                            long userId = PortalUtil.getUserId(request);
810    
811                            if ((userId > 0) && (remoteUser == null)) {
812                                    _remoteUser = String.valueOf(userId);
813                                    _remoteUserId = userId;
814                                    _userPrincipal = new ProtectedPrincipal(_remoteUser);
815                            }
816                            else {
817                                    _remoteUser = remoteUser;
818                                    _remoteUserId = GetterUtil.getLong(remoteUser);
819                                    _userPrincipal = request.getUserPrincipal();
820                            }
821                    }
822    
823                    _locale = themeDisplay.getLocale();
824                    _plid = plid;
825            }
826    
827            protected void mergePublicRenderParameters(
828                    DynamicServletRequest dynamicRequest, PortletPreferences preferences,
829                    long plid) {
830    
831                    Enumeration<PublicRenderParameter> publicRenderParameters =
832                            Collections.enumeration(_portlet.getPublicRenderParameters());
833    
834                    while (publicRenderParameters.hasMoreElements()) {
835                            PublicRenderParameter publicRenderParameter =
836                                    publicRenderParameters.nextElement();
837    
838                            String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(
839                                    publicRenderParameter);
840    
841                            boolean ignoreValue = GetterUtil.getBoolean(
842                                    preferences.getValue(ignoreKey, null));
843    
844                            if (ignoreValue) {
845                                    continue;
846                            }
847    
848                            String mappingKey =
849                                    PublicRenderParameterConfiguration.getMappingKey(
850                                            publicRenderParameter);
851    
852                            String mappingValue = GetterUtil.getString(
853                                    preferences.getValue(mappingKey, null));
854    
855                            HttpServletRequest request =
856                                    (HttpServletRequest)dynamicRequest.getRequest();
857    
858                            String[] newValues = request.getParameterValues(mappingValue);
859    
860                            if ((newValues != null) && (newValues.length != 0)) {
861                                    newValues = ArrayUtil.remove(newValues, StringPool.NULL);
862                            }
863    
864                            String name = publicRenderParameter.getIdentifier();
865    
866                            if ((newValues == null) || (newValues.length == 0)) {
867                                    QName qName = publicRenderParameter.getQName();
868    
869                                    String[] values = _publicRenderParameters.get(
870                                            PortletQNameUtil.getPublicRenderParameterName(qName));
871    
872                                    if ((values == null) || (values.length == 0) ||
873                                            Validator.isNull(values[0])) {
874    
875                                            continue;
876                                    }
877    
878                                    if (dynamicRequest.getParameter(name) == null) {
879                                            dynamicRequest.setParameterValues(name, values);
880                                    }
881                            }
882                            else {
883                                    dynamicRequest.setParameterValues(name, newValues);
884                            }
885                    }
886            }
887    
888            protected String removePortletNamespace(
889                    InvokerPortlet invokerPortlet, String portletNamespace, String name) {
890    
891                    if (name.startsWith(portletNamespace) &&
892                            ((invokerPortlet == null) || !invokerPortlet.isFacesPortlet())) {
893    
894                            name = name.substring(portletNamespace.length());
895                    }
896    
897                    return name;
898            }
899    
900            private static Log _log = LogFactoryUtil.getLog(PortletRequestImpl.class);
901    
902            private boolean _invalidSession;
903            private Locale _locale;
904            private HttpServletRequest _originalRequest;
905            private long _plid;
906            private PortalContext _portalContext;
907            private Portlet _portlet;
908            private PortletContext _portletContext;
909            private PortletMode _portletMode;
910            private String _portletName;
911            private HttpServletRequest _portletRequestDispatcherRequest;
912            private PortletPreferences _preferences;
913            private Profile _profile;
914            private Map<String, String[]> _publicRenderParameters;
915            private String _remoteUser;
916            private long _remoteUserId;
917            private HttpServletRequest _request;
918            private PortletSessionImpl _session;
919            private boolean _triggeredByActionURL;
920            private Principal _userPrincipal;
921            private boolean _wapTheme;
922            private WindowState _windowState;
923    
924            private class PortletPreferencesPrivilegedAction
925                    implements PrivilegedAction<PortletPreferences> {
926    
927                    @Override
928                    public PortletPreferences run() {
929                            return new PortletPreferencesWrapper(
930                                    getPreferencesImpl(), getLifecycle());
931                    }
932    
933            }
934    
935    }