-
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.
Merge pull request #69 from taco-official/KL-183/로그아웃-구현
feat(KL-183): logout
- Loading branch information
Showing
9 changed files
with
109 additions
and
20 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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/taco/klkl/global/config/security/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,29 @@ | ||
package taco.klkl.global.config.security; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.web.authentication.logout.LogoutHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import taco.klkl.domain.token.service.TokenService; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomLogoutHandler implements LogoutHandler { | ||
|
||
private final TokenService tokenService; | ||
|
||
@Override | ||
public void logout( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
Authentication authentication | ||
) { | ||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) { | ||
tokenService.deleteToken(userDetails.getUsername()); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/taco/klkl/global/config/security/CustomLogoutSuccessHandler.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,31 @@ | ||
package taco.klkl.global.config.security; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import taco.klkl.global.util.TokenUtil; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler { | ||
|
||
private final TokenUtil tokenUtil; | ||
|
||
@Override | ||
public void onLogoutSuccess( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
Authentication authentication | ||
) throws IOException { | ||
tokenUtil.clearAccessTokenCookie(response); | ||
response.setStatus(HttpStatus.NO_CONTENT.value()); | ||
response.getWriter().flush(); | ||
} | ||
} |
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
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