Skip to content

Commit

Permalink
Merge pull request #20 from potenday-project/develop
Browse files Browse the repository at this point in the history
유저 정보 조회 토큰으로만 가능하도록 수정
  • Loading branch information
HwangHoYoon authored Dec 15, 2023
2 parents a5c0e17 + f75bc62 commit 88585a5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
19 changes: 0 additions & 19 deletions src/main/java/com/chwipoClova/common/config/WebMvcConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public PasswordEncoder passwordEncoder() {
@Bean
public WebSecurityCustomizer ignoringCustomizer() {
return (web) -> web.ignoring().requestMatchers("/h2-console/**", "/swagger-ui/**", "/swagger-client/**", "/api-docs/**", "/css/**", "/js/**", "/json/**", "/image/**",
"/favicon",
"/v3/api-docs/**",
"/swagger-ui.html",
"/user/login"
"/swagger-ui.html"
);
}

Expand All @@ -56,17 +56,19 @@ public SecurityFilterChain securityFilterChain(final @NotNull HttpSecurity http
.sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/**").permitAll().anyRequest().authenticated()
//.requestMatchers("/user/**", "/interview/**", "/resume/**", "/").permitAll().anyRequest().authenticated()
//.requestMatchers("/**").permitAll().anyRequest().authenticated()
.requestMatchers("/interview/**", "/resume/**", "/"
,"/user/getKakaoUrl","/user/kakaoLogin","/user/kakaoCallback","/user/logout"
).permitAll().anyRequest().authenticated()


//.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()



)
//.addFilterBefore(new JwtAuthFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class)
//.exceptionHandling((exception)-> exception.authenticationEntryPoint(new JwtAuthenticationEntryPoint()))
.addFilterBefore(new JwtAuthFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class)
.exceptionHandling((exception)-> exception.authenticationEntryPoint(new JwtAuthenticationEntryPoint()))
;
return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class JwtAuthFilter extends OncePerRequestFilter {

private final JwtUtil jwtUtil;

private String TOKEN_PREFIX = "Bearer ";

@Override
// HTTP 요청이 오면 WAS(tomcat)가 HttpServletRequest, HttpServletResponse 객체를 만들어 줍니다.
// 만든 인자 값을 받아옵니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.chwipoClova.user.response.UserInfoRes;
import com.chwipoClova.user.service.UserService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -24,6 +25,7 @@ public class TokenTestController {


@Operation(summary = "토큰 테스트 용", description = "유저 정보 조회 (테스트용)")
@Hidden
@GetMapping("/getUserInfo")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.chwipoClova.user.controller;

import com.chwipoClova.common.dto.UserDetailsImpl;
import com.chwipoClova.common.response.CommonMsgResponse;
import com.chwipoClova.common.response.CommonResponse;
import com.chwipoClova.common.response.MessageCode;
import com.chwipoClova.user.entity.User;
import com.chwipoClova.user.response.UserInfoRes;
import com.chwipoClova.user.response.UserLoginRes;
import com.chwipoClova.user.response.UserSnsUrlRes;
Expand All @@ -19,6 +21,7 @@
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -30,16 +33,16 @@ public class UserController {

private final UserService userService;

@Operation(summary = "유저 정보 조회 (테스트용)", description = "유저 정보 조회 (테스트용)")
@Operation(summary = "유저 정보 조회", description = "유저 정보 조회")
@GetMapping("/getUserInfo")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK")
}
)
public UserInfoRes getUserInfo(
@Schema(description = "이메일", example = "[email protected]", name = "email") @RequestParam(name = "email") String email
) {
return userService.selectUserInfo(email);
public UserInfoRes getUserInfo(Authentication authentication) {
UserDetailsImpl userDetailsImpl = (UserDetailsImpl)authentication.getPrincipal();
Long userId = userDetailsImpl.getUser().getUserId();
return userService.selectUserInfoForUserId(userId);
}

@Operation(summary = "카카오 로그인 URL", description = "카카오 로그인 URL")
Expand Down

0 comments on commit 88585a5

Please sign in to comment.