Skip to content

Commit

Permalink
Merge pull request #124 from fourix4/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TaeHoon0 authored Jul 24, 2024
2 parents f6c0738 + 6601d1b commit 54fac88
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;

import java.security.Principal;
import java.util.Map;

@EnableWebSocketMessageBroker
@Configuration
Expand All @@ -19,6 +27,12 @@ public class StompWebSocketConfig implements WebSocketMessageBrokerConfigurer {
public void registerStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint("/ws")
.setHandshakeHandler(new DefaultHandshakeHandler() {
@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
return SecurityContextHolder.getContext().getAuthentication();
}
})
.setAllowedOriginPatterns("*")
.withSockJS();
}
Expand Down

0 comments on commit 54fac88

Please sign in to comment.