1 23 24 package org.apache.slide.common; 25 26 import java.util.ArrayList ; 27 import java.util.Enumeration ; 28 import java.util.Hashtable ; 29 import java.util.List ; 30 import org.apache.slide.authenticate.CredentialsToken; 31 import org.apache.slide.store.ResourceId; 32 import org.apache.slide.structure.ActionNode; 33 import org.apache.slide.structure.ObjectNode; 34 import org.apache.slide.structure.SubjectNode; 35 36 40 public final class SlideTokenImpl implements SlideToken { 41 42 43 45 46 51 public SlideTokenImpl(CredentialsToken credentialsToken) { 52 this.credentialsToken = credentialsToken; 53 } 54 55 56 59 public SlideTokenImpl() { 60 } 61 62 63 69 public SlideTokenImpl(CredentialsToken credentialsToken, 70 Hashtable parameters) { 71 this.credentialsToken = credentialsToken; 72 this.parameters = parameters; 73 } 74 75 76 78 79 82 private CredentialsToken credentialsToken; 83 84 85 88 private CacheInfoToken cacheInfoToken; 89 90 91 94 private boolean enforceLockTokens = false; 95 96 97 102 private boolean forceStoreEnlistment = false; 103 104 105 108 private Hashtable lockTokens = new Hashtable (); 109 110 111 114 private Hashtable parameters = new Hashtable (); 115 116 119 private Hashtable permissionCache = new Hashtable (); 120 private Hashtable lockCache = new Hashtable (); 121 private Hashtable resolveCache = new Hashtable (); 122 private Hashtable matchPrincipalCache = new Hashtable (); 123 124 127 private boolean isExternalTransaction = false; 128 129 130 132 133 138 public CredentialsToken getCredentialsToken() { 139 return credentialsToken; 140 } 141 142 143 146 public void setCredentialsToken(CredentialsToken credentialsToken) { 147 this.credentialsToken = credentialsToken; 148 } 149 150 151 156 public CacheInfoToken getCacheInfoToken() { 157 return cacheInfoToken; 158 } 159 160 161 164 public void setCacheInfoToken(CacheInfoToken cacheInfoToken) { 165 this.cacheInfoToken = cacheInfoToken; 166 } 167 168 169 174 public boolean isEnforceLockTokens() { 175 return enforceLockTokens; 176 } 177 178 179 184 public void setEnforceLockTokens(boolean enforceLockTokens) { 185 this.enforceLockTokens = enforceLockTokens; 186 } 187 188 189 196 public boolean isForceStoreEnlistment() { 197 return forceStoreEnlistment; 198 } 199 200 201 211 public void setForceStoreEnlistment(boolean forceStoreEnlistment) { 212 this.forceStoreEnlistment = forceStoreEnlistment; 213 } 214 215 216 221 public void addLockToken(String lockId) { 222 lockTokens.put(lockId, lockId); 223 } 224 225 226 231 public void removeLockToken(String lockId) { 232 lockTokens.remove(lockId); 233 } 234 235 236 239 public void clearLockTokens() { 240 lockTokens.clear(); 241 } 242 243 public List showLockTokens() { 244 return new ArrayList (lockTokens.keySet()); 245 } 246 247 253 public boolean checkLockToken(String lockToken) { 254 return lockTokens.containsKey(lockToken); 255 } 256 257 258 264 public void addParameter(String parameterName, Object parameterValue) { 265 parameters.put(parameterName, parameterValue); 266 } 267 268 269 274 public void removeParameter(String parameterName) { 275 parameters.remove(parameterName); 276 } 277 278 279 282 public void clearParameters() { 283 parameters.clear(); 284 } 285 286 287 290 public Enumeration getParameterNames() { 291 return parameters.keys(); 292 } 293 294 297 public Object getParameter(String name) { 298 return parameters.get(name); 299 } 300 301 306 public void cachePermission(ObjectNode object, ActionNode action, boolean permission){ 307 String key = new String (object.getUri()+ action.getUri()); 308 Boolean perm = new Boolean (permission); 309 permissionCache.put(key,perm); 310 } 311 312 318 public Boolean checkPermissionCache(ObjectNode object, ActionNode action){ 319 String key = new String (object.getUri()+ action.getUri()); 320 return (Boolean ) permissionCache.get(key); 321 } 322 323 329 public boolean isForceSecurity() { 330 return true; 331 } 332 333 339 public boolean isForceLock() { 340 return true; 341 } 342 343 346 public void cacheLock(ObjectNode object, ActionNode action, boolean lock) { 347 String key = new String (object.getUri()+ action.getUri()); 348 Boolean locked = new Boolean (lock); 349 lockCache.put(key,locked); 350 } 351 352 358 public Boolean checkLockCache(ObjectNode object, ActionNode action) { 359 String key = new String (object.getUri()+ action.getUri()); 360 return (Boolean ) lockCache.get(key); 361 } 362 363 366 public void cacheResolve(Uri uri, ResourceId resourceId) { 367 if (resourceId != null) { 368 resolveCache.put(uri, resourceId); 369 } else { 370 resolveCache.remove(uri); 371 } 372 } 373 374 378 public ResourceId checkResolveCache(Uri uri) { 379 return (ResourceId)resolveCache.get(uri); 380 } 381 382 385 public void cacheMatchPrincipal(SubjectNode checkSubject, SubjectNode matchSubject, boolean match) { 386 String key = String.valueOf(checkSubject)+String.valueOf(matchSubject); 387 matchPrincipalCache.put(key, new Boolean (match)); 388 } 389 390 394 public Boolean checkMatchPrincipalCache(SubjectNode checkSubject, SubjectNode matchSubject) { 395 String key = String.valueOf(checkSubject)+String.valueOf(matchSubject); 396 return (Boolean )matchPrincipalCache.get(key); 397 } 398 399 public void setForceLock(boolean forceLock) { 400 throw new UnsupportedOperationException (); 401 } 402 403 public void setForceSecurity(boolean forceSecurity) { 404 throw new UnsupportedOperationException (); 405 } 406 407 410 public boolean isExternalTransaction() { 411 return isExternalTransaction; 412 } 413 414 417 public void setExternalTx() { 418 isExternalTransaction = true; 419 } 420 421 } 422 423 | Popular Tags |