1 18 19 package cowsultants.itracker.web.actions; 20 21 import java.io.*; 22 import java.rmi.*; 23 import java.net.*; 24 import java.util.*; 25 import javax.ejb.*; 26 import javax.rmi.*; 27 import javax.naming.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 import org.apache.commons.beanutils.*; 32 import org.apache.struts.action.*; 33 import org.apache.struts.util.*; 34 35 import cowsultants.itracker.ejb.client.interfaces.*; 36 import cowsultants.itracker.ejb.client.models.*; 37 import cowsultants.itracker.ejb.client.util.*; 38 import cowsultants.itracker.web.util.*; 39 40 public abstract class ITrackerAction extends Action { 41 protected static boolean allowSaveLogin = true; 42 43 static { 44 try { 45 InitialContext ic = new InitialContext(); 46 Object scRef = ic.lookup("java:comp/env/" + SystemConfiguration.JNDI_NAME); 47 SystemConfigurationHome scHome = (SystemConfigurationHome) PortableRemoteObject.narrow(scRef, SystemConfigurationHome.class); 48 SystemConfiguration sc = scHome.create(); 49 50 allowSaveLogin = sc.getBooleanProperty("allow_save_login", true); 51 } catch(CreateException ce) { 52 } catch(NamingException ne) { 53 } 54 } 55 56 protected boolean hasPermission(int[] permissionsNeeded, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 57 if(isLoggedIn(request, response)) { 58 HttpSession session = request.getSession(false); 59 HashMap permissions = (session == null ? null : (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY)); 60 if(! UserUtilities.hasPermission(permissions, permissionsNeeded)) { 61 return false; 62 } 63 return true; 64 } 65 return false; 66 } 67 68 protected boolean hasPermission(int permissionNeeded, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 69 if(isLoggedIn(request, response)) { 70 HttpSession session = request.getSession(false); 71 HashMap permissions = (session == null ? null : (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY)); 72 if(! UserUtilities.hasPermission(permissions, permissionNeeded)) { 73 return false; 74 } 75 return true; 76 } 77 return false; 78 } 79 80 protected boolean isLoggedIn(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 81 HttpSession session = request.getSession(false); 82 UserModel user = (session == null ? null : (UserModel) session.getAttribute(Constants.USER_KEY)); 83 String login = (user == null ? null : user.getLogin()); 84 85 if(login == null || "".equals(login)) { 86 LoginUtilities.checkAutoLogin(request, allowSaveLogin); 87 return false; 88 } 89 return true; 90 } 91 92 public String getBaseURL(HttpServletRequest request) { 93 return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); 94 } 95 96 } 97 | Popular Tags |