From 27a506d943f6e55ec768ea34e5891e10f9790908 Mon Sep 17 00:00:00 2001 From: nobletrout Date: Wed, 5 Feb 2025 10:45:47 -0500 Subject: [PATCH] Update anonymous.adoc make the example code return the same thing for the do and don't do. Signed-off-by: nobletrout --- .../pages/servlet/authentication/anonymous.adoc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc b/docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc index aac99a58b01..3438b5ef37f 100644 --- a/docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc +++ b/docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc @@ -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" + } +} ---- ======