mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-21694 transform option converter (#444)
* MNT-21694 500 error on new logo upload with Legacy transforms (#284) The TransformationOptionsConverter class did not convert the newer transform option format a Map<String, String> to the legacy ImageTransformationOptions class that contains the commandOption (OPT_COMMAND_OPTIONS) property. As a result no legacy transformer is asked if it can do the transform. Originally not fixed on ACS 7 as Legacy transformers were removed, however the fix was just in the converter class and it is helpful to have identical code on branches if possible.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -52,6 +52,7 @@ import java.util.Set;
|
|||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_PDF;
|
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_PDF;
|
||||||
|
import static org.alfresco.repo.content.transform.magick.ImageTransformationOptions.OPT_COMMAND_OPTIONS;
|
||||||
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_ENLARGEMENT;
|
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_ENLARGEMENT;
|
||||||
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_PDF_ENLARGEMENT;
|
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_PDF_ENLARGEMENT;
|
||||||
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALPHA_REMOVE;
|
import static org.alfresco.repo.rendition2.RenditionDefinition2.ALPHA_REMOVE;
|
||||||
@@ -122,6 +123,7 @@ public class TransformationOptionsConverter implements InitializingBean
|
|||||||
IMAGE_OPTIONS.addAll(RESIZE_OPTIONS);
|
IMAGE_OPTIONS.addAll(RESIZE_OPTIONS);
|
||||||
IMAGE_OPTIONS.add(AUTO_ORIENT);
|
IMAGE_OPTIONS.add(AUTO_ORIENT);
|
||||||
IMAGE_OPTIONS.add(ALPHA_REMOVE);
|
IMAGE_OPTIONS.add(ALPHA_REMOVE);
|
||||||
|
IMAGE_OPTIONS.add(OPT_COMMAND_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> PDF_OPTIONS = new HashSet<>(Arrays.asList(new String[]
|
private static Set<String> PDF_OPTIONS = new HashSet<>(Arrays.asList(new String[]
|
||||||
@@ -284,6 +286,8 @@ public class TransformationOptionsConverter implements InitializingBean
|
|||||||
}
|
}
|
||||||
opts.setSourceOptionsList(sourceOptionsList);
|
opts.setSourceOptionsList(sourceOptionsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifSet(options, OPT_COMMAND_OPTIONS, (v) -> opts.setCommandOptions(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -361,13 +365,11 @@ public class TransformationOptionsConverter implements InitializingBean
|
|||||||
{
|
{
|
||||||
ImageTransformationOptions opts = (ImageTransformationOptions) options;
|
ImageTransformationOptions opts = (ImageTransformationOptions) options;
|
||||||
|
|
||||||
// TODO We don't support this any more for security reasons, however it might be possible to
|
// From a security viewpoint it would be better not to support the option of passing anything to
|
||||||
// extract some of the well know values and add them to the newer ImageMagick transform options.
|
// ImageMagick. It might be possible to extract some of the well know values and add them to the
|
||||||
|
// T-Engine engine_config.
|
||||||
String commandOptions = opts.getCommandOptions();
|
String commandOptions = opts.getCommandOptions();
|
||||||
if (commandOptions != null && !commandOptions.isBlank())
|
ifSet(commandOptions != null && !commandOptions.isBlank(), map, OPT_COMMAND_OPTIONS, commandOptions);
|
||||||
{
|
|
||||||
logger.error("ImageMagick commandOptions are no longer supported for security reasons: " + commandOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageResizeOptions imageResizeOptions = opts.getResizeOptions();
|
ImageResizeOptions imageResizeOptions = opts.getResizeOptions();
|
||||||
if (imageResizeOptions != null)
|
if (imageResizeOptions != null)
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -565,4 +565,18 @@ public class TransformationOptionsConverterTest
|
|||||||
"timeout=-1 "
|
"timeout=-1 "
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandOptionsFromOldOptions()
|
||||||
|
{
|
||||||
|
ImageTransformationOptions oldOptions = new ImageTransformationOptions();
|
||||||
|
oldOptions.setCommandOptions("-resize 350x50> -background none -gravity center");
|
||||||
|
|
||||||
|
assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG,
|
||||||
|
"ImageTransformationOptions [commandOptions=-resize 350x50> -background none -gravity center, " +
|
||||||
|
"resizeOptions=null, autoOrient=true]]",
|
||||||
|
"autoOrient=true " + // this is a default - so is also set when uploading a logo
|
||||||
|
"commandOptions=-resize 350x50> -background none -gravity center " +
|
||||||
|
"timeout=-1 ");
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user