You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/05/29 04:46:25 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/lock LockImpl.java

remm        01/05/28 19:46:25

  Modified:    src/share/org/apache/slide/lock LockImpl.java
  Log:
  - Unlock will now check that the current user is the owner of the lock, and
    has submitted the appropriate token.
  - Temporarily add some commented out code which displays some debug info,
    until we make sure the locking bugs are cleared out.
  
  Revision  Changes    Path
  1.15      +43 -7     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- LockImpl.java	2001/05/16 12:04:49	1.14
  +++ LockImpl.java	2001/05/29 02:46:25	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.14 2001/05/16 12:04:49 juergen Exp $
  - * $Revision: 1.14 $
  - * $Date: 2001/05/16 12:04:49 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.15 2001/05/29 02:46:25 remm Exp $
  + * $Revision: 1.15 $
  + * $Date: 2001/05/29 02:46:25 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    * Lock helper class.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public final class LockImpl implements Lock {
       
  @@ -174,6 +174,23 @@
        */
       public void unlock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, LockTokenNotFoundException {
  +        try {
  +            ObjectNode principal = securityHelper.getPrincipal(slideToken);
  +            
  +            // the current principal is the owner of the lock
  +            boolean condition1 = 
  +                token.getSubjectUri().startsWith(principal.getUri());
  +            // Are lock tokens enforced ?
  +            boolean condition2 = slideToken.isEnforceLockTokens();
  +            // Was a proper lock token given out ?
  +            boolean condition3 = checkLockToken(slideToken, token);
  +            
  +            if ((!condition1 && !condition2) || (!condition3 && condition2)) {
  +                return;
  +            }
  +        } catch (ObjectNotFoundException e) {
  +            return;
  +        }
           Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
           lockedUri.getStore().removeLock(lockedUri, token);
       }
  @@ -556,7 +573,17 @@
       private boolean isCompatible(SlideToken slideToken,
                                    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());
  +        */
  +        
           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
  @@ -575,19 +602,28 @@
               boolean condition2 = 
                   (token1.getSubjectUri().startsWith(token2.getSubjectUri()));
               // The two lock types are the same
  -            boolean condition3 = token2.getTypeUri()
  -                .equals(token1.getTypeUri());
  +            boolean condition3 = token1.getTypeUri()
  +                .startsWith(token2.getTypeUri());
               // The lockType is exclusive
               boolean condition4 = token1.isExclusive();
               // Was a proper lock token given out ?
               boolean condition5 = checkLockToken(slideToken, token2);
               // Are lock tokens enforced ?
               boolean condition6 = slideToken.isEnforceLockTokens();
  -            if ((condition1 && condition4) 
  +            if ((condition1 && condition4)
                   || (condition3 && !condition2 && !condition6) 
                   || (condition3 && !condition5 && condition6)) {
                   compatible = false;
               }
  +            /*
  +              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);
  +            */
           }
           return compatible;
       }