File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
docs/modules/ROOT/pages/servlet/authentication Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,11 @@ Java::
148148----
149149@GetMapping("/")
150150public 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======
You can’t perform that action at this time.
0 commit comments