-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JT-29] feat: ThreadLocal, Interceptor 추가 구현
- Loading branch information
Showing
9 changed files
with
88 additions
and
16 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
17 changes: 17 additions & 0 deletions
17
module-application/src/main/java/com/devtoon/jtoon/security/config/WebConfig.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,17 @@ | ||
package com.devtoon.jtoon.security.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import com.devtoon.jtoon.security.interceptor.MemberInterceptor; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(new MemberInterceptor()) | ||
.addPathPatterns("/**"); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...e-application/src/main/java/com/devtoon/jtoon/security/interceptor/MemberInterceptor.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,22 @@ | ||
package com.devtoon.jtoon.security.interceptor; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import com.devtoon.jtoon.security.jwt.domain.MemberThreadLocal; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
public class MemberInterceptor implements HandlerInterceptor { | ||
|
||
@Override | ||
public void afterCompletion( | ||
@NotNull HttpServletRequest request, | ||
@NotNull HttpServletResponse response, | ||
@NotNull Object handler, | ||
Exception ex) throws Exception { | ||
if (MemberThreadLocal.getMember() != null) { | ||
MemberThreadLocal.clear(); | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...le-application/src/main/java/com/devtoon/jtoon/security/jwt/domain/MemberThreadLocal.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,24 @@ | ||
package com.devtoon.jtoon.security.jwt.domain; | ||
|
||
import com.devtoon.jtoon.member.entity.Member; | ||
|
||
public final class MemberThreadLocal { | ||
|
||
private static final ThreadLocal<Member> memberThreadLocal; | ||
|
||
static { | ||
memberThreadLocal = new ThreadLocal<>(); | ||
} | ||
|
||
public static Member getMember() { | ||
return memberThreadLocal.get(); | ||
} | ||
|
||
public static void setMember(Member member) { | ||
memberThreadLocal.set(member); | ||
} | ||
|
||
public static void clear() { | ||
memberThreadLocal.remove(); | ||
} | ||
} |