-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 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
47 changes: 47 additions & 0 deletions
47
outbound/src/main/java/com/pocket/outbound/adapter/user/handler/CustomLogoutHandler.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,47 @@ | ||
package com.pocket.outbound.adapter.user.handler; | ||
|
||
import com.pocket.core.exception.jwt.SecurityCustomException; | ||
import com.pocket.core.exception.jwt.SecurityErrorCode; | ||
import com.pocket.core.redis.util.RedisUtil; | ||
import com.pocket.outbound.util.JwtUtil; | ||
import io.jsonwebtoken.ExpiredJwtException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.logout.LogoutHandler; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CustomLogoutHandler implements LogoutHandler { | ||
|
||
private final RedisUtil redisUtil; | ||
private final JwtUtil jwtUtil; | ||
|
||
@Override | ||
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { | ||
try { | ||
log.info("[*] Logout Filter"); | ||
|
||
String accessToken = jwtUtil.resolveAccessToken(request); | ||
|
||
redisUtil.saveAsValue( | ||
accessToken, | ||
"logout", | ||
jwtUtil.getExpTime(accessToken), | ||
TimeUnit.MILLISECONDS | ||
); | ||
|
||
redisUtil.delete( | ||
jwtUtil.getUsername(accessToken) + "_refresh_token" | ||
); | ||
|
||
} catch (ExpiredJwtException e) { | ||
log.warn("[*] case : accessToken expired"); | ||
throw new SecurityCustomException(SecurityErrorCode.TOKEN_EXPIRED); | ||
} | ||
} | ||
} |
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