1
0
mirror of synced 2026-08-23 10:37:39 +00:00

Merge branch '7.0.x' into 7.1.x

Closes gh-19545
This commit is contained in:
Josh Cummings
2026-08-13 15:20:20 -06:00
2 changed files with 36 additions and 1 deletions
@@ -108,7 +108,7 @@ public class CasAuthenticationToken extends AbstractAuthenticationToken implemen
protected CasAuthenticationToken(Builder<?> builder) {
super(builder);
Assert.isTrue(!"".equals(builder.principal), "principal cannot be null or empty");
Assert.notNull(!"".equals(builder.credentials), "credentials cannot be null or empty");
Assert.isTrue(!"".equals(builder.credentials), "credentials cannot be null or empty");
Assert.notNull(builder.userDetails, "userDetails cannot be null");
Assert.notNull(builder.assertion, "assertion cannot be null");
this.keyHash = builder.keyHash;
@@ -34,6 +34,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;
/**
* Tests {@link CasAuthenticationToken}.
@@ -182,4 +183,38 @@ public class CasAuthenticationTokenTests {
assertThat(authorities).containsExactlyInAnyOrder("FACTOR_ONE", "FACTOR_TWO");
}
@Test
public void toBuilderWhenPrincipalIsEmpty() {
final Assertion assertion = new AssertionImpl("test");
CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", this.ROLES,
makeUserDetails(), assertion);
assertThatIllegalArgumentException().isThrownBy(() -> token.toBuilder().principal(null).build());
assertThatIllegalArgumentException().isThrownBy(() -> token.toBuilder().principal("").build());
}
@Test
public void toBuilderWhenPrincipalIsNotEmpty() {
final Assertion assertion = new AssertionImpl("test");
CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", this.ROLES,
makeUserDetails(), assertion);
assertThatNoException().isThrownBy(() -> token.toBuilder().principal("principal").build());
}
@Test
public void toBuilderWhenCredentialsIsEmpty() {
final Assertion assertion = new AssertionImpl("test");
CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", this.ROLES,
makeUserDetails(), assertion);
assertThatIllegalArgumentException().isThrownBy(() -> token.toBuilder().credentials(null).build());
assertThatIllegalArgumentException().isThrownBy(() -> token.toBuilder().credentials("").build());
}
@Test
public void toBuilderWhenCredentialsIsNotEmpty() {
final Assertion assertion = new AssertionImpl("test");
CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", this.ROLES,
makeUserDetails(), assertion);
assertThatNoException().isThrownBy(() -> token.toBuilder().credentials("credentials").build());
}
}