diff --git a/src/main/java/com/umc/DongnaeFriend/config/JwtConfig.java b/src/main/java/com/umc/DongnaeFriend/config/JwtConfig.java index af15fc2..902da00 100644 --- a/src/main/java/com/umc/DongnaeFriend/config/JwtConfig.java +++ b/src/main/java/com/umc/DongnaeFriend/config/JwtConfig.java @@ -7,6 +7,6 @@ public class JwtConfig { @Value("${jwt.secret-key}") - public static String SECRET_KEY; + public String SECRET_KEY; } diff --git a/src/main/java/com/umc/DongnaeFriend/config/SecurityConfig.java b/src/main/java/com/umc/DongnaeFriend/config/SecurityConfig.java index 6931738..865fbbf 100644 --- a/src/main/java/com/umc/DongnaeFriend/config/SecurityConfig.java +++ b/src/main/java/com/umc/DongnaeFriend/config/SecurityConfig.java @@ -1,6 +1,7 @@ package com.umc.DongnaeFriend.config; -import com.umc.DongnaeFriend.security.JwtTokenFilter; + +import com.umc.DongnaeFriend.global.security.JwtTokenFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -30,4 +31,3 @@ protected void configure(HttpSecurity http) throws Exception { // 나머지 코드는 이전 예제와 동일 } - diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java index 67d39ea..d067631 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java @@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -35,9 +36,7 @@ public class accountBookSharingController { @GetMapping("/search") public ResponseEntity searchAll(@RequestParam("keyword") String keyword, @RequestParam("category") int category, Pageable pageable) { - log.info("searching : " + keyword + category); List res = accountBookSharingService.searchByKeyword(keyword, category, pageable); - log.info("res "); return ResponseEntity.ok(res); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java index 44692ff..54bc584 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java @@ -9,7 +9,6 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import javax.persistence.EntityManager; import java.util.List; @Repository diff --git a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/controller/DongnaeBoardController.java b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/controller/DongnaeBoardController.java index b168f28..51c4fe2 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/controller/DongnaeBoardController.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/controller/DongnaeBoardController.java @@ -3,6 +3,7 @@ import com.umc.DongnaeFriend.domain.dongnae.dto.DongnaeBoardDto; import com.umc.DongnaeFriend.domain.dongnae.respository.DongnaeBoardRepository; import com.umc.DongnaeFriend.domain.dongnae.service.DongnaeBoardService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; @@ -14,6 +15,7 @@ * [ 가계부 공유 ] * */ +@Slf4j @RestController @RequestMapping("/town-information") public class DongnaeBoardController { @@ -53,6 +55,9 @@ public ResponseEntity getLocation() { public ResponseEntity getBoards(@RequestParam("keyword") String keyword, @RequestParam("category") int category, @RequestParam("sortBy") int sort) { + + + log.info("User Id: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); return ResponseEntity.ok(dongnaeBoardService.searchByKeyword(keyword, category, sort)); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/contorller/UserController.java b/src/main/java/com/umc/DongnaeFriend/domain/user/contorller/UserController.java index d8d0374..cc30211 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/contorller/UserController.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/contorller/UserController.java @@ -8,9 +8,12 @@ import com.umc.DongnaeFriend.global.util.JwtTokenProvider; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.repository.query.Param; import org.springframework.http.*; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.HashMap; @@ -25,6 +28,7 @@ public class UserController { @Autowired UserService userService; + @Autowired JwtTokenProvider jwtTokenProvider; @@ -34,19 +38,24 @@ public class UserController { * 인증 절차 */ @PostMapping("/login") - public ResponseEntity userLogin(@RequestBody UserDto.Request request) { + public ResponseEntity userLogin(@RequestParam("accessToken") String accessToken, HttpServletRequest request, HttpServletResponse httpServletResponse) { + log.info("LoginController 진입"); + +// if (!type.equals("kakao")) { +// throw new CustomException(ErrorCode.SERVER_ERROR); +// } + + try { log.info("userLogin 진입"); //사용자 정보 가져오기 - HashMap userInfo = kakaoService.getUserInfo(request.getAccessToken()); + HashMap userInfo = kakaoService.getUserInfo(accessToken); //사용자 확인 기존 회원 -> 넘어가고, 없는 회원 -> 회원가입 - userService.userValidation(userInfo); - //토큰 생성 - String access_token = jwtTokenProvider.createAccessToken((Long) userInfo.get("userId")); - log.info("access_token : {}", access_token); - return ResponseEntity.ok(access_token); + UserDto.Response response = userService.userValidation(userInfo); + + return ResponseEntity.ok(response); } catch (IOException e) { throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/dto/UserDto.java b/src/main/java/com/umc/DongnaeFriend/domain/user/dto/UserDto.java index 469dcdb..0ebf5bc 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/dto/UserDto.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/dto/UserDto.java @@ -1,6 +1,7 @@ package com.umc.DongnaeFriend.domain.user.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; public class UserDto { @@ -16,6 +17,7 @@ public static class Request { } @Getter + @Builder @AllArgsConstructor public static class Response { diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/entity/User.java b/src/main/java/com/umc/DongnaeFriend/domain/user/entity/User.java index b6e8772..201db2e 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/entity/User.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/entity/User.java @@ -13,6 +13,7 @@ import com.umc.DongnaeFriend.domain.type.YesNo; import javax.persistence.*; import lombok.*; +import org.springframework.lang.Nullable; @Getter @Builder @@ -29,6 +30,7 @@ public class User extends BaseTimeEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "dongnae_id") + @Nullable private Dongnae dongnae; @Column(nullable = false) diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/repository/UserRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/user/repository/UserRepository.java index 5edd72b..d6d323a 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/repository/UserRepository.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/repository/UserRepository.java @@ -10,4 +10,6 @@ public interface UserRepository extends JpaRepository { Optional findById(Long id); Optional findByRefreshToken(String refresh_token); + + Optional findByKakaoId(Long id); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoService.java b/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoService.java index a4b2aaf..d3cd29f 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoService.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoService.java @@ -1,11 +1,15 @@ package com.umc.DongnaeFriend.domain.user.service; +import org.springframework.beans.factory.annotation.Value; + import java.io.IOException; import java.util.HashMap; public interface KakaoService { + + @SuppressWarnings("unchecked") HashMap getUserInfo(String access_Token) throws IOException; } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoServiceimpl.java b/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoServiceimpl.java index 4955e10..6c147f5 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoServiceimpl.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/service/KakaoServiceimpl.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.io.BufferedReader; @@ -12,6 +13,7 @@ import java.util.HashMap; import java.util.Map; +@Slf4j @Service public class KakaoServiceimpl implements KakaoService { @@ -52,23 +54,26 @@ public HashMap getUserInfo(String access_Token) throws IOExcepti Map jsonMap = objectMapper.readValue(result, new TypeReference>() { }); + System.out.println(jsonMap.get("properties")); + Long id = (Long) jsonMap.get("id"); Map properties = (Map) jsonMap.get("properties"); Map kakao_account = (Map) jsonMap.get("kakao_account"); + Map profile = (Map) kakao_account.get("profile"); - // System.out.println(properties.get("nickname")); - // System.out.println(kakao_account.get("email")); + log.info("profile : " + profile.toString()); + log.info("kakao_acount : " + kakao_account.toString()); String nickname = properties.get("nickname").toString(); + String profileImage = properties.get("profile_image").toString(); String email = kakao_account.get("email").toString(); - String gender = kakao_account.get("gender").toString(); - String age = kakao_account.get("age").toString(); + userInfo.put("id", id); userInfo.put("nickname", nickname); + userInfo.put("profileImage", profileImage); userInfo.put("email", email); - userInfo.put("gender", gender); - userInfo.put("age", age); + return userInfo; } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/user/service/UserService.java b/src/main/java/com/umc/DongnaeFriend/domain/user/service/UserService.java index 3f7e6f1..40e600c 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/user/service/UserService.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/user/service/UserService.java @@ -3,6 +3,7 @@ import com.umc.DongnaeFriend.domain.type.Age; import com.umc.DongnaeFriend.domain.type.Gender; import com.umc.DongnaeFriend.domain.type.YesNo; +import com.umc.DongnaeFriend.domain.user.dto.UserDto; import com.umc.DongnaeFriend.domain.user.entity.User; import com.umc.DongnaeFriend.domain.user.repository.UserRepository; import com.umc.DongnaeFriend.global.exception.CustomException; @@ -25,53 +26,80 @@ public class UserService { KakaoService kakaoService; + @Autowired JwtTokenProvider jwtTokenProvider; - public void userValidation(HashMap userInfo) { - Optional user= userRepository.findById((Long) userInfo.get("userId")); + public UserDto.Response userValidation(HashMap userInfo) { + Long kakao_id = (Long) userInfo.get("id"); + Optional user= userRepository.findByKakaoId(kakao_id); if (user.isEmpty()) { - userRegister(userInfo); + User new_user = userRegister(userInfo); + return UserDto.Response.builder() + .accessToken(jwtTokenProvider.createAccessToken(new_user.getId())) + .refreshToken(new_user.getRefreshToken()) + .build(); + } else { + return UserDto.Response.builder() + .accessToken(jwtTokenProvider.createAccessToken(user.get().getId())) + .refreshToken(user.get().getRefreshToken()) + .build(); } + } - //유저 회원가입 - public void userRegister(HashMap userInfo) { + //유저 회원가입 -> Refresh Token을 return + public User userRegister(HashMap userInfo) { //필수 String nickName = userInfo.get("nickname").toString(); //필수 String email = userInfo.get("email").toString(); - Optional gender = Optional.ofNullable(userInfo.get("gender").toString()); - String strGender = ""; - log.info("Gender : {}", gender.get()); - if(gender.get()=="F"){ - strGender="여성"; - }else { - strGender = "남성"; - } - log.info("strGender : {}", strGender); - - - Optional age = Optional.ofNullable(userInfo.get("age").toString()); - String[] ageRange = age.get().split("-"); - - - // refreshToken userId를 claim 으로 생성 뒤, User의 필드에 넣고 User를 저장 - String refresh_Token = jwtTokenProvider.createRefreshToken((Long) userInfo.get("usreId")); - - userRepository.save( + String profileImage = userInfo.get("profileImage").toString(); + + Long kakaoId = (Long) userInfo.get("id"); + +// Optional gender = Optional.ofNullable(userInfo.get("gender").toString()); +// String strGender = ""; +// log.info("Gender : {}", gender.get()); +// if(gender.get()=="F"){ +// strGender="여성"; +// }else { +// strGender = "남성"; +// } +// log.info("strGender : {}", strGender); +// +// +// Optional age = Optional.ofNullable(userInfo.get("age").toString()); +// String[] ageRange = age.get().split("-"); +// +// +// // refreshToken userId를 claim 으로 생성 뒤, User의 필드에 넣고 User를 저장 + String refresh_Token = jwtTokenProvider.createRefreshToken((Long) userInfo.get("id")); + + return userRepository.save( User.builder() .nickname(nickName) +// .dongnae( +// +// ) .email(email) //TODO : Gender 결정[O] - .gender(Gender.valueOf(strGender)) + .gender( +// Gender.valueOf(strGender) + Gender.MALE + ) //TODO : Age 결정[O] - .age(Age.valueOf(ageRange[0]+"대")) + .age( +// Age.valueOf(ageRange[0]+"대") + Age.AGE20 + ) .townCert(YesNo.NO) .townCertCnt(0) .infoCert(YesNo.NO) + .profileImage(profileImage) + .kakaoId(kakaoId) .refreshToken(refresh_Token) .build() ); @@ -91,4 +119,6 @@ public String createAccessTokenFromRefreshToken(String refreshToken) { return accessToken; } + + } diff --git a/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java index 986c73d..37fb335 100644 --- a/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java @@ -30,11 +30,11 @@ protected ResponseEntity handleMethodArgumentNotValidException(MethodArgument } //일반 예외처리 - @ExceptionHandler({Exception.class}) - protected ResponseEntity handleServerException(Exception ex) { - CustomException exception = new CustomException(SERVER_ERROR); - return ResponseEntity - .status(SERVER_ERROR.getHttpStatus()) - .body(new ErrorResponse(exception)); - } +// @ExceptionHandler({Exception.class}) +// protected ResponseEntity handleServerException(Exception ex) { +// CustomException exception = new CustomException(SERVER_ERROR); +// return ResponseEntity +// .status(SERVER_ERROR.getHttpStatus()) +// .body(new ErrorResponse(exception)); +// } } \ No newline at end of file diff --git a/src/main/java/com/umc/DongnaeFriend/security/JwtTokenFilter.java b/src/main/java/com/umc/DongnaeFriend/global/security/JwtTokenFilter.java similarity index 70% rename from src/main/java/com/umc/DongnaeFriend/security/JwtTokenFilter.java rename to src/main/java/com/umc/DongnaeFriend/global/security/JwtTokenFilter.java index 76834db..6c0cb55 100644 --- a/src/main/java/com/umc/DongnaeFriend/security/JwtTokenFilter.java +++ b/src/main/java/com/umc/DongnaeFriend/global/security/JwtTokenFilter.java @@ -1,9 +1,10 @@ -package com.umc.DongnaeFriend.security; +package com.umc.DongnaeFriend.global.security; import com.umc.DongnaeFriend.global.util.JwtUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; @@ -17,10 +18,22 @@ @Slf4j public class JwtTokenFilter extends OncePerRequestFilter { + + private final JwtUtil jwtUtil; + + public JwtTokenFilter(JwtUtil jwtUtil) { + this.jwtUtil = jwtUtil; + } + + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - log.info("JwtTOkenFilter 진입"); + log.info("JwtTokenFilter 진입"); + + if (request.getServletPath().contains("/user/login")) { + log.info("/user/login 진입"); + } // Request Header에서 JWT 토큰 가져오기 String authorizationHeader = request.getHeader("Authorization"); @@ -29,30 +42,37 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse //🛑 첫 로그인 시에도 이곳에서 걸리기 때문에 로그인이 안됨.(null) if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) { String token = authorizationHeader.substring(7); - log.info("token : {}",token); + log.info("token : {}", token); try { // JWT 토큰 검증 - JwtUtil.validateToken(token); + jwtUtil.validateToken(token); log.info("JWT 토큰 검증완료"); // JWT 토큰에서 사용자 정보 추출 (예: 사용자 ID) - Long userId = JwtUtil.getUserIdFromToken(token); + Long userId = jwtUtil.getUserIdFromToken(token); // 인증 객체 생성 UsernamePasswordAuthenticationToken authenticationToken = - new UsernamePasswordAuthenticationToken(userId, null, null); + new UsernamePasswordAuthenticationToken( userId,null, null); // SecurityContextHolder에 인증 객체 저장 + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + filterChain.doFilter(request, response); + } catch (Exception e) { - log.info("예외발생"); + e.printStackTrace(); // JWT 토큰 검증 실패 시, 인증 객체를 null로 설정 SecurityContextHolder.clearContext(); + filterChain.doFilter(request, response); } + } else { + log.info("Header None"); + filterChain.doFilter(request, response); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/umc/DongnaeFriend/global/util/JwtTokenProvider.java b/src/main/java/com/umc/DongnaeFriend/global/util/JwtTokenProvider.java index 85fd74b..344ba00 100644 --- a/src/main/java/com/umc/DongnaeFriend/global/util/JwtTokenProvider.java +++ b/src/main/java/com/umc/DongnaeFriend/global/util/JwtTokenProvider.java @@ -1,25 +1,27 @@ package com.umc.DongnaeFriend.global.util; +import com.umc.DongnaeFriend.config.JwtConfig; import com.umc.DongnaeFriend.domain.user.repository.UserRepository; import io.jsonwebtoken.*; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; -import javax.persistence.Id; import java.util.Date; -import static com.umc.DongnaeFriend.config.JwtConfig.SECRET_KEY; + @Log4j2 @Component public class JwtTokenProvider { + private final JwtConfig jwtConfig; + @Autowired private UserRepository userRepository; - public JwtTokenProvider(UserRepository userRepository) { + public JwtTokenProvider(JwtConfig jwtConfig, UserRepository userRepository) { + this.jwtConfig = jwtConfig; this.userRepository = userRepository; } @@ -29,6 +31,8 @@ public JwtTokenProvider(UserRepository userRepository) { //accessToken 생성 public String createAccessToken(Long userId) { + + log.info("SECRET KEY FROM PROVIDER: "+ jwtConfig.SECRET_KEY); Date now = new Date(); //현재 시간 Date validity = new Date(now.getTime() + ACCESS_TOKEN_EXPIRE_LENGTH); @@ -40,7 +44,7 @@ public String createAccessToken(Long userId) { // claims.put("email", user.getEmail()); // 사용자 이메일 return Jwts.builder() - .signWith(SignatureAlgorithm.HS512, String.valueOf(SECRET_KEY)) + .signWith(SignatureAlgorithm.HS512, String.valueOf(jwtConfig.SECRET_KEY)) .claim("userId", userId) .setIssuedAt(now) //token 발행 시간 .setExpiration(validity) @@ -53,7 +57,7 @@ public String createRefreshToken(Long userId) { Date validity = new Date(now.getTime() + REFRESH_TOKEN_EXPIRE_LENGTH); return Jwts.builder() - .signWith(SignatureAlgorithm.ES512, String.valueOf(SECRET_KEY)) + .signWith(SignatureAlgorithm.HS512, String.valueOf(jwtConfig.SECRET_KEY)) .claim("userId", userId) .setIssuedAt(now) .setExpiration(validity) diff --git a/src/main/java/com/umc/DongnaeFriend/global/util/JwtUtil.java b/src/main/java/com/umc/DongnaeFriend/global/util/JwtUtil.java index 09f0e95..a1c15b9 100644 --- a/src/main/java/com/umc/DongnaeFriend/global/util/JwtUtil.java +++ b/src/main/java/com/umc/DongnaeFriend/global/util/JwtUtil.java @@ -1,26 +1,60 @@ package com.umc.DongnaeFriend.global.util; +import com.umc.DongnaeFriend.config.JwtConfig; import com.umc.DongnaeFriend.global.exception.CustomException; import com.umc.DongnaeFriend.global.exception.ErrorCode; import io.jsonwebtoken.Claims; import io.jsonwebtoken.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; -import static com.umc.DongnaeFriend.config.JwtConfig.SECRET_KEY; +@Slf4j +@Component public class JwtUtil { - public static Long getUserIdFromToken(String token) { - Claims claims = Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token).getBody(); + private final JwtConfig jwtConfig; + + public JwtUtil(JwtConfig jwtConfig) { + this.jwtConfig = jwtConfig; + } + + public Long getUserIdFromToken(String token) { + log.info("token에서 ID 추출"); + Claims claims = Jwts.parser().setSigningKey(jwtConfig.SECRET_KEY).parseClaimsJws(token).getBody(); return Long.parseLong(claims.get("userId").toString()); } //token 유효성 검증 - public static Boolean validateToken(String token) { + public Boolean validateToken(String token) { try { - Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token); + log.info("SECRET KEY :"+ jwtConfig.SECRET_KEY); + + Jwts.parser().setSigningKey(jwtConfig.SECRET_KEY).parseClaimsJws(token); return true; - } catch (SignatureException | IllegalArgumentException | MalformedJwtException | ExpiredJwtException | - UnsupportedJwtException | NullPointerException | IllegalStateException ex) { + } catch (SignatureException e) { + log.info("Sign 오류"); + e.printStackTrace(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } catch (IllegalArgumentException e) { + log.info("잘못된 토큰"); + e.printStackTrace(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } catch (MalformedJwtException e) { + log.info("토큰 잘림"); + e.printStackTrace(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } catch (ExpiredJwtException e) { + log.info("만료된 토큰"); + e.printStackTrace(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } catch (NullPointerException e) { + log.info("토큰 없음"); + e.printStackTrace(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } catch (UnsupportedJwtException e) { + log.info("지원되지 않는 토큰"); + e.printStackTrace(); throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 857383e..c0bae2f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,8 +8,8 @@ logging: spring: datasource: url: jdbc:mysql://localhost:3306/dongnae?characterEncoding=UTF-8&serverTimezone=UTC&useLegacyDatetimeCode=false - username: - password: + username: root + password: qwe335577! driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate.ddl-auto: update @@ -18,7 +18,5 @@ spring: format_sql: true show_sql: true - - jwt: secret-key: 6B64DCA4EA2F53EDIKU9AAB215FE7 \ No newline at end of file