|
|
|
@ -69,9 +69,26 @@ public class CurrentSecurityContextArgumentResolverTests { |
|
|
|
SecurityContextHolder.clearContext(); |
|
|
|
SecurityContextHolder.clearContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void supportsParameterNoAnnotationWrongType() { |
|
|
|
|
|
|
|
assertThat(this.resolver.supportsParameter(showSecurityContextNoAnnotationTypeMismatch())).isFalse(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void supportsParameterNoAnnotation() { |
|
|
|
public void supportsParameterNoAnnotation() { |
|
|
|
assertThat(this.resolver.supportsParameter(showSecurityContextNoAnnotation())).isFalse(); |
|
|
|
assertThat(this.resolver.supportsParameter(showSecurityContextNoAnnotation())).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void supportsParameterCustomSecurityContextNoAnnotation() { |
|
|
|
|
|
|
|
assertThat(this.resolver.supportsParameter(showSecurityContextWithCustomSecurityContextNoAnnotation())) |
|
|
|
|
|
|
|
.isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void supportsParameterNoAnnotationCustomType() { |
|
|
|
|
|
|
|
assertThat(this.resolver.supportsParameter(showSecurityContextWithCustomSecurityContextNoAnnotation())) |
|
|
|
|
|
|
|
.isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -88,6 +105,24 @@ public class CurrentSecurityContextArgumentResolverTests { |
|
|
|
assertThat(customSecurityContext.getAuthentication().getPrincipal()).isEqualTo(principal); |
|
|
|
assertThat(customSecurityContext.getAuthentication().getPrincipal()).isEqualTo(principal); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void resolveArgumentWithCustomSecurityContextNoAnnotation() { |
|
|
|
|
|
|
|
String principal = "custom_security_context"; |
|
|
|
|
|
|
|
setAuthenticationPrincipalWithCustomSecurityContext(principal); |
|
|
|
|
|
|
|
CustomSecurityContext customSecurityContext = (CustomSecurityContext) this.resolver |
|
|
|
|
|
|
|
.resolveArgument(showSecurityContextWithCustomSecurityContextNoAnnotation(), null, null, null); |
|
|
|
|
|
|
|
assertThat(customSecurityContext.getAuthentication().getPrincipal()).isEqualTo(principal); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void resolveArgumentWithNoAnnotation() { |
|
|
|
|
|
|
|
String principal = "custom_security_context"; |
|
|
|
|
|
|
|
setAuthenticationPrincipal(principal); |
|
|
|
|
|
|
|
SecurityContext securityContext = (SecurityContext) this.resolver |
|
|
|
|
|
|
|
.resolveArgument(showSecurityContextNoAnnotation(), null, null, null); |
|
|
|
|
|
|
|
assertThat(securityContext.getAuthentication().getPrincipal()).isEqualTo(principal); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void resolveArgumentWithCustomSecurityContextTypeMatch() { |
|
|
|
public void resolveArgumentWithCustomSecurityContextTypeMatch() { |
|
|
|
String principal = "custom_security_context_type_match"; |
|
|
|
String principal = "custom_security_context_type_match"; |
|
|
|
@ -212,10 +247,14 @@ public class CurrentSecurityContextArgumentResolverTests { |
|
|
|
.resolveArgument(showCurrentSecurityWithErrorOnInvalidTypeMisMatch(), null, null, null)); |
|
|
|
.resolveArgument(showCurrentSecurityWithErrorOnInvalidTypeMisMatch(), null, null, null)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MethodParameter showSecurityContextNoAnnotation() { |
|
|
|
private MethodParameter showSecurityContextNoAnnotationTypeMismatch() { |
|
|
|
return getMethodParameter("showSecurityContextNoAnnotation", String.class); |
|
|
|
return getMethodParameter("showSecurityContextNoAnnotation", String.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MethodParameter showSecurityContextNoAnnotation() { |
|
|
|
|
|
|
|
return getMethodParameter("showSecurityContextNoAnnotation", SecurityContext.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MethodParameter showSecurityContextAnnotation() { |
|
|
|
private MethodParameter showSecurityContextAnnotation() { |
|
|
|
return getMethodParameter("showSecurityContextAnnotation", SecurityContext.class); |
|
|
|
return getMethodParameter("showSecurityContextAnnotation", SecurityContext.class); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -276,6 +315,11 @@ public class CurrentSecurityContextArgumentResolverTests { |
|
|
|
return getMethodParameter("showCurrentSecurityWithErrorOnInvalidTypeMisMatch", String.class); |
|
|
|
return getMethodParameter("showCurrentSecurityWithErrorOnInvalidTypeMisMatch", String.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MethodParameter showSecurityContextWithCustomSecurityContextNoAnnotation() { |
|
|
|
|
|
|
|
return getMethodParameter("showSecurityContextWithCustomSecurityContextNoAnnotation", |
|
|
|
|
|
|
|
CustomSecurityContext.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MethodParameter getMethodParameter(String methodName, Class<?>... paramTypes) { |
|
|
|
private MethodParameter getMethodParameter(String methodName, Class<?>... paramTypes) { |
|
|
|
Method method = ReflectionUtils.findMethod(TestController.class, methodName, paramTypes); |
|
|
|
Method method = ReflectionUtils.findMethod(TestController.class, methodName, paramTypes); |
|
|
|
return new MethodParameter(method, 0); |
|
|
|
return new MethodParameter(method, 0); |
|
|
|
@ -358,6 +402,12 @@ public class CurrentSecurityContextArgumentResolverTests { |
|
|
|
@CurrentSecurityWithErrorOnInvalidType String typeMisMatch) { |
|
|
|
@CurrentSecurityWithErrorOnInvalidType String typeMisMatch) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void showSecurityContextNoAnnotation(SecurityContext context) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void showSecurityContextWithCustomSecurityContextNoAnnotation(CustomSecurityContext context) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class CustomSecurityContext implements SecurityContext { |
|
|
|
static class CustomSecurityContext implements SecurityContext { |
|
|
|
|