Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)

74316: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (5.0/Cloud)
      74270: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.3)
         73963: Merged DEV to V4.1-BUG-FIX (4.1.10)
            71918: MNT-10156: In Share show appropriate HTTP status codes (such as 403) rather than the default 500
               - Throw WebScriptException with 403 status code on ContentGet layer.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74896 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-06-25 16:34:46 +00:00
parent ecad173150
commit db9e0932fa
2 changed files with 26 additions and 16 deletions

View File

@@ -34,6 +34,7 @@ import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cmis.reference.ReferenceFactory;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentService;
@@ -44,6 +45,7 @@ import org.alfresco.service.namespace.QName;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
@@ -185,26 +187,33 @@ public class ContentGet extends StreamContent implements ServletContextAware
boolean rfc5987Supported = (null != userAgent) && (userAgent.contains("MSIE") || userAgent.contains(" Chrome/") || userAgent.contains(" FireFox/"));
if (attach && rfc5987Supported)
try
{
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
//IE use file extension to get mimetype
//So we set correct extension. see MNT-11246
if(userAgent.contains("MSIE"))
if (attach && rfc5987Supported)
{
String mimeType = contentService.getReader(nodeRef, propertyQName).getMimetype();
if (!mimetypeService.getMimetypes(FilenameUtils.getExtension(name)).contains(mimeType))
{
name = FilenameUtils.removeExtension(name) + FilenameUtils.EXTENSION_SEPARATOR_STR + mimetypeService.getExtension(mimeType);
}
}
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
streamContent(req, res, nodeRef, propertyQName, attach, name, null);
//IE use file extension to get mimetype
//So we set correct extension. see MNT-11246
if(userAgent.contains("MSIE"))
{
String mimeType = contentService.getReader(nodeRef, propertyQName).getMimetype();
if (!mimetypeService.getMimetypes(FilenameUtils.getExtension(name)).contains(mimeType))
{
name = FilenameUtils.removeExtension(name) + FilenameUtils.EXTENSION_SEPARATOR_STR + mimetypeService.getExtension(mimeType);
}
}
streamContent(req, res, nodeRef, propertyQName, attach, name, null);
}
else
{
streamContent(req, res, nodeRef, propertyQName, attach, null, null);
}
}
else
catch (AccessDeniedException e)
{
streamContent(req, res, nodeRef, propertyQName, attach, null, null);
throw new WebScriptException(Status.STATUS_FORBIDDEN, e.getMessage());
}
}