Skip to content

Instantly share code, notes, and snippets.

@raupachz
Created January 9, 2022 18:02
Show Gist options
  • Save raupachz/6719948cac2c6e202d1fe1f9cfde3806 to your computer and use it in GitHub Desktop.
Save raupachz/6719948cac2c6e202d1fe1f9cfde3806 to your computer and use it in GitHub Desktop.
Decoding a JWT in a JavaServer Faces backing bean
@Named
@SessionScoped
public class UserBean implements Serializable {
private Map<String, Object> claims;
@PostConstruct
public void postConstruct() {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest httpServletRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();
String jwt = httpServletRequest.getHeader("x-amzn-oidc-data");
claims = JWT.of(jwt);
}
public String getName() {
return (String) claims.get("name");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment