-
Notifications
You must be signed in to change notification settings - Fork 157
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
Pass RealmContext instance to all API methods #566
Conversation
AuthenticatedPolarisPrincipal authenticatedPrincipal = | ||
(AuthenticatedPolarisPrincipal) securityContext.getUserPrincipal(); | ||
if (authenticatedPrincipal == null) { | ||
throw new NotAuthorizedException("Failed to find authenticatedPrincipal in SecurityContext"); | ||
} | ||
|
||
PolarisEntityManager entityManager = | ||
entityManagerFactory.getOrCreateEntityManager(callContext.getRealmContext()); | ||
entityManagerFactory.getOrCreateEntityManager(realmContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can RealmContext
be a @RequestScoped
injectable (constructor) property as opposed to an explicit method parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, for 2 reasons: 1) DW does not "understand" request-scoped REST resources, and 2) Quarkus will need the parameter anyway, to add the realm id to the generated metric tags. IOW, later on the parameter will be annotated with @MeterTag
as follows:
@Context
@MeterTag(key="realm_id",expression="realmIdentifier")
RealmContext realmContext,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hypothetically: is it possible to manually produce a @RequestScoped
bean for the realm context data in the generated API code?
CallContext callContext = CallContext.getCurrentContext(); | ||
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext(); | ||
PolarisCallContext polarisRealmContext = | ||
CallContext.getCurrentContext().getPolarisCallContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rename this variable?.. It looks like its value did not change? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, result of successive refactorings 🤦♂️
This is a first step towards fixing #463.
RealmContext
is now passed as an argument to every API and Service method generated from OpenAPI specs. Passing theRealmContext
is also a prerequisite for including the realm ID as a custom tag in generated metrics.