浏览代码

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 6 月之前
父节点
当前提交
555fe1f147
共有 1 个文件被更改,包括 12 次插入3 次删除
  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("/")
 @GetMapping("/")
 public String method(@CurrentSecurityContext SecurityContext context) {
 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"]
 [source,kotlin,role="secondary"]
 ----
 ----
 @GetMapping("/")
 @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"
+   }
+}
 ----
 ----
 ======
 ======