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

Make JWT brokers injectable #570

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dimas-b
Copy link
Contributor

@dimas-b dimas-b commented Dec 17, 2024

  • Detach TokenBrokerFactory sub-classes from Jackson-based config parsing logic.

  • Add a new unified TokenBrokerConfig under DW to hold JWT config data.

  • Resolve JWT factories through HK2 named service lookup, using the type name from TokenBrokerConfig

  • Add dedicated class NoneTokenBrokerFactory for the default do-nothing token broker implementation.

  • Yaml config (polaris-server.yml) is not affected

private String file;
private String secret;

public String getType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect you need some @JsonSetter annotations here for Jackson? (#561)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or a @JsonCreator constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Need" in what sense? It works "as is" as the receiver of the DW YAML config data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @JsonProperty for clarity.


@Override
public TokenBroker apply(RealmContext realmContext) {
if (file == null && secret == null) {
String secret = config.secret();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this check can be moved to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but I did not want to alter behaviour is this PR. Let's me know and I will move the check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for checking in the constructor, FWIW

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored (and rebased)

config.maxTokenGenerationInSeconds());
}

public interface Config {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better / simpler to have one config interface for all token broker factories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to a unified config interface.

private String file;
private String secret;

public String getType() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or a @JsonCreator constructor?

}

public interface Config {
int maxTokenGenerationInSeconds();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int maxTokenGenerationInSeconds();
Duration maxTokenGeneration();

(but I don't know if DW has support for java time)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not want to introduce functional changes in this PR. It's just a refactoring for injectability.

* Detach `TokenBrokerFactory` sub-classes from Jackson-based config parsing logic.

* Add a new unified `TokenBrokerConfig` under DW to hold JWT config data.

* Resolve JWT factories through HK2 named service lookup, using the type
  name from `TokenBrokerConfig`

* Add dedicated class `NoneTokenBrokerFactory` for the default do-nothing
  token broker implementation.

* Yaml config (`polaris-server.yml`) is not affected
@dimas-b dimas-b force-pushed the injectable-jwt-brokers branch from 29bbfb3 to b4ea9e3 Compare December 19, 2024 17:36
@dimas-b dimas-b force-pushed the injectable-jwt-brokers branch from b4ea9e3 to 39891f5 Compare December 19, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants