-
Notifications
You must be signed in to change notification settings - Fork 8
feat: WebSocket 로깅 인터셉터 작성 #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
whqtker
merged 6 commits into
solid-connection:develop
from
whqtker:feat/634-add-websocket-interceptor
Feb 3, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a11bc4
refactor: home_university와 university_info_for_apply가 FK 관계를 가지도록
whqtker ff30af8
chore: FK 변경에 따른 목데이터 수정
whqtker 1adeb67
Merge branch 'develop' of https://github.com/whqtker/local-solid-conn…
whqtker 5897bf3
Merge branch 'develop' of https://github.com/whqtker/local-solid-conn…
whqtker 2a996dd
feat: WebSocket 로깅 인터셉터 작성
whqtker 8b15a60
refactor: Principal 명시적 형 변환 대신 null 체크하여 형 변환
whqtker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/example/solidconnection/chat/config/WebSocketLoggingInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.example.solidconnection.chat.config; | ||
|
|
||
| import com.example.solidconnection.security.authentication.TokenAuthentication; | ||
| import com.example.solidconnection.security.userdetails.SiteUserDetails; | ||
| import java.security.Principal; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.messaging.Message; | ||
| import org.springframework.messaging.MessageChannel; | ||
| import org.springframework.messaging.simp.stomp.StompCommand; | ||
| import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
| import org.springframework.messaging.support.ChannelInterceptor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @Profile("dev") | ||
| public class WebSocketLoggingInterceptor implements ChannelInterceptor { | ||
|
|
||
| @Override | ||
| public Message<?> preSend(Message<?> message, MessageChannel channel) { | ||
| StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); | ||
| StompCommand command = accessor.getCommand(); | ||
|
|
||
| if (command != null) { | ||
| Long userId = extractUserId(accessor); | ||
| String destination = accessor.getDestination(); | ||
| logStompMessage(command, destination, userId); | ||
| } | ||
|
|
||
| return message; | ||
| } | ||
|
|
||
| private void logStompMessage(StompCommand command, String destination, Long userId) { | ||
| switch (command) { | ||
| case CONNECT -> log.info("[WEBSOCKET] CONNECT userId = {}", userId); | ||
| case SUBSCRIBE -> log.info("[WEBSOCKET] SUBSCRIBE {} userId = {}", destination, userId); | ||
| case SEND -> log.info("[WEBSOCKET] SEND {} userId = {}", destination, userId); | ||
| case DISCONNECT -> log.info("[WEBSOCKET] DISCONNECT userId = {}", userId); | ||
| default -> { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private Long extractUserId(StompHeaderAccessor accessor) { | ||
| Principal user = accessor.getUser(); | ||
| if (user instanceof TokenAuthentication tokenAuth) { | ||
| Object principal = tokenAuth.getPrincipal(); | ||
| if (principal instanceof SiteUserDetails details) { | ||
| return details.getSiteUser().getId(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 인터셉터 등록 순서 문제는 발생하지 않나요?
StompHandler 보다 이전에 로깅 인터셉터가 등록 되었을 때, User Principal 을 잘 가져올 수 있는지 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
둘 다 Principal을 읽기만 하기에 문제없을 것 같습니다 !