Good Day. I am developing an IAM system using Keycloak. I have a task to develop an endpoint that will accept websocket requests and produce some kind of logic. I implemented the interface RealmResourceProvider
and RealmResourceProviderFactory
and then made an endpoint. However, when I try to establish a connection, I get an exception:
Subresource for target class has no jax-rs annotations.
As follows from the exception, it is necessary to define the get or post annotations, however, when defining them, other exceptions are thrown, such as an incorrect mime type. I think this is due to the fact that keycloak uses the jax-rs library by default, which is not compatible with the javax.websocket library. I did not find anything in the official documentation of keycloak, nor did I find any examples on the Internet. Any ideas or examples? Does keycloak support such functionality at all? Keycloak version 14.00 with Wildfly server 23. Thanks
Code
public class WebSocketStreamResourceProviderFactory implements RealmResourceProviderFactory {
private final static String ID = "state-stream";
@Override
public RealmResourceProvider create(KeycloakSession session) {
return new WebSocketStreamResourceProvider(session);
}
@Override
public void init(Scope config) {
//dont need
}
@Override
public void postInit(KeycloakSessionFactory factory) {
//dont need
}
@Override
public void close() {
//dont need
}
public class WebSocketStreamResourceProvider implements RealmResourceProvider {
private final KeycloakSession session;
public WebSocketStreamResourceProvider(KeycloakSession session) {
this.session = session;
}
@Override
public Object getResource() {
//some objects
return new WebSocketStreamResource(some objects);
}
@Override
public void close() {
//dont need
}
public class WebSocketStreamResource extends Endpoint {
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
// some logic
}
}