KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > params > valves > SessionAuthValveImpl


1 package org.jahia.params.valves;
2
3 import org.jahia.exceptions.JahiaSessionExpirationException;
4 import org.jahia.params.ParamBean;
5 import org.jahia.pipelines.PipelineException;
6 import org.jahia.pipelines.valves.Valve;
7 import org.jahia.pipelines.valves.ValveContext;
8 import org.jahia.services.usermanager.JahiaUser;
9
10 /**
11  * <p>Title: </p>
12  * <p>Description: </p>
13  * <p>Copyright: Copyright (c) 2004</p>
14  * <p>Company: Jahia Ltd</p>
15  * @author not attributable
16  * @version 1.0
17  */

18
19 public class SessionAuthValveImpl implements Valve {
20     public SessionAuthValveImpl() {
21     }
22
23     public void invoke(Object JavaDoc context, ValveContext valveContext) throws PipelineException {
24         ParamBean paramBean = (ParamBean) context;
25         JahiaUser jahiaUser = null;
26         // Get the current user out of the session. If there is no user
27
// present, then assign the guest user to this session.
28
// If the site has changed, switch to user to guest user
29
try {
30             if (!"login".equals(paramBean.getEngine())) {
31                 jahiaUser = (JahiaUser) paramBean.getSession().getAttribute(ParamBean.SESSION_USER);
32             }
33         } catch (JahiaSessionExpirationException jsee) {
34             jahiaUser = null;
35         }
36
37         if (jahiaUser == null) {
38             valveContext.invokeNext(context);
39         } else {
40             paramBean.setTheUser(jahiaUser);
41         }
42     }
43
44     public void initialize() {
45     }
46
47 }
48
Popular Tags