Move inner-types so that they are always last

Move all inner-types so that they are consistently the last item
defined. This aligns with the style used by Spring Framework and
the consistency generally makes it easier to scan the source.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-26 13:35:03 -07:00
committed by Rob Winch
parent 418c3d6808
commit a2f2e9ac8d
163 changed files with 10287 additions and 10332 deletions

View File

@@ -50,6 +50,10 @@ public final class WebTestHandler {
return new WebHandlerResult(this.webHandler.exchange);
}
public static WebTestHandler bindToWebFilters(WebFilter... filters) {
return new WebTestHandler(filters);
}
public static final class WebHandlerResult {
private final ServerWebExchange exchange;
@@ -64,10 +68,6 @@ public final class WebTestHandler {
}
public static WebTestHandler bindToWebFilters(WebFilter... filters) {
return new WebTestHandler(filters);
}
static class MockWebHandler implements WebHandler {
private ServerWebExchange exchange;

View File

@@ -96,14 +96,6 @@ public class WebExpressionVoterTests {
assertThat(voter.supports(FilterInvocationChild.class)).isTrue();
}
private static class FilterInvocationChild extends FilterInvocation {
FilterInvocationChild(ServletRequest request, ServletResponse response, FilterChain chain) {
super(request, response, chain);
}
}
@Test
public void supportFilterInvocation() {
WebExpressionVoter voter = new WebExpressionVoter();
@@ -116,4 +108,12 @@ public class WebExpressionVoterTests {
assertThat(voter.supports(Object.class)).isFalse();
}
private static class FilterInvocationChild extends FilterInvocation {
FilterInvocationChild(ServletRequest request, ServletResponse response, FilterChain chain) {
super(request, response, chain);
}
}
}

View File

@@ -150,26 +150,6 @@ public class DefaultLoginPageGeneratingFilterTests {
filter.doFilter(new MockHttpServletRequest("GET", "/login"), new MockHttpServletResponse(), this.chain);
}
// Fake OpenID filter (since it's not in this module
@SuppressWarnings("unused")
private static class MockProcessingFilter extends AbstractAuthenticationProcessingFilter {
MockProcessingFilter() {
super("/someurl");
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
return null;
}
public String getClaimedIdentityFieldName() {
return "unused";
}
}
/* SEC-1111 */
@Test
public void handlesNonIso8859CharsInErrorMessage() throws Exception {
@@ -218,6 +198,25 @@ public class DefaultLoginPageGeneratingFilterTests {
assertThat(response.getContentAsString()).contains("Login with SAML 2.0");
assertThat(response.getContentAsString())
.contains("<a href=\"/saml/sso/google\">Google &lt; &gt; &quot; &#39; &amp;</a>");
} // Fake OpenID filter (since it's not in this module
@SuppressWarnings("unused")
private static class MockProcessingFilter extends AbstractAuthenticationProcessingFilter {
MockProcessingFilter() {
super("/someurl");
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
return null;
}
public String getClaimedIdentityFieldName() {
return "unused";
}
}
}

View File

@@ -180,6 +180,12 @@ public class AuthenticationPrincipalArgumentResolverTests {
return new MethodParameter(method, 0);
}
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
}
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@AuthenticationPrincipal
@@ -227,10 +233,4 @@ public class AuthenticationPrincipalArgumentResolverTests {
}
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
}
}

View File

@@ -92,11 +92,6 @@ public class AbstractSecurityWebApplicationInitializerTests {
verify(context).addListener(any(ContextLoaderListener.class));
}
@Configuration
static class MyRootConfiguration {
}
@Test
public void onStartupWhenEnableHttpSessionEventPublisherIsTrueThenAddsHttpSessionEventPublisher() {
ServletContext context = mock(ServletContext.class);
@@ -435,4 +430,9 @@ public class AbstractSecurityWebApplicationInitializerTests {
assertThat(proxy).hasFieldOrPropertyWithValue("targetBeanName", "springSecurityFilterChain");
}
@Configuration
static class MyRootConfiguration {
}
}

View File

@@ -250,6 +250,52 @@ public final class ResolvableMethod {
return new Builder<>(objectClass);
}
@SuppressWarnings("unchecked")
private static <T> T initProxy(Class<?> type, MethodInvocationInterceptor interceptor) {
Assert.notNull(type, "'type' must not be null");
if (type.isInterface()) {
ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE);
factory.addInterface(type);
factory.addInterface(Supplier.class);
factory.addAdvice(interceptor);
return (T) factory.getProxy();
}
else {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(type);
enhancer.setInterfaces(new Class<?>[] { Supplier.class });
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class);
Class<?> proxyClass = enhancer.createClass();
Object proxy = null;
if (objenesis.isWorthTrying()) {
try {
proxy = objenesis.newInstance(proxyClass, enhancer.getUseCache());
}
catch (ObjenesisException ex) {
logger.debug("Objenesis failed, falling back to default constructor", ex);
}
}
if (proxy == null) {
try {
proxy = ReflectionUtils.accessibleConstructor(proxyClass).newInstance();
}
catch (Throwable ex) {
throw new IllegalStateException(
"Unable to instantiate proxy " + "via both Objenesis and default constructor fails as well",
ex);
}
}
((Factory) proxy).setCallbacks(new Callback[] { interceptor });
return (T) proxy;
}
}
/**
* Builder for {@code ResolvableMethod}.
*/
@@ -613,50 +659,4 @@ public final class ResolvableMethod {
}
@SuppressWarnings("unchecked")
private static <T> T initProxy(Class<?> type, MethodInvocationInterceptor interceptor) {
Assert.notNull(type, "'type' must not be null");
if (type.isInterface()) {
ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE);
factory.addInterface(type);
factory.addInterface(Supplier.class);
factory.addAdvice(interceptor);
return (T) factory.getProxy();
}
else {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(type);
enhancer.setInterfaces(new Class<?>[] { Supplier.class });
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class);
Class<?> proxyClass = enhancer.createClass();
Object proxy = null;
if (objenesis.isWorthTrying()) {
try {
proxy = objenesis.newInstance(proxyClass, enhancer.getUseCache());
}
catch (ObjenesisException ex) {
logger.debug("Objenesis failed, falling back to default constructor", ex);
}
}
if (proxy == null) {
try {
proxy = ReflectionUtils.accessibleConstructor(proxyClass).newInstance();
}
catch (Throwable ex) {
throw new IllegalStateException(
"Unable to instantiate proxy " + "via both Objenesis and default constructor fails as well",
ex);
}
}
((Factory) proxy).setCallbacks(new Callback[] { interceptor });
return (T) proxy;
}
}
}

View File

@@ -204,6 +204,12 @@ public class AuthenticationPrincipalArgumentResolverTests {
return new MethodParameter(method, 0);
}
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
}
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@AuthenticationPrincipal
@@ -305,10 +311,4 @@ public class AuthenticationPrincipalArgumentResolverTests {
}
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
}
}

View File

@@ -259,6 +259,23 @@ public class CurrentSecurityContextArgumentResolverTests {
return new MethodParameter(method, 0);
}
private void setAuthenticationPrincipal(Object principal) {
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(principal, "password", "ROLE_USER"));
}
private void setAuthenticationPrincipalWithCustomSecurityContext(Object principal) {
CustomSecurityContext csc = new CustomSecurityContext();
csc.setAuthentication(new TestingAuthenticationToken(principal, "password", "ROLE_USER"));
SecurityContextHolder.setContext(csc);
}
private void setAuthenticationDetail(Object detail) {
TestingAuthenticationToken tat = new TestingAuthenticationToken("user", "password", "ROLE_USER");
tat.setDetails(detail);
SecurityContextHolder.getContext().setAuthentication(tat);
}
public static class TestController {
public void showSecurityContextNoAnnotation(String user) {
@@ -317,17 +334,6 @@ public class CurrentSecurityContextArgumentResolverTests {
}
private void setAuthenticationPrincipal(Object principal) {
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(principal, "password", "ROLE_USER"));
}
private void setAuthenticationPrincipalWithCustomSecurityContext(Object principal) {
CustomSecurityContext csc = new CustomSecurityContext();
csc.setAuthentication(new TestingAuthenticationToken(principal, "password", "ROLE_USER"));
SecurityContextHolder.setContext(csc);
}
static class CustomSecurityContext implements SecurityContext {
private Authentication authentication;
@@ -365,10 +371,4 @@ public class CurrentSecurityContextArgumentResolverTests {
}
private void setAuthenticationDetail(Object detail) {
TestingAuthenticationToken tat = new TestingAuthenticationToken("user", "password", "ROLE_USER");
tat.setDetails(detail);
SecurityContextHolder.getContext().setAuthentication(tat);
}
}

View File

@@ -348,6 +348,10 @@ public class CurrentSecurityContextArgumentResolverTests {
@CurrentSecurityWithErrorOnInvalidType Mono<String> typeMisMatch) {
}
private Authentication buildAuthenticationWithPrincipal(Object principal) {
return new TestingAuthenticationToken(principal, "password", "ROLE_USER");
}
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@CurrentSecurityContext
@@ -389,8 +393,4 @@ public class CurrentSecurityContextArgumentResolverTests {
}
private Authentication buildAuthenticationWithPrincipal(Object principal) {
return new TestingAuthenticationToken(principal, "password", "ROLE_USER");
}
}

View File

@@ -31,39 +31,6 @@ import static org.assertj.core.api.Assertions.fail;
@SuppressWarnings("unchecked")
public class ThrowableAnalyzerTests {
/**
* Exception for testing purposes. The cause is not retrievable by {@link #getCause()}
* .
*/
public static final class NonStandardException extends Exception {
private Throwable cause;
public NonStandardException(String message, Throwable cause) {
super(message);
this.cause = cause;
}
public Throwable resolveCause() {
return this.cause;
}
}
/**
* <code>ThrowableCauseExtractor</code> for handling <code>NonStandardException</code>
* instances.
*/
public static final class NonStandardExceptionCauseExtractor implements ThrowableCauseExtractor {
@Override
public Throwable extractCause(Throwable throwable) {
ThrowableAnalyzer.verifyThrowableHierarchy(throwable, NonStandardException.class);
return ((NonStandardException) throwable).resolveCause();
}
}
/**
* An array of nested throwables for testing. The cause of element 0 is element 1, the
* cause of element 1 is element 2 and so on.
@@ -282,4 +249,37 @@ public class ThrowableAnalyzerTests {
}
}
/**
* Exception for testing purposes. The cause is not retrievable by {@link #getCause()}
* .
*/
public static final class NonStandardException extends Exception {
private Throwable cause;
public NonStandardException(String message, Throwable cause) {
super(message);
this.cause = cause;
}
public Throwable resolveCause() {
return this.cause;
}
}
/**
* <code>ThrowableCauseExtractor</code> for handling <code>NonStandardException</code>
* instances.
*/
public static final class NonStandardExceptionCauseExtractor implements ThrowableCauseExtractor {
@Override
public Throwable extractCause(Throwable throwable) {
ThrowableAnalyzer.verifyThrowableHierarchy(throwable, NonStandardException.class);
return ((NonStandardException) throwable).resolveCause();
}
}
}