Update anonymous.adoc

make the example code return the same thing for the do and don't do.

Signed-off-by: nobletrout <nobletrout@gmail.com>
This commit is contained in:
nobletrout 2025-02-05 10:45:47 -05:00 committed by Steve Riesenberg
parent 5ded04da6c
commit 555fe1f147

View File

@ -148,7 +148,11 @@ Java::
----
@GetMapping("/")
public String method(@CurrentSecurityContext SecurityContext context) {
return context.getAuthentication().getName();
if (context.getAuthentication() instanceOf AnonymousAuthenticationToken) {
return "anonymous"
} else {
return "not anonymous"
}
}
----
@ -157,7 +161,12 @@ Kotlin::
[source,kotlin,role="secondary"]
----
@GetMapping("/")
fun method(@CurrentSecurityContext context : SecurityContext) : String =
context!!.authentication!!.name
fun method(@CurrentSecurityContext context : SecurityContext) : String {
return if (context!!.authentication is AnonymousAuthenticationToken) {
"anonymous"
} else {
"not anonymous"
}
}
----
======