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 cm...@apache.org on 2001/11/02 16:33:38 UTC

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

cmlenz      01/11/02 07:33:38

  Modified:    src/share/org/apache/slide/lock Lock.java LockImpl.java
  Log:
  Make the unlock() method return a boolean to indicate whether the lock
  has been successfully removed. Also, cleaned up the implementation of that
  method in LockImpl a bit, to make it more readable (I think).
  
  Revision  Changes    Path
  1.11      +8 -5      jakarta-slide/src/share/org/apache/slide/lock/Lock.java
  
  Index: Lock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/Lock.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Lock.java	2001/09/08 19:50:37	1.10
  +++ Lock.java	2001/11/02 15:33:38	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/Lock.java,v 1.10 2001/09/08 19:50:37 cmlenz Exp $
  - * $Revision: 1.10 $
  - * $Date: 2001/09/08 19:50:37 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/Lock.java,v 1.11 2001/11/02 15:33:38 cmlenz Exp $
  + * $Revision: 1.11 $
  + * $Date: 2001/11/02 15:33:38 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    * Lock helper class.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public interface Lock {
       
  @@ -109,11 +109,14 @@
        * 
        * @param crendentialsToken Credentials token
        * @param token Object containing all the lock information
  +     * 
  +     * @return <code>true</code> if the lock was successfully removed
  +     * 
        * @exception ServiceAccessException Low level service access exception
        * @exception LockTokenNotFoundException Cannot find the Lock in the 
        * Lock Store service
        */
  -    void unlock(SlideToken slideToken, NodeLock token)
  +    boolean unlock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, LockTokenNotFoundException;
       
       
  
  
  
  1.24      +26 -19    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- LockImpl.java	2001/10/04 13:38:48	1.23
  +++ LockImpl.java	2001/11/02 15:33:38	1.24
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.23 2001/10/04 13:38:48 juergen Exp $
  - * $Revision: 1.23 $
  - * $Date: 2001/10/04 13:38:48 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.24 2001/11/02 15:33:38 cmlenz Exp $
  + * $Revision: 1.24 $
  + * $Date: 2001/11/02 15:33:38 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    * Lock helper class.
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.23 $
  + * @version $Revision: 1.24 $
    */
   public final class LockImpl implements Lock {
       
  @@ -170,31 +170,38 @@
        *
        * @param crendentialsToken Credentials token
        * @param token Object containing all the lock information
  +     * 
  +     * @return <code>true</code> if the lock could be removed
  +     * 
        * @exception ServiceAccessException Low level service access exception
        * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
        */
  -    public void unlock(SlideToken slideToken, NodeLock token)
  +    public boolean unlock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, LockTokenNotFoundException {
  -        Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri(), true);
  +        
           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;
  +            if (!slideToken.isEnforceLockTokens()) {
  +                // Lock-Token checking is not being enforced, so we simply 
  +                // check whether the principal is also the owner of the lock.
  +                ObjectNode principal = securityHelper.getPrincipal(slideToken);
  +                if (!token.getSubjectUri().startsWith(principal.getUri())) {
  +                    return false;
  +                }
  +            } else if (!checkLockToken(slideToken, token)) {
  +                // Lock-Token checking is enforced, but an incorrect Lock-Token
  +                // has been submitted
  +                return false;
               }
           } catch (ObjectNotFoundException e) {
  -            return;
  +            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;
       }
       
       
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>