juergen     01/09/10 04:37:23

  Modified:    src/share/org/apache/slide/lock LockImpl.java
  Log:
  isLockedInternal do not enforce the retrieved URI to be included in the transaction 
as write. Lock and unlock do include them at the beginning of the method.
  
  Revision  Changes    Path
  1.20      +107 -107  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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- LockImpl.java     2001/09/09 12:05:57     1.19
  +++ LockImpl.java     2001/09/10 11:37:22     1.20
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 
1.19 2001/09/09 12:05:57 cmlenz Exp $
  - * $Revision: 1.19 $
  - * $Date: 2001/09/09 12:05:57 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 
1.20 2001/09/10 11:37:22 juergen Exp $
  + * $Revision: 1.20 $
  + * $Date: 2001/09/10 11:37:22 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact [EMAIL PROTECTED]
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -59,7 +59,7 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   package org.apache.slide.lock;
   
  @@ -76,9 +76,9 @@
   
   /**
    * Lock helper class.
  - * 
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.19 $
  + * @version $Revision: 1.20 $
    */
   public final class LockImpl implements Lock {
       
  @@ -87,12 +87,12 @@
       
       /**
        * Constructor.
  -     * 
  +     *
        * @param namespace Associated namespace
        * @param namespaceConfig Namespace configuration
        * @param securityHelper Security helper
        */
  -    public LockImpl(Namespace namespace, NamespaceConfig namespaceConfig, 
  +    public LockImpl(Namespace namespace, NamespaceConfig namespaceConfig,
                       Security securityHelper) {
           this.namespace = namespace;
           this.namespaceConfig = namespaceConfig;
  @@ -126,62 +126,62 @@
       
       /**
        * Put a lock on a subject.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @param token Object containing all the lock information
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
  -     * @exception ObjectIsAlreadyLockedException Object is already locked 
  +     * @exception ObjectIsAlreadyLockedException Object is already locked
        * with an incompatible lock token
  -     * @exception AccessDeniedException Insufficient credentials to allow 
  +     * @exception AccessDeniedException Insufficient credentials to allow
        * object locking
        */
       public void lock(SlideToken slideToken, NodeLock token)
  -        throws ServiceAccessException, ObjectIsAlreadyLockedException, 
  +        throws ServiceAccessException, ObjectIsAlreadyLockedException,
           AccessDeniedException, ObjectNotFoundException {
           
  -        ObjectIsAlreadyLockedException nestedException = 
  +        ObjectIsAlreadyLockedException nestedException =
               new ObjectIsAlreadyLockedException(token.getObjectUri());
  -        boolean canLock = 
  +        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 
  +        // If the User doesn't have enough priviledges to accomplish this
  +        // action, we will get a SecurityException which will in turn be
           // thrown by this function.
           if (canLock) {
  -            Uri objectUri = namespace.getUri(slideToken, token.getObjectUri());
               ObjectNode lockedObject = objectUri.getStore()
                   .retrieveObject(objectUri);
               securityHelper
  -                .checkCredentials(slideToken, lockedObject, 
  +                .checkCredentials(slideToken, lockedObject,
                                     namespaceConfig.getLockObjectAction());
  -            Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
  -            lockedUri.getStore().putLock(lockedUri, token);
  +            objectUri.getStore().putLock(objectUri, token);
           } else {
               throw nestedException;
           }
  -     
  +    
       }
       
       
       /**
        * Removes a lock.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @param token Object containing all the lock information
        * @exception ServiceAccessException Low level service access exception
  -     * @exception LockTokenNotFoundException Cannot find the Lock in the 
  +     * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
        */
       public void 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 = 
  +            boolean condition1 =
                   token.getSubjectUri().startsWith(principal.getUri());
               // Are lock tokens enforced ?
               boolean condition2 = slideToken.isEnforceLockTokens();
  @@ -194,24 +194,23 @@
           } catch (ObjectNotFoundException e) {
               return;
           }
  -        Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
           lockedUri.getStore().removeLock(lockedUri, token);
       }
       
       
       /**
        * Removes a set of linked locks.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @exception ServiceAccessException Low level service access exception
  -     * @exception LockTokenNotFoundException Cannot find the Lock in the 
  +     * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public void unlock(SlideToken slideToken, String objectUri, 
  +    public void unlock(SlideToken slideToken, String objectUri,
                          String lockId)
  -        throws ServiceAccessException, LockTokenNotFoundException, 
  +        throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
           
           Enumeration locksList = enumerateLocks(slideToken, objectUri);
  @@ -229,15 +228,15 @@
       
       /**
        * Renew a lock.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
  -     * @param token Object containing the lock info, as well as the new 
  +     * @param token Object containing the lock info, as well as the new
        * desired expiration date
        * @exception ServiceAccessException Low level service access exception
  -     * @exception LockTokenNotFoundException Cannot find the Lock in 
  +     * @exception LockTokenNotFoundException Cannot find the Lock in
        * the Lock Store service
        */
  -    public void renew(SlideToken slideToken, NodeLock token, 
  +    public void renew(SlideToken slideToken, NodeLock token,
                         Date newExpirationDate)
           throws ServiceAccessException, LockTokenNotFoundException {
           token.setExpirationDate(newExpirationDate);
  @@ -248,17 +247,17 @@
       
       /**
        * Renew a set of linked locks.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @exception ServiceAccessException Low level service access exception
  -     * @exception LockTokenNotFoundException Cannot find the Lock in the 
  +     * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public void renew(SlideToken slideToken, String objectUri, 
  +    public void renew(SlideToken slideToken, String objectUri,
                         String lockId, Date newExpirationDate)
  -        throws ServiceAccessException, LockTokenNotFoundException, 
  +        throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
           
           Enumeration locksList = enumerateLocks(slideToken, objectUri);
  @@ -274,22 +273,22 @@
       
       /**
        * Kills locks.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @param subject Subject on which locks are to be removed
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced in 
  +     * @exception ObjectNotFoundException One of the objects referenced in
        * the lock token were not found
  -     * @exception LockTokenNotFoundException Cannot find the Lock in the 
  +     * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
  -     * @exception AccessDeniedException Insufficient credentials to allow 
  +     * @exception AccessDeniedException Insufficient credentials to allow
        * forced removal of locks
        */
       public void kill(SlideToken slideToken, SubjectNode subject)
  -        throws ServiceAccessException, AccessDeniedException, 
  +        throws ServiceAccessException, AccessDeniedException,
           LockTokenNotFoundException, ObjectNotFoundException {
           
  -        // We retrieve the enumeration of locks which have been put on the 
  +        // We retrieve the enumeration of locks which have been put on the
           // subject.
           Uri subjectUri = namespace.getUri(slideToken, subject.getUri());
           Enumeration locks = subjectUri.getStore()
  @@ -297,7 +296,7 @@
           // Then, try to kill each individual lock.
           while (locks.hasMoreElements()) {
               securityHelper
  -                .checkCredentials(slideToken, subject, 
  +                .checkCredentials(slideToken, subject,
                                     namespaceConfig.getKillLockAction());
               subjectUri.getStore()
                   .killLock(subjectUri, (NodeLock) locks.nextElement());
  @@ -307,7 +306,7 @@
       
       
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri)
  -        throws ServiceAccessException, ObjectNotFoundException, 
  +        throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
           
           return enumerateLocks(slideToken, objectUri, true);
  @@ -316,7 +315,7 @@
       
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri,
                                         boolean inherited)
  -        throws ServiceAccessException, ObjectNotFoundException, 
  +        throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
           
           // We retrieve the LockStore service from the namespace.
  @@ -329,12 +328,12 @@
               Enumeration scopes = subjectUri.getScopes();
               while (scopes.hasMoreElements()) {
                   String currentScope = (String) scopes.nextElement();
  -                Uri currentScopeUri = 
  +                Uri currentScopeUri =
                       namespace.getUri(slideToken, currentScope);
  -                Enumeration currentLocks = 
  +                Enumeration currentLocks =
                       currentScopeUri.getStore().enumerateLocks(currentScopeUri);
                   while (currentLocks.hasMoreElements()) {
  -                    NodeLock currentLockToken = 
  +                    NodeLock currentLockToken =
                           (NodeLock) currentLocks.nextElement();
                       if (currentLockToken.hasExpired()) {
                           currentScopeUri.getStore()
  @@ -346,7 +345,7 @@
               }
               return locksVector.elements();
           } else {
  -            // only return the locks that explicitly and directly lock the 
  +            // only return the locks that explicitly and directly lock the
               // given subject
               return subjectUri.getStore().enumerateLocks(subjectUri);
           }
  @@ -355,19 +354,19 @@
       
       /**
        * Utility function for lock checking. Mirrors Security.checkCredentials.
  -     * 
  +     *
        * @param token Credetials token
        * @param subject Object on which the action is performed
        * @param action Action to test
  -     * @exception ObjectLockedException Can't perform specified action 
  +     * @exception ObjectLockedException Can't perform specified action
        * on object
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public void checkLock(SlideToken token, 
  +    public void checkLock(SlideToken token,
                             ObjectNode object, ActionNode action)
  -        throws ServiceAccessException, ObjectNotFoundException, 
  +        throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
           
           if (Configuration.useIntegratedLocking()) {
  @@ -389,21 +388,21 @@
       
       /**
        * Check locking for a specific action and credential.
  -     * 
  +     *
        * @param slideToken Credetials token
        * @param subject Subject to test
        * @param user User to test
        * @param action Action to test
  -     * @exception ObjectLockedException Can't perform specified action 
  +     * @exception ObjectLockedException Can't perform specified action
        * on object
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public void checkLock(SlideToken slideToken, 
  -                          ObjectNode subject, SubjectNode user, 
  +    public void checkLock(SlideToken slideToken,
  +                          ObjectNode subject, SubjectNode user,
                             ActionNode action)
  -        throws ServiceAccessException, ObjectNotFoundException, 
  +        throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
           
           if (Configuration.useIntegratedLocking()) {
  @@ -417,21 +416,21 @@
       
       /**
        * Tests if an element is locked.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @param subject Subject to test
        * @param user User to test
        * @param action Locked for action
        * @return boolean True if the subject is locked
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public boolean isLocked(SlideToken slideToken, 
  -                            ObjectNode subject, SubjectNode user, 
  +    public boolean isLocked(SlideToken slideToken,
  +                            ObjectNode subject, SubjectNode user,
                               ActionNode action, boolean tryToLock)
           throws ServiceAccessException, ObjectNotFoundException {
  -        NodeLock token = new NodeLock(subject, user, action, 
  +        NodeLock token = new NodeLock(subject, user, action,
                                         new Date(), false);
           return isLocked(slideToken, token, tryToLock);
       }
  @@ -439,26 +438,26 @@
       
       /**
        * Tests if an element is locked.
  -     * 
  +     *
        * @param crendentialsToken Credentials token
        * @param subject Subject to test
        * @param user User to test
        * @param action Locked for action
  -     * @param inheritance Set to true if we want to check if any children 
  +     * @param inheritance Set to true if we want to check if any children
        * is locked with an incompatible lock
  -     * @param tryToLock True if the check is intended to check whether 
  +     * @param tryToLock True if the check is intended to check whether
        * or not we can put a new lock
        * @return boolean True if the subject is locked
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
  -    public boolean isLocked(SlideToken slideToken, 
  -                            ObjectNode subject, SubjectNode user, 
  -                            ActionNode action, boolean inheritance, 
  +    public boolean isLocked(SlideToken slideToken,
  +                            ObjectNode subject, SubjectNode user,
  +                            ActionNode action, boolean inheritance,
                               boolean tryToLock)
           throws ServiceAccessException, ObjectNotFoundException {
  -        NodeLock token = new NodeLock(subject, user, action, new Date(), 
  +        NodeLock token = new NodeLock(subject, user, action, new Date(),
                                         inheritance);
           return isLocked(slideToken, token, tryToLock);
       }
  @@ -466,11 +465,11 @@
       
       /**
        * Tests if an element is locked.
  -     * 
  +     *
        * @param token Lock token to test
        * @return boolean True if locked
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
       public boolean isLocked(SlideToken slideToken, NodeLock token,
  @@ -487,11 +486,11 @@
       
       /**
        * Tests if an element is locked.
  -     * 
  +     *
        * @param token Lock token to test
        * @return boolean True if locked
        * @exception ServiceAccessException Low level service access exception
  -     * @exception ObjectNotFoundException One of the objects referenced 
  +     * @exception ObjectNotFoundException One of the objects referenced
        * in the lock token were not found
        */
       private boolean isLockedInternal
  @@ -499,7 +498,7 @@
            boolean tryToLock, ObjectIsAlreadyLockedException nestedException)
           throws ServiceAccessException, ObjectNotFoundException {
   
  -        Uri objectUri = namespace.getUri(slideToken, token.getObjectUri());
  +        Uri objectUri = namespace.getUri(slideToken, token.getObjectUri(), false);
           ObjectNode initialObject = objectUri.getStore()
               .retrieveObject(objectUri);
           Enumeration scopes = objectUri.getScopes();
  @@ -513,13 +512,13 @@
           // First, we parse all the parents of the subject.
           while (!isLocked && scopes.hasMoreElements()) {
               String currentScope = (String) scopes.nextElement();
  -            Uri currentScopeUri = namespace.getUri(slideToken, currentScope);
  +            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, 
  +                if (!isCompatible(slideToken, token, currentLockToken,
                                     tryToLock)) {
                       isLocked = true;
                       if (nestedException != null) {
  @@ -531,23 +530,23 @@
               }
           }
           
  -        // Then, if the desired scope is inheritable, we parse the 
  -        // locked subject's children to see if any of them has been 
  +        // 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.
           if (token.isInheritable()) {
               Stack childrenStack = new Stack();
               childrenStack.push(initialObject);
               while (!isLocked && !childrenStack.empty()) {
                   ObjectNode currentObject = (ObjectNode) childrenStack.pop();
  -                Uri currentObjectUri = 
  -                    namespace.getUri(slideToken, currentObject.getUri());
  +                Uri currentObjectUri =
  +                    namespace.getUri(slideToken, currentObject.getUri(), false);
                   // 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, 
  +                    if (!isCompatible(slideToken, token,
                                         currentLockToken, tryToLock)) {
                           isLocked = true;
                           if (nestedException != null) {
  @@ -564,7 +563,7 @@
                   Enumeration childrenUri = currentObject.enumerateChildren();
                   while (childrenUri.hasMoreElements()) {
                       String childUri = (String) childrenUri.nextElement();
  -                    Uri tempUri = namespace.getUri(slideToken, childUri);
  +                    Uri tempUri = namespace.getUri(slideToken, childUri, false);
                       ObjectNode child = tempUri.getStore()
                           .retrieveObject(tempUri);
                       childrenVector.addElement(child);
  @@ -572,7 +571,7 @@
                   
                   Enumeration children = childrenVector.elements();
                   while (children.hasMoreElements()) {
  -                    ObjectNode tempObject = 
  +                    ObjectNode tempObject =
                           (ObjectNode) children.nextElement();
                       childrenStack.push(tempObject);
                   }
  @@ -585,13 +584,13 @@
       
       
       /**
  -     * Return true if a lock token for this lock has been given in the 
  +     * Return true if a lock token for this lock has been given in the
        * credentials token.
  -     * 
  +     *
        * @param slideToken Current credentials token
        * @param token Lock token
        */
  -    private boolean checkLockToken(SlideToken slideToken, 
  +    private boolean checkLockToken(SlideToken slideToken,
                                      NodeLock token) {
           
           if (!slideToken.isEnforceLockTokens())
  @@ -604,21 +603,21 @@
       
       /**
        * Tells whether or not two locks are compatible.
  -     * 
  +     *
        * @param token1 First token
        * @param token2 Second token : object's lock
        * @param tryToLock True if we want to check for a lock creation
        * @return boolean True if the locks are compatible
        */
       private boolean isCompatible(SlideToken slideToken,
  -                                 NodeLock token1, NodeLock token2, 
  +                                 NodeLock token1, NodeLock token2,
                                    boolean tryToLock) {
           /*
             System.out.println("**** Check lock ****");
  -          System.out.println("Lock 1 : " + token1.getSubjectUri() + " action " 
  +          System.out.println("Lock 1 : " + token1.getSubjectUri() + " action "
             + token1.getTypeUri());
             System.out.println("Lock 2 : " + token2.getSubjectUri() + " on "
  -          + token2.getObjectUri() + " action " 
  +          + token2.getObjectUri() + " action "
             + token2.getTypeUri());
           */
           
  @@ -628,7 +627,7 @@
           if (token2.hasExpired()) {
               // Since the lock has expired, it is removed
               try {
  -                Uri token2Uri = namespace.getUri(slideToken, 
  +                Uri token2Uri = namespace.getUri(slideToken,
                                                    token2.getObjectUri());
                   token2Uri.getStore().removeLock(token2Uri, token2);
               } catch (SlideException e) {
  @@ -636,10 +635,10 @@
               }
           } else {
               // The lockTypes are not equal
  -            boolean condition1 = (tryToLock) 
  +            boolean condition1 = (tryToLock)
                   && (token2.getTypeUri().equals(token1.getTypeUri()));
               // The user tested is not parent of the token's user
  -            boolean condition2 = 
  +            boolean condition2 =
                   (token1.getSubjectUri().startsWith(token2.getSubjectUri()));
               // The two lock types are the same
               boolean condition3 = token2.getTypeUri()
  @@ -651,7 +650,7 @@
               // Are lock tokens enforced ?
               boolean condition6 = slideToken.isEnforceLockTokens();
               if ((condition1 && condition4)
  -                || (condition3 && !condition2 && !condition6) 
  +                || (condition3 && !condition2 && !condition6)
                   || (condition3 && !condition5 && condition6)) {
                   compatible = false;
               }
  @@ -669,3 +668,4 @@
       }
       
   }
  +
  
  
  

Reply via email to