From 17436032b544efb758203064d41a57bd450cbd02 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Sun, 15 Sep 2024 12:36:12 +0100 Subject: [PATCH] Highlight when RequestScoped must be used --- docs/src/main/asciidoc/security-jwt.adoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/main/asciidoc/security-jwt.adoc b/docs/src/main/asciidoc/security-jwt.adoc index 152469dd2af8d..b4fa7d8db2327 100644 --- a/docs/src/main/asciidoc/security-jwt.adoc +++ b/docs/src/main/asciidoc/security-jwt.adoc @@ -85,7 +85,6 @@ Create a REST endpoint in `src/main/java/org/acme/security/jwt/TokenSecuredResou package org.acme.security.jwt; import jakarta.annotation.security.PermitAll; -import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.InternalServerErrorException; @@ -496,14 +495,14 @@ import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.JsonWebToken; @Path("/secured") -@RequestScoped +@RequestScoped <1> public class TokenSecuredResource { @Inject - JsonWebToken jwt; // <1> + JsonWebToken jwt; // <2> @Inject @Claim(standard = Claims.birthdate) - String birthdate; // <2> + String birthdate; // <3> @GET @Path("permit-all") @@ -526,7 +525,7 @@ public class TokenSecuredResource { @RolesAllowed("Admin") @Produces(MediaType.TEXT_PLAIN) public String helloRolesAllowedAdmin(@Context SecurityContext ctx) { - return getResponseString(ctx) + ", birthdate: " + birthdate; // <3> + return getResponseString(ctx) + ", birthdate: " + birthdate; // <4> } private String getResponseString(SecurityContext ctx) { @@ -550,9 +549,10 @@ public class TokenSecuredResource { } } ---- -<1> Here we inject the JsonWebToken. -<2> Here we inject the `birthday` claim as `String` - this is why the `@RequestScoped` scope is now required. -<3> Here we use the injected `birthday` claim to build the final reply. +<1> `RequestScoped` scope is required to support an injection of the `birthday` claim as `String`. +<2> Here we inject the JsonWebToken. +<3> Here we inject the `birthday` claim as `String` - this is why the `@RequestScoped` scope is now required. +<4> Here we use the injected `birthday` claim to build the final reply. Now generate the token again and run: