diff --git a/src/main/java/com/umc/refit/domain/dto/chat/FCM.java b/src/main/java/com/umc/refit/domain/dto/chat/FCM.java new file mode 100644 index 0000000..a14057a --- /dev/null +++ b/src/main/java/com/umc/refit/domain/dto/chat/FCM.java @@ -0,0 +1,12 @@ +package com.umc.refit.domain.dto.chat; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class FCM { + private String otherFcm; +} \ No newline at end of file diff --git a/src/main/java/com/umc/refit/domain/dto/member/NameDto.java b/src/main/java/com/umc/refit/domain/dto/member/NameDto.java new file mode 100644 index 0000000..c5ec8fc --- /dev/null +++ b/src/main/java/com/umc/refit/domain/dto/member/NameDto.java @@ -0,0 +1,10 @@ +package com.umc.refit.domain.dto.member; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class NameDto { + private String name; +} diff --git a/src/main/java/com/umc/refit/domain/entity/Member.java b/src/main/java/com/umc/refit/domain/entity/Member.java index 8bd106a..4304ad8 100644 --- a/src/main/java/com/umc/refit/domain/entity/Member.java +++ b/src/main/java/com/umc/refit/domain/entity/Member.java @@ -31,6 +31,7 @@ public class Member implements UserDetails { private String socialType; private Integer gender; private String imageUrl; + private String fcm; @ElementCollection(fetch = FetchType.EAGER) private List roles = new ArrayList<>(); diff --git a/src/main/java/com/umc/refit/web/config/OAuth2ResourceServer.java b/src/main/java/com/umc/refit/web/config/OAuth2ResourceServer.java index 8694b93..b206f46 100644 --- a/src/main/java/com/umc/refit/web/config/OAuth2ResourceServer.java +++ b/src/main/java/com/umc/refit/web/config/OAuth2ResourceServer.java @@ -47,6 +47,8 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { , "/auth/reset/password" //패스워드 찾기 , "/static/**" //카카오 주소 api , "/*.html" //카카오 주소 api + , "/oauth2/fcm" + , "/auth/join/name" // , "/**" //임시로 모든 인증 처리 제외 ).permitAll() .anyRequest().authenticated()) diff --git a/src/main/java/com/umc/refit/web/controller/MemberController.java b/src/main/java/com/umc/refit/web/controller/MemberController.java index f3656b2..99e03ae 100644 --- a/src/main/java/com/umc/refit/web/controller/MemberController.java +++ b/src/main/java/com/umc/refit/web/controller/MemberController.java @@ -54,6 +54,12 @@ public ResEmailDto email(@RequestBody EmailDto emailDto) throws MessagingExcepti return new ResEmailDto(auth); } + @PostMapping("/join/name") + public void checkName(@RequestBody NameDto nameDto) { + String name = nameDto.getName(); + nameCheck(name); + } + /*회원 가입 API*/ @PostMapping("/join") public void join(@RequestBody JoinDto joinDto) { diff --git a/src/main/java/com/umc/refit/web/controller/OauthController.java b/src/main/java/com/umc/refit/web/controller/OauthController.java index a6b0e59..effb3ba 100644 --- a/src/main/java/com/umc/refit/web/controller/OauthController.java +++ b/src/main/java/com/umc/refit/web/controller/OauthController.java @@ -1,5 +1,6 @@ package com.umc.refit.web.controller; +import com.umc.refit.domain.dto.chat.FCM; import com.umc.refit.domain.dto.chat.OAuth2; import com.umc.refit.domain.entity.Member; import com.umc.refit.exception.ExceptionType; @@ -33,4 +34,14 @@ public OAuth2 auth(Authentication authentication, HttpServletRequest request) { return new OAuth2(member.getName()); } + + @GetMapping("/oauth2/fcm") + public FCM getFcm(HttpServletRequest request) { + + String otherId = request.getParameter("otherId"); + + Optional other = memberService.findMemberByName(otherId); + + return new FCM(other.get().getFcm()); + } } diff --git a/src/main/java/com/umc/refit/web/filter/authentication/JwtAuthenticationFilter.java b/src/main/java/com/umc/refit/web/filter/authentication/JwtAuthenticationFilter.java index 551fe69..bc2f42e 100644 --- a/src/main/java/com/umc/refit/web/filter/authentication/JwtAuthenticationFilter.java +++ b/src/main/java/com/umc/refit/web/filter/authentication/JwtAuthenticationFilter.java @@ -43,6 +43,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ String loginId = request.getParameter("loginId"); String password = request.getParameter("password"); + String fcm = request.getParameter("fcm"); Optional findMember = memberService.findMemberByLoginId(loginId); @@ -54,6 +55,11 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ } } + //fcm 토큰 저장 + Member member = findMember.get(); + member.setFcm(fcm); + memberService.updateFcm(member); + AuthenticationManager authenticationManager = httpSecurity.getSharedObject(AuthenticationManager.class); UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginId, password); Authentication authentication = authenticationManager.authenticate(authenticationToken); diff --git a/src/main/java/com/umc/refit/web/filter/authorization/JwtAuthorizationRsaFilter.java b/src/main/java/com/umc/refit/web/filter/authorization/JwtAuthorizationRsaFilter.java index 2b0b466..eef8578 100644 --- a/src/main/java/com/umc/refit/web/filter/authorization/JwtAuthorizationRsaFilter.java +++ b/src/main/java/com/umc/refit/web/filter/authorization/JwtAuthorizationRsaFilter.java @@ -45,6 +45,8 @@ protected boolean shouldNotFilter(HttpServletRequest request) { || pathMatcher.match("/auth/reset/password", path) //패스워드 찾기 || pathMatcher.match("/auth/login", path) //일반 로그인 || pathMatcher.match("/*.html", path) + || pathMatcher.match("/oauth2/fcm", path) + || pathMatcher.match("/auth/join/name", path) // || pathMatcher.match("/**", path) //API 테스트를 위해 모든 로직에 대해 인가 제외 ); } diff --git a/src/main/java/com/umc/refit/web/service/MemberService.java b/src/main/java/com/umc/refit/web/service/MemberService.java index da01e47..4241544 100644 --- a/src/main/java/com/umc/refit/web/service/MemberService.java +++ b/src/main/java/com/umc/refit/web/service/MemberService.java @@ -46,6 +46,10 @@ public void save(Member member) { memberRepository.save(member); } + public void updateFcm(Member member) { + memberRepository.save(member); + } + /* 회원 패스워드 수정 */ public void updateMemberPassword(Member member, String newPassword) { member.updatePassword(passwordEncoder.encode(newPassword)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7239804..0d9db3b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: jpa: hibernate: - ddl-auto: update + ddl-auto: create properties: hibernate: