Apply updated Code Style

Closes gh-13881
This commit is contained in:
Marcus Da Coregio
2023-09-29 11:44:32 -03:00
parent 650692964e
commit 64e2a2ff8b
1172 changed files with 10805 additions and 8768 deletions

View File

@@ -40,15 +40,15 @@ public class AuthenticationCredentialsNotFoundEventTests {
@Test
public void testRejectsNulls2() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
new AuthenticationCredentialsNotFoundException("test")));
.isThrownBy(() -> new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
new AuthenticationCredentialsNotFoundException("test")));
}
@Test
public void testRejectsNulls3() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(),
SecurityConfig.createList("TEST"), null));
.isThrownBy(() -> new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(),
SecurityConfig.createList("TEST"), null));
}
}

View File

@@ -44,7 +44,7 @@ public class AuthorizationFailureEventTests {
@Test
public void rejectsNullSecureObject() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationFailureEvent(null, this.attributes, this.foo, this.exception));
.isThrownBy(() -> new AuthorizationFailureEvent(null, this.attributes, this.foo, this.exception));
}
@Test
@@ -56,8 +56,8 @@ public class AuthorizationFailureEventTests {
@Test
public void rejectsNullAuthentication() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationFailureEvent(new SimpleMethodInvocation(), this.attributes, null,
this.exception));
.isThrownBy(() -> new AuthorizationFailureEvent(new SimpleMethodInvocation(), this.attributes, null,
this.exception));
}
@Test

View File

@@ -48,7 +48,7 @@ public class SecurityConfigTests {
@Test
public void testNoArgConstructorDoesntExist() throws Exception {
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> SecurityConfig.class.getDeclaredConstructor((Class[]) null));
.isThrownBy(() -> SecurityConfig.class.getDeclaredConstructor((Class[]) null));
}
@Test

View File

@@ -69,21 +69,21 @@ public class Jsr250MethodSecurityMetadataSourceTests {
@Test
public void noRoleMethodHasNoAttributes() throws Exception {
Collection<ConfigAttribute> accessAttributes = this.mds
.findAttributes(this.a.getClass().getMethod("noRoleMethod"), null);
.findAttributes(this.a.getClass().getMethod("noRoleMethod"), null);
assertThat(accessAttributes).isNull();
}
@Test
public void classRoleIsAppliedToNoRoleMethod() throws Exception {
Collection<ConfigAttribute> accessAttributes = this.mds
.findAttributes(this.userAllowed.getClass().getMethod("noRoleMethod"), null);
.findAttributes(this.userAllowed.getClass().getMethod("noRoleMethod"), null);
assertThat(accessAttributes).isNull();
}
@Test
public void methodRoleOverridesClassRole() throws Exception {
Collection<ConfigAttribute> accessAttributes = this.mds
.findAttributes(this.userAllowed.getClass().getMethod("adminMethod"), null);
.findAttributes(this.userAllowed.getClass().getMethod("adminMethod"), null);
assertThat(accessAttributes).hasSize(1);
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_ADMIN");
}

View File

@@ -42,15 +42,16 @@ public class Jsr250VoterTests {
attrs.add(new Jsr250SecurityConfig("B"));
attrs.add(new Jsr250SecurityConfig("C"));
assertThat(voter.vote(new TestingAuthenticationToken("user", "pwd", "A"), new Object(), attrs))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
assertThat(voter.vote(new TestingAuthenticationToken("user", "pwd", "B"), new Object(), attrs))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
assertThat(voter.vote(new TestingAuthenticationToken("user", "pwd", "C"), new Object(), attrs))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
assertThat(voter.vote(new TestingAuthenticationToken("user", "pwd", "NONE"), new Object(), attrs))
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
assertThat(voter.vote(new TestingAuthenticationToken("user", "pwd", "A"), new Object(),
SecurityConfig.createList("A", "B", "C"))).isEqualTo(AccessDecisionVoter.ACCESS_ABSTAIN);
SecurityConfig.createList("A", "B", "C")))
.isEqualTo(AccessDecisionVoter.ACCESS_ABSTAIN);
}
}

View File

@@ -53,9 +53,9 @@ public class AbstractSecurityExpressionHandlerTests {
public void beanNamesAreCorrectlyResolved() {
this.handler.setApplicationContext(new AnnotationConfigApplicationContext(TestConfiguration.class));
Expression expression = this.handler.getExpressionParser()
.parseExpression("@number10.compareTo(@number20) < 0");
.parseExpression("@number10.compareTo(@number20) < 0");
assertThat(expression.getValue(this.handler.createEvaluationContext(mock(Authentication.class), new Object())))
.isEqualTo(true);
.isEqualTo(true);
}
@Test

View File

@@ -138,7 +138,7 @@ public class DefaultMethodSecurityExpressionHandlerTests {
map.put("key2", "value2");
map.put("key3", "value3");
Expression expression = this.handler.getExpressionParser()
.parseExpression("(filterObject.key eq 'key1') or (filterObject.value eq 'value2')");
.parseExpression("(filterObject.key eq 'key1') or (filterObject.value eq 'value2')");
EvaluationContext context = this.handler.createEvaluationContext(this.authentication, this.methodInvocation);
Object filtered = this.handler.filter(map, expression, context);
assertThat(filtered == map);
@@ -181,8 +181,9 @@ public class DefaultMethodSecurityExpressionHandlerTests {
this.methodInvocation);
verifyNoInteractions(mockAuthenticationSupplier);
assertThat(context.getRootObject()).extracting(TypedValue::getValue)
.asInstanceOf(InstanceOfAssertFactories.type(MethodSecurityExpressionRoot.class))
.extracting(SecurityExpressionRoot::getAuthentication).isEqualTo(this.authentication);
.asInstanceOf(InstanceOfAssertFactories.type(MethodSecurityExpressionRoot.class))
.extracting(SecurityExpressionRoot::getAuthentication)
.isEqualTo(this.authentication);
verify(mockAuthenticationSupplier).get();
}

View File

@@ -47,7 +47,7 @@ public class MethodExpressionVoterTests {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
assertThat(this.am.vote(this.joe, mi,
createAttributes(new PreInvocationExpressionAttribute(null, null, "hasRole('blah')"))))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
@Test
@@ -64,7 +64,7 @@ public class MethodExpressionVoterTests {
assertThat(this.am.vote(this.joe, mi,
createAttributes(new PreInvocationExpressionAttribute(null, null,
"(#argument == principal) and (principal == 'joe')"))))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
@Test
@@ -73,7 +73,7 @@ public class MethodExpressionVoterTests {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
assertThat(this.am.vote(this.joe, mi,
createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "collection", null))))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
// All objects should have been removed, because the expression is always false
assertThat(arg).isEmpty();
}
@@ -117,7 +117,7 @@ public class MethodExpressionVoterTests {
assertThat(this.am.vote(this.joe, mi,
createAttributes(new PreInvocationExpressionAttribute(null, null,
"T(org.springframework.security.access.expression.method.SecurityRules).isJoe(#argument)"))))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
private List<ConfigAttribute> createAttributes(ConfigAttribute... attributes) {

View File

@@ -164,7 +164,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
@Test
public void customAnnotationAtInterfaceLevelIsDetected() {
ConfigAttribute[] attrs = this.mds.getAttributes(this.annotatedAtInterfaceLevel)
.toArray(new ConfigAttribute[0]);
.toArray(new ConfigAttribute[0]);
assertThat(attrs).hasSize(1);
}

View File

@@ -36,7 +36,7 @@ public class RoleHierarchyAuthoritiesMapperTests {
rh.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C");
RoleHierarchyAuthoritiesMapper mapper = new RoleHierarchyAuthoritiesMapper(rh);
Collection<? extends GrantedAuthority> authorities = mapper
.mapAuthorities(AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_D"));
.mapAuthorities(AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_D"));
assertThat(authorities).hasSize(4);
mapper = new RoleHierarchyAuthoritiesMapper(new NullRoleHierarchy());
authorities = mapper.mapAuthorities(AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_D"));

View File

@@ -55,11 +55,14 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities0), authorities0)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities0), authorities0))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities2), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities2), authorities2))
.isTrue();
}
@Test
@@ -71,10 +74,12 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2))
.isTrue();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_D");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities3)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities3))
.isTrue();
}
@Test
@@ -91,35 +96,39 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_A > ROLE_C\nROLE_C > ROLE_D\nROLE_B > ROLE_D");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput1), authoritiesOutput1)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput1), authoritiesOutput1))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput2), authoritiesOutput2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput2), authoritiesOutput2))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput3), authoritiesOutput3)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput3), authoritiesOutput3))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput4), authoritiesOutput4)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authoritiesInput4), authoritiesOutput4))
.isTrue();
}
@Test
public void testCyclesInRoleHierarchy() {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
assertThatExceptionOfType(CycleInRoleHierarchyException.class)
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_A"));
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_A"));
assertThatExceptionOfType(CycleInRoleHierarchyException.class)
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_A"));
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_A"));
assertThatExceptionOfType(CycleInRoleHierarchyException.class)
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_A"));
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_A"));
assertThatExceptionOfType(CycleInRoleHierarchyException.class).isThrownBy(() -> roleHierarchyImpl
.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_E\nROLE_E > ROLE_D\nROLE_D > ROLE_B"));
.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_E\nROLE_E > ROLE_D\nROLE_D > ROLE_B"));
assertThatExceptionOfType(CycleInRoleHierarchyException.class)
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B"));
.isThrownBy(() -> roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B"));
}
@Test
public void testNoCyclesInRoleHierarchy() {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
assertThatNoException().isThrownBy(() -> roleHierarchyImpl
.setHierarchy("ROLE_A > ROLE_B\nROLE_A > ROLE_C\nROLE_C > ROLE_D\nROLE_B > ROLE_D"));
.setHierarchy("ROLE_A > ROLE_B\nROLE_A > ROLE_C\nROLE_C > ROLE_D\nROLE_B > ROLE_D"));
}
// SEC-863
@@ -131,11 +140,14 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthoritiesCompareByAuthorityString(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities0), authorities0)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities0), authorities0))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthoritiesCompareByAuthorityString(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2))
.isTrue();
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthoritiesCompareByAuthorityString(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities2), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities2), authorities2))
.isTrue();
}
@Test
@@ -147,10 +159,12 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE A > ROLE B\nROLE B > ROLE>C");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities2))
.isTrue();
roleHierarchyImpl.setHierarchy("ROLE A > ROLE B\nROLE B > ROLE>C\nROLE>C > ROLE D");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities3)).isTrue();
roleHierarchyImpl.getReachableGrantedAuthorities(authorities1), authorities3))
.isTrue();
}
// gh-6954
@@ -163,7 +177,7 @@ public class RoleHierarchyImplTests {
roleHierarchyImpl.setHierarchy(
"ROLE_A > ROLE_B\n" + "ROLE_B > ROLE_AUTHENTICATED\n" + "ROLE_AUTHENTICATED > ROLE_UNAUTHENTICATED");
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities))
.containsExactlyInAnyOrderElementsOf(allAuthorities);
.containsExactlyInAnyOrderElementsOf(allAuthorities);
}
// gh-6954
@@ -174,9 +188,9 @@ public class RoleHierarchyImplTests {
"ROLE_LOW", "ROLE_LOWER");
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl
.setHierarchy("ROLE_HIGHEST > ROLE_HIGHER\n" + "ROLE_HIGHER > ROLE_LOW\n" + "ROLE_LOW > ROLE_LOWER");
.setHierarchy("ROLE_HIGHEST > ROLE_HIGHER\n" + "ROLE_HIGHER > ROLE_LOW\n" + "ROLE_LOW > ROLE_LOWER");
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities))
.containsExactlyInAnyOrderElementsOf(allAuthorities);
.containsExactlyInAnyOrderElementsOf(allAuthorities);
}
// gh-6954
@@ -188,7 +202,7 @@ public class RoleHierarchyImplTests {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_HIGHEST > ROLE_HIGHER > ROLE_LOW > ROLE_LOWER");
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(flatAuthorities))
.containsExactlyInAnyOrderElementsOf(allAuthorities);
.containsExactlyInAnyOrderElementsOf(allAuthorities);
}
}

View File

@@ -60,8 +60,8 @@ public class RoleHierarchyUtilsTests {
@Test
public void roleHierarchyFromMapWhenMapEmptyThenThrowsIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(
() -> RoleHierarchyUtils.roleHierarchyFromMap(Collections.<String, List<String>>emptyMap()));
assertThatIllegalArgumentException()
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(Collections.<String, List<String>>emptyMap()));
}
@Test
@@ -69,7 +69,7 @@ public class RoleHierarchyUtilsTests {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put(null, Arrays.asList("ROLE_B", "ROLE_C"));
assertThatIllegalArgumentException()
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
}
@Test
@@ -77,7 +77,7 @@ public class RoleHierarchyUtilsTests {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("", Arrays.asList("ROLE_B", "ROLE_C"));
assertThatIllegalArgumentException()
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
}
@Test
@@ -85,7 +85,7 @@ public class RoleHierarchyUtilsTests {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("ROLE_A", null);
assertThatIllegalArgumentException()
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
}
@Test
@@ -93,7 +93,7 @@ public class RoleHierarchyUtilsTests {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("ROLE_A", Collections.<String>emptyList());
assertThatIllegalArgumentException()
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
.isThrownBy(() -> RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap));
}
}

View File

@@ -79,19 +79,19 @@ public class TestHelperTests {
authoritiesStrings5.add("ROLE_A");
assertThat(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities1), authoritiesStrings1))
.isTrue();
.isTrue();
assertThat(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities2), authoritiesStrings2))
.isTrue();
.isTrue();
assertThat(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities3), authoritiesStrings3))
.isTrue();
.isTrue();
assertThat(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities4), authoritiesStrings4))
.isTrue();
.isTrue();
assertThat(CollectionUtils.isEqualCollection(
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities5), authoritiesStrings5))
.isTrue();
.isTrue();
}
// SEC-863
@@ -121,7 +121,8 @@ public class TestHelperTests {
List<GrantedAuthority> authorities1 = HierarchicalRolesTestHelper.createAuthorityList("ROLE_A", "ROLE_B");
List<GrantedAuthority> authorities2 = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B");
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthoritiesCompareByAuthorityString(authorities1,
authorities2)).isTrue();
authorities2))
.isTrue();
}
// SEC-863

View File

@@ -57,15 +57,15 @@ public class AfterInvocationProviderManagerTests {
List<ConfigAttribute> attr2and3 = SecurityConfig.createList(new String[] { "GIVE_ME_SWAP2", "GIVE_ME_SWAP3" });
List<ConfigAttribute> attr4 = SecurityConfig.createList(new String[] { "NEVER_CAUSES_SWAP" });
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr1, "content-before-swapping"))
.isEqualTo("swap1");
.isEqualTo("swap1");
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr2, "content-before-swapping"))
.isEqualTo("swap2");
.isEqualTo("swap2");
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr3, "content-before-swapping"))
.isEqualTo("swap3");
.isEqualTo("swap3");
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr4, "content-before-swapping"))
.isEqualTo("content-before-swapping");
.isEqualTo("content-before-swapping");
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr2and3, "content-before-swapping"))
.isEqualTo("swap3");
.isEqualTo("swap3");
}
@Test

View File

@@ -53,7 +53,7 @@ public class RunAsUserTokenTests {
@Test
public void testNoArgConstructorDoesntExist() {
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> RunAsUserToken.class.getDeclaredConstructor((Class[]) null));
.isThrownBy(() -> RunAsUserToken.class.getDeclaredConstructor((Class[]) null));
}
@Test
@@ -61,8 +61,8 @@ public class RunAsUserTokenTests {
RunAsUserToken token = new RunAsUserToken("my_password", "Test", "Password",
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"), UsernamePasswordAuthenticationToken.class);
assertThat(token.toString()
.lastIndexOf("Original Class: " + UsernamePasswordAuthenticationToken.class.getName().toString()) != -1)
.isTrue();
.lastIndexOf("Original Class: " + UsernamePasswordAuthenticationToken.class.getName().toString()) != -1)
.isTrue();
}
// SEC-1792

View File

@@ -216,7 +216,7 @@ public class MethodSecurityInterceptorTests {
mdsReturnsNull();
SecurityContextHolder.getContext().setAuthentication(this.token);
assertThat(this.advisedTarget.publicMakeLowerCase("HELLO"))
.isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken false");
.isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken false");
assertThat(!this.token.isAuthenticated()).isTrue();
}
@@ -227,7 +227,7 @@ public class MethodSecurityInterceptorTests {
mdsReturnsUserRole();
given(this.authman.authenticate(token)).willThrow(new BadCredentialsException("rejected"));
assertThatExceptionOfType(AuthenticationException.class)
.isThrownBy(() -> this.advisedTarget.makeLowerCase("HELLO"));
.isThrownBy(() -> this.advisedTarget.makeLowerCase("HELLO"));
}
@Test
@@ -239,7 +239,7 @@ public class MethodSecurityInterceptorTests {
String result = this.advisedTarget.makeLowerCase("HELLO");
// Note we check the isAuthenticated remained true in following line
assertThat(result)
.isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken true");
.isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken true");
verify(this.eventPublisher).publishEvent(any(AuthorizedEvent.class));
}
@@ -251,10 +251,10 @@ public class MethodSecurityInterceptorTests {
createTarget(true);
mdsReturnsUserRole();
given(this.authman.authenticate(this.token)).willReturn(this.token);
willThrow(new AccessDeniedException("rejected")).given(this.adm).decide(any(Authentication.class),
any(MethodInvocation.class), any(List.class));
willThrow(new AccessDeniedException("rejected")).given(this.adm)
.decide(any(Authentication.class), any(MethodInvocation.class), any(List.class));
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.advisedTarget.makeUpperCase("HELLO"));
.isThrownBy(() -> this.advisedTarget.makeUpperCase("HELLO"));
verify(this.eventPublisher).publishEvent(any(AuthorizationFailureEvent.class));
}
@@ -305,7 +305,7 @@ public class MethodSecurityInterceptorTests {
public void emptySecurityContextIsRejected() {
mdsReturnsUserRole();
assertThatExceptionOfType(AuthenticationCredentialsNotFoundException.class)
.isThrownBy(() -> this.advisedTarget.makeUpperCase("hello"));
.isThrownBy(() -> this.advisedTarget.makeUpperCase("hello"));
}
@Test

View File

@@ -128,7 +128,7 @@ public class AspectJMethodSecurityInterceptorTests {
willThrow(new AccessDeniedException("denied")).given(this.adm).decide(any(), any(), any());
SecurityContextHolder.getContext().setAuthentication(this.token);
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
verify(this.aspectJCallback, never()).proceedWithObject();
}
@@ -153,7 +153,7 @@ public class AspectJMethodSecurityInterceptorTests {
this.interceptor.setAfterInvocationManager(aim);
given(this.aspectJCallback.proceedWithObject()).willThrow(new RuntimeException());
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
verifyNoMoreInteractions(aim);
}
@@ -171,7 +171,7 @@ public class AspectJMethodSecurityInterceptorTests {
given(runAs.buildRunAs(eq(this.token), any(MethodInvocation.class), any(List.class))).willReturn(runAsToken);
given(this.aspectJCallback.proceedWithObject()).willThrow(new RuntimeException());
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
.isThrownBy(() -> this.interceptor.invoke(this.joinPoint, this.aspectJCallback));
// Check we've changed back
assertThat(SecurityContextHolder.getContext()).isSameAs(ctx);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(this.token);

View File

@@ -46,7 +46,7 @@ public class DelegatingMethodSecurityMetadataSourceTests {
List sources = new ArrayList();
MethodSecurityMetadataSource delegate = mock(MethodSecurityMetadataSource.class);
given(delegate.getAttributes(ArgumentMatchers.<Method>any(), ArgumentMatchers.any(Class.class)))
.willReturn(null);
.willReturn(null);
sources.add(delegate);
this.mds = new DelegatingMethodSecurityMetadataSource(sources);
assertThat(this.mds.getMethodSecurityMetadataSources()).isSameAs(sources);
@@ -74,7 +74,7 @@ public class DelegatingMethodSecurityMetadataSourceTests {
// Exercise the cached case
assertThat(this.mds.getAttributes(mi)).isSameAs(attributes);
assertThat(this.mds.getAttributes(new SimpleMethodInvocation(null, String.class.getMethod("length"))))
.isEmpty();
.isEmpty();
}
}

View File

@@ -61,11 +61,11 @@ public class AffirmativeBasedTests {
this.abstain = mock(AccessDecisionVoter.class);
this.deny = mock(AccessDecisionVoter.class);
given(this.grant.vote(any(Authentication.class), any(Object.class), any(List.class)))
.willReturn(AccessDecisionVoter.ACCESS_GRANTED);
.willReturn(AccessDecisionVoter.ACCESS_GRANTED);
given(this.abstain.vote(any(Authentication.class), any(Object.class), any(List.class)))
.willReturn(AccessDecisionVoter.ACCESS_ABSTAIN);
.willReturn(AccessDecisionVoter.ACCESS_ABSTAIN);
given(this.deny.vote(any(Authentication.class), any(Object.class), any(List.class)))
.willReturn(AccessDecisionVoter.ACCESS_DENIED);
.willReturn(AccessDecisionVoter.ACCESS_DENIED);
}
@Test
@@ -95,7 +95,7 @@ public class AffirmativeBasedTests {
this.mgr = new AffirmativeBased(
Arrays.<AccessDecisionVoter<? extends Object>>asList(this.deny, this.abstain, this.abstain));
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.mgr.decide(this.user, new Object(), this.attrs));
.isThrownBy(() -> this.mgr.decide(this.user, new Object(), this.attrs));
}
@Test
@@ -104,7 +104,7 @@ public class AffirmativeBasedTests {
Arrays.<AccessDecisionVoter<? extends Object>>asList(this.abstain, this.abstain, this.abstain));
assertThat(!this.mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.mgr.decide(this.user, new Object(), this.attrs));
.isThrownBy(() -> this.mgr.decide(this.user, new Object(), this.attrs));
}
@Test

View File

@@ -68,7 +68,7 @@ public class ConsensusBasedTests {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_WE_DO_NOT_HAVE")));
.isThrownBy(() -> mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_WE_DO_NOT_HAVE")));
}
@Test
@@ -77,7 +77,7 @@ public class ConsensusBasedTests {
ConsensusBased mgr = makeDecisionManager();
assertThat(!mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL")));
.isThrownBy(() -> mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL")));
}
@Test

View File

@@ -35,7 +35,7 @@ public class RoleHierarchyVoterTests {
TestingAuthenticationToken auth = new TestingAuthenticationToken("user", "password", "ROLE_A");
RoleHierarchyVoter voter = new RoleHierarchyVoter(roleHierarchyImpl);
assertThat(voter.vote(auth, new Object(), SecurityConfig.createList("ROLE_B")))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
}

View File

@@ -37,7 +37,7 @@ public class RoleVoterTests {
Authentication userAB = new TestingAuthenticationToken("user", "pass", "A", "B");
// Vote on attribute list that has two attributes A and C (i.e. only one matching)
assertThat(voter.vote(userAB, this, SecurityConfig.createList("A", "C")))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
// SEC-3128
@@ -47,7 +47,7 @@ public class RoleVoterTests {
voter.setRolePrefix("");
Authentication notAuthenitcated = null;
assertThat(voter.vote(notAuthenitcated, this, SecurityConfig.createList("A")))
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
}

View File

@@ -53,7 +53,7 @@ public class AbstractAuthenticationTokenTests {
List<GrantedAuthority> gotAuthorities = (List<GrantedAuthority>) token.getAuthorities();
assertThat(gotAuthorities).isNotSameAs(this.authorities);
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> gotAuthorities.set(0, new SimpleGrantedAuthority("ROLE_SUPER_USER")));
.isThrownBy(() -> gotAuthorities.set(0, new SimpleGrantedAuthority("ROLE_SUPER_USER")));
}
@Test

View File

@@ -35,10 +35,10 @@ public class AuthenticationTrustResolverImplTests {
AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
assertThat(trustResolver.isAnonymous(
new AnonymousAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))))
.isTrue();
.isTrue();
assertThat(trustResolver.isAnonymous(
new TestingAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))))
.isFalse();
.isFalse();
}
@Test
@@ -46,10 +46,10 @@ public class AuthenticationTrustResolverImplTests {
AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
assertThat(trustResolver.isRememberMe(
new RememberMeAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))))
.isTrue();
.isTrue();
assertThat(trustResolver.isAnonymous(
new TestingAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))))
.isFalse();
.isFalse();
}
@Test

View File

@@ -118,7 +118,7 @@ public class DefaultAuthenticationEventPublisherTests {
Properties p = new Properties();
p.put(MockAuthenticationException.class.getName(), "NoSuchClass");
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> this.publisher.setAdditionalExceptionMappings(p));
.isThrownBy(() -> this.publisher.setAdditionalExceptionMappings(p));
}
@Test
@@ -174,7 +174,7 @@ public class DefaultAuthenticationEventPublisherTests {
public void defaultAuthenticationFailureEventClassSetNullThen() {
this.publisher = new DefaultAuthenticationEventPublisher();
assertThatIllegalArgumentException()
.isThrownBy(() -> this.publisher.setDefaultAuthenticationFailureEvent(null));
.isThrownBy(() -> this.publisher.setDefaultAuthenticationFailureEvent(null));
}
@Test
@@ -192,7 +192,7 @@ public class DefaultAuthenticationEventPublisherTests {
public void defaultAuthenticationFailureEventMissingAppropriateConstructorThen() {
this.publisher = new DefaultAuthenticationEventPublisher();
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> this.publisher
.setDefaultAuthenticationFailureEvent(AuthenticationFailureEventWithoutAppropriateConstructor.class));
.setDefaultAuthenticationFailureEvent(AuthenticationFailureEventWithoutAppropriateConstructor.class));
}
private static final class AuthenticationFailureEventWithoutAppropriateConstructor

View File

@@ -61,7 +61,7 @@ public class DelegatingReactiveAuthenticationManagerTests {
// delay to try and force delegate2 to finish (i.e. make sure we didn't use
// flatMap)
given(this.delegate1.authenticate(any()))
.willReturn(Mono.just(this.authentication).delayElement(Duration.ofMillis(100)));
.willReturn(Mono.just(this.authentication).delayElement(Duration.ofMillis(100)));
DelegatingReactiveAuthenticationManager manager = new DelegatingReactiveAuthenticationManager(this.delegate1,
this.delegate2);
StepVerifier.create(manager.authenticate(this.authentication)).expectNext(this.authentication).verifyComplete();
@@ -72,8 +72,9 @@ public class DelegatingReactiveAuthenticationManagerTests {
given(this.delegate1.authenticate(any())).willReturn(Mono.error(new BadCredentialsException("Test")));
DelegatingReactiveAuthenticationManager manager = new DelegatingReactiveAuthenticationManager(this.delegate1,
this.delegate2);
StepVerifier.create(manager.authenticate(this.authentication)).expectError(BadCredentialsException.class)
.verify();
StepVerifier.create(manager.authenticate(this.authentication))
.expectError(BadCredentialsException.class)
.verify();
}
}

View File

@@ -113,7 +113,7 @@ public class ProviderManagerTests {
@Test
public void testStartupFailsIfProvidersContainNullElement() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ProviderManager(Arrays.asList(mock(AuthenticationProvider.class), null)));
.isThrownBy(() -> new ProviderManager(Arrays.asList(mock(AuthenticationProvider.class), null)));
}
// gh-8689
@@ -173,9 +173,9 @@ public class ProviderManagerTests {
@Test
public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() {
ProviderManager mgr = new ProviderManager(Arrays
.asList(createProviderWhichThrows(new BadCredentialsException("")), createProviderWhichReturns(null)));
.asList(createProviderWhichThrows(new BadCredentialsException("")), createProviderWhichReturns(null)));
assertThatExceptionOfType(BadCredentialsException.class)
.isThrownBy(() -> mgr.authenticate(mock(Authentication.class)));
.isThrownBy(() -> mgr.authenticate(mock(Authentication.class)));
}
// SEC-546
@@ -186,7 +186,7 @@ public class ProviderManagerTests {
AuthenticationProvider otherProvider = mock(AuthenticationProvider.class);
ProviderManager authMgr = new ProviderManager(Arrays.asList(iThrowAccountStatusException, otherProvider));
assertThatExceptionOfType(AccountStatusException.class)
.isThrownBy(() -> authMgr.authenticate(mock(Authentication.class)));
.isThrownBy(() -> authMgr.authenticate(mock(Authentication.class)));
verifyNoInteractions(otherProvider);
}
@@ -208,7 +208,7 @@ public class ProviderManagerTests {
AuthenticationManager parent = mock(AuthenticationManager.class);
ProviderManager mgr = new ProviderManager(Collections.singletonList(iThrowAccountStatusException), parent);
assertThatExceptionOfType(AccountStatusException.class)
.isThrownBy(() -> mgr.authenticate(mock(Authentication.class)));
.isThrownBy(() -> mgr.authenticate(mock(Authentication.class)));
verifyNoInteractions(parent);
}
@@ -224,7 +224,7 @@ public class ProviderManagerTests {
Collections.singletonList(createProviderWhichThrows(new BadCredentialsException(""))), parent);
mgr.setAuthenticationEventPublisher(publisher);
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> mgr.authenticate(authReq))
.satisfies((ex) -> verify(publisher).publishAuthenticationFailure(ex, authReq));
.satisfies((ex) -> verify(publisher).publishAuthenticationFailure(ex, authReq));
}
@Test
@@ -240,7 +240,7 @@ public class ProviderManagerTests {
BadCredentialsException expected = new BadCredentialsException("I'm the one from the parent");
given(parent.authenticate(authReq)).willThrow(expected);
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> mgr.authenticate(authReq))
.isSameAs(expected);
.isSameAs(expected);
}
@Test
@@ -264,7 +264,7 @@ public class ProviderManagerTests {
createProviderWhichThrows(new BadCredentialsException("Oops"))), null);
Authentication authReq = mock(Authentication.class);
assertThatExceptionOfType(InternalAuthenticationServiceException.class)
.isThrownBy(() -> mgr.authenticate(authReq));
.isThrownBy(() -> mgr.authenticate(authReq));
}
// gh-6281
@@ -279,7 +279,7 @@ public class ProviderManagerTests {
childMgr.setAuthenticationEventPublisher(publisher);
final Authentication authReq = mock(Authentication.class);
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> childMgr.authenticate(authReq))
.isSameAs(badCredentialsExParent);
.isSameAs(badCredentialsExParent);
verify(publisher).publishAuthenticationFailure(badCredentialsExParent, authReq); // Parent
// publishes
verifyNoMoreInteractions(publisher); // Child should not publish (duplicate event)

View File

@@ -66,7 +66,7 @@ public class ReactiveUserDetailsServiceAuthenticationManagerTests {
@Test
public void constructorNullUserDetailsService() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new UserDetailsRepositoryReactiveAuthenticationManager(null));
.isThrownBy(() -> new UserDetailsRepositoryReactiveAuthenticationManager(null));
}
@Test

View File

@@ -127,7 +127,7 @@ public class UserDetailsRepositoryReactiveAuthenticationManagerTests {
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken.unauthenticated(this.user,
this.user.getPassword());
assertThatExceptionOfType(BadCredentialsException.class)
.isThrownBy(() -> this.manager.authenticate(token).block());
.isThrownBy(() -> this.manager.authenticate(token).block());
verifyNoMoreInteractions(this.userDetailsPasswordService);
}
@@ -151,9 +151,11 @@ public class UserDetailsRepositoryReactiveAuthenticationManagerTests {
given(this.encoder.matches(any(), any())).willReturn(true);
this.manager.setPasswordEncoder(this.encoder);
this.manager.setPostAuthenticationChecks(this.postAuthenticationChecks);
assertThatExceptionOfType(LockedException.class).isThrownBy(() -> this.manager
assertThatExceptionOfType(LockedException.class)
.isThrownBy(() -> this.manager
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated(this.user, this.user.getPassword()))
.block()).withMessage("account is locked");
.block())
.withMessage("account is locked");
verify(this.postAuthenticationChecks).check(eq(this.user));
}
@@ -182,7 +184,7 @@ public class UserDetailsRepositoryReactiveAuthenticationManagerTests {
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken.unauthenticated(expiredUser,
expiredUser.getPassword());
assertThatExceptionOfType(AccountExpiredException.class)
.isThrownBy(() -> this.manager.authenticate(token).block());
.isThrownBy(() -> this.manager.authenticate(token).block());
}
@Test

View File

@@ -45,7 +45,7 @@ public class UsernamePasswordAuthenticationTokenTests {
// Now let's create a UsernamePasswordAuthenticationToken without any
// GrantedAuthorty[]s (different constructor)
UsernamePasswordAuthenticationToken noneGrantedToken = UsernamePasswordAuthenticationToken
.unauthenticated("Test", "Password");
.unauthenticated("Test", "Password");
assertThat(!noneGrantedToken.isAuthenticated()).isTrue();
// check we're allowed to still set it to untrusted
noneGrantedToken.setAuthenticated(false);
@@ -68,7 +68,7 @@ public class UsernamePasswordAuthenticationTokenTests {
public void testNoArgConstructorDoesntExist() throws Exception {
Class<?> clazz = UsernamePasswordAuthenticationToken.class;
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> clazz.getDeclaredConstructor((Class[]) null));
.isThrownBy(() -> clazz.getDeclaredConstructor((Class[]) null));
}
@Test

View File

@@ -45,7 +45,7 @@ public class AnonymousAuthenticationTokenTests {
assertThatIllegalArgumentException().isThrownBy(() -> new AnonymousAuthenticationToken("key", null, ROLES_12));
assertThatIllegalArgumentException().isThrownBy(() -> new AnonymousAuthenticationToken("key", "Test", null));
assertThatIllegalArgumentException()
.isThrownBy(() -> new AnonymousAuthenticationToken("key", "Test", AuthorityUtils.NO_AUTHORITIES));
.isThrownBy(() -> new AnonymousAuthenticationToken("key", "Test", AuthorityUtils.NO_AUTHORITIES));
}
@Test
@@ -68,7 +68,7 @@ public class AnonymousAuthenticationTokenTests {
@Test
public void testNoArgConstructorDoesntExist() {
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> AnonymousAuthenticationToken.class.getDeclaredConstructor((Class[]) null));
.isThrownBy(() -> AnonymousAuthenticationToken.class.getDeclaredConstructor((Class[]) null));
}
@Test
@@ -104,7 +104,7 @@ public class AnonymousAuthenticationTokenTests {
@Test
public void constructorWhenNullAuthoritiesThenThrowIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AnonymousAuthenticationToken("key", "principal", null));
.isThrownBy(() -> new AnonymousAuthenticationToken("key", "principal", null));
}
@Test

View File

@@ -88,9 +88,9 @@ public class DaoAuthenticationProviderTests {
provider.setUserDetailsService(new MockUserDetailsServiceUserRod());
provider.setUserCache(new MockUserCache());
UsernamePasswordAuthenticationToken authenticationToken = UsernamePasswordAuthenticationToken
.unauthenticated("rod", null);
.unauthenticated("rod", null);
assertThatExceptionOfType(BadCredentialsException.class)
.isThrownBy(() -> provider.authenticate(authenticationToken));
.isThrownBy(() -> provider.authenticate(authenticationToken));
}
@Test
@@ -123,7 +123,7 @@ public class DaoAuthenticationProviderTests {
// Check that wrong password causes BadCredentialsException, rather than
// CredentialsExpiredException
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> provider
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("peter", "wrong_password")));
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("peter", "wrong_password")));
}
@Test
@@ -143,7 +143,7 @@ public class DaoAuthenticationProviderTests {
provider.setUserDetailsService(new MockUserDetailsServiceSimulateBackendError());
provider.setUserCache(new MockUserCache());
assertThatExceptionOfType(InternalAuthenticationServiceException.class)
.isThrownBy(() -> provider.authenticate(token));
.isThrownBy(() -> provider.authenticate(token));
}
@Test
@@ -329,7 +329,7 @@ public class DaoAuthenticationProviderTests {
DaoAuthenticationProvider provider = createProvider();
provider.setUserDetailsService(new MockUserDetailsServiceReturnsNull());
assertThatExceptionOfType(AuthenticationServiceException.class).isThrownBy(() -> provider.authenticate(token))
.withMessage("UserDetailsService returned null, which is an interface contract violation");
.withMessage("UserDetailsService returned null, which is an interface contract violation");
}
@Test
@@ -449,7 +449,7 @@ public class DaoAuthenticationProviderTests {
UsernamePasswordAuthenticationToken foundUser = UsernamePasswordAuthenticationToken.unauthenticated("rod",
"koala");
UsernamePasswordAuthenticationToken notFoundUser = UsernamePasswordAuthenticationToken
.unauthenticated("notFound", "koala");
.unauthenticated("notFound", "koala");
PasswordEncoder encoder = new BCryptPasswordEncoder(10, new SecureRandom());
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setHideUserNotFoundExceptions(false);
@@ -468,13 +468,15 @@ public class DaoAuthenticationProviderTests {
for (int i = 0; i < sampleSize; i++) {
long start = System.currentTimeMillis();
assertThatExceptionOfType(UsernameNotFoundException.class)
.isThrownBy(() -> provider.authenticate(notFoundUser));
.isThrownBy(() -> provider.authenticate(notFoundUser));
userNotFoundTimes.add(System.currentTimeMillis() - start);
}
double userFoundAvg = avg(userFoundTimes);
double userNotFoundAvg = avg(userNotFoundTimes);
assertThat(Math.abs(userNotFoundAvg - userFoundAvg) <= 3).withFailMessage("User not found average "
+ userNotFoundAvg + " should be within 3ms of user found average " + userFoundAvg).isTrue();
assertThat(Math.abs(userNotFoundAvg - userFoundAvg) <= 3)
.withFailMessage("User not found average " + userNotFoundAvg
+ " should be within 3ms of user found average " + userFoundAvg)
.isTrue();
}
private double avg(List<Long> counts) {

View File

@@ -35,7 +35,7 @@ public class AuthenticationEventTests {
private Authentication getAuthentication() {
UsernamePasswordAuthenticationToken authentication = UsernamePasswordAuthenticationToken
.unauthenticated("Principal", "Credentials");
.unauthenticated("Principal", "Credentials");
authentication.setDetails("127.0.0.1");
return authentication;
}
@@ -65,7 +65,7 @@ public class AuthenticationEventTests {
@Test
public void testRejectsNullAuthenticationException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthenticationFailureDisabledEvent(getAuthentication(), null));
.isThrownBy(() -> new AuthenticationFailureDisabledEvent(getAuthentication(), null));
}
}

View File

@@ -31,7 +31,7 @@ public class LoggerListenerTests {
private Authentication getAuthentication() {
UsernamePasswordAuthenticationToken authentication = UsernamePasswordAuthenticationToken
.unauthenticated("Principal", "Credentials");
.unauthenticated("Principal", "Credentials");
authentication.setDetails("127.0.0.1");
return authentication;
}

View File

@@ -121,7 +121,7 @@ public class DefaultJaasAuthenticationProviderTests {
@Test
public void authenticateBadUser() {
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.provider
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("asdf", "password")));
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("asdf", "password")));
verifyFailedLogin();
}
@@ -236,7 +236,7 @@ public class DefaultJaasAuthenticationProviderTests {
private void verifyFailedLogin() {
ArgumentCaptor<JaasAuthenticationFailedEvent> event = ArgumentCaptor
.forClass(JaasAuthenticationFailedEvent.class);
.forClass(JaasAuthenticationFailedEvent.class);
verify(this.publisher).publishEvent(event.capture());
assertThat(event.getValue()).isInstanceOf(JaasAuthenticationFailedEvent.class);
assertThat(event.getValue().getException()).isNotNull();

View File

@@ -76,20 +76,20 @@ public class JaasAuthenticationProviderTests {
@Test
public void testBadPassword() {
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.jaasProvider
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "asdf")));
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("user", "asdf")));
assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
assertThat(this.eventCheck.failedEvent.getException()).withFailMessage("Failure event exception was null")
.isNotNull();
.isNotNull();
assertThat(this.eventCheck.successEvent).as("Success event was fired").isNull();
}
@Test
public void testBadUser() {
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.jaasProvider
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("asdf", "password")));
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("asdf", "password")));
assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
assertThat(this.eventCheck.failedEvent.getException()).withFailMessage("Failure event exception was null")
.isNotNull();
.isNotNull();
assertThat(this.eventCheck.successEvent).as("Success event was fired").isNull();
}
@@ -110,7 +110,7 @@ public class JaasAuthenticationProviderTests {
myJaasProvider.setCallbackHandlers(this.jaasProvider.getCallbackHandlers());
myJaasProvider.setLoginContextName(this.jaasProvider.getLoginContextName());
assertThatIllegalArgumentException().isThrownBy(() -> myJaasProvider.afterPropertiesSet())
.withMessageStartingWith("loginConfig must be set on");
.withMessageStartingWith("loginConfig must be set on");
}
// SEC-1239
@@ -150,10 +150,10 @@ public class JaasAuthenticationProviderTests {
myJaasProvider.setLoginConfig(this.jaasProvider.getLoginConfig());
myJaasProvider.setLoginContextName(null);
assertThatIllegalArgumentException().isThrownBy(myJaasProvider::afterPropertiesSet)
.withMessageStartingWith("loginContextName must be set on");
.withMessageStartingWith("loginContextName must be set on");
myJaasProvider.setLoginContextName("");
assertThatIllegalArgumentException().isThrownBy(myJaasProvider::afterPropertiesSet)
.withMessageStartingWith("loginContextName must be set on");
.withMessageStartingWith("loginContextName must be set on");
}
@Test
@@ -169,7 +169,7 @@ public class JaasAuthenticationProviderTests {
Collection<? extends GrantedAuthority> list = auth.getAuthorities();
Set<String> set = AuthorityUtils.authorityListToSet(list);
assertThat(set.contains("ROLE_ONE")).withFailMessage("GrantedAuthorities should not contain ROLE_ONE")
.isFalse();
.isFalse();
assertThat(set.contains("ROLE_TEST1")).withFailMessage("GrantedAuthorities should contain ROLE_TEST1").isTrue();
assertThat(set.contains("ROLE_TEST2")).withFailMessage("GrantedAuthorities should contain ROLE_TEST2").isTrue();
boolean foundit = false;
@@ -177,14 +177,14 @@ public class JaasAuthenticationProviderTests {
if (a instanceof JaasGrantedAuthority) {
JaasGrantedAuthority grant = (JaasGrantedAuthority) a;
assertThat(grant.getPrincipal()).withFailMessage("Principal was null on JaasGrantedAuthority")
.isNotNull();
.isNotNull();
foundit = true;
}
}
assertThat(foundit).as("Could not find a JaasGrantedAuthority").isTrue();
assertThat(this.eventCheck.successEvent).as("Success event should be fired").isNotNull();
assertThat(this.eventCheck.successEvent.getAuthentication()).withFailMessage("Auth objects should be equal")
.isEqualTo(auth);
.isEqualTo(auth);
assertThat(this.eventCheck.failedEvent).as("Failure event should not be fired").isNull();
}
@@ -226,13 +226,13 @@ public class JaasAuthenticationProviderTests {
assertThat(this.jaasProvider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
Authentication auth = this.jaasProvider.authenticate(token);
assertThat(auth.getAuthorities()).withFailMessage("Only ROLE_TEST1 and ROLE_TEST2 should have been returned")
.hasSize(2);
.hasSize(2);
}
@Test
public void testUnsupportedAuthenticationObjectReturnsNull() {
assertThat(this.jaasProvider
.authenticate(new TestingAuthenticationToken("foo", "bar", AuthorityUtils.NO_AUTHORITIES))).isNull();
.authenticate(new TestingAuthenticationToken("foo", "bar", AuthorityUtils.NO_AUTHORITIES))).isNull();
}
private static class MockLoginContext extends LoginContext {

View File

@@ -29,13 +29,13 @@ public class JaasGrantedAuthorityTests {
@Test
public void authorityWithNullRoleFailsAssertion() {
assertThatIllegalArgumentException().isThrownBy(() -> new JaasGrantedAuthority(null, null))
.withMessageContaining("role cannot be null");
.withMessageContaining("role cannot be null");
}
@Test
public void authorityWithNullPrincipleFailsAssertion() {
assertThatIllegalArgumentException().isThrownBy(() -> new JaasGrantedAuthority("role", null))
.withMessageContaining("principal cannot be null");
.withMessageContaining("principal cannot be null");
}
}

View File

@@ -83,9 +83,10 @@ public class SecurityContextLoginModuleTests {
SecurityContextHolder.getContext().setAuthentication(this.auth);
assertThat(this.module.login()).as("Login should succeed, there is an authentication set").isTrue();
assertThat(this.module.commit()).withFailMessage("The authentication is not null, this should return true")
.isTrue();
.isTrue();
assertThat(this.subject.getPrincipals().contains(this.auth))
.withFailMessage("Principals should contain the authentication").isTrue();
.withFailMessage("Principals should contain the authentication")
.isTrue();
}
@Test
@@ -95,9 +96,10 @@ public class SecurityContextLoginModuleTests {
this.module.setSecurityContextHolderStrategy(securityContextHolderStrategy);
assertThat(this.module.login()).as("Login should succeed, there is an authentication set").isTrue();
assertThat(this.module.commit()).withFailMessage("The authentication is not null, this should return true")
.isTrue();
.isTrue();
assertThat(this.subject.getPrincipals().contains(this.auth))
.withFailMessage("Principals should contain the authentication").isTrue();
.withFailMessage("Principals should contain the authentication")
.isTrue();
}
@Test
@@ -107,7 +109,8 @@ public class SecurityContextLoginModuleTests {
assertThat(this.module.logout()).as("Should return true as it succeeds").isTrue();
assertThat(this.module.getAuthentication()).as("Authentication should be null").isNull();
assertThat(this.subject.getPrincipals().contains(this.auth))
.withFailMessage("Principals should not contain the authentication after logout").isFalse();
.withFailMessage("Principals should not contain the authentication after logout")
.isFalse();
}
@Test

View File

@@ -59,19 +59,19 @@ public class InMemoryConfigurationTests {
@Test
public void constructorNullMapped() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new InMemoryConfiguration((Map<String, AppConfigurationEntry[]>) null));
.isThrownBy(() -> new InMemoryConfiguration((Map<String, AppConfigurationEntry[]>) null));
}
@Test
public void constructorEmptyMap() {
assertThat(new InMemoryConfiguration(Collections.<String, AppConfigurationEntry[]>emptyMap())
.getAppConfigurationEntry("name")).isNull();
.getAppConfigurationEntry("name")).isNull();
}
@Test
public void constructorEmptyMapNullDefault() {
assertThat(new InMemoryConfiguration(Collections.<String, AppConfigurationEntry[]>emptyMap(), null)
.getAppConfigurationEntry("name")).isNull();
.getAppConfigurationEntry("name")).isNull();
}
@Test

View File

@@ -43,7 +43,7 @@ public class RemoteAuthenticationManagerImplTests {
given(am.authenticate(any(Authentication.class))).willThrow(new BadCredentialsException(""));
manager.setAuthenticationManager(am);
assertThatExceptionOfType(RemoteAuthenticationException.class)
.isThrownBy(() -> manager.attemptAuthentication("rod", "password"));
.isThrownBy(() -> manager.attemptAuthentication("rod", "password"));
}
@Test

View File

@@ -64,7 +64,7 @@ public class RemoteAuthenticationProviderTests {
RemoteAuthenticationProvider provider = new RemoteAuthenticationProvider();
provider.setRemoteAuthenticationManager(new MockRemoteAuthenticationManager(true));
Authentication result = provider
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("rod", "password"));
.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("rod", "password"));
assertThat(result.getPrincipal()).isEqualTo("rod");
assertThat(result.getCredentials()).isEqualTo("password");
assertThat(AuthorityUtils.authorityListToSet(result.getAuthorities())).contains("foo");
@@ -74,8 +74,8 @@ public class RemoteAuthenticationProviderTests {
public void testNullCredentialsDoesNotCauseNullPointerException() {
RemoteAuthenticationProvider provider = new RemoteAuthenticationProvider();
provider.setRemoteAuthenticationManager(new MockRemoteAuthenticationManager(false));
assertThatExceptionOfType(RemoteAuthenticationException.class).isThrownBy(
() -> provider.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("rod", null)));
assertThatExceptionOfType(RemoteAuthenticationException.class)
.isThrownBy(() -> provider.authenticate(UsernamePasswordAuthenticationToken.unauthenticated("rod", null)));
}
@Test

View File

@@ -41,10 +41,10 @@ public class RememberMeAuthenticationTokenTests {
@Test
public void testConstructorRejectsNulls() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new RememberMeAuthenticationToken(null, "Test", ROLES_12));
.isThrownBy(() -> new RememberMeAuthenticationToken(null, "Test", ROLES_12));
assertThatIllegalArgumentException().isThrownBy(() -> new RememberMeAuthenticationToken("key", null, ROLES_12));
assertThatIllegalArgumentException().isThrownBy(
() -> new RememberMeAuthenticationToken("key", "Test", Arrays.asList((GrantedAuthority) null)));
assertThatIllegalArgumentException()
.isThrownBy(() -> new RememberMeAuthenticationToken("key", "Test", Arrays.asList((GrantedAuthority) null)));
}
@Test

View File

@@ -41,7 +41,7 @@ public class AuthenticatedReactiveAuthorizationManagerTests {
Authentication authentication;
AuthenticatedReactiveAuthorizationManager<Object> manager = AuthenticatedReactiveAuthorizationManager
.authenticated();
.authenticated();
@Test
public void checkWhenAuthenticatedThenReturnTrue() {

View File

@@ -41,7 +41,7 @@ public class AuthorityAuthorizationManagerTests {
@Test
public void hasRoleWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasRole(null))
.withMessage("role cannot be null");
.withMessage("role cannot be null");
}
@Test
@@ -49,40 +49,40 @@ public class AuthorityAuthorizationManagerTests {
String ROLE_PREFIX = "ROLE_";
String ROLE_USER = ROLE_PREFIX + "USER";
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasRole(ROLE_USER))
.withMessage(ROLE_USER + " should not start with " + ROLE_PREFIX + " since " + ROLE_PREFIX
+ " is automatically prepended when using hasRole. Consider using hasAuthority instead.");
.withMessage(ROLE_USER + " should not start with " + ROLE_PREFIX + " since " + ROLE_PREFIX
+ " is automatically prepended when using hasRole. Consider using hasAuthority instead.");
}
@Test
public void hasAuthorityWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAuthority(null))
.withMessage("authority cannot be null");
.withMessage("authority cannot be null");
}
@Test
public void hasAnyRoleWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null))
.withMessage("roles cannot be empty");
.withMessage("roles cannot be empty");
}
@Test
public void hasAnyRoleWhenEmptyThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(new String[] {}))
.withMessage("roles cannot be empty");
.withMessage("roles cannot be empty");
}
@Test
public void hasAnyRoleWhenContainNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole("ADMIN", null, "USER"))
.withMessage("roles cannot contain null values");
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole("ADMIN", null, "USER"))
.withMessage("roles cannot contain null values");
}
@Test
public void hasAnyRoleWhenCustomRolePrefixNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null, new String[] { "ADMIN", "USER" }))
.withMessage("rolePrefix cannot be null");
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null, new String[] { "ADMIN", "USER" }))
.withMessage("rolePrefix cannot be null");
}
@Test
@@ -90,29 +90,29 @@ public class AuthorityAuthorizationManagerTests {
String ROLE_PREFIX = "ROLE_";
String ROLE_USER = ROLE_PREFIX + "USER";
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(new String[] { ROLE_USER }))
.withMessage(ROLE_USER + " should not start with " + ROLE_PREFIX + " since " + ROLE_PREFIX
+ " is automatically prepended when using hasAnyRole. Consider using hasAnyAuthority instead.");
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(new String[] { ROLE_USER }))
.withMessage(ROLE_USER + " should not start with " + ROLE_PREFIX + " since " + ROLE_PREFIX
+ " is automatically prepended when using hasAnyRole. Consider using hasAnyAuthority instead.");
}
@Test
public void hasAnyAuthorityWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(null))
.withMessage("authorities cannot be empty");
.withMessage("authorities cannot be empty");
}
@Test
public void hasAnyAuthorityWhenEmptyThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(new String[] {}))
.withMessage("authorities cannot be empty");
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(new String[] {}))
.withMessage("authorities cannot be empty");
}
@Test
public void hasAnyAuthorityWhenContainNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority("ADMIN", null, "USER"))
.withMessage("authorities cannot contain null values");
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority("ADMIN", null, "USER"))
.withMessage("authorities cannot contain null values");
}
@Test
@@ -237,7 +237,7 @@ public class AuthorityAuthorizationManagerTests {
public void setRoleHierarchyWhenNullThenIllegalArgumentException() {
AuthorityAuthorizationManager<Object> manager = AuthorityAuthorizationManager.hasRole("USER");
assertThatIllegalArgumentException().isThrownBy(() -> manager.setRoleHierarchy(null))
.withMessage("roleHierarchy cannot be null");
.withMessage("roleHierarchy cannot be null");
}
@Test

View File

@@ -143,37 +143,37 @@ public class AuthorityReactiveAuthorizationManagerTests {
@Test
public void hasRoleWhenNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasRole((String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasRole((String) null));
}
@Test
public void hasAuthorityWhenNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAuthority((String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAuthority((String) null));
}
@Test
public void hasAnyRoleWhenNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyRole((String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyRole((String) null));
}
@Test
public void hasAnyAuthorityWhenNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyAuthority((String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyAuthority((String) null));
}
@Test
public void hasAnyRoleWhenOneIsNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyRole("ROLE_ADMIN", (String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyRole("ROLE_ADMIN", (String) null));
}
@Test
public void hasAnyAuthorityWhenOneIsNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyAuthority("ADMIN", (String) null));
.isThrownBy(() -> AuthorityReactiveAuthorizationManager.hasAnyAuthority("ADMIN", (String) null));
}
}

View File

@@ -59,7 +59,8 @@ public class AuthorizationManagerTests {
Object object = new Object();
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> manager.verify(() -> authentication, object)).withMessage("Access Denied");
.isThrownBy(() -> manager.verify(() -> authentication, object))
.withMessage("Access Denied");
}
}

View File

@@ -38,7 +38,7 @@ class AuthorizationAnnotationUtilsTests {
(p, m, args) -> null);
Method method = proxy.getClass().getDeclaredMethod("findAll");
assertThatNoException()
.isThrownBy(() -> AuthorizationAnnotationUtils.findUniqueAnnotation(method, PreAuthorize.class));
.isThrownBy(() -> AuthorizationAnnotationUtils.findUniqueAnnotation(method, PreAuthorize.class));
}
private interface BaseRepository<T> {

View File

@@ -52,15 +52,15 @@ public class AuthorizationManagerAfterMethodInterceptorTests {
public void instantiateWhenMethodMatcherNullThenException() {
AuthorizationManager<MethodInvocationResult> mockAuthorizationManager = mock(AuthorizationManager.class);
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerAfterMethodInterceptor(null, mockAuthorizationManager))
.withMessage("pointcut cannot be null");
.isThrownBy(() -> new AuthorizationManagerAfterMethodInterceptor(null, mockAuthorizationManager))
.withMessage("pointcut cannot be null");
}
@Test
public void instantiateWhenAuthorizationManagerNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerAfterMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
.isThrownBy(() -> new AuthorizationManagerAfterMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
}
@Test
@@ -83,7 +83,7 @@ public class AuthorizationManagerAfterMethodInterceptorTests {
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
MethodInvocation invocation = mock(MethodInvocation.class);
AuthorizationManager<MethodInvocationResult> authorizationManager = AuthenticatedAuthorizationManager
.authenticated();
.authenticated();
AuthorizationManagerAfterMethodInterceptor advice = new AuthorizationManagerAfterMethodInterceptor(
Pointcut.TRUE, authorizationManager);
advice.setSecurityContextHolderStrategy(strategy);
@@ -96,7 +96,7 @@ public class AuthorizationManagerAfterMethodInterceptorTests {
AuthorizationManagerAfterMethodInterceptor advice = new AuthorizationManagerAfterMethodInterceptor(
Pointcut.TRUE, AuthenticatedAuthorizationManager.authenticated());
assertThatIllegalArgumentException().isThrownBy(() -> advice.setAuthorizationEventPublisher(null))
.withMessage("eventPublisher cannot be null");
.withMessage("eventPublisher cannot be null");
}
@Test

View File

@@ -47,16 +47,16 @@ public class AuthorizationManagerAfterReactiveMethodInterceptorTests {
@Test
public void instantiateWhenPointcutNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerAfterReactiveMethodInterceptor(null,
mock(ReactiveAuthorizationManager.class)))
.withMessage("pointcut cannot be null");
.isThrownBy(() -> new AuthorizationManagerAfterReactiveMethodInterceptor(null,
mock(ReactiveAuthorizationManager.class)))
.withMessage("pointcut cannot be null");
}
@Test
public void instantiateWhenAuthorizationManagerNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerAfterReactiveMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
.isThrownBy(() -> new AuthorizationManagerAfterReactiveMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
}
@Test
@@ -70,8 +70,9 @@ public class AuthorizationManagerAfterReactiveMethodInterceptorTests {
AuthorizationManagerAfterReactiveMethodInterceptor interceptor = new AuthorizationManagerAfterReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class)).extracting(Mono::block)
.isEqualTo("john");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class))
.extracting(Mono::block)
.isEqualTo("john");
verify(mockReactiveAuthorizationManager).verify(any(), any());
}
@@ -86,8 +87,10 @@ public class AuthorizationManagerAfterReactiveMethodInterceptorTests {
AuthorizationManagerAfterReactiveMethodInterceptor interceptor = new AuthorizationManagerAfterReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class)).extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class)).containsExactly("john", "bob");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class))
.extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class))
.containsExactly("john", "bob");
verify(mockReactiveAuthorizationManager, times(2)).verify(any(), any());
}
@@ -99,13 +102,14 @@ public class AuthorizationManagerAfterReactiveMethodInterceptorTests {
ReactiveAuthorizationManager<MethodInvocationResult> mockReactiveAuthorizationManager = mock(
ReactiveAuthorizationManager.class);
given(mockReactiveAuthorizationManager.verify(any(), any()))
.willReturn(Mono.error(new AccessDeniedException("Access Denied")));
.willReturn(Mono.error(new AccessDeniedException("Access Denied")));
AuthorizationManagerAfterReactiveMethodInterceptor interceptor = new AuthorizationManagerAfterReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> assertThat(result)
.asInstanceOf(InstanceOfAssertFactories.type(Mono.class)).extracting(Mono::block))
.withMessage("Access Denied");
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class))
.extracting(Mono::block))
.withMessage("Access Denied");
verify(mockReactiveAuthorizationManager).verify(any(), any());
}

View File

@@ -51,16 +51,15 @@ public class AuthorizationManagerBeforeMethodInterceptorTests {
@Test
public void instantiateWhenMethodMatcherNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(
() -> new AuthorizationManagerBeforeMethodInterceptor(null, mock(AuthorizationManager.class)))
.withMessage("pointcut cannot be null");
.isThrownBy(() -> new AuthorizationManagerBeforeMethodInterceptor(null, mock(AuthorizationManager.class)))
.withMessage("pointcut cannot be null");
}
@Test
public void instantiateWhenAuthorizationManagerNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerBeforeMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
.isThrownBy(() -> new AuthorizationManagerBeforeMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
}
@Test
@@ -93,7 +92,7 @@ public class AuthorizationManagerBeforeMethodInterceptorTests {
AuthorizationManagerBeforeMethodInterceptor advice = new AuthorizationManagerBeforeMethodInterceptor(
Pointcut.TRUE, AuthenticatedAuthorizationManager.authenticated());
assertThatIllegalArgumentException().isThrownBy(() -> advice.setAuthorizationEventPublisher(null))
.withMessage("eventPublisher cannot be null");
.withMessage("eventPublisher cannot be null");
}
@Test

View File

@@ -47,17 +47,17 @@ public class AuthorizationManagerBeforeReactiveMethodInterceptorTests {
@Test
public void instantiateWhenPointcutNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerBeforeReactiveMethodInterceptor(null,
mock(ReactiveAuthorizationManager.class)))
.withMessage("pointcut cannot be null");
.isThrownBy(() -> new AuthorizationManagerBeforeReactiveMethodInterceptor(null,
mock(ReactiveAuthorizationManager.class)))
.withMessage("pointcut cannot be null");
}
@Test
public void instantiateWhenAuthorizationManagerNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AuthorizationManagerBeforeReactiveMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
.isThrownBy(() -> new AuthorizationManagerBeforeReactiveMethodInterceptor(mock(Pointcut.class), null))
.withMessage("authorizationManager cannot be null");
}
@Test
@@ -71,8 +71,9 @@ public class AuthorizationManagerBeforeReactiveMethodInterceptorTests {
AuthorizationManagerBeforeReactiveMethodInterceptor interceptor = new AuthorizationManagerBeforeReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class)).extracting(Mono::block)
.isEqualTo("john");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class))
.extracting(Mono::block)
.isEqualTo("john");
verify(mockReactiveAuthorizationManager).verify(any(), eq(mockMethodInvocation));
}
@@ -87,8 +88,10 @@ public class AuthorizationManagerBeforeReactiveMethodInterceptorTests {
AuthorizationManagerBeforeReactiveMethodInterceptor interceptor = new AuthorizationManagerBeforeReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class)).extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class)).containsExactly("john", "bob");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class))
.extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class))
.containsExactly("john", "bob");
verify(mockReactiveAuthorizationManager).verify(any(), eq(mockMethodInvocation));
}
@@ -100,13 +103,14 @@ public class AuthorizationManagerBeforeReactiveMethodInterceptorTests {
ReactiveAuthorizationManager<MethodInvocation> mockReactiveAuthorizationManager = mock(
ReactiveAuthorizationManager.class);
given(mockReactiveAuthorizationManager.verify(any(), eq(mockMethodInvocation)))
.willReturn(Mono.error(new AccessDeniedException("Access Denied")));
.willReturn(Mono.error(new AccessDeniedException("Access Denied")));
AuthorizationManagerBeforeReactiveMethodInterceptor interceptor = new AuthorizationManagerBeforeReactiveMethodInterceptor(
Pointcut.TRUE, mockReactiveAuthorizationManager);
Object result = interceptor.invoke(mockMethodInvocation);
assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> assertThat(result)
.asInstanceOf(InstanceOfAssertFactories.type(Mono.class)).extracting(Mono::block))
.withMessage("Access Denied");
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Mono.class))
.extracting(Mono::block))
.withMessage("Access Denied");
verify(mockReactiveAuthorizationManager).verify(any(), eq(mockMethodInvocation));
}

View File

@@ -54,7 +54,7 @@ public class Jsr250AuthorizationManagerTests {
public void setRolePrefixWhenNullThenException() {
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatIllegalArgumentException().isThrownBy(() -> manager.setRolePrefix(null))
.withMessage("rolePrefix cannot be null");
.withMessage("rolePrefix cannot be null");
}
@Test
@@ -131,7 +131,7 @@ public class Jsr250AuthorizationManagerTests {
"multipleAnnotations");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test
@@ -177,7 +177,7 @@ public class Jsr250AuthorizationManagerTests {
"inheritedAnnotations");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test
@@ -187,7 +187,7 @@ public class Jsr250AuthorizationManagerTests {
ClassLevelAnnotations.class, "inheritedAnnotations");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
public static class TestClass implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {

View File

@@ -38,19 +38,19 @@ class MethodExpressionAuthorizationManagerTests {
@Test
void instantiateWhenExpressionStringNullThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new MethodExpressionAuthorizationManager(null))
.withMessage("expressionString cannot be empty");
.withMessage("expressionString cannot be empty");
}
@Test
void instantiateWhenExpressionStringEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new MethodExpressionAuthorizationManager(""))
.withMessage("expressionString cannot be empty");
.withMessage("expressionString cannot be empty");
}
@Test
void instantiateWhenExpressionStringBlankThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new MethodExpressionAuthorizationManager(" "))
.withMessage("expressionString cannot be empty");
.withMessage("expressionString cannot be empty");
}
@Test
@@ -63,7 +63,7 @@ class MethodExpressionAuthorizationManagerTests {
void setExpressionHandlerWhenNullThenIllegalArgumentException() {
MethodExpressionAuthorizationManager manager = new MethodExpressionAuthorizationManager("hasRole('ADMIN')");
assertThatIllegalArgumentException().isThrownBy(() -> manager.setExpressionHandler(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test

View File

@@ -58,7 +58,7 @@ public class PostAuthorizeAuthorizationManagerTests {
public void setExpressionHandlerWhenNullThenException() {
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
assertThatIllegalArgumentException().isThrownBy(() -> manager.setExpressionHandler(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -153,7 +153,7 @@ public class PostAuthorizeAuthorizationManagerTests {
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, result));
.isThrownBy(() -> manager.check(authentication, result));
}
@Test
@@ -164,7 +164,7 @@ public class PostAuthorizeAuthorizationManagerTests {
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, result));
.isThrownBy(() -> manager.check(authentication, result));
}
public static class TestClass implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {

View File

@@ -56,7 +56,7 @@ public class PostAuthorizeReactiveAuthorizationManagerTests {
@Test
public void setExpressionHandlerWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PostAuthorizeReactiveAuthorizationManager(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -118,7 +118,7 @@ public class PostAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkRequiresAdminWhenClassAnnotationsThenMethodAnnotationsTakePrecedence() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "securedAdmin");
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
@@ -135,7 +135,7 @@ public class PostAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "securedUser");
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
@@ -152,25 +152,25 @@ public class PostAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
"inheritedAnnotations");
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, result));
.isThrownBy(() -> manager.check(authentication, result));
}
@Test
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "inheritedAnnotations");
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
PostAuthorizeReactiveAuthorizationManager manager = new PostAuthorizeReactiveAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, result));
.isThrownBy(() -> manager.check(authentication, result));
}
public static class TestClass implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {

View File

@@ -74,7 +74,7 @@ public class PostFilterAuthorizationMethodInterceptorTests {
public void setExpressionHandlerWhenNullThenException() {
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> advice.setExpressionHandler(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -82,7 +82,7 @@ public class PostFilterAuthorizationMethodInterceptorTests {
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
MethodMatcher methodMatcher = advice.getPointcut().getMethodMatcher();
assertThat(methodMatcher.matches(NoPostFilterClass.class.getMethod("doSomething"), NoPostFilterClass.class))
.isFalse();
.isFalse();
}
@Test
@@ -91,7 +91,7 @@ public class PostFilterAuthorizationMethodInterceptorTests {
MethodMatcher methodMatcher = advice.getPointcut().getMethodMatcher();
assertThat(
methodMatcher.matches(TestClass.class.getMethod("doSomethingArray", String[].class), TestClass.class))
.isTrue();
.isTrue();
}
@Test
@@ -115,7 +115,7 @@ public class PostFilterAuthorizationMethodInterceptorTests {
"inheritedAnnotations");
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> advice.invoke(methodInvocation));
.isThrownBy(() -> advice.invoke(methodInvocation));
}
@Test
@@ -124,7 +124,7 @@ public class PostFilterAuthorizationMethodInterceptorTests {
ConflictingAnnotations.class, "inheritedAnnotations");
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> advice.invoke(methodInvocation));
.isThrownBy(() -> advice.invoke(methodInvocation));
}
@Test

View File

@@ -52,22 +52,24 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests {
@Test
public void setExpressionHandlerWhenNullThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new PostFilterAuthorizationReactiveMethodInterceptor(null))
.withMessage("expressionHandler cannot be null");
.isThrownBy(() -> new PostFilterAuthorizationReactiveMethodInterceptor(null))
.withMessage("expressionHandler cannot be null");
}
@Test
public void methodMatcherWhenMethodHasNotPostFilterAnnotationThenNotMatches() throws Exception {
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
assertThat(interceptor.getPointcut().getMethodMatcher()
.matches(NoPostFilterClass.class.getMethod("doSomething"), NoPostFilterClass.class)).isFalse();
assertThat(interceptor.getPointcut()
.getMethodMatcher()
.matches(NoPostFilterClass.class.getMethod("doSomething"), NoPostFilterClass.class)).isFalse();
}
@Test
public void methodMatcherWhenMethodHasPostFilterAnnotationThenMatches() throws Exception {
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
assertThat(interceptor.getPointcut().getMethodMatcher()
.matches(TestClass.class.getMethod("doSomethingFlux", Flux.class), TestClass.class)).isTrue();
assertThat(interceptor.getPointcut()
.getMethodMatcher()
.matches(TestClass.class.getMethod("doSomethingFlux", Flux.class), TestClass.class)).isTrue();
}
@Test
@@ -97,8 +99,10 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests {
};
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
Object result = interceptor.invoke(methodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class)).extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class)).containsOnly("john");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class))
.extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class))
.containsOnly("john");
}
@Test
@@ -107,7 +111,7 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests {
"inheritedAnnotations");
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> interceptor.invoke(methodInvocation));
.isThrownBy(() -> interceptor.invoke(methodInvocation));
}
@Test
@@ -116,7 +120,7 @@ public class PostFilterAuthorizationReactiveMethodInterceptorTests {
ConflictingAnnotations.class, "inheritedAnnotations");
PostFilterAuthorizationReactiveMethodInterceptor interceptor = new PostFilterAuthorizationReactiveMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> interceptor.invoke(methodInvocation));
.isThrownBy(() -> interceptor.invoke(methodInvocation));
}
@PostFilter("filterObject == 'john'")

View File

@@ -56,7 +56,7 @@ public class PreAuthorizeAuthorizationManagerTests {
public void setExpressionHandlerWhenNullThenException() {
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
assertThatIllegalArgumentException().isThrownBy(() -> manager.setExpressionHandler(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -121,7 +121,7 @@ public class PreAuthorizeAuthorizationManagerTests {
"inheritedAnnotations");
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test
@@ -131,7 +131,7 @@ public class PreAuthorizeAuthorizationManagerTests {
ClassLevelAnnotations.class, "inheritedAnnotations");
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test

View File

@@ -53,7 +53,7 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
@Test
public void setExpressionHandlerWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PreAuthorizeReactiveAuthorizationManager(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -62,7 +62,8 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
"doSomething", new Class[] {}, new Object[] {});
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
AuthorizationDecision decision = manager
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation).block();
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation)
.block();
assertThat(decision).isNull();
}
@@ -72,7 +73,8 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
"doSomethingString", new Class[] { String.class }, new Object[] { "grant" });
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
AuthorizationDecision decision = manager
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation).block();
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation)
.block();
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isTrue();
}
@@ -83,7 +85,8 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
"doSomethingString", new Class[] { String.class }, new Object[] { "deny" });
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
AuthorizationDecision decision = manager
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation).block();
.check(ReactiveAuthenticationUtils.getAuthentication(), methodInvocation)
.block();
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isFalse();
}
@@ -91,7 +94,7 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkRequiresAdminWhenClassAnnotationsThenMethodAnnotationsTakePrecedence() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "securedAdmin");
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
@@ -107,7 +110,7 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "securedUser");
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
@@ -123,23 +126,23 @@ public class PreAuthorizeReactiveAuthorizationManagerTests {
@Test
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
"inheritedAnnotations");
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
Mono<Authentication> authentication = Mono
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
.just(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(),
ClassLevelAnnotations.class, "inheritedAnnotations");
PreAuthorizeReactiveAuthorizationManager manager = new PreAuthorizeReactiveAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
public static class TestClass implements InterfaceAnnotationsOne, InterfaceAnnotationsTwo {

View File

@@ -76,7 +76,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
public void setExpressionHandlerWhenNullThenException() {
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> advice.setExpressionHandler(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -84,7 +84,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
MethodMatcher methodMatcher = advice.getPointcut().getMethodMatcher();
assertThat(methodMatcher.matches(NoPreFilterClass.class.getMethod("doSomething"), NoPreFilterClass.class))
.isFalse();
.isFalse();
}
@Test
@@ -92,7 +92,8 @@ public class PreFilterAuthorizationMethodInterceptorTests {
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
MethodMatcher methodMatcher = advice.getPointcut().getMethodMatcher();
assertThat(methodMatcher.matches(TestClass.class.getMethod("doSomethingListFilterTargetMatch", List.class),
TestClass.class)).isTrue();
TestClass.class))
.isTrue();
}
@Test
@@ -100,8 +101,8 @@ public class PreFilterAuthorizationMethodInterceptorTests {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
"doSomethingListFilterTargetNotMatch", new Class[] { List.class }, new Object[] { new ArrayList<>() });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> advice.invoke(methodInvocation)).withMessage(
"Filter target was null, or no argument with name 'filterTargetNotMatch' found in method.");
assertThatIllegalArgumentException().isThrownBy(() -> advice.invoke(methodInvocation))
.withMessage("Filter target was null, or no argument with name 'filterTargetNotMatch' found in method.");
}
@Test
@@ -110,7 +111,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
"doSomethingListFilterTargetMatch", new Class[] { List.class }, new Object[] { null });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> advice.invoke(methodInvocation))
.withMessage("Filter target was null, or no argument with name 'list' found in method.");
.withMessage("Filter target was null, or no argument with name 'list' found in method.");
}
@Test
@@ -132,7 +133,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
"doSomethingListFilterTargetNotProvided", new Class[] { List.class }, new Object[] { null });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> advice.invoke(methodInvocation))
.withMessage("Filter target was null. Make sure you passing the correct value in the method argument.");
.withMessage("Filter target was null. Make sure you passing the correct value in the method argument.");
}
@Test
@@ -154,8 +155,8 @@ public class PreFilterAuthorizationMethodInterceptorTests {
"doSomethingArrayFilterTargetNotProvided", new Class[] { String[].class },
new Object[] { new String[] {} });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalStateException().isThrownBy(() -> advice.invoke(methodInvocation)).withMessage(
"Pre-filtering on array types is not supported. Using a Collection will solve this problem.");
assertThatIllegalStateException().isThrownBy(() -> advice.invoke(methodInvocation))
.withMessage("Pre-filtering on array types is not supported. Using a Collection will solve this problem.");
}
@Test
@@ -165,7 +166,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
new Object[] { "", new ArrayList<>() });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalStateException().isThrownBy(() -> advice.invoke(methodInvocation))
.withMessage("Unable to determine the method argument for filtering. Specify the filter target.");
.withMessage("Unable to determine the method argument for filtering. Specify the filter target.");
}
@Test
@@ -174,7 +175,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
"inheritedAnnotations");
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> advice.invoke(methodInvocation));
.isThrownBy(() -> advice.invoke(methodInvocation));
}
@Test
@@ -183,7 +184,7 @@ public class PreFilterAuthorizationMethodInterceptorTests {
ConflictingAnnotations.class, "inheritedAnnotations");
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> advice.invoke(methodInvocation));
.isThrownBy(() -> advice.invoke(methodInvocation));
}
@Test

View File

@@ -54,7 +54,7 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
@Test
public void setExpressionHandlerWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PreFilterAuthorizationReactiveMethodInterceptor(null))
.withMessage("expressionHandler cannot be null");
.withMessage("expressionHandler cannot be null");
}
@Test
@@ -69,22 +69,24 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
public void setParameterNameDiscovererWhenNullThenException() {
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.setParameterNameDiscoverer(null))
.withMessage("parameterNameDiscoverer cannot be null");
.withMessage("parameterNameDiscoverer cannot be null");
}
@Test
public void methodMatcherWhenMethodHasNotPreFilterAnnotationThenNotMatches() throws Exception {
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThat(interceptor.getPointcut().getMethodMatcher().matches(NoPreFilterClass.class.getMethod("doSomething"),
NoPreFilterClass.class)).isFalse();
assertThat(interceptor.getPointcut()
.getMethodMatcher()
.matches(NoPreFilterClass.class.getMethod("doSomething"), NoPreFilterClass.class)).isFalse();
}
@Test
public void methodMatcherWhenMethodHasPreFilterAnnotationThenMatches() throws Exception {
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThat(interceptor.getPointcut().getMethodMatcher()
.matches(TestClass.class.getMethod("doSomethingFluxFilterTargetMatch", Flux.class), TestClass.class))
.isTrue();
assertThat(interceptor.getPointcut()
.getMethodMatcher()
.matches(TestClass.class.getMethod("doSomethingFluxFilterTargetMatch", Flux.class), TestClass.class))
.isTrue();
}
@Test
@@ -92,8 +94,8 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class,
"doSomethingFluxFilterTargetNotMatch", new Class[] { Flux.class }, new Object[] { Flux.empty() });
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation)).withMessage(
"Filter target was null, or no argument with name 'filterTargetNotMatch' found in method.");
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation))
.withMessage("Filter target was null, or no argument with name 'filterTargetNotMatch' found in method.");
}
@Test
@@ -102,7 +104,7 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
"doSomethingFluxFilterTargetMatch", new Class[] { Flux.class }, new Object[] { null });
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation))
.withMessage("Filter target was null, or no argument with name 'flux' found in method.");
.withMessage("Filter target was null, or no argument with name 'flux' found in method.");
}
@Test
@@ -132,8 +134,10 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
};
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
Object result = interceptor.invoke(methodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class)).extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class)).containsOnly("john");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.type(Flux.class))
.extracting(Flux::collectList)
.extracting(Mono::block, InstanceOfAssertFactories.list(String.class))
.containsOnly("john");
}
@Test
@@ -142,7 +146,7 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
"inheritedAnnotations");
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> interceptor.invoke(methodInvocation));
.isThrownBy(() -> interceptor.invoke(methodInvocation));
}
@Test
@@ -151,7 +155,7 @@ public class PreFilterAuthorizationReactiveMethodInterceptorTests {
ConflictingAnnotations.class, "inheritedAnnotations");
PreFilterAuthorizationReactiveMethodInterceptor interceptor = new PreFilterAuthorizationReactiveMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> interceptor.invoke(methodInvocation));
.isThrownBy(() -> interceptor.invoke(methodInvocation));
}
@PreFilter("filterObject == 'john'")

View File

@@ -115,7 +115,7 @@ public class SecuredAuthorizationManagerTests {
"inheritedAnnotations");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test
@@ -125,7 +125,7 @@ public class SecuredAuthorizationManagerTests {
ClassLevelAnnotations.class, "inheritedAnnotations");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> manager.check(authentication, methodInvocation));
.isThrownBy(() -> manager.check(authentication, methodInvocation));
}
@Test

View File

@@ -54,7 +54,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
@SuppressWarnings("unchecked")
public void scheduleRunnable() {
given((ScheduledFuture<Object>) this.delegate.schedule(this.wrappedRunnable, 1, TimeUnit.SECONDS))
.willReturn(this.expectedResult);
.willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.schedule(this.runnable, 1, TimeUnit.SECONDS);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).schedule(this.wrappedRunnable, 1, TimeUnit.SECONDS);
@@ -72,7 +72,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
@SuppressWarnings("unchecked")
public void scheduleAtFixedRate() {
given((ScheduledFuture<Object>) this.delegate.scheduleAtFixedRate(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS))
.willReturn(this.expectedResult);
.willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.scheduleAtFixedRate(this.runnable, 1, 2, TimeUnit.SECONDS);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).scheduleAtFixedRate(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS);
@@ -82,7 +82,8 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
@SuppressWarnings("unchecked")
public void scheduleWithFixedDelay() {
given((ScheduledFuture<Object>) this.delegate.scheduleWithFixedDelay(this.wrappedRunnable, 1, 2,
TimeUnit.SECONDS)).willReturn(this.expectedResult);
TimeUnit.SECONDS))
.willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.scheduleWithFixedDelay(this.runnable, 1, 2, TimeUnit.SECONDS);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).scheduleWithFixedDelay(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS);

View File

@@ -73,19 +73,23 @@ public abstract class AbstractDelegatingSecurityContextTestSupport {
protected MockedStatic<DelegatingSecurityContextRunnable> delegatingSecurityContextRunnable;
public final void explicitSecurityContextSetup() throws Exception {
this.delegatingSecurityContextCallable.when(() -> DelegatingSecurityContextCallable.create(eq(this.callable),
this.securityContextCaptor.capture(), any())).thenReturn(this.wrappedCallable);
this.delegatingSecurityContextRunnable.when(() -> DelegatingSecurityContextRunnable.create(eq(this.runnable),
this.securityContextCaptor.capture(), any())).thenReturn(this.wrappedRunnable);
this.delegatingSecurityContextCallable
.when(() -> DelegatingSecurityContextCallable.create(eq(this.callable),
this.securityContextCaptor.capture(), any()))
.thenReturn(this.wrappedCallable);
this.delegatingSecurityContextRunnable
.when(() -> DelegatingSecurityContextRunnable.create(eq(this.runnable),
this.securityContextCaptor.capture(), any()))
.thenReturn(this.wrappedRunnable);
}
public final void currentSecurityContextSetup() throws Exception {
this.delegatingSecurityContextCallable
.when(() -> DelegatingSecurityContextCallable.create(eq(this.callable), isNull(), any()))
.thenReturn(this.wrappedCallable);
.when(() -> DelegatingSecurityContextCallable.create(eq(this.callable), isNull(), any()))
.thenReturn(this.wrappedCallable);
this.delegatingSecurityContextRunnable
.when(() -> DelegatingSecurityContextRunnable.create(eq(this.runnable), isNull(), any()))
.thenReturn(this.wrappedRunnable);
.when(() -> DelegatingSecurityContextRunnable.create(eq(this.runnable), isNull(), any()))
.thenReturn(this.wrappedRunnable);
}
@BeforeEach

View File

@@ -81,7 +81,7 @@ public class DelegatingSecurityContextCallableTests {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertThat(strategy.getContext())
.isEqualTo(DelegatingSecurityContextCallableTests.this.securityContext);
.isEqualTo(DelegatingSecurityContextCallableTests.this.securityContext);
return super.answer(invocation);
}
});
@@ -100,7 +100,7 @@ public class DelegatingSecurityContextCallableTests {
@Test
public void constructorNullDelegateNonNullSecurityContext() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingSecurityContextCallable<>(null, this.securityContext));
.isThrownBy(() -> new DelegatingSecurityContextCallable<>(null, this.securityContext));
}
@Test
@@ -111,7 +111,7 @@ public class DelegatingSecurityContextCallableTests {
@Test
public void constructorNullSecurityContext() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingSecurityContextCallable<>(this.delegate, null));
.isThrownBy(() -> new DelegatingSecurityContextCallable<>(this.delegate, null));
}
@Test
@@ -158,7 +158,7 @@ public class DelegatingSecurityContextCallableTests {
@Test
public void createNullDelegate() {
assertThatIllegalArgumentException()
.isThrownBy(() -> DelegatingSecurityContextCallable.create(null, this.securityContext));
.isThrownBy(() -> DelegatingSecurityContextCallable.create(null, this.securityContext));
}
@Test

View File

@@ -97,7 +97,7 @@ public class DelegatingSecurityContextRunnableTests {
@Test
public void constructorNullDelegateNonNullSecurityContext() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingSecurityContextRunnable(null, this.securityContext));
.isThrownBy(() -> new DelegatingSecurityContextRunnable(null, this.securityContext));
}
@Test
@@ -108,7 +108,7 @@ public class DelegatingSecurityContextRunnableTests {
@Test
public void constructorNullSecurityContext() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingSecurityContextRunnable(this.delegate, null));
.isThrownBy(() -> new DelegatingSecurityContextRunnable(this.delegate, null));
}
@Test
@@ -156,7 +156,7 @@ public class DelegatingSecurityContextRunnableTests {
@Test
public void createNullDelegate() {
assertThatIllegalArgumentException()
.isThrownBy(() -> DelegatingSecurityContextRunnable.create(null, this.securityContext));
.isThrownBy(() -> DelegatingSecurityContextRunnable.create(null, this.securityContext));
}
@Test

View File

@@ -38,8 +38,9 @@ public class JavaVersionTests {
private void assertClassVersion(Class<?> clazz) throws Exception {
String classResourceName = clazz.getName().replaceAll("\\.", "/") + ".class";
try (InputStream input = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(classResourceName)) {
try (InputStream input = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(classResourceName)) {
DataInputStream data = new DataInputStream(input);
data.readInt();
data.readShort(); // minor

View File

@@ -33,8 +33,8 @@ public class SpringSecurityMessageSourceTests {
@Test
public void testOperation() {
SpringSecurityMessageSource msgs = new SpringSecurityMessageSource();
assertThat("\u4E0D\u5141\u8BB8\u8BBF\u95EE").isEqualTo(
msgs.getMessage("AbstractAccessDecisionManager.accessDenied", null, Locale.SIMPLIFIED_CHINESE));
assertThat("\u4E0D\u5141\u8BB8\u8BBF\u95EE")
.isEqualTo(msgs.getMessage("AbstractAccessDecisionManager.accessDenied", null, Locale.SIMPLIFIED_CHINESE));
}
@Test
@@ -59,7 +59,7 @@ public class SpringSecurityMessageSourceTests {
LocaleContextHolder.setLocale(Locale.US);
MessageSourceAccessor msgs = SpringSecurityMessageSource.getAccessor();
assertThat("Access is denied")
.isEqualTo(msgs.getMessage("AbstractAccessDecisionManager.accessDenied", "Ooops"));
.isEqualTo(msgs.getMessage("AbstractAccessDecisionManager.accessDenied", "Ooops"));
// Revert to original Locale
Locale.setDefault(beforeSystem);
LocaleContextHolder.setLocale(beforeHolder);

View File

@@ -33,7 +33,7 @@ public class AuthorityUtilsTests {
@Test
public void commaSeparatedStringIsParsedCorrectly() {
List<GrantedAuthority> authorityArray = AuthorityUtils
.commaSeparatedStringToAuthorityList(" ROLE_A, B, C, ROLE_D\n,\n E ");
.commaSeparatedStringToAuthorityList(" ROLE_A, B, C, ROLE_D\n,\n E ");
Set<String> authorities = AuthorityUtils.authorityListToSet(authorityArray);
assertThat(authorities.contains("B")).isTrue();
assertThat(authorities.contains("C")).isTrue();

View File

@@ -46,7 +46,7 @@ public class MapBasedAttributes2GrantedAuthoritiesMapperTests {
public void testAfterPropertiesSetEmptyMap() throws Exception {
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
assertThatIllegalArgumentException()
.isThrownBy(() -> mapper.setAttributes2grantedAuthoritiesMap(new HashMap()));
.isThrownBy(() -> mapper.setAttributes2grantedAuthoritiesMap(new HashMap()));
}
@Test
@@ -206,8 +206,8 @@ public class MapBasedAttributes2GrantedAuthoritiesMapperTests {
}
Collection expectedColl = Arrays.asList(expectedGas);
assertThat(resultColl.containsAll(expectedColl))
.withFailMessage("Role collections should match; result: " + resultColl + ", expected: " + expectedColl)
.isTrue();
.withFailMessage("Role collections should match; result: " + resultColl + ", expected: " + expectedColl)
.isTrue();
}
}

View File

@@ -44,7 +44,7 @@ public class SimpleAuthoritiesMapperTests {
public void defaultPrefixIsCorrectlyApplied() {
SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
Set<String> mapped = AuthorityUtils
.authorityListToSet(mapper.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "ROLE_bbb")));
.authorityListToSet(mapper.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "ROLE_bbb")));
assertThat(mapped.contains("ROLE_AaA")).isTrue();
assertThat(mapped.contains("ROLE_bbb")).isTrue();
}
@@ -76,7 +76,7 @@ public class SimpleAuthoritiesMapperTests {
SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
mapper.setConvertToUpperCase(true);
Set<String> mapped = AuthorityUtils
.authorityListToSet(mapper.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "AAA")));
.authorityListToSet(mapper.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "AAA")));
assertThat(mapped).hasSize(1);
}

View File

@@ -37,7 +37,8 @@ public class SimpleMappableRolesRetrieverTests {
r.setMappableAttributes(roles);
Set<String> result = r.getMappableAttributes();
assertThat(roles.containsAll(result) && result.containsAll(roles))
.withFailMessage("Role collections do not match; result: " + result + ", expected: " + roles).isTrue();
.withFailMessage("Role collections do not match; result: " + result + ", expected: " + roles)
.isTrue();
}
}

View File

@@ -125,8 +125,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests {
}
Collection<String> expectedColl = Arrays.asList(expectedGas);
assertThat(expectedColl.containsAll(resultColl) && resultColl.containsAll(expectedColl))
.withFailMessage("Role collections do not match; result: " + resultColl + ", expected: " + expectedColl)
.isTrue();
.withFailMessage("Role collections do not match; result: " + resultColl + ", expected: " + expectedColl)
.isTrue();
}
private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() {

View File

@@ -129,9 +129,9 @@ public class ListeningSecurityContextHolderStrategyTests {
@Test
public void constructorWhenNullListenerThenIllegalArgument() {
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> new ListeningSecurityContextHolderStrategy(new ThreadLocalSecurityContextHolderStrategy(),
(SecurityContextChangedListener) null));
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new ListeningSecurityContextHolderStrategy(new ThreadLocalSecurityContextHolderStrategy(),
(SecurityContextChangedListener) null));
}
}

View File

@@ -43,8 +43,8 @@ public class ReactiveSecurityContextHolderTests {
SecurityContext expectedContext = new SecurityContextImpl(
new TestingAuthenticationToken("user", "password", "ROLE_USER"));
Mono<SecurityContext> context = Mono.subscriberContext()
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
// @formatter:off
StepVerifier.create(context)
.expectNext(expectedContext)

View File

@@ -36,49 +36,49 @@ public class AnnotationParameterNameDiscovererTests {
@Test
public void getParameterNamesInterfaceSingleParam() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
}
@Test
public void getParameterNamesInterfaceSingleParamAnnotatedWithMultiParams() {
assertThat(this.discoverer.getParameterNames(
ReflectionUtils.findMethod(Dao.class, "findMessageByToAndFrom", String.class, String.class)))
.isEqualTo(new String[] { "to", null });
.isEqualTo(new String[] { "to", null });
}
@Test
public void getParameterNamesInterfaceNoAnnotation() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
}
@Test
public void getParameterNamesClassSingleParam() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
}
@Test
public void getParameterNamesClassSingleParamAnnotatedWithMultiParams() {
assertThat(this.discoverer.getParameterNames(
ReflectionUtils.findMethod(Dao.class, "findMessageByToAndFrom", String.class, String.class)))
.isEqualTo(new String[] { "to", null });
.isEqualTo(new String[] { "to", null });
}
@Test
public void getParameterNamesClassNoAnnotation() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
}
@Test
public void getParameterNamesConstructor() throws Exception {
assertThat(this.discoverer.getParameterNames(Impl.class.getDeclaredConstructor(String.class)))
.isEqualTo(new String[] { "id" });
.isEqualTo(new String[] { "id" });
}
@Test
@@ -89,31 +89,31 @@ public class AnnotationParameterNameDiscovererTests {
@Test
public void getParameterNamesClassAnnotationOnInterface() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(DaoImpl.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
.getParameterNames(ReflectionUtils.findMethod(DaoImpl.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByTo", String.class)))
.isEqualTo(new String[] { "to" });
}
@Test
public void getParameterNamesClassAnnotationOnImpl() {
assertThat(this.discoverer.getParameterNames(
ReflectionUtils.findMethod(Dao.class, "findMessageByToAndFrom", String.class, String.class)))
.isEqualTo(new String[] { "to", null });
.isEqualTo(new String[] { "to", null });
assertThat(this.discoverer.getParameterNames(
ReflectionUtils.findMethod(DaoImpl.class, "findMessageByToAndFrom", String.class, String.class)))
.isEqualTo(new String[] { "to", "from" });
.isEqualTo(new String[] { "to", "from" });
}
@Test
public void getParameterNamesClassAnnotationOnBaseClass() {
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
assertThat(this.discoverer.getParameterNames(
ReflectionUtils.findMethod(DaoImpl.class, "findMessageByIdNoAnnotation", String.class)))
.isEqualTo(new String[] { "id" });
.getParameterNames(ReflectionUtils.findMethod(Dao.class, "findMessageByIdNoAnnotation", String.class)))
.isNull();
assertThat(this.discoverer
.getParameterNames(ReflectionUtils.findMethod(DaoImpl.class, "findMessageByIdNoAnnotation", String.class)))
.isEqualTo(new String[] { "id" });
}
interface Dao {

View File

@@ -47,7 +47,7 @@ public class DefaultSecurityParameterNameDiscovererTests {
@Test
public void constructorDefault() {
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(this.discoverer, "parameterNameDiscoverers");
.getField(this.discoverer, "parameterNameDiscoverers");
assertThat(discoverers).hasSize(2);
ParameterNameDiscoverer annotationDisc = discoverers.get(0);
assertThat(annotationDisc).isInstanceOf(AnnotationParameterNameDiscoverer.class);
@@ -62,7 +62,7 @@ public class DefaultSecurityParameterNameDiscovererTests {
this.discoverer = new DefaultSecurityParameterNameDiscoverer(
Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils
.getField(this.discoverer, "parameterNameDiscoverers");
.getField(this.discoverer, "parameterNameDiscoverers");
assertThat(discoverers).hasSize(3);
assertThat(discoverers.get(0)).isInstanceOf(LocalVariableTableParameterNameDiscoverer.class);
ParameterNameDiscoverer annotationDisc = discoverers.get(1);

View File

@@ -39,13 +39,13 @@ public class MapReactiveUserDetailsServiceTests {
@Test
public void constructorNullUsers() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new MapReactiveUserDetailsService((Collection<UserDetails>) null));
.isThrownBy(() -> new MapReactiveUserDetailsService((Collection<UserDetails>) null));
}
@Test
public void constructorEmptyUsers() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new MapReactiveUserDetailsService(Collections.emptyList()));
.isThrownBy(() -> new MapReactiveUserDetailsService(Collections.emptyList()));
}
@Test

View File

@@ -65,7 +65,7 @@ public class UserTests {
@Test
public void testNoArgConstructorDoesntExist() {
assertThatExceptionOfType(NoSuchMethodException.class)
.isThrownBy(() -> User.class.getDeclaredConstructor((Class[]) null));
.isThrownBy(() -> User.class.getDeclaredConstructor((Class[]) null));
}
@Test
@@ -142,15 +142,19 @@ public class UserTests {
@Test
public void withUserWhenDetailsPasswordEncoderThenEncodes() {
UserDetails userDetails = User.withUsername("user").password("password").roles("USER").build();
UserDetails withEncodedPassword = User.withUserDetails(userDetails).passwordEncoder((p) -> p + "encoded")
.build();
UserDetails withEncodedPassword = User.withUserDetails(userDetails)
.passwordEncoder((p) -> p + "encoded")
.build();
assertThat(withEncodedPassword.getPassword()).isEqualTo("passwordencoded");
}
@Test
public void withUsernameWhenPasswordEncoderAndPasswordThenEncodes() {
UserDetails withEncodedPassword = User.withUsername("user").password("password")
.passwordEncoder((p) -> p + "encoded").roles("USER").build();
UserDetails withEncodedPassword = User.withUsername("user")
.password("password")
.passwordEncoder((p) -> p + "encoded")
.roles("USER")
.build();
assertThat(withEncodedPassword.getPassword()).isEqualTo("passwordencoded");
}

View File

@@ -100,7 +100,7 @@ public class JdbcDaoImplTests {
public void testLookupFailsWithWrongUsername() throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDao();
assertThatExceptionOfType(UsernameNotFoundException.class)
.isThrownBy(() -> dao.loadUserByUsername("UNKNOWN_USER"));
.isThrownBy(() -> dao.loadUserByUsername("UNKNOWN_USER"));
}
@Test
@@ -119,7 +119,7 @@ public class JdbcDaoImplTests {
assertThat(user.getAuthorities()).hasSize(2);
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities())).contains("ARBITRARY_PREFIX_ROLE_TELLER");
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()))
.contains("ARBITRARY_PREFIX_ROLE_SUPERVISOR");
.contains("ARBITRARY_PREFIX_ROLE_SUPERVISOR");
}
@Test

View File

@@ -71,7 +71,7 @@ public class AnonymousAuthenticationTokenMixinTests extends AbstractMixinTests {
+ "\"principal\": \"user\", \"authenticated\": true, \"keyHash\": " + HASH_KEY.hashCode() + ","
+ "\"authorities\": [\"java.util.ArrayList\", []]}";
assertThatExceptionOfType(JsonMappingException.class)
.isThrownBy(() -> this.mapper.readValue(jsonString, AnonymousAuthenticationToken.class));
.isThrownBy(() -> this.mapper.readValue(jsonString, AnonymousAuthenticationToken.class));
}
@Test

View File

@@ -120,7 +120,7 @@ public class RememberMeAuthenticationTokenMixinTests extends AbstractMixinTests
assertThat(((User) token.getPrincipal()).getUsername()).isEqualTo("admin");
assertThat(((User) token.getPrincipal()).getPassword()).isEqualTo("1234");
assertThat(((User) token.getPrincipal()).getAuthorities()).hasSize(1)
.contains(new SimpleGrantedAuthority("ROLE_USER"));
.contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(((User) token.getPrincipal()).isEnabled()).isEqualTo(true);
}

View File

@@ -61,7 +61,7 @@ public class SimpleGrantedAuthorityMixinTests extends AbstractMixinTests {
public void deserializeGrantedAuthorityWithoutRoleTest() throws IOException {
String json = "{\"@class\": \"org.springframework.security.core.authority.SimpleGrantedAuthority\"}";
assertThatExceptionOfType(JsonMappingException.class)
.isThrownBy(() -> this.mapper.readValue(json, SimpleGrantedAuthority.class));
.isThrownBy(() -> this.mapper.readValue(json, SimpleGrantedAuthority.class));
}
}

View File

@@ -36,7 +36,7 @@ class UnmodifiableMapDeserializerTests extends AbstractMixinTests {
@Test
void shouldSerialize() throws Exception {
String mapJson = mapper
.writeValueAsString(Collections.unmodifiableMap(Collections.singletonMap("Key", "Value")));
.writeValueAsString(Collections.unmodifiableMap(Collections.singletonMap("Key", "Value")));
JSONAssert.assertEquals(DEFAULT_MAP_JSON, mapJson, true);
}
@@ -46,8 +46,9 @@ class UnmodifiableMapDeserializerTests extends AbstractMixinTests {
Map<String, String> map = mapper.readValue(DEFAULT_MAP_JSON,
Collections.unmodifiableMap(Collections.emptyMap()).getClass());
assertThat(map).isNotNull().isInstanceOf(Collections.unmodifiableMap(Collections.emptyMap()).getClass())
.containsAllEntriesOf(Collections.singletonMap("Key", "Value"));
assertThat(map).isNotNull()
.isInstanceOf(Collections.unmodifiableMap(Collections.emptyMap()).getClass())
.containsAllEntriesOf(Collections.singletonMap("Key", "Value"));
}
}

View File

@@ -73,7 +73,7 @@ public class UserDeserializerTests extends AbstractMixinTests {
String userJsonWithoutPasswordString = USER_JSON.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_SET_JSON,
"[]");
assertThatIllegalArgumentException()
.isThrownBy(() -> this.mapper.readValue(userJsonWithoutPasswordString, User.class));
.isThrownBy(() -> this.mapper.readValue(userJsonWithoutPasswordString, User.class));
}
@Test

View File

@@ -48,7 +48,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
+ SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON + "}";
public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON
.replace(UserDeserializerTests.USER_JSON, "\"admin\"");
.replace(UserDeserializerTests.USER_JSON, "\"admin\"");
private static final String NON_USER_PRINCIPAL_JSON = "{"
+ "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", "
@@ -58,15 +58,15 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
"\"details\": \"details\", ");
private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON
.replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON)
.replaceAll(UserDeserializerTests.USER_PASSWORD, "null")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON);
.replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON)
.replaceAll(UserDeserializerTests.USER_PASSWORD, "null")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON);
private static final String UNAUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_STRINGPRINCIPAL_JSON
.replace("\"authenticated\": true, ", "\"authenticated\": false, ")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON);
.replace("\"authenticated\": true, ", "\"authenticated\": false, ")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON);
@Test
public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest()
@@ -82,7 +82,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
throws JsonProcessingException, JSONException {
User user = createDefaultUser();
UsernamePasswordAuthenticationToken token = UsernamePasswordAuthenticationToken
.authenticated(user.getUsername(), user.getPassword(), user.getAuthorities());
.authenticated(user.getUsername(), user.getPassword(), user.getAuthorities());
String serializedJson = this.mapper.writeValueAsString(token);
JSONAssert.assertEquals(AUTHENTICATED_STRINGPRINCIPAL_JSON, serializedJson, true);
}
@@ -120,8 +120,9 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
UsernamePasswordAuthenticationToken.class);
assertThat(token).isNotNull();
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1)
.contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull()
.hasSize(1)
.contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(token.isAuthenticated()).isEqualTo(true);
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
}
@@ -162,8 +163,9 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
UsernamePasswordAuthenticationToken.class);
assertThat(token).isNotNull();
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1)
.contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull()
.hasSize(1)
.contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(token.isAuthenticated()).isEqualTo(true);
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(token.getDetails()).isExactlyInstanceOf(String.class).isEqualTo("details");
@@ -182,7 +184,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
@Test
public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException {
this.mapper.setDefaultPropertyInclusion(Value.construct(Include.ALWAYS, Include.NON_NULL))
.setSerializationInclusion(Include.NON_ABSENT);
.setSerializationInclusion(Include.NON_ABSENT);
UsernamePasswordAuthenticationToken original = UsernamePasswordAuthenticationToken.unauthenticated("Frodo",
null);
String serialized = this.mapper.writeValueAsString(original);

View File

@@ -57,7 +57,7 @@ public class InMemoryUserDetailsManagerTests {
String newPassword = "newPassword";
this.manager.updatePassword(userNotLowerCase, newPassword);
assertThat(this.manager.loadUserByUsername(userNotLowerCase.getUsername()).getPassword())
.isEqualTo(newPassword);
.isEqualTo(newPassword);
}
@Test
@@ -75,7 +75,7 @@ public class InMemoryUserDetailsManagerTests {
Properties properties = new Properties();
properties.setProperty("joe", "");
assertThatIllegalArgumentException().isThrownBy(() -> new InMemoryUserDetailsManager(properties))
.withMessage("The entry with username 'joe' could not be converted to an UserDetails");
.withMessage("The entry with username 'joe' could not be converted to an UserDetails");
}
@Test
@@ -83,7 +83,7 @@ public class InMemoryUserDetailsManagerTests {
Properties properties = new Properties();
properties.setProperty("joe", "{noop}joespassword");
assertThatIllegalArgumentException().isThrownBy(() -> new InMemoryUserDetailsManager(properties))
.withMessage("The entry with username 'joe' could not be converted to an UserDetails");
.withMessage("The entry with username 'joe' could not be converted to an UserDetails");
}
@Test

View File

@@ -103,8 +103,8 @@ public class JdbcUserDetailsManagerTests {
this.template.execute("create table users(username varchar(20) not null primary key,"
+ "password varchar(20) not null, enabled boolean not null)");
this.template
.execute("create table authorities (username varchar(20) not null, authority varchar(20) not null, "
+ "constraint fk_authorities_users foreign key(username) references users(username))");
.execute("create table authorities (username varchar(20) not null, authority varchar(20) not null, "
+ "constraint fk_authorities_users foreign key(username) references users(username))");
PopulatedDatabase.createGroupTables(this.template);
PopulatedDatabase.insertGroupData(this.template);
}
@@ -195,7 +195,7 @@ public class JdbcUserDetailsManagerTests {
@Test
public void changePasswordFailsForUnauthenticatedUser() {
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.manager.changePassword("password", "newPassword"));
.isThrownBy(() -> this.manager.changePassword("password", "newPassword"));
}
@Test
@@ -246,7 +246,7 @@ public class JdbcUserDetailsManagerTests {
given(am.authenticate(any(Authentication.class))).willThrow(new BadCredentialsException(""));
this.manager.setAuthenticationManager(am);
assertThatExceptionOfType(BadCredentialsException.class)
.isThrownBy(() -> this.manager.changePassword("password", "newPassword"));
.isThrownBy(() -> this.manager.changePassword("password", "newPassword"));
// Check password hasn't changed.
UserDetails newJoe = this.manager.loadUserByUsername("joe");
assertThat(newJoe.getPassword()).isEqualTo("password");
@@ -298,7 +298,7 @@ public class JdbcUserDetailsManagerTests {
public void renameGroupIsSuccessful() {
this.manager.renameGroup("GROUP_0", "GROUP_X");
assertThat(this.template.queryForObject("select id from groups where group_name = 'GROUP_X'", Integer.class))
.isZero();
.isZero();
}
@Test
@@ -311,13 +311,13 @@ public class JdbcUserDetailsManagerTests {
public void removeUserFromGroupDeletesGroupMemberRow() {
this.manager.removeUserFromGroup("jerry", "GROUP_1");
assertThat(this.template.queryForList("select group_id from group_members where username = 'jerry'"))
.hasSize(1);
.hasSize(1);
}
@Test
public void findGroupAuthoritiesReturnsCorrectAuthorities() {
assertThat(AuthorityUtils.createAuthorityList("ROLE_A"))
.isEqualTo(this.manager.findGroupAuthorities("GROUP_0"));
.isEqualTo(this.manager.findGroupAuthorities("GROUP_0"));
}
@Test

View File

@@ -47,8 +47,8 @@ public class MethodInvocationUtilsTests {
@Test
public void exceptionIsRaisedIfArgInfoOmittedAndMethodNameIsNotUnique() {
assertThatIllegalArgumentException().isThrownBy(
() -> MethodInvocationUtils.createFromClass(BusinessServiceImpl.class, "methodReturningAList"));
assertThatIllegalArgumentException()
.isThrownBy(() -> MethodInvocationUtils.createFromClass(BusinessServiceImpl.class, "methodReturningAList"));
}
@Test