1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.controller.ControllerRequest; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.DBObject; 70 import com.jcorporate.expresso.core.dbobj.Schema; 71 import com.jcorporate.expresso.core.dbobj.SchemaFactory; 72 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 73 import com.jcorporate.expresso.core.dbobj.ValidValue; 74 75 import java.util.Enumeration ; 76 import java.util.Iterator ; 77 import java.util.Vector ; 78 79 80 87 public class DBObjSecurity 88 extends SecurityDBObject { 89 92 public static final String DBOBJECT_NAME = "DBObjectName"; 93 public static final String GROUP_NAME = "GroupName"; 94 public static final String METHOD_ALLOWED_CODE = "MethodCode"; 95 96 private Vector dbObjList = null; 98 99 102 public DBObjSecurity() 103 throws DBException { 104 super(); 105 } 106 107 108 113 public DBObjSecurity(int uid) 114 throws DBException { 115 super(uid); 116 } 117 118 124 public DBObjSecurity(ControllerRequest request) 125 throws DBException { 126 super(request); 127 } 128 129 132 protected void checkAllRefs() 133 throws DBException { 134 checkRef(GROUP_NAME, new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT), 135 "Invalid " + getString(getMetaData().getDescription(GROUP_NAME))); 136 } 137 138 139 147 private void doSchema(String schemaName, String schemaDescrip, 148 Vector oList) 149 throws DBException { 150 153 Schema oneSchema = SchemaFactory.getInstance().getSchema(schemaName); 154 if (oneSchema == null) { 155 return; 156 } 157 DBObject oneDBObj = null; 158 ValidValue oneVal = null; 159 160 161 for (Enumeration e = oneSchema.getMembers(); e.hasMoreElements();) { 162 oneDBObj = (DBObject) e.nextElement(); 163 oneVal = new ValidValue(oneDBObj.getClass().getName(), 164 schemaDescrip + ": " + 165 oneDBObj.getMetaData().getDescription()); 166 oList.addElement(oneVal); 167 } 168 } 169 170 171 179 public synchronized Vector getValidValues(String fieldName) 180 throws DBException { 181 if (fieldName.equals(METHOD_ALLOWED_CODE)) { 182 Vector myValues = new Vector (4); 183 myValues.addElement(new ValidValue(SecuredDBObject.ADD, "Add")); 184 myValues.addElement(new ValidValue(SecuredDBObject.UPDATE, "Update")); 185 myValues.addElement(new ValidValue(SecuredDBObject.DELETE, "Delete")); 186 myValues.addElement(new ValidValue(SecuredDBObject.SEARCH, "Search")); 187 188 return myValues; 189 } else if (fieldName.equals(DBOBJECT_NAME)) { 190 if (dbObjList == null) { 191 SchemaList myList = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT); 192 myList.setDataContext(getDataContext()); 193 194 SchemaList oneList = null; 195 dbObjList = new Vector (10); 196 dbObjList.addElement(new ValidValue("com.jcorporate.expresso." + "core.dbobj.AutoDBObject", 197 "Expresso: Automatic DB Objects")); 198 doSchema("com.jcorporate.expresso.core.ExpressoSchema", 199 "Expresso", dbObjList); 200 201 202 203 204 DBOtherMap otherList = new DBOtherMap(); 205 otherList.setDataContext(getDataContext()); 206 207 DBOtherMap oneOther = null; 208 209 for (Iterator e2 = otherList.searchAndRetrieveList().iterator(); 210 e2.hasNext();) { 211 oneOther = (DBOtherMap) e2.next(); 212 dbObjList.addElement(new ValidValue(oneOther.getField("DBObjName"), 213 oneOther.getField("Descrip"))); 214 } 215 216 for (Iterator sl = myList.searchAndRetrieveList().iterator(); 217 sl.hasNext();) { 218 oneList = (SchemaList) sl.next(); 219 doSchema(oneList.getField("SchemaClass"), 220 oneList.getField("Descrip"), dbObjList); 221 } 222 223 } 224 225 return dbObjList; 226 } 227 228 return super.getValidValues(fieldName); 229 } 230 231 232 235 protected synchronized void setupFields() 236 throws DBException { 237 setTargetTable("DBOBJSECURITY"); 238 setName("DBOBJSECURITY"); 239 setDescription("DB Object Security"); 240 setCharset("ISO-8859-1"); 241 addField(DBOBJECT_NAME, "varchar", 80, false, "dbobjName"); 242 addField(GROUP_NAME, "char", 30, false, "groupName"); 243 addField(METHOD_ALLOWED_CODE, "char", 1, false, "methodAllowed"); 244 addKey(DBOBJECT_NAME); 245 addKey(METHOD_ALLOWED_CODE); 246 addKey(GROUP_NAME); 247 setStringFilter(DBOBJECT_NAME, "stripFilter"); 248 setStringFilter(GROUP_NAME, "stripFilter"); 249 setStringFilter(METHOD_ALLOWED_CODE, "stripFilter"); 250 setMultiValued(GROUP_NAME); 251 setLookupObject(GROUP_NAME, UserGroup.class.getName()); 252 setMultiValued(METHOD_ALLOWED_CODE); 253 setMultiValued(DBOBJECT_NAME); 254 } 255 256 } 257 258 | Popular Tags |