Explorar o código

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>
nobletrout hai 6 meses
pai
achega
555fe1f147
Modificáronse 1 ficheiros con 12 adicións e 3 borrados
  1. 12 3
      docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc

+ 12 - 3
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"
+   }
+}
 ----
 ======