// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package test;

import com.opensymphony.webwork.*;
import com.opensymphony.xwork.*;
import com.opensymphony.xwork.interceptor.*;

public class LoginInterceptor extends AroundInterceptor {
   private boolean loggedin;
   protected void before(ActionInvocation inv) {
       loggedin = (ServletActionContext.getRequest().getSession().getAttribute("user") != null);
   }
   protected void after(ActionInvocation inv, String result) {
   }
   public String intercept(ActionInvocation inv) throws Exception {
       loggedin = false;
       before(inv);
       if(loggedin) {
           return inv.invoke();
       } else {
           return "not.logged.in";
       }
   }
}
