Accessing theme-resources inside packed jar custom authenticator

Hello All,

I am developing a custom FormAuthenticator and I would like to add the form a JavaScript file to the form using form.addScript(). The script in under theme-resources/resources/scripts inside the JAR as shown in the screenshot. I tried by all means but it did not help at all, and loading the script logs 404 error in the console as it is not found.

I would appreciate if anyone can help with that.
Screenshot 2024-07-12 044808

This can easily be achieved with code like this:

@Override
public void buildPage(FormContext context, LoginFormsProvider form) {
  ...
  Theme theme = context.getSession().theme().getTheme(Theme.Type.LOGIN);
  UrlBean urlBean = new UrlBean(context.getRealm(), theme, new URI(""), null);
  form.addScript(urlBean.getResourcesPath() + "/scripts/timer.js");
  ...
}
1 Like