1 19 20 package za.org.coefficient.interceptors; 21 22 import org.apache.commons.httpclient.Cookie; 23 24 import za.org.coefficient.core.CoefficientInterceptor; 25 import za.org.coefficient.interfaces.CoefficientContext; 26 import za.org.coefficient.util.common.InvokerFactory; 27 28 33 public class PersistentLoginInterceptor extends CoefficientInterceptor { 34 36 private static final String CHECKED_FOR_COOKIES = "__checked_for_cookies"; 37 38 40 protected int handleInvoke(CoefficientContext ctx) throws Exception { 41 int retVal = INVOKE_PROCESS_CHILD; 42 String mod = ctx.getParameter("module", ""); 43 String op = ctx.getParameter("op", ""); 44 if ((ctx.getCurrentUser() == null) 45 && (ctx.getSessionAttribute(CHECKED_FOR_COOKIES) == null) 46 && (!mod.equalsIgnoreCase("security") && !op.equals("login"))) { 47 Cookie[] cookies = ctx.getCookies(); 49 if (cookies != null) { 50 String username = null; 51 String password = null; 52 for (int i = 0; i < cookies.length; i++) { 53 Cookie cookie = cookies[i]; 54 if ("coefficient_username".equals(cookie.getName())) { 55 username = cookie.getValue(); 56 if(username != null && username.trim().equals("")) { 58 username = null; 59 } 60 } 61 if ("coefficient_password".equals(cookie.getName())) { 62 password = cookie.getValue(); 63 if(password != null && password.trim().equals("")) { 65 password = null; 66 } 67 } 68 } 69 if ((username != null) && (password != null)) { 70 ctx.setRequestAttribute("password", password); 71 ctx.setRequestAttribute("username", username); 72 ctx.setRequestAttribute("hashedPassword", new Boolean (true)); 73 Object context = InvokerFactory.getRemoteInvoker() 74 .invokeOpOnModule("Security", "login", ctx); 75 if(context instanceof CoefficientContext) { 76 ctx = (CoefficientContext)context; 77 } 78 ctx.removeRequestAttribute("password"); 79 ctx.removeRequestAttribute("username"); 80 ctx.removeRequestAttribute("hashedPassword"); 81 } 82 } 83 ctx.setSessionAttribute(CHECKED_FOR_COOKIES, new Boolean (true)); 84 } 85 86 return retVal; 88 } 89 } 90 | Popular Tags |