quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Websocket: Configurator in CDI context #22526

Open speedfl opened 2 years ago

speedfl commented 2 years ago

Description

Hello Quarkus team

It could be nice to add javax.websocket.server.ServerEndpointConfig.Configurator in CDI context so we can apply custom logic inside for authentication for example.

@ServerEndpoint(value = "/controller/{application}", configurator = AuthConfigurator.class)
@ApplicationScoped
@Slf4j
public class ControllerWebsocketServer {
@ApplicationScoped
public class AuthConfigurator extends Configurator {

  private static final String AUTHORIZATION_HEADER = "Authorization";

  @Inject
  SomeBean someBean;

  public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

  }

Implementation ideas

No response

quarkus-bot[bot] commented 2 years ago

/cc @manovotn, @mkouba

omarkad2 commented 1 year ago

Is there a workaround for this ?

lumuniz commented 1 year ago

did anyone get it? @speedfl @mkouba

mkouba commented 1 year ago

Hm, the specification does not seem to define the lifecycle of the ServerEndpointConfig.Configurator provided by the user so :shrug:. I mean Quarkus can try to lookup the bean first but we should be careful here...

Is there a workaround for this ?

You can lookup the beans using the CDI.current().select(SomeBean.class).get() or Arc.container().instance(SomeBean.class).get() directly in the AuthConfigurator. However, keep in mind that the SomeBean could be identified as an unused bean and removed. You might need to mark the bean as unremovable.