mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-7119 Throw explicit exception rather than logging message.
Also address other code review comments.
This commit is contained in:
@@ -33,6 +33,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
@@ -170,8 +171,11 @@ public class RMMethodSecurityPostProcessor implements BeanFactoryPostProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stringValue
|
||||
* @return
|
||||
* Convert the lines of a string to a map, separating keys from values by the first "=" sign.
|
||||
*
|
||||
* @param stringValue The multi-line string.
|
||||
* @return The resulting map.
|
||||
* @throws AlfrescoRuntimeException If a non-blank line does not contain an "=" sign.
|
||||
*/
|
||||
protected Map<String, String> convertToMap(String stringValue)
|
||||
{
|
||||
@@ -180,14 +184,14 @@ public class RMMethodSecurityPostProcessor implements BeanFactoryPostProcessor
|
||||
for (String value : values)
|
||||
{
|
||||
String trimmed = value.trim();
|
||||
if (trimmed.equals(""))
|
||||
if (trimmed.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String[] pair = trimmed.split("=", 2);
|
||||
if (pair.length != 2)
|
||||
{
|
||||
LOGGER.error("Error converting string to map: {}", trimmed);
|
||||
throw new AlfrescoRuntimeException("Could not convert string to map " + trimmed);
|
||||
}
|
||||
map.put(pair[0], pair[1]);
|
||||
}
|
||||
|
@@ -34,13 +34,17 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RMMethodSecurityPostProcessor}.
|
||||
*
|
||||
* See RM-7119.
|
||||
*/
|
||||
public class RMMethodSecurityPostProcessorUnitTest
|
||||
{
|
||||
/** The class under test. */
|
||||
private RMMethodSecurityPostProcessor rmMethodSecurityPostProcessor = new RMMethodSecurityPostProcessor();
|
||||
|
||||
@Test
|
||||
@@ -77,4 +81,11 @@ public class RMMethodSecurityPostProcessorUnitTest
|
||||
Map<String, String> actual = rmMethodSecurityPostProcessor.convertToMap("a=b=c\nd=e=f");
|
||||
assertEquals("Issue with handling of = symbol in value.", ImmutableMap.of("a", "b=c", "d", "e=f"), actual);
|
||||
}
|
||||
|
||||
/** Check that if a line is missing an equals sign then we get an exception. */
|
||||
@Test(expected = AlfrescoRuntimeException.class)
|
||||
public void testConvertToMap_missingEquals()
|
||||
{
|
||||
rmMethodSecurityPostProcessor.convertToMap("a=b\ncd");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user