Fix Nullability

This commit is contained in:
Rob Winch 2025-08-21 13:41:02 -05:00
parent b8b1a92ad4
commit d9210c6596
No known key found for this signature in database
2 changed files with 2 additions and 2 deletions

View File

@ -29,7 +29,7 @@ class HelloMessageService : MessageService {
@PreAuthorize("isAuthenticated()")
override fun getMessage(): String {
val authentication: Authentication = SecurityContextHolder.getContext().authentication
val authentication: Authentication? = SecurityContextHolder.getContext().authentication
return "Hello $authentication"
}

View File

@ -47,7 +47,7 @@ class WithCustomUserDetailsTests {
fun getMessageWithUserDetailsServiceBeanName() {
val message: String = messageService.getMessage()
assertThat(message).contains("customUsername");
val principal = SecurityContextHolder.getContext().authentication.principal
val principal = SecurityContextHolder.getContext().authentication!!.principal
assertThat(principal).isInstanceOf(CustomUserDetails::class.java)
}
// end::custom-user-details-service[]