SEC-2344: Remove check for DefaultParamterNameDiscoverer

Spring Security not requires Spring 4, so there is no need to perform a
check if Spring 4 is present.
This commit is contained in:
Rob Winch 2014-11-20 12:09:38 -06:00
parent 3089f1603e
commit 0704f88e99
2 changed files with 6 additions and 70 deletions

View File

@ -22,6 +22,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.PrioritizedParameterNameDiscoverer;
@ -56,11 +57,6 @@ public class DefaultSecurityParameterNameDiscoverer extends
private final Log logger = LogFactory.getLog(getClass());
private static final String DEFAULT_PARAMETER_NAME_DISCOVERER_CLASSNAME =
"org.springframework.core.DefaultParameterNameDiscoverer";
private static final boolean DEFAULT_PARAM_DISCOVERER_PRESENT =
ClassUtils.isPresent(DEFAULT_PARAMETER_NAME_DISCOVERER_CLASSNAME, DefaultSecurityParameterNameDiscoverer.class.getClassLoader());
private static final String DATA_PARAM_CLASSNAME = "org.springframework.data.repository.query.Param";
private static final boolean DATA_PARAM_PRESENT =
ClassUtils.isPresent(DATA_PARAM_CLASSNAME, DefaultSecurityParameterNameDiscoverer.class.getClassLoader());
@ -91,22 +87,6 @@ public class DefaultSecurityParameterNameDiscoverer extends
}
addDiscoverer(new AnnotationParameterNameDiscoverer(annotationClassesToUse));
if (DEFAULT_PARAM_DISCOVERER_PRESENT) {
try {
Class<? extends ParameterNameDiscoverer> paramNameDiscoverClass = (Class<? extends ParameterNameDiscoverer>) ClassUtils
.forName(DEFAULT_PARAMETER_NAME_DISCOVERER_CLASSNAME,
getClass().getClassLoader());
addDiscoverer(paramNameDiscoverClass.newInstance());
} catch (Exception e) {
logger.warn(
"Could not use "
+ DEFAULT_PARAMETER_NAME_DISCOVERER_CLASSNAME
+ ". Falling back to LocalVariableTableParameterNameDiscoverer.", e);
addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
}
} else {
addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
}
addDiscoverer(new DefaultParameterNameDiscoverer());
}
}

View File

@ -24,6 +24,7 @@ import java.util.Set;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.SpringVersion;
@ -46,8 +47,6 @@ public class DefaultSecurityParameterNameDiscovererTests {
@Test
public void constructorDefault() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("3."));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
@ -59,14 +58,11 @@ public class DefaultSecurityParameterNameDiscovererTests {
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(1)).isInstanceOf(
LocalVariableTableParameterNameDiscoverer.class);
assertThat(discoverers.get(1).getClass()).isEqualTo(DefaultParameterNameDiscoverer.class);
}
@Test
public void constructorDiscoverers() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("3."));
discoverer = new DefaultSecurityParameterNameDiscoverer(Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
@ -82,47 +78,7 @@ public class DefaultSecurityParameterNameDiscovererTests {
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(2)).isInstanceOf(
LocalVariableTableParameterNameDiscoverer.class);
}
@Test
public void constructorDefaultSpring4() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("4."));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
assertThat(discoverers.size()).isEqualTo(2);
ParameterNameDiscoverer annotationDisc = discoverers.get(0);
assertThat(annotationDisc).isInstanceOf(
AnnotationParameterNameDiscoverer.class);
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(1).getClass().getName()).isEqualTo("org.springframework.core.DefaultParameterNameDiscoverer");
}
@Test
public void constructorDiscoverersSpring4() {
Assume.assumeTrue(SpringVersion.getVersion().startsWith("4."));
discoverer = new DefaultSecurityParameterNameDiscoverer(Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(discoverer, "parameterNameDiscoverers");
assertThat(discoverers.size()).isEqualTo(3);
assertThat(discoverers.get(0)).isInstanceOf(
LocalVariableTableParameterNameDiscoverer.class);
ParameterNameDiscoverer annotationDisc = discoverers.get(1);
assertThat(annotationDisc).isInstanceOf(
AnnotationParameterNameDiscoverer.class);
Set<String> annotationsToUse = (Set<String>)ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
assertThat(annotationsToUse).containsOnly(P.class.getName());
assertThat(discoverers.get(2).getClass().getName()).isEqualTo("org.springframework.core.DefaultParameterNameDiscoverer");
assertThat(discoverers.get(2).getClass()).isEqualTo
(DefaultParameterNameDiscoverer.class);
}
}