Skip to content

Commit

Permalink
Merge pull request #40 from TEAM-DHS/fix/logout
Browse files Browse the repository at this point in the history
[FIX] 로그아웃 에러 해결
  • Loading branch information
mingulmangul authored Nov 22, 2023
2 parents 47eb310 + ef7d355 commit 01af29f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

import com.efub.dhs.domain.member.dto.AuthRequestDto;
import com.efub.dhs.domain.member.dto.AuthResponseDto;
Expand Down Expand Up @@ -47,6 +48,9 @@ public AuthResponseDto logIn(@RequestBody @Valid AuthRequestDto requestDto) {
@ResponseStatus(HttpStatus.NO_CONTENT)
public void logout(HttpServletRequest request) {
String accessToken = resolveToken(request);
if (accessToken == null) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Empty Access Token.");
}
jwtService.removeJwtToken(accessToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.authorizeRequests()
.antMatchers("/members/**").authenticated()
.antMatchers(HttpMethod.GET).permitAll()
.antMatchers("/auth/logout").authenticated()
.antMatchers("/auth/**", "/oauth/**").permitAll()
.anyRequest().authenticated()
.and()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/efub/dhs/global/jwt/entity/JwtToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Getter
@AllArgsConstructor
@RedisHash(value = "jwtToken", timeToLive = 60 * 60 * 24 * 2)
@RedisHash(value = "jwtToken", timeToLive = 60 * 60 * 24 * 14)
public class JwtToken {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.efub.dhs.global.jwt.service;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import com.efub.dhs.global.jwt.auth.JwtAuthProvider;
import com.efub.dhs.global.jwt.entity.JwtToken;
Expand Down Expand Up @@ -34,6 +36,6 @@ public JwtToken refreshToken(String accessToken) {

private JwtToken getJwtToken(String accessToken) {
return jwtRepository.findByAccessToken(accessToken)
.orElseThrow(() -> new SecurityException("JWT token is invalid."));
.orElseThrow(() -> new ResponseStatusException(HttpStatus.FORBIDDEN, "Invalid Access Token."));
}
}

0 comments on commit 01af29f

Please sign in to comment.