Skip to content

Commit 555fe1f

Browse files
nobletroutsjohnr
authored andcommitted
Update anonymous.adoc
make the example code return the same thing for the do and don't do. Signed-off-by: nobletrout <[email protected]>
1 parent 5ded04d commit 555fe1f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/modules/ROOT/pages/servlet/authentication/anonymous.adoc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ Java::
148148
----
149149
@GetMapping("/")
150150
public String method(@CurrentSecurityContext SecurityContext context) {
151-
return context.getAuthentication().getName();
151+
if (context.getAuthentication() instanceOf AnonymousAuthenticationToken) {
152+
return "anonymous"
153+
} else {
154+
return "not anonymous"
155+
}
152156
}
153157
----
154158
@@ -157,7 +161,12 @@ Kotlin::
157161
[source,kotlin,role="secondary"]
158162
----
159163
@GetMapping("/")
160-
fun method(@CurrentSecurityContext context : SecurityContext) : String =
161-
context!!.authentication!!.name
164+
fun method(@CurrentSecurityContext context : SecurityContext) : String {
165+
return if (context!!.authentication is AnonymousAuthenticationToken) {
166+
"anonymous"
167+
} else {
168+
"not anonymous"
169+
}
170+
}
162171
----
163172
======

0 commit comments

Comments
 (0)