1 package org.javabb.interceptor; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import org.javabb.infra.UserContext; 7 import org.javabb.vo.User; 8 9 import com.opensymphony.xwork.Action; 10 import com.opensymphony.xwork.ActionContext; 11 import com.opensymphony.xwork.ActionInvocation; 12 import com.opensymphony.xwork.interceptor.AroundInterceptor; 13 14 29 30 34 public class LoginInterceptor extends AroundInterceptor { 35 36 41 protected void before(ActionInvocation invocation) throws Exception { 42 43 } 44 45 52 protected void after(ActionInvocation invocation, String result) throws Exception { 53 } 55 56 59 public String intercept(ActionInvocation invocation) throws Exception { 60 61 boolean loggedIn = false; 62 User user = null; 63 ActionContext ctx = ActionContext.getContext(); 64 Map session = ctx.getSession(); 65 user = UserContext.getContext().getUser(); 66 67 String guest = (String ) session.get("jbbguest"); 68 69 if ((guest != null) && (user != null) 70 && (user.getUser() != null) 71 && !"".equals(user.getUser())) { 72 loggedIn = true; 73 session.remove("jbbUrlBeforeLogin"); 74 } else { 75 loggedIn = false; 76 if(!"login".equals(ctx.getName())){ 77 Map parameters = ctx.getParameters(); 78 String lastURL = ""; 79 80 for (Iterator i = parameters.keySet().iterator(); i.hasNext();) { 81 String param = (String ) i.next(); 82 String [] value = (String []) parameters.get(param); 83 lastURL += (param + "=" + value[0] + "&"); 84 } 85 86 int lastLength = Math.max(0, lastURL.length() - 1); 87 lastURL = lastURL.substring(0, lastLength); 88 89 lastURL = ctx.getName() + ".jbb?" + lastURL; 90 session.put("jbbUrlBeforeLogin", lastURL); 92 } 93 } 94 95 if (loggedIn == false) { 96 return Action.LOGIN; 98 } 99 100 String result = invocation.invoke(); 102 after(invocation, result); 103 104 return result; 105 } 106 } 107 | Popular Tags |