Source Code Cross Referenced for PortalRequestProcessor.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » struts » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portal.struts;
022:
023:        import com.liferay.portal.LayoutPermissionException;
024:        import com.liferay.portal.PortletActiveException;
025:        import com.liferay.portal.RequiredLayoutException;
026:        import com.liferay.portal.RequiredRoleException;
027:        import com.liferay.portal.UserActiveException;
028:        import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
029:        import com.liferay.portal.kernel.portlet.LiferayWindowState;
030:        import com.liferay.portal.kernel.security.permission.ActionKeys;
031:        import com.liferay.portal.kernel.security.permission.PermissionChecker;
032:        import com.liferay.portal.kernel.util.JavaConstants;
033:        import com.liferay.portal.kernel.util.ParamUtil;
034:        import com.liferay.portal.kernel.util.StringMaker;
035:        import com.liferay.portal.kernel.util.StringPool;
036:        import com.liferay.portal.kernel.util.Validator;
037:        import com.liferay.portal.model.Layout;
038:        import com.liferay.portal.model.Portlet;
039:        import com.liferay.portal.model.PortletPreferencesIds;
040:        import com.liferay.portal.model.User;
041:        import com.liferay.portal.model.UserTracker;
042:        import com.liferay.portal.model.UserTrackerPath;
043:        import com.liferay.portal.model.impl.LayoutImpl;
044:        import com.liferay.portal.security.auth.PrincipalException;
045:        import com.liferay.portal.service.LayoutLocalServiceUtil;
046:        import com.liferay.portal.service.PortletLocalServiceUtil;
047:        import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
048:        import com.liferay.portal.service.permission.PortletPermissionUtil;
049:        import com.liferay.portal.service.persistence.UserTrackerPathUtil;
050:        import com.liferay.portal.theme.ThemeDisplay;
051:        import com.liferay.portal.util.*;
052:        import com.liferay.portlet.CachePortlet;
053:        import com.liferay.portlet.PortletConfigFactory;
054:        import com.liferay.portlet.PortletInstanceFactory;
055:        import com.liferay.portlet.PortletPreferencesFactoryUtil;
056:        import com.liferay.portlet.PortletURLImpl;
057:        import com.liferay.portlet.RenderRequestFactory;
058:        import com.liferay.portlet.RenderRequestImpl;
059:        import com.liferay.portlet.RenderResponseFactory;
060:        import com.liferay.portlet.RenderResponseImpl;
061:        import com.liferay.util.CollectionFactory;
062:        import com.liferay.util.HttpUtil;
063:        import com.liferay.util.servlet.SessionErrors;
064:
065:        import java.io.IOException;
066:
067:        import java.util.Date;
068:        import java.util.Iterator;
069:        import java.util.List;
070:        import java.util.Map.Entry;
071:        import java.util.Map;
072:        import java.util.Set;
073:
074:        import javax.portlet.PortletConfig;
075:        import javax.portlet.PortletContext;
076:        import javax.portlet.PortletMode;
077:        import javax.portlet.PortletPreferences;
078:        import javax.portlet.WindowState;
079:
080:        import javax.servlet.ServletContext;
081:        import javax.servlet.ServletException;
082:        import javax.servlet.http.HttpServletRequest;
083:        import javax.servlet.http.HttpServletResponse;
084:        import javax.servlet.http.HttpSession;
085:        import javax.servlet.jsp.PageContext;
086:
087:        import org.apache.commons.logging.Log;
088:        import org.apache.commons.logging.LogFactory;
089:        import org.apache.struts.action.ActionMapping;
090:        import org.apache.struts.config.ForwardConfig;
091:        import org.apache.struts.tiles.TilesRequestProcessor;
092:
093:        /**
094:         * <a href="PortalRequestProcessor.java.html"><b><i>View Source</i></b></a>
095:         *
096:         * @author Brian Wing Shun Chan
097:         * @author Jorge Ferrer
098:         *
099:         */
100:        public class PortalRequestProcessor extends TilesRequestProcessor {
101:
102:            public PortalRequestProcessor() {
103:
104:                // auth.forward.last.path.
105:
106:                _lastPaths = CollectionFactory.getHashSet();
107:
108:                _lastPaths.add(_PATH_PORTAL_LAYOUT);
109:
110:                _addPaths(_lastPaths, PropsUtil.AUTH_FORWARD_LAST_PATHS);
111:
112:                // auth.public.path.
113:
114:                _publicPaths = CollectionFactory.getHashSet();
115:
116:                _publicPaths.add(_PATH_C);
117:                _publicPaths.add(_PATH_PORTAL_CSS);
118:                _publicPaths.add(_PATH_PORTAL_CSS_CACHED);
119:                _publicPaths.add(_PATH_PORTAL_FLASH);
120:                _publicPaths.add(_PATH_PORTAL_J_LOGIN);
121:                _publicPaths.add(_PATH_PORTAL_JAVASCRIPT);
122:                _publicPaths.add(_PATH_PORTAL_JAVASCRIPT_CACHED);
123:                _publicPaths.add(_PATH_PORTAL_LAYOUT);
124:                _publicPaths.add(_PATH_PORTAL_LOGIN);
125:                _publicPaths.add(_PATH_PORTAL_LOGIN_CAPTCHA);
126:                _publicPaths.add(_PATH_PORTAL_RENDER_PORTLET);
127:                _publicPaths.add(_PATH_PORTAL_TCK);
128:
129:                _addPaths(_publicPaths, PropsUtil.AUTH_PUBLIC_PATHS);
130:
131:                _trackerIgnorePaths = CollectionFactory.getHashSet();
132:
133:                _addPaths(_trackerIgnorePaths,
134:                        PropsUtil.SESSION_TRACKER_IGNORE_PATHS);
135:            }
136:
137:            public void process(HttpServletRequest req, HttpServletResponse res)
138:                    throws IOException, ServletException {
139:
140:                String path = super .processPath(req, res);
141:
142:                ActionMapping mapping = (ActionMapping) moduleConfig
143:                        .findActionConfig(path);
144:
145:                if ((mapping == null) && !path.startsWith(_PATH_WSRP)) {
146:                    String lastPath = getLastPath(req);
147:
148:                    if (_log.isDebugEnabled()) {
149:                        _log.debug("Last path " + lastPath);
150:                    }
151:
152:                    res.sendRedirect(lastPath);
153:
154:                    return;
155:                }
156:
157:                super .process(req, res);
158:
159:                try {
160:                    if (isPortletPath(path)) {
161:                        cleanUp(req);
162:                    }
163:                } catch (Exception e) {
164:                    _log.error(e, e);
165:                }
166:            }
167:
168:            protected void callParentDoForward(String uri,
169:                    HttpServletRequest req, HttpServletResponse res)
170:                    throws IOException, ServletException {
171:
172:                super .doForward(uri, req, res);
173:            }
174:
175:            protected void doForward(String uri, HttpServletRequest req,
176:                    HttpServletResponse res) throws IOException,
177:                    ServletException {
178:
179:                StrutsUtil.forward(uri, getServletContext(), req, res);
180:            }
181:
182:            protected void doInclude(String uri, HttpServletRequest req,
183:                    HttpServletResponse res) throws IOException,
184:                    ServletException {
185:
186:                StrutsUtil.include(uri, getServletContext(), req, res);
187:            }
188:
189:            protected HttpServletRequest callParentProcessMultipart(
190:                    HttpServletRequest req) {
191:
192:                return super .processMultipart(req);
193:            }
194:
195:            protected HttpServletRequest processMultipart(HttpServletRequest req) {
196:
197:                // Disable Struts from automatically wrapping a multipart request
198:
199:                return req;
200:            }
201:
202:            protected String callParentProcessPath(HttpServletRequest req,
203:                    HttpServletResponse res) throws IOException {
204:
205:                return super .processPath(req, res);
206:            }
207:
208:            protected StringMaker getFriendlyTrackerPath(String path,
209:                    ThemeDisplay themeDisplay, HttpServletRequest req)
210:                    throws Exception {
211:
212:                if (!path.equals(_PATH_PORTAL_LAYOUT)) {
213:                    return null;
214:                }
215:
216:                long plid = ParamUtil.getLong(req, "p_l_id");
217:
218:                if (plid == 0) {
219:                    return null;
220:                }
221:
222:                Layout layout = LayoutLocalServiceUtil.getLayout(plid);
223:
224:                String layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(
225:                        layout, themeDisplay);
226:
227:                StringMaker sm = new StringMaker();
228:
229:                sm.append(layoutFriendlyURL);
230:
231:                String portletId = ParamUtil.getString(req, "p_p_id");
232:
233:                if (Validator.isNull(portletId)) {
234:                    return sm;
235:                }
236:
237:                long companyId = PortalUtil.getCompanyId(req);
238:
239:                Portlet portlet = PortletLocalServiceUtil.getPortletById(
240:                        companyId, portletId);
241:
242:                if (portlet == null) {
243:                    String strutsPath = path.substring(1, path
244:                            .lastIndexOf(StringPool.SLASH));
245:
246:                    portlet = PortletLocalServiceUtil.getPortletByStrutsPath(
247:                            companyId, strutsPath);
248:                }
249:
250:                if ((portlet == null) || !portlet.isActive()) {
251:                    sm.append(StringPool.QUESTION);
252:                    sm.append(req.getQueryString());
253:
254:                    return sm;
255:                }
256:
257:                String namespace = PortalUtil.getPortletNamespace(portletId);
258:
259:                FriendlyURLMapper friendlyURLMapper = portlet
260:                        .getFriendlyURLMapperInstance();
261:
262:                if (friendlyURLMapper == null) {
263:                    sm.append(StringPool.QUESTION);
264:                    sm.append(req.getQueryString());
265:
266:                    return sm;
267:                }
268:
269:                PortletURLImpl portletURL = new PortletURLImpl(req, portletId,
270:                        plid, false);
271:
272:                Iterator itr = req.getParameterMap().entrySet().iterator();
273:
274:                while (itr.hasNext()) {
275:                    Entry entry = (Entry) itr.next();
276:
277:                    String key = (String) entry.getKey();
278:
279:                    if (key.startsWith(namespace)) {
280:                        key = key.substring(namespace.length());
281:
282:                        Object value = entry.getValue();
283:
284:                        if (value instanceof  String[]) {
285:                            portletURL.setParameter(key, (String[]) entry
286:                                    .getValue());
287:                        } else {
288:                            portletURL.setParameter(key, (String) entry
289:                                    .getValue());
290:                        }
291:                    }
292:                }
293:
294:                String portletFriendlyURL = friendlyURLMapper
295:                        .buildPath(portletURL);
296:
297:                if (portletFriendlyURL != null) {
298:                    sm.append(portletFriendlyURL);
299:                } else {
300:                    sm.append(StringPool.QUESTION);
301:                    sm.append(req.getQueryString());
302:                }
303:
304:                return sm;
305:            }
306:
307:            protected String processPath(HttpServletRequest req,
308:                    HttpServletResponse res) throws IOException {
309:
310:                String path = super .processPath(req, res);
311:
312:                HttpSession ses = req.getSession();
313:
314:                ThemeDisplay themeDisplay = (ThemeDisplay) req
315:                        .getAttribute(WebKeys.THEME_DISPLAY);
316:
317:                // Current users
318:
319:                UserTracker userTracker = LiveUsers.getUserTracker(ses.getId());
320:
321:                if ((userTracker != null) && (path != null)
322:                        && (!path.equals(_PATH_C))
323:                        && (path.indexOf(_PATH_J_SECURITY_CHECK) == -1)
324:                        && (path.indexOf(_PATH_PORTAL_PROTECTED) == -1)
325:                        && (!_trackerIgnorePaths.contains(path))) {
326:
327:                    StringMaker sm = null;
328:
329:                    try {
330:                        if (PropsValues.SESSION_TRACKER_FRIENDLY_PATHS_ENABLED) {
331:                            sm = getFriendlyTrackerPath(path, themeDisplay, req);
332:                        }
333:                    } catch (Exception e) {
334:                        _log.error(e, e);
335:                    }
336:
337:                    if (sm == null) {
338:                        sm = new StringMaker();
339:
340:                        sm.append(path);
341:                        sm.append(StringPool.QUESTION);
342:                        sm.append(req.getQueryString());
343:                    }
344:
345:                    UserTrackerPath userTrackerPath = UserTrackerPathUtil
346:                            .create(0);
347:
348:                    userTrackerPath.setUserTrackerId(userTracker
349:                            .getUserTrackerId());
350:                    userTrackerPath.setPath(sm.toString());
351:                    userTrackerPath.setPathDate(new Date());
352:
353:                    userTracker.addPath(userTrackerPath);
354:                }
355:
356:                String remoteUser = req.getRemoteUser();
357:
358:                User user = null;
359:
360:                try {
361:                    user = PortalUtil.getUser(req);
362:                } catch (Exception e) {
363:                }
364:
365:                // Last path
366:
367:                if ((path != null) && (_lastPaths.contains(path))
368:                        && (!_trackerIgnorePaths.contains(path))) {
369:
370:                    boolean saveLastPath = ParamUtil.getBoolean(req,
371:                            "save_last_path", true);
372:
373:                    // Exclusive and pop up window states should never be set as the
374:                    // last path
375:
376:                    if (LiferayWindowState.isExclusive(req)
377:                            || LiferayWindowState.isPopUp(req)) {
378:
379:                        saveLastPath = false;
380:                    }
381:
382:                    // Save last path
383:
384:                    if (saveLastPath) {
385:
386:                        // Was a last path set by another servlet that dispatched to
387:                        // the MainServlet? If so, use that last path instead.
388:
389:                        LastPath lastPath = (LastPath) req
390:                                .getAttribute(WebKeys.LAST_PATH);
391:
392:                        if (lastPath == null) {
393:                            lastPath = new LastPath(themeDisplay.getPathMain(),
394:                                    path, req.getParameterMap());
395:                        }
396:
397:                        ses.setAttribute(WebKeys.LAST_PATH, lastPath);
398:                    }
399:                }
400:
401:                // Authenticated users can always log out
402:
403:                if ((remoteUser != null || user != null) && (path != null)
404:                        && (path.equals(_PATH_PORTAL_LOGOUT))) {
405:
406:                    return _PATH_PORTAL_LOGOUT;
407:                }
408:
409:                // Authenticated users can retrieve CSS and JavaScript
410:
411:                if ((remoteUser != null || user != null)
412:                        && (path != null)
413:                        && (path.equals(_PATH_PORTAL_CSS)
414:                                || path.equals(_PATH_PORTAL_CSS_CACHED)
415:                                || path.equals(_PATH_PORTAL_JAVASCRIPT) || path
416:                                .equals(_PATH_PORTAL_JAVASCRIPT_CACHED))) {
417:
418:                    return path;
419:                }
420:
421:                // Authenticated users can always agree to terms of use
422:
423:                if ((remoteUser != null || user != null) && (path != null)
424:                        && (path.equals(_PATH_PORTAL_UPDATE_TERMS_OF_USE))) {
425:
426:                    return _PATH_PORTAL_UPDATE_TERMS_OF_USE;
427:                }
428:
429:                // Authenticated users must still exist in the system
430:
431:                if ((remoteUser != null) && (user == null)) {
432:                    return _PATH_PORTAL_LOGOUT;
433:                }
434:
435:                // Authenticated users must agree to Terms of Use
436:
437:                if ((user != null) && (!user.isAgreedToTermsOfUse())) {
438:                    if (PropsValues.TERMS_OF_USE_REQUIRED) {
439:                        return _PATH_PORTAL_TERMS_OF_USE;
440:                    }
441:                }
442:
443:                // Authenticated users must be active
444:
445:                if ((user != null) && (!user.isActive())) {
446:                    SessionErrors.add(req, UserActiveException.class.getName());
447:
448:                    return _PATH_PORTAL_ERROR;
449:                }
450:
451:                // Authenticated users may not be allowed to have simultaneous logins
452:
453:                if (!PropsValues.AUTH_SIMULTANEOUS_LOGINS) {
454:                    Boolean staleSession = (Boolean) ses
455:                            .getAttribute(WebKeys.STALE_SESSION);
456:
457:                    if ((user != null) && (staleSession != null)
458:                            && (staleSession.booleanValue())) {
459:
460:                        return _PATH_PORTAL_ERROR;
461:                    }
462:                }
463:
464:                // Authenticated users must have a current password
465:
466:                if ((user != null) && (user.isPasswordReset())) {
467:                    return _PATH_PORTAL_CHANGE_PASSWORD;
468:                }
469:
470:                // Authenticated users must have at least one personalized page
471:
472:                if (user != null) {
473:                    List layouts = themeDisplay.getLayouts();
474:
475:                    if ((layouts == null) || (layouts.size() == 0)) {
476:                        SessionErrors.add(req, RequiredLayoutException.class
477:                                .getName());
478:
479:                        return _PATH_PORTAL_ERROR;
480:                    }
481:                }
482:
483:                // Users must sign in
484:
485:                if (!isPublicPath(path)) {
486:                    if (user == null) {
487:                        SessionErrors.add(req, PrincipalException.class
488:                                .getName());
489:
490:                        return _PATH_PORTAL_LOGIN;
491:                    }
492:                }
493:
494:                ActionMapping mapping = (ActionMapping) moduleConfig
495:                        .findActionConfig(path);
496:
497:                if (path.startsWith(_PATH_WSRP)) {
498:                    path = _PATH_WSRP;
499:                } else {
500:                    path = mapping.getPath();
501:                }
502:
503:                // Authenticated users must have at least one role
504:
505:                if (user != null) {
506:                    try {
507:
508:                        // FIX ME
509:
510:                        if (false) {
511:                            SessionErrors.add(req, RequiredRoleException.class
512:                                    .getName());
513:
514:                            return _PATH_PORTAL_ERROR;
515:                        }
516:                    } catch (Exception e) {
517:                        e.printStackTrace();
518:                    }
519:                }
520:
521:                // Define the portlet objects
522:
523:                if (isPortletPath(path)) {
524:                    try {
525:                        Portlet portlet = null;
526:
527:                        long companyId = PortalUtil.getCompanyId(req);
528:                        String portletId = ParamUtil.getString(req, "p_p_id");
529:
530:                        if (Validator.isNotNull(portletId)) {
531:                            portlet = PortletLocalServiceUtil.getPortletById(
532:                                    companyId, portletId);
533:                        }
534:
535:                        if (portlet == null) {
536:                            String strutsPath = path.substring(1, path
537:                                    .lastIndexOf(StringPool.SLASH));
538:
539:                            portlet = PortletLocalServiceUtil
540:                                    .getPortletByStrutsPath(companyId,
541:                                            strutsPath);
542:                        }
543:
544:                        if (portlet != null && portlet.isActive()) {
545:                            defineObjects(req, res, portlet);
546:                        }
547:                    } catch (Exception e) {
548:                        req.setAttribute(PageContext.EXCEPTION, e);
549:
550:                        path = _PATH_COMMON_ERROR;
551:                    }
552:                }
553:
554:                // Authenticated users must have access to at least one layout
555:
556:                if (SessionErrors.contains(req, LayoutPermissionException.class
557:                        .getName())) {
558:
559:                    return _PATH_PORTAL_ERROR;
560:                }
561:
562:                return path;
563:            }
564:
565:            protected boolean callParentProcessRoles(HttpServletRequest req,
566:                    HttpServletResponse res, ActionMapping mapping)
567:                    throws IOException, ServletException {
568:
569:                return super .processRoles(req, res, mapping);
570:            }
571:
572:            protected boolean processRoles(HttpServletRequest req,
573:                    HttpServletResponse res, ActionMapping mapping)
574:                    throws IOException, ServletException {
575:
576:                String path = mapping.getPath();
577:
578:                if (isPublicPath(path)) {
579:                    return true;
580:                }
581:
582:                boolean authorized = true;
583:
584:                User user = null;
585:
586:                try {
587:                    user = PortalUtil.getUser(req);
588:                } catch (Exception e) {
589:                }
590:
591:                if ((user != null) && isPortletPath(path)) {
592:                    try {
593:
594:                        // Authenticated users can always log out
595:
596:                        if (path.equals(_PATH_PORTAL_LOGOUT)) {
597:                            return true;
598:                        }
599:
600:                        Portlet portlet = null;
601:
602:                        String portletId = ParamUtil.getString(req, "p_p_id");
603:
604:                        if (Validator.isNotNull(portletId)) {
605:                            portlet = PortletLocalServiceUtil.getPortletById(
606:                                    user.getCompanyId(), portletId);
607:                        }
608:
609:                        String strutsPath = path.substring(1, path
610:                                .lastIndexOf(StringPool.SLASH));
611:
612:                        if (portlet != null) {
613:                            if (!strutsPath.equals(portlet.getStrutsPath())) {
614:                                throw new PrincipalException();
615:                            }
616:                        } else {
617:                            portlet = PortletLocalServiceUtil
618:                                    .getPortletByStrutsPath(
619:                                            user.getCompanyId(), strutsPath);
620:                        }
621:
622:                        if ((portlet != null) && portlet.isActive()) {
623:                            ThemeDisplay themeDisplay = (ThemeDisplay) req
624:                                    .getAttribute(WebKeys.THEME_DISPLAY);
625:
626:                            Layout layout = themeDisplay.getLayout();
627:                            PermissionChecker permissionChecker = themeDisplay
628:                                    .getPermissionChecker();
629:
630:                            if (!PortletPermissionUtil.contains(
631:                                    permissionChecker, layout.getPlid(),
632:                                    portlet, ActionKeys.VIEW)) {
633:
634:                                throw new PrincipalException();
635:                            }
636:                        } else if (portlet != null && !portlet.isActive()) {
637:                            SessionErrors.add(req, PortletActiveException.class
638:                                    .getName());
639:
640:                            authorized = false;
641:                        }
642:                    } catch (Exception e) {
643:                        SessionErrors.add(req, PrincipalException.class
644:                                .getName());
645:
646:                        authorized = false;
647:                    }
648:                }
649:
650:                if (!authorized) {
651:                    ForwardConfig forwardConfig = mapping
652:                            .findForward(_PATH_PORTAL_ERROR);
653:
654:                    processForwardConfig(req, res, forwardConfig);
655:
656:                    return false;
657:                } else {
658:                    return true;
659:                }
660:            }
661:
662:            protected String getLastPath(HttpServletRequest req) {
663:                HttpSession ses = req.getSession();
664:
665:                ThemeDisplay themeDisplay = (ThemeDisplay) req
666:                        .getAttribute(WebKeys.THEME_DISPLAY);
667:
668:                Boolean httpsInitial = (Boolean) ses
669:                        .getAttribute(WebKeys.HTTPS_INITIAL);
670:
671:                String portalURL = null;
672:
673:                if ((PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS)
674:                        && (httpsInitial != null)
675:                        && (!httpsInitial.booleanValue())) {
676:
677:                    portalURL = PortalUtil.getPortalURL(req, false);
678:                } else {
679:                    portalURL = PortalUtil.getPortalURL(req);
680:                }
681:
682:                StringMaker sm = new StringMaker();
683:
684:                sm.append(portalURL);
685:                sm.append(themeDisplay.getPathMain());
686:                sm.append(_PATH_PORTAL_LAYOUT);
687:
688:                if (!PropsValues.AUTH_FORWARD_BY_LAST_PATH) {
689:                    if (req.getRemoteUser() != null) {
690:
691:                        // If we do not forward by last path and the user is logged in,
692:                        // forward to the user's default layout to prevent a lagging
693:                        // loop
694:
695:                        sm.append(StringPool.QUESTION);
696:                        sm.append("p_l_id");
697:                        sm.append(StringPool.EQUAL);
698:                        sm.append(LayoutImpl.DEFAULT_PLID);
699:                    }
700:
701:                    return sm.toString();
702:                }
703:
704:                LastPath lastPath = (LastPath) ses
705:                        .getAttribute(WebKeys.LAST_PATH);
706:
707:                if (lastPath == null) {
708:                    return sm.toString();
709:                }
710:
711:                Map parameterMap = lastPath.getParameterMap();
712:
713:                // Only test for existing mappings for last paths that were set when the
714:                // user accessed a layout directly instead of through its friendly URL
715:
716:                if (lastPath.getContextPath()
717:                        .equals(themeDisplay.getPathMain())) {
718:                    ActionMapping mapping = (ActionMapping) moduleConfig
719:                            .findActionConfig(lastPath.getPath());
720:
721:                    if ((mapping == null) || (parameterMap == null)) {
722:                        return sm.toString();
723:                    }
724:                }
725:
726:                StringMaker lastPathSM = new StringMaker();
727:
728:                lastPathSM.append(portalURL);
729:                lastPathSM.append(lastPath.getContextPath());
730:                lastPathSM.append(lastPath.getPath());
731:                lastPathSM.append(HttpUtil.parameterMapToString(parameterMap));
732:
733:                return lastPathSM.toString();
734:            }
735:
736:            protected boolean isPortletPath(String path) {
737:                if ((path != null) && (!path.equals(_PATH_C))
738:                        && (!path.startsWith(_PATH_COMMON))
739:                        && (path.indexOf(_PATH_J_SECURITY_CHECK) == -1)
740:                        && (!path.startsWith(_PATH_PORTAL))
741:                        && (!path.startsWith(_PATH_WSRP))) {
742:
743:                    return true;
744:                } else {
745:                    return false;
746:                }
747:            }
748:
749:            protected boolean isPublicPath(String path) {
750:                if ((path != null) && (_publicPaths.contains(path))
751:                        || (path.startsWith(_PATH_COMMON))
752:                        || (path.startsWith(_PATH_WSRP))) {
753:
754:                    return true;
755:                } else {
756:                    return false;
757:                }
758:            }
759:
760:            protected void defineObjects(HttpServletRequest req,
761:                    HttpServletResponse res, Portlet portlet) throws Exception {
762:
763:                String portletId = portlet.getPortletId();
764:
765:                ServletContext ctx = (ServletContext) req
766:                        .getAttribute(WebKeys.CTX);
767:
768:                CachePortlet cachePortlet = PortletInstanceFactory.create(
769:                        portlet, ctx);
770:
771:                PortletPreferencesIds portletPreferencesIds = PortletPreferencesFactoryUtil
772:                        .getPortletPreferencesIds(req, portletId);
773:
774:                PortletPreferences portletPreferences = PortletPreferencesLocalServiceUtil
775:                        .getPreferences(portletPreferencesIds);
776:
777:                PortletConfig portletConfig = PortletConfigFactory.create(
778:                        portlet, ctx);
779:                PortletContext portletCtx = portletConfig.getPortletContext();
780:
781:                RenderRequestImpl renderRequestImpl = RenderRequestFactory
782:                        .create(req, portlet, cachePortlet, portletCtx,
783:                                WindowState.MAXIMIZED, PortletMode.VIEW,
784:                                portletPreferences);
785:
786:                RenderResponseImpl renderResponseImpl = RenderResponseFactory
787:                        .create(renderRequestImpl, res, portletId, portlet
788:                                .getCompanyId());
789:
790:                renderRequestImpl.defineObjects(portletConfig,
791:                        renderResponseImpl);
792:
793:                req.setAttribute(WebKeys.PORTLET_STRUTS_EXECUTE, Boolean.TRUE);
794:            }
795:
796:            protected void cleanUp(HttpServletRequest req) throws Exception {
797:
798:                // Clean up portlet objects that may have been created by defineObjects
799:                // for portlets that are called directly from a Struts path
800:
801:                RenderRequestImpl renderRequestImpl = (RenderRequestImpl) req
802:                        .getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
803:
804:                if (renderRequestImpl != null) {
805:                    RenderRequestFactory.recycle(renderRequestImpl);
806:                }
807:
808:                RenderResponseImpl renderResponseImpl = (RenderResponseImpl) req
809:                        .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
810:
811:                if (renderResponseImpl != null) {
812:                    RenderResponseFactory.recycle(renderResponseImpl);
813:                }
814:            }
815:
816:            private void _addPaths(Set paths, String propsKey) {
817:                String[] pathsArray = PropsUtil.getArray(propsKey);
818:
819:                for (int i = 0; i < pathsArray.length; i++) {
820:                    paths.add(pathsArray[i]);
821:                }
822:            }
823:
824:            private static String _PATH_C = "/c";
825:
826:            private static String _PATH_COMMON = "/common";
827:
828:            private static String _PATH_COMMON_ERROR = "/common/error";
829:
830:            private static String _PATH_J_SECURITY_CHECK = "/j_security_check";
831:
832:            private static String _PATH_PORTAL = "/portal";
833:
834:            private static String _PATH_PORTAL_CHANGE_PASSWORD = "/portal/change_password";
835:
836:            private static String _PATH_PORTAL_CSS = "/portal/css";
837:
838:            private static String _PATH_PORTAL_CSS_CACHED = "/portal/css_cached";
839:
840:            private static String _PATH_PORTAL_ERROR = "/portal/error";
841:
842:            private static String _PATH_PORTAL_FLASH = "/portal/flash";
843:
844:            private static String _PATH_PORTAL_J_LOGIN = "/portal/j_login";
845:
846:            private static String _PATH_PORTAL_JAVASCRIPT = "/portal/javascript";
847:
848:            private static String _PATH_PORTAL_JAVASCRIPT_CACHED = "/portal/javascript_cached";
849:
850:            private static String _PATH_PORTAL_LAYOUT = "/portal/layout";
851:
852:            private static String _PATH_PORTAL_LOGIN = "/portal/login";
853:
854:            private static String _PATH_PORTAL_LOGIN_CAPTCHA = "/portal/login_captcha";
855:
856:            private static String _PATH_PORTAL_LOGOUT = "/portal/logout";
857:
858:            private static String _PATH_PORTAL_PROTECTED = "/portal/protected";
859:
860:            private static String _PATH_PORTAL_RENDER_PORTLET = "/portal/render_portlet";
861:
862:            private static String _PATH_PORTAL_TCK = "/portal/tck";
863:
864:            private static String _PATH_PORTAL_TERMS_OF_USE = "/portal/terms_of_use";
865:
866:            private static String _PATH_PORTAL_UPDATE_TERMS_OF_USE = "/portal/update_terms_of_use";
867:
868:            private static String _PATH_WSRP = "/wsrp";
869:
870:            private static Log _log = LogFactory
871:                    .getLog(PortalRequestProcessor.class);
872:
873:            private Set _lastPaths;
874:            private Set _publicPaths;
875:            private Set _trackerIgnorePaths;
876:
877:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.