1 /*
2 * #%L
3 * Coser :: Web
4 * %%
5 * Copyright (C) 2011 Codelutin, Chatellier Eric, Chemit Tony
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * #L%
20 */
21
22 package fr.ifremer.coser.web.actions.auth;
23
24 import com.opensymphony.xwork2.ActionContext;
25 import com.opensymphony.xwork2.ActionInvocation;
26 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
27
28 import java.util.Map;
29
30 /**
31 * Authentication interceptor.
32 * <p/>
33 * Last update : $Date$
34 * By : $Author$
35 *
36 * @author chatellier
37 * @version $Revision$
38 */
39 public class LoginInterceptor extends AbstractInterceptor {
40
41 private static final long serialVersionUID = 1L;
42
43 public static final String SESSION_PARAMETER_LOGIN = "login";
44
45 @Override
46 public String intercept(ActionInvocation invocation) throws Exception {
47 ActionContext context = invocation.getInvocationContext();
48 Map<String, Object> session = context.getSession();
49 Object login = session.get(SESSION_PARAMETER_LOGIN);
50 String result;
51 if (login == null) {
52 // do login
53 result = "redirect-login";
54 } else {
55 result = invocation.invoke();
56 }
57 return result;
58 }
59 }