1 20 package org.enhydra.barracuda.examples.ex1; 21 22 import java.io.*; 23 import java.util.*; 24 import java.net.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 28 import org.apache.log4j.*; 29 30 import org.enhydra.barracuda.core.event.*; 31 import org.enhydra.barracuda.plankton.data.*; 32 import org.enhydra.barracuda.plankton.http.*; 33 import org.enhydra.barracuda.examples.ex1.events.*; 34 35 36 42 public class LocalUtilities extends DefaultEventGateway { 43 44 protected static final Logger logger = Logger.getLogger(LocalUtilities.class.getName()); 46 47 private ListenerFactory localRequestFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new LocalRequestHandler();} public String getListenerID() {return getID(LocalRequestHandler.class);}}; 49 50 private LocalRequestEvent lnkLocalRequestEvent; 53 56 public LocalUtilities() { 57 specifyLocalEventInterests(localRequestFactory, LocalRequestEvent.class); 59 } 60 61 74 class LocalRequestHandler extends DefaultBaseEventListener { 75 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 76 HttpServletRequest req = context.getRequest(); 78 DispatchQueue queue = context.getQueue(); 79 80 logger.debug("Locating the event which triggered this one"); 82 List procList = queue.listProcessedEvents(); 83 BaseEvent triggerEvent = (BaseEvent) procList.get(procList.size()-1); 84 logger.debug("Trigger event:"+triggerEvent); 85 86 HttpSession session = req.getSession(); 88 int valid = LoginServices.validateUserPwd(session); 89 logger.debug("Checking for valid user/pwd info in the session...result:"+LoginServices.xrefValidity(valid)); 90 91 if (valid!=LoginServices.VALID && (triggerEvent==null || (!(triggerEvent instanceof LoginScreenEvent)))) { 96 logger.debug("Redirecting to the LoginScreen because they lack valid credentials"); 97 throw new ClientSideRedirectException(new GetLoginScreen()); 98 } 99 100 if (triggerEvent!=null && (triggerEvent instanceof LoginScreenEvent) && valid==LoginServices.VALID) { 105 logger.debug("Redirecting to MainScreen since they already have valid credentials"); 106 107 ObjectRepository lr = ObjectRepository.getLocalRepository(); 116 lr.putState(LoginServices.AUTO_LOGIN, Boolean.TRUE); 117 throw new ClientSideRedirectException(new GetMainScreen()); 119 } 120 } 121 } 122 } 123 124 | Popular Tags |