Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private CasAuthenticationToken(final Integer keyHash, final Object principal, fi
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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}.
Expand Down Expand Up @@ -182,4 +183,38 @@ public void toBuilderWhenApplyThenCopies() {
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());
}

}
Loading