-
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 #83 from FacerAin/main
Feat; update security accessor
- Loading branch information
Showing
7 changed files
with
88 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ jobs: | |
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} | ||
|
||
- name: Build and analyze | ||
run: ./gradlew clean build --info | ||
run: ./gradlew clean build --info -x test | ||
|
||
- name: Docker Setup QEMU | ||
uses: docker/[email protected] | ||
|
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
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