1 package org.getahead.dwrdemo.filter; 2 3 import java.lang.reflect.Method ; 4 5 import javax.servlet.http.HttpSession ; 6 7 import org.directwebremoting.AjaxFilter; 8 import org.directwebremoting.AjaxFilterChain; 9 import org.directwebremoting.WebContextFactory; 10 11 15 public class AuthenticationAjaxFilter implements AjaxFilter 16 { 17 20 public Object doFilter(Object object, Method method, Object [] params, AjaxFilterChain chain) throws Exception  21 { 22 if (authenticateName.equals(method.getName())) 24 { 25 return chain.doFilter(object, method, params); 26 } 27 28 Object user = getUser(); 29 if (user != null) 30 { 31 return chain.doFilter(object, method, params); 32 } 33 34 throw new SecurityException ("Not authenticated"); 35 } 36 37 40 public String getAuthenticateName() 41 { 42 return authenticateName; 43 } 44 45 48 public void setAuthenticateName(String authenticateName) 49 { 50 this.authenticateName = authenticateName; 51 } 52 53 56 private String authenticateName = "authenticate"; 57 58 62 public static void setUser(Object user) 63 { 64 HttpSession session = WebContextFactory.get().getSession(true); 65 session.setAttribute(USER, user); 66 } 67 68 72 public static Object getUser() 73 { 74 HttpSession session = WebContextFactory.get().getSession(true); 75 return session.getAttribute(USER); 76 } 77 78 81 private static final String USER = "org.directwebremoting.filter.AuthenticationAjaxFilter.USER"; 82 } 83
| Popular Tags
|