-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from dnd-side-project/dev
Dev->Main
- Loading branch information
Showing
5 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
36 changes: 36 additions & 0 deletions
36
src/main/java/org/dnd/timeet/common/interceptor/CustomHandshakeInterceptor.java
This file contains 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,36 @@ | ||
package org.dnd.timeet.common.interceptor; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.http.server.ServerHttpRequest; | ||
import org.springframework.http.server.ServerHttpResponse; | ||
import org.springframework.http.server.ServletServerHttpRequest; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.socket.WebSocketHandler; | ||
import org.springframework.web.socket.server.HandshakeInterceptor; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
public class CustomHandshakeInterceptor implements HandshakeInterceptor { | ||
|
||
@Override | ||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, | ||
WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { | ||
if (request instanceof ServletServerHttpRequest) { | ||
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
if (authentication != null) { | ||
attributes.put("user", authentication.getPrincipal()); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, | ||
WebSocketHandler wsHandler, Exception exception) { | ||
} | ||
} |
This file contains 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
This file contains 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