) value)
{
- property.getValue().add(propertyValue);
+ property.getValue().add(decimalValue(propertyValue));
}
}
else
{
- property.getValue().add(BigDecimal.valueOf((Double) value));
+ property.getValue().add(decimalValue(value));
}
return property;
@@ -712,6 +712,15 @@ public class PropertyUtil
}
}
+ private BigDecimal decimalValue(Serializable value)
+ {
+ if ((value instanceof Float) || (value instanceof Double))
+ {
+ return BigDecimal.valueOf(((Number) value).doubleValue());
+ }
+ return null;
+ }
+
/**
* Converts Date object to XMLGregorianCalendar object
*
diff --git a/source/java/org/alfresco/repo/web/scripts/RepoClassPathStore.java b/source/java/org/alfresco/repo/web/scripts/RepoClassPathStore.java
new file mode 100644
index 0000000000..b9c28164ac
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/RepoClassPathStore.java
@@ -0,0 +1,75 @@
+/*
+ * 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 .
+ */
+package org.alfresco.repo.web.scripts;
+
+import java.io.IOException;
+
+import org.springframework.extensions.webscripts.ClassPathStore;
+
+import freemarker.cache.TemplateLoader;
+
+/**
+ * Extension of the SpringSurf ClassPathStore to ensure that the examination of
+ * last modified dates on classpath bound resources does not cause a performance
+ * degredation in REST heavy client applications.
+ *
+ * In the repository, due to the possibility of Repository bound resources, all
+ * WebScript search path lists have the "delay" set to either zero seconds (no delay)
+ * or something close to that. This means that the FreeMarker template cache is
+ * always or often requesting the last modified date of a classpath resource - and
+ * the resources do not change. Note that the /extension classpath store still uses
+ * the original ClassPathStore. Otherwise all stores can be refreshed as usual via
+ * the Refresh WebScripts command.
+ *
+ * @author Kevin Roast
+ */
+public class RepoClassPathStore extends ClassPathStore
+{
+ @Override
+ public TemplateLoader getTemplateLoader()
+ {
+ return new ClassPathTemplateLoader();
+ }
+
+ @Override
+ public long lastModified(String documentPath)
+ throws IOException
+ {
+ return -1L;
+ }
+
+ /**
+ * Class Path Store implementation of a Template Loader
+ *
+ * Retrieves templates either from classes in the class path or classes inside of JAR files
+ * within the class path
+ *
+ * This implementation always returns a fixed last modified date of -1.
+ */
+ private class ClassPathTemplateLoader extends ClassPathStore.ClassPathTemplateLoader
+ {
+ /**
+ * @see freemarker.cache.TemplateLoader#getLastModified(java.lang.Object)
+ */
+ public long getLastModified(Object templateSource)
+ {
+ return -1L;
+ }
+ }
+}
diff --git a/source/java/org/alfresco/repo/web/scripts/RepositoryTemplateProcessor.java b/source/java/org/alfresco/repo/web/scripts/RepositoryTemplateProcessor.java
index 91d669463b..5e829984f8 100644
--- a/source/java/org/alfresco/repo/web/scripts/RepositoryTemplateProcessor.java
+++ b/source/java/org/alfresco/repo/web/scripts/RepositoryTemplateProcessor.java
@@ -26,19 +26,19 @@ import java.util.List;
import org.alfresco.processor.ProcessorExtension;
import org.alfresco.repo.template.FreeMarkerProcessor;
import org.alfresco.repo.template.QNameAwareObjectWrapper;
-import org.springframework.extensions.surf.util.AbstractLifecycleBean;
-import org.springframework.extensions.webscripts.SearchPath;
-import org.springframework.extensions.webscripts.Store;
-import org.springframework.extensions.webscripts.TemplateProcessor;
-import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
+import org.springframework.extensions.surf.util.AbstractLifecycleBean;
+import org.springframework.extensions.webscripts.SearchPath;
+import org.springframework.extensions.webscripts.Store;
+import org.springframework.extensions.webscripts.TemplateProcessor;
+import org.springframework.extensions.webscripts.WebScriptException;
-import freemarker.cache.MruCacheStorage;
import freemarker.cache.MultiTemplateLoader;
+import freemarker.cache.StrongCacheStorage;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
@@ -59,7 +59,6 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
protected Configuration templateConfig;
protected FreeMarkerProcessor freeMarkerProcessor;
private int updateDelay = 1;
- private int cacheSize = 512;
/* (non-Javadoc)
@@ -90,12 +89,9 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
/**
* @param cacheSize the size of the MRU template cache, default is 256
*/
+ @Deprecated
public void setCacheSize(int cacheSize)
{
- if (cacheSize >= 0)
- {
- this.cacheSize = cacheSize;
- }
}
/**
@@ -167,7 +163,7 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
Configuration config = new Configuration();
// setup template cache
- config.setCacheStorage(new MruCacheStorage(this.cacheSize, this.cacheSize << 1));
+ config.setCacheStorage(new StrongCacheStorage());
config.setTemplateUpdateDelay(updateDelay);
// setup template loaders
diff --git a/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java b/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java
index cad3b2d065..eacc8c63e5 100644
--- a/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java
+++ b/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java
@@ -27,6 +27,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.jscript.Scopeable;
import org.alfresco.repo.jscript.ScriptNode;
+import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -49,6 +50,7 @@ public class ScriptCommentService extends BaseScopableProcessorExtension
private ServiceRegistry serviceRegistry;
private NodeService nodeService;
+ private BehaviourFilter behaviourFilter;
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
@@ -56,6 +58,11 @@ public class ScriptCommentService extends BaseScopableProcessorExtension
this.nodeService = serviceRegistry.getNodeService();
}
+ public void setBehaviourFilter(BehaviourFilter behaviourFilter)
+ {
+ this.behaviourFilter = behaviourFilter;
+ }
+
public ScriptNode createCommentsFolder(ScriptNode node)
{
final NodeRef nodeRef = node.getNodeRef();
@@ -65,21 +72,34 @@ public class ScriptCommentService extends BaseScopableProcessorExtension
public NodeRef doWork() throws Exception
{
NodeRef commentsFolder = null;
- nodeService.addAspect(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussable"), null);
- List assocs = nodeService.getChildAssocs(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"), RegexQNamePattern.MATCH_ALL);
- if (assocs.size() != 0)
+
+ // ALF-5240: turn off auditing round the discussion node creation to prevent
+ // the source document from being modified by the first user leaving a comment
+ behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
+
+ try
{
- NodeRef forumFolder = assocs.get(0).getChildRef();
-
- Map props = new HashMap(1);
- props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME);
- commentsFolder = nodeService.createNode(
- forumFolder,
- ContentModel.ASSOC_CONTAINS,
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME),
- QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "topic"),
- props).getChildRef();
+ nodeService.addAspect(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussable"), null);
+ List assocs = nodeService.getChildAssocs(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"), RegexQNamePattern.MATCH_ALL);
+ if (assocs.size() != 0)
+ {
+ NodeRef forumFolder = assocs.get(0).getChildRef();
+
+ Map props = new HashMap(1);
+ props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME);
+ commentsFolder = nodeService.createNode(
+ forumFolder,
+ ContentModel.ASSOC_CONTAINS,
+ QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME),
+ QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "topic"),
+ props).getChildRef();
+ }
}
+ finally
+ {
+ behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
+ }
+
return commentsFolder;
}
diff --git a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
index 59c2b038d8..25ef02d82f 100644
--- a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
@@ -19,6 +19,8 @@
package org.alfresco.repo.web.scripts.groups;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Set;
@@ -31,16 +33,17 @@ import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.PropertyMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONObject;
/**
* Unit test of Groups REST APIs.
@@ -67,6 +70,8 @@ public class GroupsTest extends BaseWebScriptTest
private String TEST_GROUPC = "TesTC";
private String TEST_GROUPD = "TESTD";
private String TEST_GROUPE = "TestE";
+ private String TEST_GROUPF = "TestF";
+ private String TEST_GROUPG = "TestG";
private String TEST_LINK = "TESTLINK";
private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName";
@@ -89,6 +94,10 @@ public class GroupsTest extends BaseWebScriptTest
* USER_THREE
* GROUPC
* USER_TWO
+ * GROUPF
+ * GROUPD
+ * GROUPG
+ * GROUPD
*/
private synchronized String createTestTree()
{
@@ -102,7 +111,7 @@ public class GroupsTest extends BaseWebScriptTest
if(!authorityService.authorityExists(rootGroupName))
{
- this.authenticationComponent.setSystemUserAsCurrentUser();
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, TEST_ROOTGROUP, TEST_ROOTGROUP_DISPLAY_NAME, authorityService.getDefaultZones());
String groupA = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPA, TEST_GROUPA, authorityService.getDefaultZones());
@@ -115,7 +124,13 @@ public class GroupsTest extends BaseWebScriptTest
authorityService.addAuthority(groupB, groupE);
authorityService.addAuthority(groupB, USER_TWO);
authorityService.addAuthority(groupB, USER_THREE);
-
+ String groupF = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPF, TEST_GROUPF, authorityService.getDefaultZones());
+ authorityService.addAuthority(rootGroupName, groupF);
+ authorityService.addAuthority(groupF, groupD);
+ String groupG = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPG, TEST_GROUPG, authorityService.getDefaultZones());
+ authorityService.addAuthority(rootGroupName, groupG);
+ authorityService.addAuthority(groupG, groupD);
+
String groupC = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPC, TEST_GROUPC,authorityService.getDefaultZones());
authorityService.addAuthority(rootGroupName, groupC);
authorityService.addAuthority(groupC, USER_TWO);
@@ -429,7 +444,6 @@ public class GroupsTest extends BaseWebScriptTest
*/
public void testLinkChild() throws Exception
{
-
String myRootGroup = "GT_LGROOT";
try
@@ -799,12 +813,11 @@ public class GroupsTest extends BaseWebScriptTest
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_SHARE), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
- System.out.println(response.getContentAsString());
+// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("Can't find Group E in Share zone", 1, data.length());
JSONObject authority = data.getJSONObject(0);
assertEquals("", TEST_GROUPE, authority.getString("shortName"));
-
}
// Negative test Search for a group in a wrong zone
@@ -812,7 +825,7 @@ public class GroupsTest extends BaseWebScriptTest
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_WCM), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
- System.out.println(response.getContentAsString());
+// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("length not 0", 0, data.length());
}
@@ -820,6 +833,180 @@ public class GroupsTest extends BaseWebScriptTest
}
+ public void testSearchGroupsPaging() throws Exception
+ {
+ createTestTree();
+
+ JSONArray data = getDataArray(URL_GROUPS + "?shortNameFilter=*");
+ int defaultSize = data.length();
+ String firstGroup = data.get(0).toString();
+
+ assertTrue("There should be at least 6 groups in default zone!", defaultSize > 5);
+
+ // Test maxItems works
+ data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&maxItems=3");
+ assertEquals("There should only be 3 groups!", 3, data.length());
+ assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString());
+
+ // Test skipCount works
+ data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount=2");
+ assertEquals("The number of groups returned is wrong!", defaultSize-2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount
+ data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&skipCount=2&maxItems=3");
+ assertEquals("The number of groups returned is wrong!", 3, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount when maxItems is too big.
+ // Shoudl return last 2 items.
+ int skipCount = defaultSize-2;
+ data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount="+skipCount+"&maxItems=5");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+ }
+
+ public void testGetRootGroupsPaging() throws Exception
+ {
+ createTestTree();
+
+ JSONArray data = getDataArray(URL_ROOTGROUPS);
+ int defaultSize = data.length();
+ String firstGroup = data.get(0).toString();
+
+ assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2);
+
+ // Test maxItems works
+ data = getDataArray(URL_ROOTGROUPS + "?maxItems=2");
+ assertEquals("There should only be 2 groups!", 2, data.length());
+ assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString());
+
+ // Test skipCount works
+ data = getDataArray(URL_ROOTGROUPS + "?skipCount=1");
+ assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount
+ data = getDataArray(URL_ROOTGROUPS + "?skipCount=1&maxItems=2");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount when maxItems is too big.
+ // Shoudl return last 2 items.
+ int skipCount = defaultSize-1;
+ data = getDataArray(URL_ROOTGROUPS + "?skipCount="+skipCount+"&maxItems=5");
+ assertEquals("The number of groups returned is wrong!", 1, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+ }
+
+ public void testGetParentsPaging() throws Exception
+ {
+ createTestTree();
+
+ // Test for immediate parents
+ String baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents";
+
+ JSONArray data = getDataArray(baseUrl);
+ int defaultSize = data.length();
+ String firstGroup = data.get(0).toString();
+
+ assertEquals("There should be at least 3 groups in default zone!", 3, defaultSize);
+
+ // Test maxItems works
+ data = getDataArray(baseUrl +"?maxItems=2");
+ assertEquals("There should only be 2 groups!", 2, data.length());
+ assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString());
+
+ // Test skipCount works
+ data = getDataArray(baseUrl + "?skipCount=1");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount
+ data = getDataArray(baseUrl + "?skipCount=1&maxItems=1");
+ assertEquals("The number of groups returned is wrong!", 1, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount when maxItems is too big.
+ // Shoudl return last 2 items.
+ data = getDataArray(baseUrl + "?skipCount=1&maxItems=5");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ //Test for ALL parents
+ baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL";
+
+ data = getDataArray(baseUrl);
+ defaultSize = data.length();
+ firstGroup = data.get(0).toString();
+
+ assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2);
+
+ // Test maxItems works
+ data = getDataArray(baseUrl +"&maxItems=2");
+ assertEquals("There should only be 3 groups!", 2, data.length());
+ assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString());
+
+ // Test skipCount works
+ data = getDataArray(baseUrl + "&skipCount=1");
+ assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount
+ data = getDataArray(baseUrl + "&skipCount=1&maxItems=2");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount when maxItems is too big.
+ // Shoudl return last 2 items.
+ int skipCount = defaultSize-2;
+ data = getDataArray(baseUrl + "&skipCount="+skipCount+"&maxItems=5");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+ }
+
+ public void testGetChildGroupsPaging() throws Exception
+ {
+ createTestTree();
+
+ // Test for immediate parents
+ String baseUrl = URL_GROUPS + "/" + TEST_ROOTGROUP + "/children?authorityType=GROUP";
+
+ JSONArray data = getDataArray(baseUrl);
+ int defaultSize = data.length();
+ String firstGroup = data.get(0).toString();
+
+ assertEquals("There should be 6 groups in default zone!", 6, defaultSize);
+
+ // Test maxItems works
+ data = getDataArray(baseUrl +"&maxItems=2");
+ assertEquals("There should only be 3 groups!", 2, data.length());
+ assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString());
+
+ // Test skipCount works
+ data = getDataArray(baseUrl + "&skipCount=2");
+ assertEquals("The number of groups returned is wrong!", 4, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount
+ data = getDataArray(baseUrl + "&skipCount=2&maxItems=2");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+
+ // Test maxItems and skipCount when maxItems is too big.
+ // Shoudl return last 2 items.
+ data = getDataArray(baseUrl + "&skipCount=4&maxItems=5");
+ assertEquals("The number of groups returned is wrong!", 2, data.length());
+ assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString()));
+ }
+
+ private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException
+ {
+ Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ return data;
+ }
/**
* Detailed test of get Parents
*/
diff --git a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java
index 445b168f2f..3786e4652e 100644
--- a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java
@@ -24,11 +24,12 @@ import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
-import org.alfresco.repo.action.executer.TestModeable;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
+import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
+import org.alfresco.repo.web.scripts.invite.InviteServiceTest;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -37,6 +38,7 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
+import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.json.JSONArray;
@@ -62,6 +64,7 @@ public class InvitationTest extends BaseWebScriptTest
private AuthenticationComponent authenticationComponent;
private PersonService personService;
private NodeService nodeService;
+ private TransactionService transactionService;
private String userOne = "InvitationTestOne" + GUID.generate();
private String userTwo = "InvitationTestTwo" + GUID.generate();
@@ -72,7 +75,6 @@ public class InvitationTest extends BaseWebScriptTest
private List createdSites = new ArrayList(5);
private List createdInvitations = new ArrayList(10);
- private TestModeable mailActionExecutor;
private final Map> userProperties = new HashMap>(3);
@@ -99,13 +101,12 @@ public class InvitationTest extends BaseWebScriptTest
"authenticationComponent");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
+ this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
- // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
- // during unit testing
+ // turn off email sending to prevent errors during unit testing
// (or sending out email by accident from tests)
- mailActionExecutor = (TestModeable) getServer().getApplicationContext().getBean("mail");
- mailActionExecutor.setTestMode(true);
-
+ InviteServiceTest.configureMailExecutorForTestMode(this.getServer());
+
this.authenticationComponent.setSystemUserAsCurrentUser();
// Create users
@@ -162,11 +163,18 @@ public class InvitationTest extends BaseWebScriptTest
// Clear the list
this.createdInvitations.clear();
- // Switch the MailActionExecutor back to normal mode.
- mailActionExecutor.setTestMode(false);
- personService.deletePerson(userOne);
- personService.deletePerson(userTwo);
- personService.deletePerson(userThree);
+ RetryingTransactionCallback deleteCallback = new RetryingTransactionCallback()
+ {
+ @Override
+ public Void execute() throws Throwable
+ {
+ personService.deletePerson(userOne);
+ personService.deletePerson(userTwo);
+ personService.deletePerson(userThree);
+ return null;
+ }
+ };
+ transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
}
private JSONObject createSite(String sitePreset, String shortName, String title, String description,
diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java
index b961430290..10e08d9110 100644
--- a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java
@@ -58,6 +58,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.extensions.surf.util.URLEncoder;
import org.springframework.extensions.webscripts.Status;
+import org.springframework.extensions.webscripts.TestWebScriptServer;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
@@ -134,7 +135,7 @@ public class InviteServiceTest extends BaseWebScriptTest
this.transactionService = (TransactionService) getServer().getApplicationContext()
.getBean("TransactionService");
- configureMailExecutorForTestMode();
+ configureMailExecutorForTestMode(this.getServer());
// We're using a MailActionExecuter defined in outboundSMTP-test-context.xml which
// sets the testMode property to true via spring injection. This will prevent emails
@@ -231,7 +232,7 @@ public class InviteServiceTest extends BaseWebScriptTest
/**
* This method turns off email-sending within the MailActionExecuter bean.
*/
- private void configureMailExecutorForTestMode()
+ public static void configureMailExecutorForTestMode(TestWebScriptServer server)
{
// This test class depends on a MailActionExecuter bean which sends out emails
// in a live system. We want to prevent these emails from being sent during
@@ -259,8 +260,8 @@ public class InviteServiceTest extends BaseWebScriptTest
//
// Therefore we've decided to do [3].
- ChildApplicationContextFactory outboundSmptSubsystem
- = (ChildApplicationContextFactory)getServer().getApplicationContext().getBean("OutboundSMTP");
+ ChildApplicationContextFactory outboundSmptSubsystem
+ = (ChildApplicationContextFactory)server.getApplicationContext().getBean("OutboundSMTP");
ApplicationContext childAppCtxt = outboundSmptSubsystem.getApplicationContext();
MailActionExecuter mailActionExecutor = (MailActionExecuter)childAppCtxt.getBean("mail");
mailActionExecutor.setTestMode(true);
diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java b/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java
index c34aacf7b0..d554558a42 100644
--- a/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java
+++ b/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java
@@ -352,11 +352,11 @@ public class RulePut extends RulePost
private ActionCondition getCondition(List conditions, String id)
{
ActionCondition result = null;
- for (ActionCondition сondition : conditions)
+ for (ActionCondition condition : conditions)
{
- if (сondition.getId().equalsIgnoreCase(id))
+ if (condition.getId().equalsIgnoreCase(id))
{
- result = сondition;
+ result = condition;
break;
}
}
diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java b/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java
index 2def66e08f..455a3cdd52 100644
--- a/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java
@@ -24,6 +24,7 @@ import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.rule.LinkRules;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
@@ -35,7 +36,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.namespace.QName;
-import org.apache.commons.digester.Rules;
+import org.alfresco.service.transaction.TransactionService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -72,6 +73,7 @@ public class RuleServiceTest extends BaseWebScriptTest
private static final String TEST_FOLDER = "test_folder-" + System.currentTimeMillis();
private static final String TEST_FOLDER_2 = "test_folder-2-" + System.currentTimeMillis();
+ private TransactionService transactionService;
private NodeService nodeService;
private FileFolderService fileFolderService;
private AuthenticationComponent authenticationComponent;
@@ -86,6 +88,7 @@ public class RuleServiceTest extends BaseWebScriptTest
protected void setUp() throws Exception
{
super.setUp();
+ this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
this.ruleService = (RuleService) getServer().getApplicationContext().getBean("RuleService");
@@ -154,9 +157,18 @@ public class RuleServiceTest extends BaseWebScriptTest
protected void tearDown() throws Exception
{
super.tearDown();
- nodeService.deleteNode(testNodeRef2);
- nodeService.deleteNode(testNodeRef);
- nodeService.deleteNode(testWorkNodeRef);
+ RetryingTransactionCallback deleteCallback = new RetryingTransactionCallback()
+ {
+ @Override
+ public Void execute() throws Throwable
+ {
+ nodeService.deleteNode(testNodeRef2);
+ nodeService.deleteNode(testNodeRef);
+ nodeService.deleteNode(testWorkNodeRef);
+ return null;
+ }
+ };
+ this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
this.authenticationComponent.clearCurrentSecurityContext();
}
@@ -677,6 +689,7 @@ public class RuleServiceTest extends BaseWebScriptTest
assertEquals(0, ruleService.getRules(testNodeRef).size());
}
+ @SuppressWarnings("unused")
public void testRuleReorder() throws Exception
{
assertEquals(0, ruleService.getRules(testNodeRef).size());
@@ -754,11 +767,6 @@ public class RuleServiceTest extends BaseWebScriptTest
return result;
}
- private JSONObject buildTestRule() throws JSONException
- {
- return buildTestRule("test_rule");
- }
-
private JSONObject buildTestRule(String title) throws JSONException
{
JSONObject result = new JSONObject();
diff --git a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java
index 3a5bacd679..2d6b7681f3 100644
--- a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java
@@ -87,7 +87,8 @@ public class SiteServiceTest extends BaseWebScriptTest
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
-
+ // sets the testMode property to true via spring injection. This will prevent emails
+ // from being sent from within this test case.
this.authenticationComponent.setSystemUserAsCurrentUser();
// Create users
diff --git a/source/java/org/alfresco/repo/web/scripts/transfer/BeginTransferCommandProcessor.java b/source/java/org/alfresco/repo/web/scripts/transfer/BeginTransferCommandProcessor.java
index a00ad81406..fb201f7b04 100644
--- a/source/java/org/alfresco/repo/web/scripts/transfer/BeginTransferCommandProcessor.java
+++ b/source/java/org/alfresco/repo/web/scripts/transfer/BeginTransferCommandProcessor.java
@@ -22,6 +22,7 @@ package org.alfresco.repo.web.scripts.transfer;
import java.io.StringWriter;
import org.alfresco.repo.transfer.RepoTransferReceiverImpl;
+import org.alfresco.repo.transfer.TransferCommons;
import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferReceiver;
import org.apache.commons.logging.Log;
@@ -57,8 +58,26 @@ public class BeginTransferCommandProcessor implements CommandProcessor
String transferId = null;
try
{
- // attempt to take the transfer lock
- transferId = receiver.start();
+ String [] fromRepositoryIdValues = req.getParameterValues(TransferCommons.PARAM_FROM_REPOSITORYID);
+ String [] transferToSelfValues = req.getParameterValues(TransferCommons.PARAM_ALLOW_TRANSFER_TO_SELF);
+
+ String fromRepositoryId = null;
+ if(fromRepositoryIdValues.length > 0)
+ {
+ fromRepositoryId = fromRepositoryIdValues[0];
+ }
+
+ boolean transferToSelf = false;
+ if(transferToSelfValues.length > 0)
+ {
+ if(transferToSelfValues[0].equalsIgnoreCase("true"))
+ {
+ transferToSelf = true;
+ }
+ }
+
+ // attempt to start the transfer
+ transferId = receiver.start(fromRepositoryId, transferToSelf);
// Create a temporary folder into which we can place transferred files
receiver.getStagingFolder(transferId);
@@ -82,7 +101,8 @@ public class BeginTransferCommandProcessor implements CommandProcessor
return Status.STATUS_OK;
- } catch (Exception ex)
+ }
+ catch (Exception ex)
{
logger.debug("exception caught", ex);
if(transferId != null)
diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java
index 02f306b056..d024795ff2 100644
--- a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java
@@ -559,7 +559,14 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
assertNotNull(transition);
- assertEquals(startTransition.getId(), transition.getString("id"));
+ if(startTransition.getId() == null)
+ {
+ assertEquals("", transition.getString("id"));
+ }
+ else
+ {
+ assertEquals(startTransition.getId(), transition.getString("id"));
+ }
assertEquals(startTransition.getTitle(), transition.getString("title"));
assertEquals(startTransition.getDescription(), transition.getString("description"));
assertEquals(startTransition.isDefault(), transition.getBoolean("isDefault"));
diff --git a/source/java/org/alfresco/repo/webdav/AbstractMoveOrCopyMethod.java b/source/java/org/alfresco/repo/webdav/AbstractMoveOrCopyMethod.java
index c2da470535..c2d4169505 100644
--- a/source/java/org/alfresco/repo/webdav/AbstractMoveOrCopyMethod.java
+++ b/source/java/org/alfresco/repo/webdav/AbstractMoveOrCopyMethod.java
@@ -51,6 +51,7 @@ public abstract class AbstractMoveOrCopyMethod extends HierarchicalMethod
protected abstract void moveOrCopy(
FileFolderService fileFolderService,
NodeRef sourceNodeRef,
+ NodeRef sourceParentNodeRef,
NodeRef destParentNodeRef,
String name) throws Exception;
@@ -84,6 +85,8 @@ public abstract class AbstractMoveOrCopyMethod extends HierarchicalMethod
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
+ FileInfo sourceParentInfo = getDAVHelper().getParentNodeForPath(rootNodeRef, sourcePath, servletPath);
+
// the destination parent must exist
String destPath = getDestinationPath();
FileInfo destParentInfo = null;
@@ -137,11 +140,12 @@ public abstract class AbstractMoveOrCopyMethod extends HierarchicalMethod
}
NodeRef sourceNodeRef = sourceInfo.getNodeRef();
+ NodeRef sourceParentNodeRef = sourceParentInfo.getNodeRef();
NodeRef destParentNodeRef = destParentInfo.getNodeRef();
String name = getDAVHelper().splitPath(destPath)[1];
- moveOrCopy(fileFolderService, sourceNodeRef, destParentNodeRef, name);
+ moveOrCopy(fileFolderService, sourceNodeRef, sourceParentNodeRef, destParentNodeRef, name);
// Set the response status
if (destInfo == null)
@@ -152,5 +156,6 @@ public abstract class AbstractMoveOrCopyMethod extends HierarchicalMethod
{
m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
- }
+ }
+
}
diff --git a/source/java/org/alfresco/repo/webdav/CopyMethod.java b/source/java/org/alfresco/repo/webdav/CopyMethod.java
index e0deb378b0..d5c5313e43 100644
--- a/source/java/org/alfresco/repo/webdav/CopyMethod.java
+++ b/source/java/org/alfresco/repo/webdav/CopyMethod.java
@@ -39,6 +39,7 @@ public class CopyMethod extends AbstractMoveOrCopyMethod
protected void moveOrCopy(
FileFolderService fileFolderService,
NodeRef sourceNodeRef,
+ NodeRef sourceParentNodeRef,
NodeRef destParentNodeRef,
String name) throws Exception
{
diff --git a/source/java/org/alfresco/repo/webdav/LockMethod.java b/source/java/org/alfresco/repo/webdav/LockMethod.java
index 1022c82937..30e2ea18b5 100644
--- a/source/java/org/alfresco/repo/webdav/LockMethod.java
+++ b/source/java/org/alfresco/repo/webdav/LockMethod.java
@@ -344,6 +344,7 @@ public class LockMethod extends WebDAVMethod
// Store lock scope (shared/exclusive)
getNodeService().setProperty(lockNode.getNodeRef(), WebDAVModel.PROP_LOCK_SCOPE, this.createExclusive ? WebDAV.XML_EXCLUSIVE : WebDAV.XML_SHARED);
+ logger.debug("Properties of the " + lockNode + " was changed");
}
/**
@@ -389,27 +390,48 @@ public class LockMethod extends WebDAVMethod
xml.startDocument();
- String nsdec = generateNamespaceDeclarations(null);
- xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP + nsdec, WebDAV.XML_NS_PROP + nsdec, getDAVHelper().getNullAttributes());
-
// Output the lock details
- generateLockDiscoveryXML(xml, lockNode, false, scope, WebDAV.getDepthName(m_depth), lt, owner);
+ String nsdec = "";
- // Close off the XML
- xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP);
+ if (WebDAV.AGENT_MS_6_1_7600.equals(m_userAgent))
+ {
+ nsdec = generateNamespaceDeclarations(null, true);
+ xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP + nsdec, WebDAV.XML_NS_PROP + nsdec, getDAVHelper().getNullAttributes());
+
+ // Output the lock details
+ generateLockDiscoveryXML(xml, lockNode, false, scope, WebDAV.getDepthName(m_depth), lt, owner);
+
+ // Close off the XML
+ xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP);
+
+ }
+ else
+ {
+ nsdec = generateNamespaceDeclarations(null, false);
+ xml.startElement(EMPTY_NS, WebDAV.XML_PROP, WebDAV.XML_PROP + nsdec, getDAVHelper().getNullAttributes());
+
+ // Output the lock details
+ generateLockDiscoveryXML(xml, lockNode, true, scope, WebDAV.getDepthName(m_depth), lt, owner);
+
+ // Close off the XML
+ xml.endElement(EMPTY_NS, WebDAV.XML_PROP, WebDAV.XML_PROP);
+ }
}
/**
* Generates a list of namespace declarations for the response
*/
- protected String generateNamespaceDeclarations(HashMap nameSpaces)
+ protected String generateNamespaceDeclarations(HashMap nameSpaces, boolean withPrefix)
{
StringBuilder ns = new StringBuilder();
ns.append(" ");
ns.append(WebDAV.XML_NS);
- ns.append(":");
- ns.append(WebDAV.DAV_NS);
+ if (withPrefix)
+ {
+ ns.append(":");
+ ns.append(WebDAV.DAV_NS);
+ }
ns.append("=\"");
ns.append(WebDAV.DEFAULT_NAMESPACE_URI);
ns.append("\"");
diff --git a/source/java/org/alfresco/repo/webdav/MoveMethod.java b/source/java/org/alfresco/repo/webdav/MoveMethod.java
index 20b0b37d61..cc71d87736 100644
--- a/source/java/org/alfresco/repo/webdav/MoveMethod.java
+++ b/source/java/org/alfresco/repo/webdav/MoveMethod.java
@@ -44,6 +44,7 @@ public class MoveMethod extends AbstractMoveOrCopyMethod
protected void moveOrCopy(
FileFolderService fileFolderService,
NodeRef sourceNodeRef,
+ NodeRef sourceParentNodeRef,
NodeRef destParentNodeRef,
String name) throws Exception
{
@@ -68,15 +69,7 @@ public class MoveMethod extends AbstractMoveOrCopyMethod
checkNode(fileInfo);
- if (getNodeService().getPrimaryParent(sourceNodeRef).getParentRef().equals(destParentNodeRef))
- {
- // It is renaming operation
- fileFolderService.rename(sourceNodeRef, name);
- }
- else
- {
- // It is move operation
- fileFolderService.move(sourceNodeRef, destParentNodeRef, name);
- }
+ // It is move operation
+ fileFolderService.move(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, name);
}
}
diff --git a/source/java/org/alfresco/repo/webdav/WebDAV.java b/source/java/org/alfresco/repo/webdav/WebDAV.java
index a688b89d13..dd1b442fd1 100644
--- a/source/java/org/alfresco/repo/webdav/WebDAV.java
+++ b/source/java/org/alfresco/repo/webdav/WebDAV.java
@@ -35,6 +35,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
+import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -124,6 +125,10 @@ public class WebDAV
public static final String HEADER_KEY_NOT = "Not";
+ // User agents
+
+ public static final String AGENT_MS_6_1_7600 = "Microsoft-WebDAV-MiniRedir/6.1.7600";
+
// General string constants
public static final String ASTERISK = "*";
@@ -243,7 +248,7 @@ public class WebDAV
// WebDAV creation date/time formatter
- private static SimpleDateFormat _creationDateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ private static String CREATION_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
// HTTP header date/time formatter
// NOTE: According to RFC2616 dates should always be in English and in
@@ -281,7 +286,7 @@ public class WebDAV
*/
public static String formatCreationDate(Date date)
{
- return _creationDateFormatter.format(date);
+ return DateFormatUtils.formatUTC(date, CREATION_DATE_FORMAT);
}
/**
@@ -292,7 +297,7 @@ public class WebDAV
*/
public static String formatCreationDate(long ldate)
{
- return _creationDateFormatter.format(new Date(ldate));
+ return DateFormatUtils.formatUTC(ldate, CREATION_DATE_FORMAT);
}
/**
diff --git a/source/java/org/alfresco/repo/webdav/WebDAVMethod.java b/source/java/org/alfresco/repo/webdav/WebDAVMethod.java
index beff51a5d2..9bad063b6e 100644
--- a/source/java/org/alfresco/repo/webdav/WebDAVMethod.java
+++ b/source/java/org/alfresco/repo/webdav/WebDAVMethod.java
@@ -312,7 +312,7 @@ public abstract class WebDAVMethod
catch (AccessDeniedException e)
{
// Return a forbidden status
- throw new WebDAVServerException(HttpServletResponse.SC_UNAUTHORIZED, e);
+ throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN, e);
}
catch (Throwable e)
{
diff --git a/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
index f706064c68..8ff24080ba 100644
--- a/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
+++ b/source/java/org/alfresco/repo/webdav/auth/BaseAuthenticationFilter.java
@@ -273,7 +273,7 @@ public abstract class BaseAuthenticationFilter
{
public T doWork() throws Exception
{
- return transactionService.getRetryingTransactionHelper().doInTransaction(callback);
+ return transactionService.getRetryingTransactionHelper().doInTransaction(callback, transactionService.isReadOnly());
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
}
@@ -375,7 +375,7 @@ public abstract class BaseAuthenticationFilter
authenticationComponent.setCurrentUser(userName);
return createUserEnvironment(session, userName, authenticationService.getCurrentTicket(), true);
}
- });
+ }, transactionService.isReadOnly());
}
/**
diff --git a/source/java/org/alfresco/repo/webdav/auth/BaseNTLMAuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/BaseNTLMAuthenticationFilter.java
index 8179f01b5e..60849084ea 100644
--- a/source/java/org/alfresco/repo/webdav/auth/BaseNTLMAuthenticationFilter.java
+++ b/source/java/org/alfresco/repo/webdav/auth/BaseNTLMAuthenticationFilter.java
@@ -19,10 +19,12 @@
package org.alfresco.repo.webdav.auth;
import java.io.IOException;
+import java.io.PrintWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Enumeration;
import java.util.List;
import java.util.Random;
@@ -263,7 +265,10 @@ public abstract class BaseNTLMAuthenticationFilter extends BaseSSOAuthentication
sreq.getRemoteAddr() + ":" + sreq.getRemotePort() + ") SID:" + sreq.getSession().getId());
// Send back a request for NTLM authentication
- restartLoginChallenge(context, sreq, sresp);
+ sresp.setHeader(WWW_AUTHENTICATE, AUTH_NTLM);
+ sresp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ writeLoginPageLink(sreq, sresp);
+ sresp.flushBuffer();
return false;
}
else
@@ -985,20 +990,50 @@ public abstract class BaseNTLMAuthenticationFilter extends BaseSSOAuthentication
*/
public void restartLoginChallenge(ServletContext context, HttpServletRequest req, HttpServletResponse res) throws IOException
{
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("restartLoginChallenge...");
+
// Remove any existing session and NTLM details from the session
HttpSession session = req.getSession(false);
if (session != null)
{
- session.invalidate();
+ clearSession(session);
}
- // Force the logon to start again
- res.setHeader(WWW_AUTHENTICATE, AUTH_NTLM);
- res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
- writeLoginPageLink(req, res);
+ String userAgent = req.getHeader("user-agent");
+ if (userAgent != null && userAgent.indexOf("Safari") != -1)
+ {
+ final PrintWriter out = res.getWriter();
+ out.println("");
+ out.println("Login authentication failed. Please close and re-open Safari to try again.
");
+ out.println("");
+ out.close();
+ }
+ else
+ {
+ // Force the logon to start again
+ res.setHeader(WWW_AUTHENTICATE, AUTH_NTLM);
+ res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ writeLoginPageLink(req, res);
+ }
res.flushBuffer();
}
+ /**
+ * Removes all attributes stored in session
+ *
+ * @param session Session
+ */
+ @SuppressWarnings("unchecked")
+ private void clearSession(HttpSession session)
+ {
+ Enumeration names = (Enumeration) session.getAttributeNames();
+ while (names.hasMoreElements())
+ {
+ session.removeAttribute(names.nextElement());
+ }
+ }
+
/**
* Disable NTLMv2 support, must be called from the implementation constructor
diff --git a/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
index 908761604d..fdee62b105 100644
--- a/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
+++ b/source/java/org/alfresco/repo/webdav/auth/BaseSSOAuthenticationFilter.java
@@ -315,7 +315,9 @@ public abstract class BaseSSOAuthenticationFilter extends BaseAuthenticationFilt
protected void redirectToLoginPage(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
- if ( hasLoginPage())
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("redirectToLoginPage...");
+ if (hasLoginPage())
res.sendRedirect(req.getContextPath() + "/faces" + getLoginPage());
}