Skip to content

[KEYCLOAK-11719] - Remove need for servlets/undertow from Quarkus dist#6600

Closed
bb-matthewc wants to merge 1 commit intokeycloak:masterfrom
jonm-bb:vertx
Closed

[KEYCLOAK-11719] - Remove need for servlets/undertow from Quarkus dist#6600
bb-matthewc wants to merge 1 commit intokeycloak:masterfrom
jonm-bb:vertx

Conversation

@bb-matthewc
Copy link
Contributor

No description provided.

@stianst stianst self-requested a review December 16, 2019 14:18
@stianst stianst self-assigned this Dec 16, 2019
@stianst stianst requested a review from pedroigor December 16, 2019 14:18
public class QuarkusFilter implements javax.ws.rs.container.ContainerRequestFilter,
javax.ws.rs.container.ContainerResponseFilter {

private static final Logger LOGGER = LoggerFactory.getLogger("QuarkusFilter");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just use QuarkusFilter.class.getName() here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

String keycloakSession = "";
for (String item: list) {
//NewCookie adds quotes around the cookie value for the KEYCLOAK_SESSION (due to /), so skipping this one.
if (item.contains("KEYCLOAK_SESSION")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have this constant already with the cookie name org.keycloak.services.managers.AuthenticationManager#KEYCLOAK_SESSION_COOKIE.

I think same goes for Set-Cookie which can be grabbed from javax.ws.rs.core.HttpHeaders#SET_COOKIE.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should wait for fix in Quarkus here, as this stuff is not very nice

@Provider
@Priority(1)
public class QuarkusFilter implements javax.ws.rs.container.ContainerRequestFilter,
javax.ws.rs.container.ContainerResponseFilter {
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 not sure whether or not a ContainerResponseFilter is invoked if an exception is thrown by applications. If not, we won't be able to perform the ending aspects of this filter such as cleaning up sessions, transactions, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think back in the early days I did try to use a JAX-RS filter instead of the servlet filter, but it didn't always work. Can't remember what the problems where though, just that I ended up with a servlet filter because I couldn't get JAX-RS filter to work fully

@pedroigor
Copy link
Contributor

Two main comments:

  • Shall we wait for issue #1340: allow multiple Set-Cookie headers vert-x3/vertx-web#1341 to me merged and be available from Quarks ? It seems to me that we would avoid those additional changes. In fact, I told you that I would be checking with Quarkus team their plans for this and I did not.

  • See my comment about the execution order of ContainerResponseFilter.

Thanks.

@pedroigor
Copy link
Contributor

@jonm-bb, this change from Stuart should help with the cookie issue quarkusio/quarkus#6218.

@bb-matthewc
Copy link
Contributor Author

Hi @pedroigor, thanks for the review. Makes sense to wait as the code will be a lot cleaner! Will fix up the other comments and push the changes when the cookie fix is in place.

<modules>
<module>quarkus</module>
</modules>
<build>
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this adds jandex indexes for all modules. Is that needed? Or do we just need it on Hibernate entities and services?

I don't think it will have any side-effect on having jandex indexes included on WildFly, but we'd need to check that since we need to build everything in one go when doing releases.

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 remember it complained about a fair number missing from the index and I tried adding them individually. Will see if I can break it down into something more manageable than everything...

public void filter(ContainerRequestContext containerRequestContext) throws IOException {

if (containerRequestContext.getMediaType() == null) {
containerRequestContext.getHeaders().add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it may have some unforeseen side-effects

@Provider
@Priority(1)
public class QuarkusFilter implements javax.ws.rs.container.ContainerRequestFilter,
javax.ws.rs.container.ContainerResponseFilter {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think back in the early days I did try to use a JAX-RS filter instead of the servlet filter, but it didn't always work. Can't remember what the problems where though, just that I ended up with a servlet filter because I couldn't get JAX-RS filter to work fully

public class QuarkusFilter implements javax.ws.rs.container.ContainerRequestFilter,
javax.ws.rs.container.ContainerResponseFilter {

private static final Logger LOGGER = LoggerFactory.getLogger("QuarkusFilter");
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

String keycloakSession = "";
for (String item: list) {
//NewCookie adds quotes around the cookie value for the KEYCLOAK_SESSION (due to /), so skipping this one.
if (item.contains("KEYCLOAK_SESSION")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should wait for fix in Quarkus here, as this stuff is not very nice

</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need quarkus-vertx-web? Not sure what it does, but I thought we only needed quarkus-verts and quarkus-resteasy


# Required for jandex index
quarkus.index-dependency.MultivalueMap.group-id=org.jboss.spec.javax.ws.rs
quarkus.index-dependency.MultivalueMap.artifact-id=jboss-jaxrs-api_2.1_spec No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a bit strange that this is needed and wouldn't then be handled by quarkus-resteasy automatically?

public class ObjectMapperResolver implements ContextResolver<ObjectMapper> {
protected ObjectMapper mapper = new ObjectMapper();

public ObjectMapperResolver() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be better to just change the constructor below to use the system property directly instead of getting "indent" passed from somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we just use the ObjectMapper instance from JsonSerialization instead of creating another instance, do we would have any collateral effect?

@stianst stianst added the Hold label Jan 10, 2020
@stianst stianst added this to the 10.0.0 milestone Mar 17, 2020
@stianst stianst removed the Hold label Apr 20, 2020
@stianst stianst modified the milestones: 10.0.0, 11.0.0 Apr 21, 2020
@pedroigor
Copy link
Contributor

@jonm-bb I've opened #7063. Basically, your changes plus others.

Do you want to have those changes here so we can continue discussions on this PR or can we move discussions to that one? Whatever you think is the best as you did most of the work :)

@stianst
Copy link
Contributor

stianst commented May 14, 2020

Merged in #7063.

Thanks @bb-matthewc

@stianst stianst closed this May 14, 2020
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.

3 participants