Dave Ward e31ea91e51 Merged V4.0-BUG-FIX to HEAD
35224: ALF-12038: Remove trailing JSON comma causing IE7 script error
   35226: ALF-13401 - Saving PowerPoint (mac 2011) via CIFS fails in Mac OS X Lion
   35239: ALF-13409: Further fix to deal with concurrent deletion of a user's site invitations in background
   35245: ALF-13281: Enabled use of autocomplete in IE for forms runtime. This change also allows multiple events to be attached per validation handler
   35253: ALF-13640: Fixed issues with updating task associations + added new test + fixed existing activiti-component-tests
   35271: Translation updates (fixes: ALF-13434) - based on EN r35212. (Dutch still to follow)
   35281: ALF-13227: Fix CSS for Wiki layout of nested lists
   35284: SPANISH: Update from Gloria
   35290: More debug + unit test for mac powerpoint shuffle.
   35291: Added isTemporary method
   35295: ALF-13453	: Remote Code Execution (can create reverse shell).
   - Added ability for XMLUtil parse callers to provide an  optional array of XMLFilterImpl to be used while parsing. 
   -Added secureParseXSL methods that automatically install an XMLFilterImpl that causes a parse failure if any insecure namespaces are encountered.
   35303: Fix for ALF-12444 Node Browser improvement: Index single node and remove single node from indexes
   Part of ALF-13723 SOLR does not include the same query unit tests as lucene
   35305: ALF-13723 SOLR does not include the same query unit tests as lucene
   - test template
   35306: ALF-13723 SOLR does not include the same query unit tests as lucene
   - template for creating test cores
   35323: ALF-13420: Natural sort on form option labels and improvement for CSS - specifically to address transform action in document details.
   35328: ALF-13409: Avoid concurrency issues in unit test tear downs by deleting users before sites. User deletion deletes invitations synchronously. Site deletion deletes invitations concurrently to avoid UI timeouts. The potential to access invitations that are being concurrently deleted still exists, but always did!
   35331: ALF-12126: Ensure that DND upload is disabled for users with only consumer access
   35335: ALF-13708: Merged V3.4-BUG-FIX (3.4.10) to V4.0-BUG-FIX (4.0.2)
      35235: ALF-13673: Amp-loaded duplicated mimetypes should be handled
         - Modified code to allow duplicates to replace parts of the existing mimetype definitions.
         - A warning is logged each time. 
   35336: Spanish and Dutch updates from Gloria, based on EN r35212
   35355: Merged V3.4-BUG-FIX to V4.0-BUG-FIX
      35213: ALF-13686: Merged PATCHES/V3.4.8 to V3.4-BUG-FIX
         34943: ALF-13121: Option to create users either as user1 or user1@domain.com after kerberos authentication
         - New Kerberos subsystem parameter kerberos.authentication.stripUsernameSuffix introduced
         - When true (the default) the @domain sufix will be stripped from Kerberos authenticated usernames in CIFS, SPP, WebDAV and the Web Client
         - When false, should enable a multi-domain customer to use Alfresco (says Mr Gninot)
         35096: ALF-13121: Added missing stripKerberosUsernameSuffix property to sharepointAuthenticationHandler
      35215: ALF-13065: Ensure Wiki new page save button is available on HTML edit action
      35219: ALF-11898: Fixed TinyMCE create HTML content problem for Explorer client
      35261: Translation updates based on EN r35144
      35339: AD 2008 R2, user import via LDAP fails with over 1000 users
      - Problem discovered by Community user with simple workaround
      https://forums.alfresco.com/en/viewtopic.php?f=57&t=43960&sid=5569e5cfbccb3776e11ef4a8e9d50378&p=129664#p129664
      35353: Merged V3.4 to V3.4-BUG-FIX
         35279: ALF-13713: Merged PATCHES/V3.4.8 to V3.4
            35146: Merged DEV to PATCHES/V3.4.8
               35130: ALF-13472: Webdav Does not allow a user to access spaces without read permission on parent spaces
                  Receiving of indirect lock is wrapped into AuthenticationUtil.runAs() invocation to provide a possibility of getting indirect lock for users with appropriate access rights for requested resource
         35280: ALF-10353: Internet Explorer hangs when using the object picker with a larger number of documents
         - reviewed by DD
         35318: ALF-13715: Merged HEAD to V3.4
            31743: Fixed ALF-10157: Web Form Details page for the "Selected Web Content Forms": script error appears on help button click: container.jsp (line 382)
         35341: ALF-13552: Merged V4.0 to V3.4
            35296: ALF-13453: Remote Code Execution (can create reverse shell) - Fix by Shane
            35304: ALF-13453: Extra fix to ensure xalan namespace isn't declared with global scope and can't be hijacked by an input stylesheet
            35307: ALF-13453: Duplicated extra fix to duplicate code in XSLTRenderingEngine!
      35354: Merged V3.4 to V3.4-BUG-FIX (RECORD ONLY)
         35266: Merged V3.4-BUG-FIX to V3.4
            35261: Translation updates based on EN r35144
         35334: Merged V3.4-BUG-FIX to V3.4
            35235: ALF-13673: Amp-loaded duplicated mimetypes should be handled
               - Modified code to allow duplicates to replace parts of the existing mimetype definitions.
               - A warning is logged each time. 
   35356: Merged V4.0 to V4.0-BUG-FIX
      35292: ALF-13721: Merged PATCHES/V4.0.0 to V4.0
         35240: Fix for ALF-13685 The SOLr textContent webscript is not protected by authentication and permission checks.
         35242: Fix for ALF-13685 The SOLr textContent webscript is not protected by authentication and permission checks.
         - /wcs/api/solr and /wcservice/api/solr
      35304: ALF-13453: Extra fix to ensure xalan namespace isn't declared with global scope and can't be hijacked by an input stylesheet
      35307: ALF-13453: Duplicated extra fix to duplicate code in XSLTRenderingEngine!
   35357: Merged V4.0 to V4.0-BUG-FIX (RECORD ONLY)
      35048: Merged V4.0-BUG-FIX to V4.0
         35031: Fix for ALF-12309: Script errors on site pages
      35293: Merged V4.0-BUG-FIX to V4.0
         35172: ALF-13626: category.put.json.ftl has wrong bracket
      35296: Merged V4.0-BUG-FIX to V4.0
         35295: ALF-13453: Remote Code Execution (can create reverse shell)
           - Fix by Shane


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35359 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-04-18 09:42:39 +00:00

463 lines
18 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.filesys.repo.rules;
import java.util.ArrayList;
import java.util.Date;
import org.alfresco.filesys.repo.OpenFileMode;
import org.alfresco.filesys.repo.ResultCallback;
import org.alfresco.filesys.repo.TempNetworkFile;
import org.alfresco.filesys.repo.rules.ScenarioInstance.Ranking;
import org.alfresco.filesys.repo.rules.ScenarioRenameShuffleInstance.InternalState;
import org.alfresco.filesys.repo.rules.commands.CallbackCommand;
import org.alfresco.filesys.repo.rules.commands.CloseFileCommand;
import org.alfresco.filesys.repo.rules.commands.CompoundCommand;
import org.alfresco.filesys.repo.rules.commands.CopyContentCommand;
import org.alfresco.filesys.repo.rules.commands.CreateFileCommand;
import org.alfresco.filesys.repo.rules.commands.DeleteFileCommand;
import org.alfresco.filesys.repo.rules.commands.DoNothingCommand;
import org.alfresco.filesys.repo.rules.commands.OpenFileCommand;
import org.alfresco.filesys.repo.rules.commands.ReduceQuotaCommand;
import org.alfresco.filesys.repo.rules.commands.RemoveNoContentFileOnError;
import org.alfresco.filesys.repo.rules.commands.RemoveTempFileCommand;
import org.alfresco.filesys.repo.rules.commands.RenameFileCommand;
import org.alfresco.filesys.repo.rules.commands.ReturnValueCommand;
import org.alfresco.filesys.repo.rules.operations.CloseFileOperation;
import org.alfresco.filesys.repo.rules.operations.CreateFileOperation;
import org.alfresco.filesys.repo.rules.operations.DeleteFileOperation;
import org.alfresco.filesys.repo.rules.operations.OpenFileOperation;
import org.alfresco.filesys.repo.rules.operations.RenameFileOperation;
import org.alfresco.jlan.server.filesys.NetworkFile;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* An open file scenario is ...
* <p>
* 1) open(readOnly)
* 2) close(readOnly)
* <p>
* 1) open(readOnly)
* 2) open(readWrite)
* 3) close(readOnly)
* 4 close(readWrite) updates the repo
* <p>
* 1) open(readOnly)
* 2) open(readWrite)
* 3) open(readWrite) - does nothing. Increments Open Count.
* 4) close(readWrite) - does nothing. Decrements Open Count.
* 5) close(readWrite) - updates the repo.
* 6) close(readOnly) - closes read only
* <p>
* 1) open (readWrite)
* 2) open (readOnly) - file already open for read/write
* 3) close
* 4) close
*
*/
class ScenarioOpenFileInstance implements ScenarioInstance
{
private static Log logger = LogFactory.getLog(ScenarioOpenFileInstance.class);
private Date startTime = new Date();
private String name;
enum InternalState
{
NONE,
OPEN
} ;
InternalState state = InternalState.NONE;
/**
* For each read only open file
*/
private NetworkFile fileHandleReadOnly;
private int openReadOnlyCount = 0;
/**
* For each read/write open file
*/
private NetworkFile fileHandleReadWrite;
private int openReadWriteCount = 0;
/**
* Timeout in ms. Default 30 seconds.
*/
private long timeout = 30000;
private boolean isComplete = false;
private Ranking ranking = Ranking.HIGH;
/**
* Evaluate the next operation
* @param operation
*/
public Command evaluate(Operation operation)
{
/**
* Anti-pattern : timeout - this scenario does not timeout
*/
// Date now = new Date();
// if(now.getTime() > startTime.getTime() + getTimeout())
// {
// if(logger.isDebugEnabled())
// {
// logger.debug("Instance timed out");
// }
// }
/**
* Anti Pattern - Delete of the open file.
*/
if(operation instanceof DeleteFileOperation)
{
DeleteFileOperation d = (DeleteFileOperation)operation;
if(d.getName() == null)
{
return null;
}
if(name.equalsIgnoreCase(d.getName()))
{
logger.debug("Anti-Pattern - delete of the open file, scenario:" + this);
isComplete = true;
return null;
}
}
switch (state)
{
case NONE:
if(operation instanceof CreateFileOperation)
{
CreateFileOperation c = (CreateFileOperation)operation;
name = c.getName();
if(name != null)
{
ArrayList<Command> commands = new ArrayList<Command>();
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
commands.add(new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath(), c.getAllocationSize()));
postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands);
}
}
else if(operation instanceof OpenFileOperation)
{
OpenFileOperation o = (OpenFileOperation)operation;
name = o.getName();
if(name != null)
{
ArrayList<Command> commands = new ArrayList<Command>();
commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath()));
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands);
}
}
// Scenario Not Started
isComplete = true;
return null;
case OPEN:
if(operation instanceof CloseFileOperation)
{
CloseFileOperation c = (CloseFileOperation)operation;
if(c.getName() == null)
{
return null;
}
if(name.equalsIgnoreCase(c.getName()))
{
NetworkFile file = c.getNetworkFile();
if(isReadOnly(file))
{
// Read Only File
if(openReadOnlyCount == 1)
{
if(logger.isDebugEnabled())
{
logger.debug("Close of last read only file handle:" + this);
}
openReadOnlyCount = 0;
if(openReadWriteCount <= 0)
{
if(logger.isDebugEnabled())
{
logger.debug("Scenario is complete:" + this);
}
isComplete=true;
}
if (file instanceof TempNetworkFile)
{
logger.debug("this is the last close of a temp read only file");
ArrayList<Command> commands = new ArrayList<Command>();
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
commands.add(new CloseFileCommand(c.getName(), file, c.getRootNodeRef(), c.getPath()));
postCommitCommands.add(new RemoveTempFileCommand((TempNetworkFile)file));
return new CompoundCommand(commands, postCommitCommands);
}
else
{
return new CloseFileCommand(c.getName(), file, c.getRootNodeRef(), c.getPath());
}
}
if(logger.isDebugEnabled())
{
logger.debug("Only decrement count of read only file handle:" + this);
}
openReadOnlyCount--;
return new DoNothingCommand();
}
else
{
// This is a close of a Read Write File
// Read Only File
if(openReadWriteCount == 1)
{
if(logger.isDebugEnabled())
{
logger.debug("Close of last read write file handle:" + this);
}
openReadWriteCount = 0;
if(openReadOnlyCount <= 0)
{
if(logger.isDebugEnabled())
{
logger.debug("Scenario is complete:" + this);
}
isComplete=true;
}
//
ArrayList<Command> commands = new ArrayList<Command>();
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
ArrayList<Command> postErrorCommands = new ArrayList<Command>();
commands.add(new CloseFileCommand(c.getName(), file, c.getRootNodeRef(), c.getPath()));
//postErrorCommands.add(new RemoveNoContentFileOnError(c.getName(), c.getRootNodeRef(), c.getPath()));
if(c.isDeleteOnClose())
{
postCommitCommands.add(new ReduceQuotaCommand(c.getName(), file, c.getRootNodeRef(), c.getPath()));
}
if (file instanceof TempNetworkFile)
{
postCommitCommands.add(new RemoveTempFileCommand((TempNetworkFile)file));
}
return new CompoundCommand(commands, postCommitCommands, postErrorCommands);
}
if(logger.isDebugEnabled())
{
logger.debug("Only decrement count of read write file handle:" + this);
}
openReadWriteCount--;
return new DoNothingCommand();
}
}
}
else if(operation instanceof OpenFileOperation)
{
OpenFileOperation o = (OpenFileOperation)operation;
if(o.getName() == null)
{
return null;
}
if(name != null && name.equalsIgnoreCase(o.getName()))
{
if(o.getMode() == OpenFileMode.READ_WRITE)
{
// This is an open of a read write access
if(openReadWriteCount == 0)
{
logger.debug("Open first read/write from scenario:" + this);
ArrayList<Command> commands = new ArrayList<Command>();
commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath()));
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands);
}
else
{
// TODO Need a permission check here and increment post check
openReadWriteCount++;
logger.debug("Return already open read/write file handle from scenario:" + this);
return new ReturnValueCommand(fileHandleReadWrite);
}
}
else
{
// This is an open for read only access
if(openReadWriteCount > 0)
{
//however the file is already open for read/write
openReadWriteCount++;
logger.debug("Return already open read/write file handle from scenario:" + this);
return new ReturnValueCommand(fileHandleReadWrite);
}
if(openReadOnlyCount == 0)
{
logger.debug("Open first read only from scenario:" + this);
ArrayList<Command> commands = new ArrayList<Command>();
commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath()));
ArrayList<Command> postCommitCommands = new ArrayList<Command>();
postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands);
}
else
{
openReadOnlyCount++;
logger.debug("Return already open only file handle from scenario:" + this);
return new ReturnValueCommand(fileHandleReadOnly);
}
}
}
}
break;
}
return null;
}
@Override
public boolean isComplete()
{
return isComplete;
}
public String toString()
{
return "ScenarioOpenFileInstance name:" + name;
}
public void setTimeout(long timeout)
{
this.timeout = timeout;
}
public long getTimeout()
{
return timeout;
}
@Override
public Ranking getRanking()
{
return ranking;
}
public void setRanking(Ranking ranking)
{
this.ranking = ranking;
}
public String getName()
{
return name;
}
/**
* Called for open file.
*/
private ResultCallback newOpenFileCallbackCommand()
{
return new ResultCallback()
{
@Override
public void execute(Object result)
{
if(result instanceof NetworkFile)
{
// Now update the state of this scenario - we have an open fileHandle
NetworkFile fileHandle = (NetworkFile)result;
state = InternalState.OPEN;
if(isReadOnly(fileHandle))
{
openReadOnlyCount++;
fileHandleReadOnly=fileHandle;
if(logger.isDebugEnabled())
{
logger.debug("file opened read only:" + result + ", name:" + name);
}
}
else
{
openReadWriteCount++;
fileHandleReadWrite=fileHandle;
if(logger.isDebugEnabled())
{
logger.debug("file opened read write :" + result + ", name:" + name);
}
}
}
}
@Override
public TxnReadState getTransactionRequired()
{
return TxnReadState.TXN_NONE;
}
};
}
private boolean isReadOnly(NetworkFile file)
{
return (file.getGrantedAccess() == NetworkFile.READONLY);
}
}