1 64 65 package com.jcorporate.expresso.core.controller; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBConnectionPool; 69 import com.jcorporate.expresso.core.db.DBException; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.services.dbobj.ControllerSecurity; 72 73 87 abstract public class SecureIfSetController extends DBController { 88 89 92 public SecureIfSetController() { 93 94 } 95 96 108 public boolean stateAllowed(String newState, ControllerRequest params) 109 throws com.jcorporate.expresso.core.controller.ControllerException { 110 if (isDBConnectionAvailable(params.getDataContext())) { 111 return super.stateAllowed(newState, params); 112 } else { 113 return true; 114 } 115 } 116 117 124 public boolean isDBConnectionAvailable(String dataContext) { 125 try { 126 DBConnectionPool pool = DBConnectionPool.getInstance(dataContext); 127 DBConnection connection = pool.getConnection("Security Check"); 128 try { 129 ControllerSecurity cs = new ControllerSecurity(SecuredDBObject.SYSTEM_ACCOUNT); 130 cs.setDataContext(dataContext); 131 cs.count(); 132 } finally { 133 if (connection != null) { 134 connection.release(); 135 } 136 } 137 } catch (DBException ex) { 138 return false; 139 } 140 141 return true; 142 } 143 144 145 } | Popular Tags |