Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix security-jwt.adoc according to quickstart project #6708

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions docs/src/main/asciidoc/security-jwt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ import java.security.Principal;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -687,8 +688,8 @@ import java.util.ArrayList;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.json.JsonString;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -703,12 +704,12 @@ import org.eclipse.microprofile.jwt.JsonWebToken;
/**
* Version 3 of the TokenSecuredResource
*/
@Path("/secured")
@RequestScoped
@Path("/secured")
@RequestScoped
public class TokenSecuredResourceV3 {

@Inject
JsonWebToken jwt;
@Inject
JsonWebToken jwt;

...

Expand Down Expand Up @@ -781,7 +782,9 @@ import java.util.Optional;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.json.JsonString;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -804,7 +807,7 @@ public class TokenSecuredResource {
JsonWebToken jwt;
@Inject // <1>
@Claim(standard = Claims.birthdate) // <2>
Optional<String> birthdate; // <3>
Optional<JsonString> birthdate; // <3>

...

Expand All @@ -818,7 +821,7 @@ public class TokenSecuredResource {

// If the JWT contains a birthdate claim, use the day of the month as a pick
if (birthdate.isPresent()) { // <4>
String bdayString = birthdate.get(); <5>
String bdayString = birthdate.get().getString(); <5>
LocalDate bday = LocalDate.parse(bdayString);
numbers.add(bday.getDayOfMonth());
remaining --;
Expand All @@ -835,7 +838,7 @@ public class TokenSecuredResource {
----
<1> We use CDI `@Inject` along with...
<2> an {mp-jwt} `@Claim(standard = Claims.birthdate)` qualifier to inject the `birthdate` claim directly as
<3> an `Optional<String>` value.
<3> an `Optional<JsonString>` value.
<4> Now we check whether the injected `birthdate` field is present
<5> and if it is, get its value.

Expand Down