Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Sep 24, 2023
1 parent f4fbb24 commit 1551f31
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/jasper/config/WebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse res
logger.debug("STOMP Handshake");
if (request instanceof ServletServerHttpRequest servletRequest) {
var httpServletRequest = servletRequest.getServletRequest();
logger.debug("STOMP Handshake Header: {}", httpServletRequest.getHeader(AUTHORIZATION_HEADER));
var token = httpServletRequest.getHeader(AUTHORIZATION_HEADER);
if (isNotBlank(token)) {
attributes.put("jwt", token.substring("Bearer ".length()));
Expand Down Expand Up @@ -151,6 +152,7 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
var headers = message.getHeaders().get("nativeHeaders", Map.class);
var token = ((ArrayList<String>) headers.get("jwt")).get(0);
var origin = auth.getOrigin();
logger.debug("STOMP SUBSCRIBE Header: {} {}", origin, token);
if (tokenProvider.validateToken(token, origin)) {
logger.debug("STOMP SUBSCRIBE Credentials Header");
auth.clear(tokenProvider.getAuthentication(token, origin));
Expand All @@ -161,8 +163,15 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
}
if (auth.canSubscribeTo(accessor.getDestination())) return message;
logger.error("{} can't subscribe to {}", auth.getUserTag(), accessor.getDestination());
logger.debug("Auth: {}", auth.getAuthentication());
logger.debug("Principal: {}", auth.getPrincipal());
logger.debug("Type: {}", auth.getAuthentication().getClass());
logger.debug("Origin: {}", auth.getOrigin());
logger.debug("Client List: {}", props.getSecurity().getClients().keySet());
logger.debug("Client: {}", auth.getClient());
logger.debug("JWKS: {}", auth.getClient().getAuthentication().getJwt().getJwksUri());
} catch (Exception e) {
logger.warn("Cannot authorize websocket subscription.");
logger.warn("Cannot authorize websocket subscription.", e);
}
logger.error("Websocket authentication failed.");
return null;
Expand Down

0 comments on commit 1551f31

Please sign in to comment.