Why is the JWT in my OpenLiberty Application null at this point?

28 Views Asked by At

I am trying to get a JWT in my OpenLiberty Application as follows:

@Path("/hello")
@RequestScoped
public class DemoBoundary {

    @Inject
    JsonWebToken jwt;

    @GET
    @PermitAll
    public String helloWorld(@Context SecurityContext ctx){
        System.out.println(jwt.getTokenID());
        return "hello world";
    }
}

My server.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jakartaee-10.0</feature>
        <feature>microProfile-6.0</feature>
    </featureManager>

    <!-- This template enables security. To get the full use of all the capabilities, a keystore and user registry are required. -->

    <!-- For the keystore, default keys are generated and stored in a keystore. To provide the keystore password, generate an 
        encoded password using bin/securityUtility encode and add it below in the password attribute of the keyStore element. 
        Then uncomment the keyStore element. -->
    <!--
    <keyStore password=""/> 
    -->

    <!--For a user registry configuration, configure your user registry. For example, configure a basic user registry using the
        basicRegistry element. Specify your own user name below in the name attribute of the user element. For the password,
        generate an encoded password using bin/securityUtility encode and add it in the password attribute of the user element.
        Then uncomment the user element. -->
    <basicRegistry id="basic" realm="BasicRealm">
        <!--
        <user name="yourUserName" password="" />
        -->
    </basicRegistry>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <!-- Configures the application on a specified context root -->
    <webApplication contextRoot="/app-name" location="app-name.war" />

    <!-- Default SSL configuration enables trust for default certificates from the Java runtime -->
    <ssl id="defaultSSLConfig" trustDefaultCerts="true" />
</server>

In other J2E Platforms like Quarkus it works like this but in OpenLiberty it does not! When making a Post Request with the default https://jwt.io/ to test if the token get's injected, but when debugging the application inside the helloWorld method the injected jwt is always null. Am I missing somthing here?

0

There are 0 best solutions below