1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.RequestContext; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.core.misc.ConfigContext; 72 import com.jcorporate.expresso.core.misc.ConfigManager; 73 import com.jcorporate.expresso.core.misc.StringUtil; 74 import org.apache.log4j.Logger; 75 76 77 132 public abstract class SecurityDBObject extends SecuredDBObject { 133 private static Logger log = Logger.getLogger(SecurityDBObject.class); 134 public static final String SECURITY_CONTEXT = "SecurityDB"; 135 public static final String SECURITY_OBJECTS = "SecurityDBObjs"; 136 137 public SecurityDBObject() throws DBException { 138 super(); 139 } 140 141 148 public SecurityDBObject(int uid) throws DBException { 149 super(uid); 150 } 151 152 159 public SecurityDBObject(RequestContext request) throws DBException { 160 super(request); 161 } 162 163 168 public void setDataContext(String newContext) { 169 try { 170 setDBName(newContext); 171 } catch (DBException e) { 172 throw new IllegalArgumentException (e.getMessage()); 173 } 174 } 175 176 189 public void setDBName(String newContext) throws DBException { 190 super.setDBName(newContext); 191 overrideDataContext(newContext); 192 } 193 194 202 protected void overrideDataContext(String newContext) { 203 try { 204 if (newContext == null || newContext.length() == 0) { 205 newContext = DBConnection.DEFAULT_DB_CONTEXT_NAME; 206 } 207 208 ConfigContext config = ConfigManager.getContext(newContext); 210 if (config != null && config.hasSetupTables()) { 211 String securityDB = StringUtil.notNull(Setup.getValue(newContext, 212 SECURITY_CONTEXT)); 213 String objNames = StringUtil.notNull(Setup.getValue(newContext, 214 SECURITY_OBJECTS)); 215 216 if (objNames.indexOf(getClass().getName()) >= 0) { 219 super.setDBName(securityDB); 220 } 221 } 222 } catch (Exception ex) { 223 String errorMessage = "Problem overriding newContext name: " 224 + newContext + ": " 225 + ex.getMessage(); 226 log.error(errorMessage, ex); 227 throw new IllegalArgumentException (errorMessage); 228 } 229 } 230 } 231 | Popular Tags |