1 package de.webman.acl; 2 3 import com.teamkonzept.lib.ConfigurationManager; 4 import com.teamkonzept.lib.TKException; 5 import com.teamkonzept.lib.TKVector; 6 import de.webman.acl.db.*; 7 import de.webman.acl.resolver.ResolverFactory; 8 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 9 10 17 public class PolicyFactory 18 extends ObjectFactoryBase 19 implements ObjectFactory 20 { 21 22 24 26 29 private static PolicyFactory SINGLETON = null; 30 31 32 34 37 private PolicyFactory () 38 { 39 super(); 40 } 41 42 43 45 51 public static synchronized final PolicyFactory getInstance () 52 throws TKException 53 { 54 if (SINGLETON == null) 55 { 56 SINGLETON = new PolicyFactory(); 57 SINGLETON.configurationChanged(); 58 ConfigurationManager.getInstance() 59 .registerConfigurationListener(SINGLETON, 60 PROPERTY_GROUP_NAME); 61 } 62 63 return SINGLETON; 64 } 65 66 67 69 74 public final ObjectDBInterface getDBInterface () 75 { 76 return PolicyDBInterface.getInstance(); 77 } 78 79 85 public final ObjectDBData getDBData (Integer id) 86 { 87 return new PolicyDBData(id, null, null, null, null, null, null); 88 } 89 90 96 public final ObjectDBData getDBData (WMObject object) 97 { 98 return new PolicyDBData((Policy) object); 99 } 100 101 107 public final WMObject buildObject (ObjectDBData data) 108 { 109 return new Policy((PolicyDBData) data); 110 } 111 112 113 115 122 public final Policy getPolicy (Integer id) 123 throws TKException 124 { 125 return (Policy) getObject(id); 126 } 127 128 134 public final TKVector getPolicies () 135 throws TKException 136 { 137 return getObjects(); 138 } 139 140 150 public final TKVector getPolicyProxies (Integer login, 151 Integer context, 152 Integer type, 153 Integer reference) 154 throws TKException 155 { 156 TKVector proxies = null; 157 158 try 159 { 160 PolicyDBData data = new PolicyDBData(null, 162 login, 163 null, 164 context, 165 type, 166 reference, 167 null); 168 Class choice = PolicyDBInterface.WM_POLICY_SELECT_BY_USER; 170 171 if (context != null) 172 { 173 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_USER_CONTEXT; 174 175 if (type != null) 176 { 177 if (Policy.CONTENT_TREE_ID.equals(type)) 178 { 179 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_CONTENT_TREE; 180 } 181 else if (Policy.SITE_TREE_ID.equals(type)) 182 { 183 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_SITE_TREE; 184 } 185 else 186 { 187 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_USER_CONTEXT_TYPE; 188 189 if (reference != null) 190 { 191 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_USER_CONTEXT_TYPE_REFERENCE; 192 } 193 } 194 } 195 } 196 197 data.setQuery(choice); 198 data.setPrototype(new ObjectCollectionDBData(null, 199 null, 200 PolicyDBInterface.PRIMARY_KEY_NAME, 201 null)); 202 203 proxies = getObjectIDs(data); 205 } 206 catch (Exception x) 207 { 208 throw WebmanExceptionHandler.getException(x); 209 } 210 211 return proxies; 212 } 213 214 226 public final TKVector getPolicyProxies (Integer event, 227 Integer login, 228 Integer context, 229 Integer type, 230 Integer reference, 231 boolean access) 232 throws TKException 233 { 234 TKVector proxies = null; 235 236 try 237 { 238 PolicyDBData data = new PolicyDBData(null, 240 login, 241 null, 242 context, 243 type, 244 reference, 245 access 246 ? PolicyDBInterface.MODE_ALLOW 247 : PolicyDBInterface.MODE_DENY); 248 Class choice = PolicyDBInterface.WM_POLICY_SELECT_BY_ATOMIC_EVENT; 250 251 if (Policy.CONTENT_TREE_ID.equals(type)) 252 { 253 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_CONTENT_TREE_EVENT; 254 } 255 else if (Policy.SITE_TREE_ID.equals(type)) 256 { 257 choice = PolicyDBInterface.WM_POLICY_SELECT_BY_SITE_TREE_EVENT; 258 } 259 260 data.setQuery(choice); 261 data.setPrototype(new ObjectCollectionDBData(EventDBInterface.PRIMARY_KEY_NAME, 262 event, 263 PolicyDBInterface.PRIMARY_KEY_NAME, 264 null)); 265 266 proxies = getObjectIDs(data); 268 } 269 catch (Exception x) 270 { 271 throw WebmanExceptionHandler.getException(x); 272 } 273 274 return proxies; 275 } 276 277 290 public final Policy createPolicy (Login login, 291 Role role, 292 Context context, 293 Integer type, 294 Integer reference, 295 boolean access) 296 throws TKException 297 { 298 return (Policy) createObject(new PolicyDBData(null, 299 login.getID(), 300 role.getID(), 301 context.getID(), 302 type, 303 reference, 304 access 305 ? PolicyDBInterface.MODE_ALLOW 306 : PolicyDBInterface.MODE_DENY)); 307 } 308 309 315 public final void modifyPolicy (Policy policy) 316 throws TKException 317 { 318 if (policy.isModifiedAssociations()) 319 { 320 ResolverFactory.getInstance().removeResolver(policy.getLogin()); 321 } 322 323 modifyObject(policy); 324 } 325 326 332 public final void deletePolicy (Policy policy) 333 throws TKException 334 { 335 ResolverFactory.getInstance().removeResolver(policy.getLogin()); 336 337 deleteObject(policy); 338 } 339 340 } 341 | Popular Tags |