Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 로그아웃 반환 Dto 설정 #22

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,25 @@ public ResponseEntity<TokenResponseDto> login(@RequestBody LoginRequestDto login

@PostMapping(value = "/logout")
@Operation(summary = "로그아웃", description = "JWt 토큰을 redis에서 삭제합니다")
public ResponseEntity<Void> logout( @RequestHeader(name = "ACCESS_TOKEN", required = false) String accessToken,
public ResponseEntity<LogoutResponseDto> logout( @RequestHeader(name = "ACCESS_TOKEN", required = false) String accessToken,
@RequestHeader(name = "REFRESH_TOKEN", required = false) String refreshToken) {
String message = "";
HttpStatus status = HttpStatus.OK;
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserDetailsImpl userDetails = (UserDetailsImpl) principal;
String email = userDetails.getUsername();
log.info("토큰으로부터 이메일을 추출하였습니다.: "+email);
memberService.logout(email, accessToken);
return ResponseEntity.ok().build();
try {
memberService.logout(email, accessToken);
message ="로그아웃을 성공적으로 완료했습니다.";
} catch (Exception ex){
throw new CustomException("로그아웃과정 중 에러가 발생했습니다. : "+ ex.getMessage());
}
LogoutResponseDto logoutResponseDto
= LogoutResponseDto.builder().
result(message).
build();
return ResponseEntity.status(status).body(logoutResponseDto);
}

@PatchMapping("/address")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.SafeNet.Backend.domain.member.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;

@Builder
@Data
@AllArgsConstructor
@ToString
@Schema(description ="로그아웃 Dto")
public class LogoutResponseDto {
@Schema(description = "로그아웃 결과", required = true, example = "로그아웃에 성공했습니다.")
@NotNull
String result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import com.SafeNet.Backend.global.auth.JwtTokenProvider;
import com.SafeNet.Backend.global.exception.JwtAccessDeniedHandler;
import com.SafeNet.Backend.global.exception.JwtAuthenticationEntryPoint;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
Expand Down Expand Up @@ -59,10 +56,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/", "/api/auth/**", "/swagger-ui/**", "/v3/api-docs/**", "/s3/test", "/ws-stomp/**").permitAll() // 특정 경로에 대한 접근 허용
// .requestMatchers(HttpMethod.GET,"/api/v2/posts/{postId}").permitAll() // GET 요청 허용
.anyRequest().authenticated()) // 나머지 요청은 인증 필요
//.formLogin(form -> form
// .loginPage("/login").permitAll()) // 로그인 페이지 설정
//.logout(logout -> logout
// .logoutSuccessUrl("/").permitAll()) // 로그아웃 성공시 리다이렉션 설정
.exceptionHandling(authenticationManager -> authenticationManager
.accessDeniedHandler(jwtAccessDeniedHandler)
.authenticationEntryPoint(jwtAuthenticationEntryPoint))
Expand Down
Loading