pnever      2003/09/08 06:42:53

  Modified:    src/share/org/apache/slide/lock LockImpl.java
  Log:
  isCompatible did not take NON-lock-inheritance properly into account
  
  Revision  Changes    Path
  1.32      +162 -145  jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java
  
  Index: LockImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- LockImpl.java     21 Jul 2003 08:05:39 -0000      1.31
  +++ LockImpl.java     8 Sep 2003 13:42:53 -0000       1.32
  @@ -72,6 +72,8 @@
   import org.apache.slide.common.ServiceAccessException;
   import org.apache.slide.common.SlideException;
   import org.apache.slide.common.SlideToken;
  +import org.apache.slide.common.SlideTokenImpl;
  +import org.apache.slide.common.SlideTokenWrapper;
   import org.apache.slide.common.Uri;
   import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.security.Security;
  @@ -88,10 +90,10 @@
    * @version $Revision$
    */
   public final class LockImpl implements Lock {
  -
  +    
       // ----------------------------------------------------------- Constructors
  -
  -
  +    
  +    
       /**
        * Constructor.
        *
  @@ -105,32 +107,32 @@
           this.namespaceConfig = namespaceConfig;
           this.securityHelper = securityHelper;
       }
  -
  -
  +    
  +    
       // ----------------------------------------------------- Instance Variables
  -
  -
  +    
  +    
       /**
        * Namespace.
        */
       private Namespace namespace;
  -
  -
  +    
  +    
       /**
        * Namespace configuration.
        */
       private NamespaceConfig namespaceConfig;
  -
  -
  +    
  +    
       /**
        * Security helper.
        */
       private Security securityHelper;
  -
  -
  +    
  +    
       // ----------------------------------------------------------- Lock Methods
  -
  -
  +    
  +    
       /**
        * Put a lock on a subject.
        *
  @@ -147,13 +149,13 @@
       public void lock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, ObjectIsAlreadyLockedException,
           AccessDeniedException, ObjectNotFoundException {
  -
  +        
           ObjectIsAlreadyLockedException nestedException =
               new ObjectIsAlreadyLockedException(token.getObjectUri());
           Uri objectUri = namespace.getUri(slideToken, token.getObjectUri(), true);
           boolean canLock =
               !isLockedInternal(slideToken, token, true, nestedException);
  -
  +        
           // Then we try to lock the subject.
           // If the User doesn't have enough priviledges to accomplish this
           // action, we will get a SecurityException which will in turn be
  @@ -168,10 +170,10 @@
           } else {
               throw nestedException;
           }
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Removes a lock.
        *
  @@ -186,7 +188,7 @@
        */
       public boolean unlock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, LockTokenNotFoundException {
  -
  +        
           try {
               if (!slideToken.isEnforceLockTokens()) {
                   // Lock-Token checking is not being enforced, so we simply
  @@ -203,15 +205,15 @@
           } catch (ObjectNotFoundException e) {
               return false;
           }
  -
  +        
           // all checks successful, so try to actually remove the lock
           Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri(),
                                            true);
           lockedUri.getStore().removeLock(lockedUri, token);
           return true;
       }
  -
  -
  +    
  +    
       /**
        * Removes a set of linked locks.
        *
  @@ -226,7 +228,7 @@
                          String lockId)
           throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
  -
  +        
           Enumeration locksList = enumerateLocks(slideToken, objectUri, false);
           while (locksList.hasMoreElements()) {
               NodeLock currentLock = (NodeLock) locksList.nextElement();
  @@ -236,10 +238,10 @@
                   unlock(slideToken, currentLock);
               }
           }
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Renew a lock.
        *
  @@ -257,8 +259,8 @@
           Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
           lockedUri.getStore().renewLock(lockedUri, token);
       }
  -
  -
  +    
  +    
       /**
        * Renew a set of linked locks.
        *
  @@ -273,7 +275,7 @@
                         String lockId, Date newExpirationDate)
           throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
  -
  +        
           Enumeration locksList = enumerateLocks(slideToken, objectUri, false);
           while (locksList.hasMoreElements()) {
               NodeLock currentLock = (NodeLock) locksList.nextElement();
  @@ -281,10 +283,10 @@
                   renew(slideToken, currentLock, newExpirationDate);
               }
           }
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Kills locks.
        *
  @@ -301,7 +303,7 @@
       public void kill(SlideToken slideToken, SubjectNode subject)
           throws ServiceAccessException, AccessDeniedException,
           LockTokenNotFoundException, ObjectNotFoundException {
  -
  +        
           // We retrieve the enumeration of locks which have been put on the
           // subject.
           Uri subjectUri = namespace.getUri(slideToken, subject.getUri());
  @@ -315,24 +317,24 @@
               subjectUri.getStore()
                   .killLock(subjectUri, (NodeLock) locks.nextElement());
           }
  -
  +        
       }
  -
  +    
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri)
           throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
  -
  +        
           return enumerateLocks(slideToken, objectUri, true);
       }
  -
  +    
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri,
                                         boolean inherited)
           throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
  -
  +        
           // We retrieve the LockStore service from the namespace.
           Uri subjectUri = namespace.getUri(slideToken, objectUri);
  -
  +        
           Enumeration scopes = null;
           if (inherited) {
               // traverse the namespace up to the root node, and add any locks
  @@ -371,8 +373,8 @@
           }
           return locksVector.elements();
       }
  -
  -
  +    
  +    
       /**
        * Utility function for lock checking. Mirrors Security.checkCredentials.
        *
  @@ -389,47 +391,47 @@
                             ObjectNode object, ActionNode action)
           throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
  -
  +        
           if (Configuration.useIntegratedLocking()) {
  -
  +            
               Uri objectUri = namespace.getUri(token, object.getUri());
               ObjectNode realObject = objectUri.getStore()
                   .retrieveObject(objectUri);
  -
  +            
               Uri subjectUri = namespace.getUri(token, 
computeSubjectUriFromPrincipal(token));
               SubjectNode subject = (SubjectNode) subjectUri
                   .getStore().retrieveObject(subjectUri);
               checkLock(token, realObject, subject, action);
  -
  +            
           }
       }
  -
  -
  +    
  +    
       private String computeSubjectUriFromPrincipal(SlideToken token) {
  -
  +        
           String result;
           String configParam = namespaceConfig.getParameter("user_collection");
  -
  +        
           String userCollection;
           if ( configParam != null && configParam.length() > 0) {
               userCollection =  "/" + configParam;
           } else {
               userCollection =  "/";
           }
  -
  -
  +        
  +        
           String userId = token.getCredentialsToken().getPublicCredentials();
           if (userId.equals("/")) userId = "";
  -             else userId = "/" + userId;
  -
  +        else userId = "/" + userId;
  +        
           result = namespaceConfig.getUsersPath() + userCollection + userId;
  -//        System.out.println("##### Subject URI = " + result);
  +        //        System.out.println("##### Subject URI = " + result);
           return result;
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * Check locking for a specific action and credential.
        *
  @@ -448,16 +450,16 @@
                             ActionNode action)
           throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
  -
  +        
           if (Configuration.useIntegratedLocking()) {
               if (isLocked(slideToken, subject, user, action, false)) {
                   throw new ObjectLockedException(subject.getUri());
               }
           }
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Tests if an element is locked.
        *
  @@ -478,8 +480,8 @@
                                         new Date(), false);
           return isLocked(slideToken, token, tryToLock);
       }
  -
  -
  +    
  +    
       /**
        * Tests if an element is locked.
        *
  @@ -505,8 +507,8 @@
                                         inheritance);
           return isLocked(slideToken, token, tryToLock);
       }
  -
  -
  +    
  +    
       /**
        * Tests if an element is locked.
        *
  @@ -519,13 +521,13 @@
       public boolean isLocked(SlideToken slideToken, NodeLock token,
                               boolean tryToLock)
           throws ServiceAccessException, ObjectNotFoundException {
  -
  +        
           return isLockedInternal(slideToken, token, tryToLock, null);
  -
  +        
       }
  -
  +    
       public void clearExpiredLocks( SlideToken slideToken, String objectUri, 
UnlockListener listener ) throws SlideException {
  -
  +        
           Uri uri =
               namespace.getUri(slideToken, objectUri);
           Enumeration currentLocks =
  @@ -545,10 +547,10 @@
               }
           }
       }
  -
  +    
       // -------------------------------------------------------- Private Methods
  -
  -
  +    
  +    
       /**
        * Tests if an element is locked.
        *
  @@ -562,16 +564,16 @@
           (SlideToken slideToken, NodeLock token,
            boolean tryToLock, ObjectIsAlreadyLockedException nestedException)
           throws ServiceAccessException, ObjectNotFoundException {
  -
  +        
           Uri objectUri = namespace.getUri(slideToken, token.getObjectUri(), false);
           ObjectNode initialObject = objectUri.getStore()
               .retrieveObject(objectUri);
           Enumeration scopes = objectUri.getScopes();
  -
  +        
           // At the end of the test, this boolean's value is true if we can
           // actually put the lock on the desired subject.
           boolean isLocked = false;
  -
  +        
           // We parse all of the scopes which encompass the subject we want
           // to lock.
           // First, we parse all the parents of the subject.
  @@ -580,7 +582,7 @@
               Uri currentScopeUri = namespace.getUri(slideToken, currentScope, false);
               Enumeration locks = currentScopeUri.getStore()
                   .enumerateLocks(currentScopeUri);
  -
  +            
               while (locks.hasMoreElements()) {
                   NodeLock currentLockToken = (NodeLock) locks.nextElement();
                   if (!isCompatible(slideToken, token, currentLockToken,
  @@ -589,12 +591,12 @@
                       if (nestedException != null) {
                           nestedException.addException
                               (new ObjectLockedException
  -                             (currentScopeUri.toString()));
  +                                 (currentScopeUri.toString()));
                       }
                   }
               }
           }
  -
  +        
           // Then, if the desired scope is inheritable, we parse the
           // locked subject's children to see if any of them has been
           // locked with an incompatible lock.
  @@ -608,7 +610,7 @@
                   // We test the compatibility of the child
                   Enumeration locks = currentObjectUri.getStore()
                       .enumerateLocks(currentObjectUri);
  -
  +                
                   while (locks.hasMoreElements()) {
                       NodeLock currentLockToken = (NodeLock) locks.nextElement();
                       if (!isCompatible(slideToken, token,
  @@ -617,13 +619,13 @@
                           if (nestedException != null) {
                               nestedException.addException
                                   (new ObjectLockedException
  -                                 (currentObjectUri.toString()));
  +                                     (currentObjectUri.toString()));
                           }
                       }
                   }
  -
  +                
                   // We get the children and add them to the Stack.
  -
  +                
                   Vector childrenVector = new Vector();
                   Enumeration childrenUri = currentObject.enumerateChildren();
                   while (childrenUri.hasMoreElements()) {
  @@ -633,7 +635,7 @@
                           .retrieveObject(tempUri);
                       childrenVector.addElement(child);
                   }
  -
  +                
                   Enumeration children = childrenVector.elements();
                   while (children.hasMoreElements()) {
                       ObjectNode tempObject =
  @@ -642,12 +644,12 @@
                   }
               }
           }
  -
  +        
           return isLocked;
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Return true if a lock token for this lock has been given in the
        * credentials token.
  @@ -657,15 +659,15 @@
        */
       private boolean checkLockToken(SlideToken slideToken,
                                      NodeLock token) {
  -
  +        
           if (!slideToken.isEnforceLockTokens())
               return true;
  -
  +        
           return (slideToken.checkLockToken(token.getLockId()));
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * Tells whether or not two locks are compatible.
        *
  @@ -678,77 +680,92 @@
                                    NodeLock token1, NodeLock token2,
                                    boolean tryToLock) {
           /*
  -          System.out.println("**** Check lock ****");
  -          System.out.println("Lock 1 : " + token1.getSubjectUri() + " action "
  -          + token1.getTypeUri());
  -          System.out.println("Lock 2 : " + token2.getSubjectUri() + " on "
  -          + token2.getObjectUri() + " action "
  -          + token2.getTypeUri());
  -        */
  -
  +         System.out.println("**** Check lock ****");
  +         System.out.println("Lock 1 : " + token1.getSubjectUri() + " action "
  +         + token1.getTypeUri());
  +         System.out.println("Lock 2 : " + token2.getSubjectUri() + " on "
  +         + token2.getObjectUri() + " action "
  +         + token2.getTypeUri());
  +         */
  +        
           boolean compatible = true;
  -
  +        
           // We first check whether or not the lock is still valid
           if (token2.hasExpired()) {
               // Since the lock has expired, it is removed
               try {
  -                Uri token2Uri = namespace.getUri(slideToken,
  -                                                 token2.getObjectUri());
  -                token2Uri.getStore().removeLock(token2Uri, token2);
  +                if (slideToken.isForceStoreEnlistment()) {
  +                    Uri token2Uri = namespace.getUri(slideToken,
  +                                                     token2.getObjectUri());
  +                    token2Uri.getStore().removeLock(token2Uri, token2);
  +                }
               } catch (SlideException e) {
                   e.printStackTrace();
               }
           } else {
  -            // The lockTypes are not equal
  -            boolean condition1 = (tryToLock)
  -                && (token2.getTypeUri().equals(token1.getTypeUri()));
  -            // The user tested is not parent of the token's user
  +            // lock-types-are-equal
  +            boolean condition1 = token2.getTypeUri().equals(token1.getTypeUri());
  +            // user-of-tokens-are-equal OR user-of-token2-is-parent
               boolean condition2 =
                   (token1.getSubjectUri().startsWith(token2.getSubjectUri()));
  -            // The two lock types are the same
  +            // lock-types-are-equal OR lock-type-of-token1-is-parent
               boolean condition3 = token2.getTypeUri()
                   .startsWith(token1.getTypeUri());
  -            // The lockType is exclusive
  +            // token1-is-exclusive
               boolean condition4 = token1.isExclusive();
  -            // Was a proper lock token given out ?
  +            // check-token2-against-slidetoken
               boolean condition5 = checkLockToken(slideToken, token2);
  -            // Are lock tokens enforced ?
  +            // enforced-locktokens
               boolean condition6 = slideToken.isEnforceLockTokens();
  -            if ((condition1 && condition4)
  -                || (condition3 && !condition2 && !condition6)
  -                || (condition3 && !condition5 && condition6)) {
  +            // token2-is-inheritable
  +            boolean condition7 = token2.isInheritable();
  +            
  +            if ((tryToLock && condition1 && condition4 && condition7)
  +                || (condition3 && !condition2 && !condition6 && condition7)
  +                || (condition3 && !condition5 && condition6 && condition7)
  +               ){
                   compatible = false;
               }
  -
  +            
               // sharing the lock is OK
  -            if (token1.isShared() && token2.isShared() && condition1 ) {
  +            if (token1.isShared() && token2.isShared() && tryToLock && condition1 ) 
{
                   compatible = true;
               }
  -
  -//              System.out.println();
  -//              System.out.println("Token1 = " + token1);
  -//              System.out.println("   .getTypeUri    = " + token1.getTypeUri());
  -//              System.out.println("   .getSubjectUri = " + token1.getSubjectUri());
  -//              System.out.println("   .getObjectUri  = " + token1.getObjectUri());
  -//              System.out.println("   .isExclusive   = " + token1.isExclusive());
  -//              System.out.println("Token2 = " + token1);
  -//              System.out.println("   .getTypeUri    = " + token2.getTypeUri());
  -//              System.out.println("   .getSubjectUri = " + token2.getSubjectUri());
  -//              System.out.println("   .getObjectUri  = " + token2.getObjectUri());
  -//              System.out.println("   .isExclusive   = " + token2.isExclusive());
  -//              System.out.println("C1:" + condition1);
  -//              System.out.println("C2:" + condition2);
  -//              System.out.println("C3:" + condition3);
  -//              System.out.println("C4:" + condition4);
  -//              System.out.println("C5:" + condition5);
  -//              System.out.println("C6:" + condition6);
  -//              System.out.println("Compatible:" + compatible);
  -
  +            
  +            //              System.out.println();
  +            //            System.out.println("SlideToken:");
  +            //            System.out.println("   .showLockTokens      = " + 
((SlideTokenImpl)slideToken).showLockTokens());
  +            //            System.out.println("   .isEnforceLockTokens = " + 
slideToken.isEnforceLockTokens());
  +            //              System.out.println("Token1 = " + token1);
  +            //            System.out.println("   .getLockId       = " + 
token1.getLockId());
  +            //              System.out.println("   .getTypeUri    = " + 
token1.getTypeUri());
  +            //              System.out.println("   .getSubjectUri = " + 
token1.getSubjectUri());
  +            //              System.out.println("   .getObjectUri  = " + 
token1.getObjectUri());
  +            //              System.out.println("   .isExclusive   = " + 
token1.isExclusive());
  +            //            System.out.println("   .isInheritable() = " + 
token1.isInheritable());
  +            //            System.out.println("Token2 = " + token2);
  +            //            System.out.println("   .getLockId       = " + 
token2.getLockId());
  +            //              System.out.println("   .getTypeUri    = " + 
token2.getTypeUri());
  +            //              System.out.println("   .getSubjectUri = " + 
token2.getSubjectUri());
  +            //              System.out.println("   .getObjectUri  = " + 
token2.getObjectUri());
  +            //              System.out.println("   .isExclusive   = " + 
token2.isExclusive());
  +            //            System.out.println("   .isInheritable() = " + 
token2.isInheritable());
  +            //            System.out.println("Parameter tryToLock: "+tryToLock);
  +            //            System.out.println("C1 
(lock-types-are-equal).................................: " + condition1);
  +            //            System.out.println("C2 (user-of-tokens-are-equal OR 
user-of-token2-is-parent).: " + condition2);
  +            //            System.out.println("C3 (lock-types-are-equal OR 
lock-type-of-token1-is-parent): " + condition3);
  +            //            System.out.println("C4 
(token1-is-exclusive)..................................: " + condition4);
  +            //            System.out.println("C5 
(check-token2-against-slidetoken)......................: " + condition5);
  +            //            System.out.println("C6 
(enforced-locktokens)..................................: " + condition6);
  +            //            System.out.println("C7 
(token2-is-inheritable)................................: " + condition7);
  +            //            System.out.println("Compatible (tryToLock && C1 && C4 && 
C7 || C3 && !C2 && !C6 && C7 || C3 && !C5 && C6 && C7): " + compatible);
  +            
           }
           return compatible;
       }
  -
  +    
   }
  +
   
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to