From 61f192dcaf6aa06aee40d03f7029e95f2b57ac34 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Thu, 22 Jun 2023 21:09:36 +0900 Subject: [PATCH 01/14] =?UTF-8?q?refactor:=20=ED=9A=8C=EC=9B=90=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EC=A1=B0=ED=9A=8C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/rainbow/sof/domain/user/entity/User.java | 2 +- .../java/com/rainbow/sof/domain/user/mapper/UserMapper.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/entity/User.java b/server/src/main/java/com/rainbow/sof/domain/user/entity/User.java index d692c7a1..10da457a 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/entity/User.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/entity/User.java @@ -41,7 +41,7 @@ public User(long userId, String password, String email, String name, @Column(nullable = false) private String password; @Email - @Column(nullable = false, updatable = false) + @Column(nullable = false) private String email; @Column(nullable = false) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java b/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java index 5492aef8..30ad319f 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java @@ -32,7 +32,7 @@ default MyPageResponseDto userToMyPageDto(User user){ List AnsweList = user.getAnswerList().stream() .map(answer ->AnswerDto.MyPageAnswerResponse.builder() .answerId(answer.getAnswerId()) - .modifiedAt(answer.getModifiedAt()) + .createdAt(answer.getModifiedAt()) .modifiedAt(answer.getModifiedAt()) .content(answer.getContent()) .build()) @@ -42,6 +42,7 @@ default MyPageResponseDto userToMyPageDto(User user){ .name(user.getName()) .createdAt(user.getCreatedAt()) .questionList(questionList) + .AnswerList(AnsweList) .build(); } } From b2aa2e9fab6ea3e9330a1dba8985c60ba2fba8da Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 00:17:08 +0900 Subject: [PATCH 02/14] =?UTF-8?q?fix:=20=EC=88=9C=ED=99=98=20=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20-=20confi?= =?UTF-8?q?g=EC=99=80=20UserService=EA=B0=84=20=EC=88=9C=ED=99=98=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=20=EB=AC=B8=EC=A0=9C=20=EB=B0=9C=EC=83=9D=20?= =?UTF-8?q?-=20=20=EC=9B=90=EC=9D=B8=EC=9D=B8=20PasswordEncoder=20?= =?UTF-8?q?=EB=A5=BC=20=EB=B3=84=EB=8F=84=EC=9D=98=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/PasswordEncoderBean.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 server/src/main/java/com/rainbow/sof/domain/user/service/PasswordEncoderBean.java diff --git a/server/src/main/java/com/rainbow/sof/domain/user/service/PasswordEncoderBean.java b/server/src/main/java/com/rainbow/sof/domain/user/service/PasswordEncoderBean.java new file mode 100644 index 00000000..042bb42d --- /dev/null +++ b/server/src/main/java/com/rainbow/sof/domain/user/service/PasswordEncoderBean.java @@ -0,0 +1,15 @@ +package com.rainbow.sof.domain.user.service; + +import org.springframework.context.annotation.Bean; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Component; + +@Component +public class PasswordEncoderBean { + @Bean + public PasswordEncoder passwordEncoder() { + + return PasswordEncoderFactories.createDelegatingPasswordEncoder(); + } +} From 6b754096b08c3db00daf4bf8994cfc0f0eb9965e Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 13:57:02 +0900 Subject: [PATCH 03/14] =?UTF-8?q?fix:=20oAuth=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=ED=9B=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?-=20@SpringBootTest=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rainbow/sof/domain/answer/AnswerControllerTest.java | 6 ++++-- .../rainbow/sof/domain/question/QuestionControllerTest.java | 6 ++++-- .../sof/domain/question/QuestionVoteControllerTest.java | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/com/rainbow/sof/domain/answer/AnswerControllerTest.java b/server/src/test/java/com/rainbow/sof/domain/answer/AnswerControllerTest.java index 262efd5c..d89c5bc6 100644 --- a/server/src/test/java/com/rainbow/sof/domain/answer/AnswerControllerTest.java +++ b/server/src/test/java/com/rainbow/sof/domain/answer/AnswerControllerTest.java @@ -17,6 +17,7 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; @@ -37,8 +38,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@Import({SecurityConfiguration.class, JwtTokenizer.class}) -@WebMvcTest(AnswerController.class) +//@Import({SecurityConfiguration.class, JwtTokenizer.class}) +//@WebMvcTest(AnswerController.class) +@SpringBootTest @AutoConfigureMockMvc @AutoConfigureRestDocs @TestInstance(TestInstance.Lifecycle.PER_CLASS) diff --git a/server/src/test/java/com/rainbow/sof/domain/question/QuestionControllerTest.java b/server/src/test/java/com/rainbow/sof/domain/question/QuestionControllerTest.java index b817b847..a51f51e0 100644 --- a/server/src/test/java/com/rainbow/sof/domain/question/QuestionControllerTest.java +++ b/server/src/test/java/com/rainbow/sof/domain/question/QuestionControllerTest.java @@ -20,6 +20,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -49,8 +50,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@Import({SecurityConfiguration.class, JwtTokenizer.class}) -@WebMvcTest(QuestionController.class) +//@Import({SecurityConfiguration.class, JwtTokenizer.class}) +//@WebMvcTest(QuestionController.class) +@SpringBootTest @AutoConfigureMockMvc @AutoConfigureRestDocs @TestInstance(TestInstance.Lifecycle.PER_CLASS) diff --git a/server/src/test/java/com/rainbow/sof/domain/question/QuestionVoteControllerTest.java b/server/src/test/java/com/rainbow/sof/domain/question/QuestionVoteControllerTest.java index 605f8d8f..8874fe45 100644 --- a/server/src/test/java/com/rainbow/sof/domain/question/QuestionVoteControllerTest.java +++ b/server/src/test/java/com/rainbow/sof/domain/question/QuestionVoteControllerTest.java @@ -18,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; @@ -38,8 +39,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@Import({SecurityConfiguration.class, JwtTokenizer.class}) -@WebMvcTest(QuestionVoteController.class) +//@Import({SecurityConfiguration.class, JwtTokenizer.class}) +//@WebMvcTest(QuestionVoteController.class) +@SpringBootTest @AutoConfigureMockMvc @AutoConfigureRestDocs @TestInstance(TestInstance.Lifecycle.PER_CLASS) From 47f6f41ce718356913e00435ffe41cb842006b56 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 13:58:28 +0900 Subject: [PATCH 04/14] =?UTF-8?q?refactor:=20DEFAULT=5FURL=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rainbow/sof/domain/user/util/CustomEnumUri.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/util/CustomEnumUri.java b/server/src/main/java/com/rainbow/sof/domain/user/util/CustomEnumUri.java index a891ff79..87783fc8 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/util/CustomEnumUri.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/util/CustomEnumUri.java @@ -4,7 +4,7 @@ public enum CustomEnumUri { - + DEFAULT_URL("/api/v1"), USER_DEFAULT_URL("/api/v1/users"), DELETE_ACTION_URL("/signup"), QUESTION_DEFAULT_URL("/api/v1/questions"); From e8742db582e105868e38c30d7500ce0d2612b97d Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 13:59:29 +0900 Subject: [PATCH 05/14] =?UTF-8?q?feat:=20OAuth=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=95=84=ED=84=B0=20=EC=B6=94=EA=B0=80=20-=20OAuth?= =?UTF-8?q?2LoginAuthenticationFilter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauthHandler/OAuth2FailureHandler.java | 16 ++++ .../oauthHandler/OAuth2SuccessHandler.java | 94 +++++++++++++++++++ .../user/config/CustomFilterConfigurer.java | 22 ++++- 3 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2FailureHandler.java create mode 100644 server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2SuccessHandler.java diff --git a/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2FailureHandler.java b/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2FailureHandler.java new file mode 100644 index 00000000..5670b51b --- /dev/null +++ b/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2FailureHandler.java @@ -0,0 +1,16 @@ +//package com.rainbow.sof.domain.user.auth.handler.oauthHandler; +// +//import org.springframework.security.core.AuthenticationException; +//import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; +// +//import javax.servlet.ServletException; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +// +//public class OAuth2FailureHandler extends SimpleUrlAuthenticationFailureHandler { +// @Override +// public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { +// chain.doFilter(httpRequest,response); +// } +//} diff --git a/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2SuccessHandler.java b/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2SuccessHandler.java new file mode 100644 index 00000000..ac620469 --- /dev/null +++ b/server/src/main/java/com/rainbow/sof/domain/user/auth/handler/oauthHandler/OAuth2SuccessHandler.java @@ -0,0 +1,94 @@ +package com.rainbow.sof.domain.user.auth.handler.oauthHandler; + +import com.rainbow.sof.domain.user.auth.jwt.DelegateTokenService; +import com.rainbow.sof.domain.user.auth.jwt.JwtTokenizer; +import com.rainbow.sof.domain.user.entity.User; +import com.rainbow.sof.domain.user.service.UserService; +import com.rainbow.sof.global.error.BusinessLogicException; +import com.rainbow.sof.global.error.ExceptionCode; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static com.rainbow.sof.domain.user.util.CustomEnumUri.*; + +@Slf4j +public class OAuth2SuccessHandler extends SimpleUrlAuthenticationSuccessHandler { + private final DelegateTokenService delegateTokenService; + private final UserService userService; + + public OAuth2SuccessHandler(DelegateTokenService delegateTokenService, UserService userService) { + this.delegateTokenService = delegateTokenService; + this.userService = userService; + } + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { + OAuth2User UserData = (OAuth2User)authentication.getPrincipal(); + String email = String.valueOf(UserData.getAttributes().get("email")); + String name = String.valueOf(UserData.getAttributes().get("name")); + + User createUser = User.builder().email(email) + .name(name) + .password("Q1234123452234522").build(); + User oAuth2User= saveUser(createUser); + log.info("onAuthenticationSuccess: {} ", oAuth2User.getName()); + log.info("onAuthenticationSuccess: {}" ,oAuth2User.getEmail()); + redirect(request, response,oAuth2User); + + } + + private User saveUser(User oAuth2User) { + try { + return userService.createUser(oAuth2User); + }catch (BusinessLogicException e){ + + return e.getExceptionCode().equals(ExceptionCode.USER_EXISTS) ? + userService.findByUserFromEmail(oAuth2User.getEmail()) : + null; + } + } + + private void redirect(HttpServletRequest request, HttpServletResponse response, User user) throws IOException { + String accessToken = delegateTokenService.delegateAccessToken(user); + String refreshToken = delegateTokenService.delegateRefreshToken(user); + + + String uri = createURI().toString(); + response.setHeader("Authorization", "Bearer " + accessToken); + response.setHeader("Refresh",refreshToken); + + getRedirectStrategy().sendRedirect(request, response, "/mypage"); + String s = getRedirectStrategy().toString(); + } + + //TODO: 클라이언트 주소로 변경 필요 + private URI createURI() { + return UriComponentsBuilder + .newInstance() + .scheme("http") + .host("localhost") +// .port(80) + .path("/receive-token.html") + .build() + .toUri(); + } + + +} +// Map oAuth2UserData = new HashMap<>(); +// oAuth2UserData.put("email", String.valueOf(oAuth2User.getAttributes().get("email"))); +// oAuth2UserData.put("name", String.valueOf(oAuth2User.getAttributes().get("name"))); +// User createUser= saveUser(oAuth2UserData); \ No newline at end of file diff --git a/server/src/main/java/com/rainbow/sof/domain/user/config/CustomFilterConfigurer.java b/server/src/main/java/com/rainbow/sof/domain/user/config/CustomFilterConfigurer.java index bf3c54e5..405fd1f6 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/config/CustomFilterConfigurer.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/config/CustomFilterConfigurer.java @@ -4,25 +4,35 @@ import com.rainbow.sof.domain.user.auth.filter.JwtVerificationFilterV2; import com.rainbow.sof.domain.user.auth.handler.loginhandle.UserAuthenticationFailureHandler; import com.rainbow.sof.domain.user.auth.handler.loginhandle.UserAuthenticationSuccessHandler; +import com.rainbow.sof.domain.user.auth.handler.oauthHandler.OAuth2SuccessHandler; +import com.rainbow.sof.domain.user.auth.jwt.DelegateTokenService; import com.rainbow.sof.domain.user.auth.jwt.JwtTokenizer; +import com.rainbow.sof.domain.user.service.UserService; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter; +import org.springframework.stereotype.Component; +@Component public class CustomFilterConfigurer extends AbstractHttpConfigurer { private final JwtTokenizer jwtTokenizer; + public final DelegateTokenService delegateTokenService; - public CustomFilterConfigurer(JwtTokenizer jwtTokenizer) { + + public CustomFilterConfigurer(JwtTokenizer jwtTokenizer, DelegateTokenService delegateTokenService) { this.jwtTokenizer = jwtTokenizer; + this.delegateTokenService = delegateTokenService; + } @Override public void configure(HttpSecurity builder) throws Exception { AuthenticationManager authenticationManager = builder.getSharedObject(AuthenticationManager.class); - JwtAuthenticationFilter jwtAuthenticationFilter = new JwtAuthenticationFilter(authenticationManager,jwtTokenizer); + JwtAuthenticationFilter jwtAuthenticationFilter = new JwtAuthenticationFilter(authenticationManager,jwtTokenizer,delegateTokenService); jwtAuthenticationFilter.setFilterProcessesUrl("/api/v1/login"); jwtAuthenticationFilter.setAuthenticationSuccessHandler(new UserAuthenticationSuccessHandler()); @@ -30,7 +40,11 @@ public void configure(HttpSecurity builder) throws Exception { JwtVerificationFilterV2 jwtVerificationFilterV2 = new JwtVerificationFilterV2(jwtTokenizer); - builder.addFilter(jwtAuthenticationFilter) - .addFilterAfter(jwtVerificationFilterV2,JwtAuthenticationFilter.class); + builder.addFilterAfter(jwtVerificationFilterV2, OAuth2LoginAuthenticationFilter.class) + .addFilterBefore(jwtAuthenticationFilter,JwtVerificationFilterV2.class); } + +//.addFilter(jwtAuthenticationFilter) +// .addFilterAfter(jwtVerificationFilterV2,JwtAuthenticationFilter.class); + } From 6e36861798005366df94d3204374720169576587 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 13:59:52 +0900 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20OAuth=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20URL=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/config/SecurityConfiguration.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java b/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java index eb8d937a..17b409bb 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java @@ -1,15 +1,22 @@ package com.rainbow.sof.domain.user.config; import com.rainbow.sof.domain.user.auth.handler.authError.UserAuthenticationEntryPoint; +import com.rainbow.sof.domain.user.auth.handler.oauthHandler.OAuth2SuccessHandler; +import com.rainbow.sof.domain.user.auth.jwt.DelegateTokenService; import com.rainbow.sof.domain.user.auth.jwt.JwtTokenizer; import com.rainbow.sof.domain.user.config.CustomFilterConfigurer; +import com.rainbow.sof.domain.user.service.UserService; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.stereotype.Component; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -23,15 +30,20 @@ @Configuration public class SecurityConfiguration { private final JwtTokenizer jwtTokenizer; + private final DelegateTokenService delegateTokenService; + private final UserService userService; + private final static String USER_DETAIL_URL="/api/v1/users"; - public SecurityConfiguration(JwtTokenizer jwtTokenizer) { + public SecurityConfiguration(JwtTokenizer jwtTokenizer, DelegateTokenService delegateTokenService, UserService userService) { this.jwtTokenizer = jwtTokenizer; + this.delegateTokenService = delegateTokenService; + this.userService = userService; } - @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{ + http .headers().frameOptions().sameOrigin() .and() @@ -44,9 +56,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{ .exceptionHandling() .authenticationEntryPoint(new UserAuthenticationEntryPoint()) .and() - .apply(customFilterConfigurer()) + .oauth2Login(oauth2 -> oauth2 + .loginPage("/api/v1/oath/login") + .successHandler(new OAuth2SuccessHandler(delegateTokenService,userService)) + ) + .apply(customFilterConfigurers()) .and() .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry + .antMatchers("/api/v1/oath/login").permitAll() .antMatchers(HttpMethod.PATCH,"/api/v1/questions/**").hasRole("USER") .antMatchers(HttpMethod.POST,"/api/v1/questions/**").hasRole("USER") .antMatchers(HttpMethod.DELETE,"/api/v1/questions/**").hasRole("USER") @@ -57,14 +74,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{ } @Bean - public CustomFilterConfigurer customFilterConfigurer(){ - return new CustomFilterConfigurer(jwtTokenizer); - } - @Bean - public PasswordEncoder passwordEncoder(){ - return PasswordEncoderFactories.createDelegatingPasswordEncoder(); + public CustomFilterConfigurer customFilterConfigurers(){ + return new CustomFilterConfigurer(jwtTokenizer, delegateTokenService); } +// @Bean +// public PasswordEncoder passwordEncoder(){ +// return PasswordEncoderFactories.createDelegatingPasswordEncoder(); +// } + + @Bean CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); From 267667dde307d00a0210c1cf38d6783907db8dcf Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:00:30 +0900 Subject: [PATCH 07/14] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94=20-?= =?UTF-8?q?=20=EB=A7=8C=EC=95=BD=EC=9D=98=20=EC=83=81=ED=99=A9=EC=9D=84=20?= =?UTF-8?q?=EB=8C=80=EB=B9=84=20=ED=95=98=EC=97=AC=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=ED=95=98=EC=A7=80=EB=8A=94=20=EC=95=8A=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/filter/JwtAuthenticationFilter.java | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/auth/filter/JwtAuthenticationFilter.java b/server/src/main/java/com/rainbow/sof/domain/user/auth/filter/JwtAuthenticationFilter.java index 43e40133..6a4e8046 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/auth/filter/JwtAuthenticationFilter.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/auth/filter/JwtAuthenticationFilter.java @@ -1,6 +1,7 @@ package com.rainbow.sof.domain.user.auth.filter; import com.fasterxml.jackson.databind.ObjectMapper; +import com.rainbow.sof.domain.user.auth.jwt.DelegateTokenService; import com.rainbow.sof.domain.user.auth.jwt.JwtTokenizer; import com.rainbow.sof.domain.user.dto.singleDto.UserDto; import com.rainbow.sof.domain.user.entity.User; @@ -22,9 +23,12 @@ public class JwtAuthenticationFilter extends UsernamePasswordAuthenticationFilter { private final AuthenticationManager authenticationManager; private final JwtTokenizer tokenizer; - public JwtAuthenticationFilter(AuthenticationManager authenticationManager, JwtTokenizer tokenizer) { + public final DelegateTokenService delegateTokenService; + + public JwtAuthenticationFilter(AuthenticationManager authenticationManager, JwtTokenizer tokenizer, DelegateTokenService delegateTokenService) { this.authenticationManager = authenticationManager; this.tokenizer = tokenizer; + this.delegateTokenService = delegateTokenService; } @Override @@ -47,8 +51,8 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR User user = (User)authResult.getPrincipal(); - String accessToken = delegateAccessToken(user); - String refreshToken = delegateRefreshToken(user); + String accessToken = delegateTokenService.delegateAccessToken(user); + String refreshToken = delegateTokenService.delegateRefreshToken(user); response.setHeader("Authorization", "Bearer " + accessToken); response.setHeader("Refresh",refreshToken); @@ -57,25 +61,26 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR } - private String delegateAccessToken(User user){ - Map claims = new HashMap<>(); - claims.put("email",user.getEmail()); - - Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); - String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); - String subject=user.getEmail(); - - return tokenizer.generateAccessToken(claims,subject,expiration,base64EncodedSecretKeyString); - - } - - private String delegateRefreshToken(User user){ - - Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); - String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); - String subject=user.getEmail(); - - return tokenizer.generateRefreshToken(subject,expiration,base64EncodedSecretKeyString); - - } + //TODO: 이전 토큰 생성 메서드 +// private String delegateAccessToken(User user){ +// Map claims = new HashMap<>(); +// claims.put("email",user.getEmail()); +// +// Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); +// String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); +// String subject=user.getEmail(); +// +// return tokenizer.generateAccessToken(claims,subject,expiration,base64EncodedSecretKeyString); +// +// } +// +// private String delegateRefreshToken(User user){ +// +// Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); +// String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); +// String subject=user.getEmail(); +// +// return tokenizer.generateRefreshToken(subject,expiration,base64EncodedSecretKeyString); +// +// } } From 0af0fb0a19e7ce9fc8e06cd1de34934fbdea02d9 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:01:08 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=ED=99=94=20-?= =?UTF-8?q?=20JWT=20=EC=99=80=20oAuth=20=EC=9D=98=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/auth/jwt/DelegateTokenService.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/DelegateTokenService.java diff --git a/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/DelegateTokenService.java b/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/DelegateTokenService.java new file mode 100644 index 00000000..922924dc --- /dev/null +++ b/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/DelegateTokenService.java @@ -0,0 +1,40 @@ +package com.rainbow.sof.domain.user.auth.jwt; + +import com.rainbow.sof.domain.user.entity.User; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +@Component +public class DelegateTokenService { + private final JwtTokenizer tokenizer; + + public DelegateTokenService(JwtTokenizer tokenizer) { + this.tokenizer = tokenizer; + } + + public String delegateAccessToken(User user){ + Map claims = new HashMap<>(); + claims.put("email",user.getEmail()); + + Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); + String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); + String subject=user.getEmail(); + + return tokenizer.generateAccessToken(claims,subject,expiration,base64EncodedSecretKeyString); + + } + + public String delegateRefreshToken(User user){ + + Date expiration = tokenizer.getTokenExpiration(tokenizer.getAccessTokenExpirationMinutes()); + String base64EncodedSecretKeyString = tokenizer.secretKeyEncodeBase64(tokenizer.getSecretKeySting()); + String subject=user.getEmail(); + + return tokenizer.generateRefreshToken(subject,expiration,base64EncodedSecretKeyString); + + } +} From 4a70d9afebec69d50b3b57f61f26ddd76238596a Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:01:45 +0900 Subject: [PATCH 09/14] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=ED=95=84=ED=84=B0=ED=99=94=EB=A1=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?-=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=EC=9D=B4?= =?UTF-8?q?=20=ED=95=84=ED=84=B0=EC=97=90=EC=84=9C=20=EC=9E=91=EB=8F=99?= =?UTF-8?q?=ED=95=98=EB=AF=80=EB=A1=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=97=90=EC=84=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sof/domain/user/controller/UserController.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java b/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java index 98e7c7ad..26900ff7 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java @@ -41,14 +41,6 @@ public ResponseEntity postSignup(@Valid @RequestBody UserDto.SignUpPost signU } -// @PostMapping("/login") -// public ResponseEntity postLogin(@AuthenticationName String email){ -// User user = service.findByUserFromEmail(email); -// URI location = UriCreator.createUri(USER_DEFAULT_URL,user.getUserId()); -// response.setHeader("Location", String.valueOf(location)); -// return ResponseEntity.ok().body(user.getUserId()); -// } - // @PostMapping("/logout") // public ResponseEntity postLogin(){ // From f91efb9a88a2cabcf8abf012b6f92f1987a4363c Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:02:50 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20Oauht=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20-=20OauhtCreateUser?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sof/domain/user/service/UserService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/service/UserService.java b/server/src/main/java/com/rainbow/sof/domain/user/service/UserService.java index 43146905..e38ae7bb 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/service/UserService.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/service/UserService.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.util.Map; import java.util.Optional; @Service @@ -28,6 +29,21 @@ public User createUser(User user){ return saveUser(user); } + public User OauhtCreateUser(User user){ + verifyExistsEmail(user.getEmail()); + String passwordEncode = passwordEncoder.encode(user.getPassword()); + user.updatePassword(passwordEncode); + return saveUser(user); + } + +// public User createUser(Map userdata){ +// verifyExistsEmail(email); +// User user = findByUserFromEmail(email); +// String passwordEncode = passwordEncoder.encode(user.getPassword()); +// user.updatePassword(passwordEncode); +// return saveUser(user); +// } + public User updateUser(String email, long id, UserDto.Patch patchUser){ verifyExistsEmail(patchUser.getName()); User updateUser = checkToFindByUserFromEmail(email,id); From 745f3c657fd5dd5137ffa23e128839d8393bd505 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:03:13 +0900 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20OAuth=202=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80=20-=20OAuth=202=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/build.gradle b/server/build.gradle index db79c5b3..26dda73c 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -54,6 +54,9 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + //OAuth 2 의존성 추가 + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + //스프링 테스트를 위한 의존성추가 testImplementation 'org.springframework.security:spring-security-test' implementation 'junit:junit:4.13.1' From 617b349b93ab24a6f92262c788b68e9d305148c9 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 14:09:22 +0900 Subject: [PATCH 12/14] merge breach --- .../question/service/QuestionService.java | 2 +- .../user/config/SecurityConfiguration.java | 19 +++++++++++++++---- .../rainbow/sof/global/config/WebConfig.java | 11 ----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/question/service/QuestionService.java b/server/src/main/java/com/rainbow/sof/domain/question/service/QuestionService.java index df899292..83c8f4b1 100644 --- a/server/src/main/java/com/rainbow/sof/domain/question/service/QuestionService.java +++ b/server/src/main/java/com/rainbow/sof/domain/question/service/QuestionService.java @@ -20,7 +20,7 @@ @Transactional @Service public class QuestionService { - private final int SIZE = 10; + private final int SIZE = 15; private final QuestionRepository questionRepository; private final UserService userService; diff --git a/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java b/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java index 17b409bb..3cf31d04 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/config/SecurityConfiguration.java @@ -86,9 +86,20 @@ public CustomFilterConfigurer customFilterConfigurers(){ @Bean CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - configuration.addAllowedOrigin("http://localhost:3000"); - configuration.addAllowedOrigin("http://ec2-52-78-15-107.ap-northeast-2.compute.amazonaws.com"); + CorsConfiguration config = new CorsConfiguration(); + + config.setAllowCredentials(true); + config.setAllowedOrigins(List.of("http://ec2-52-78-15-107.ap-northeast-2.compute.amazonaws.com","http://localhost:3000")); + config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); + config.setAllowedHeaders(List.of("*")); + config.setExposedHeaders(List.of("*")); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + return source; + /*CorsConfiguration configuration = new CorsConfiguration(); + configuration.addAllowedOrigin("*"); + //configuration.addAllowedOrigin("http://ec2-52-78-15-107.ap-northeast-2.compute.amazonaws.com"); configuration.setAllowedMethods(Arrays.asList("GET","POST", "PATCH", "DELETE")); configuration.setAllowedHeaders( List.of("Authorization","X-AUTH-TOKEN") @@ -100,7 +111,7 @@ CorsConfigurationSource corsConfigurationSource() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/api/v1/**", configuration); - return source; + return source;*/ } diff --git a/server/src/main/java/com/rainbow/sof/global/config/WebConfig.java b/server/src/main/java/com/rainbow/sof/global/config/WebConfig.java index b8335efb..417a1d6e 100644 --- a/server/src/main/java/com/rainbow/sof/global/config/WebConfig.java +++ b/server/src/main/java/com/rainbow/sof/global/config/WebConfig.java @@ -18,17 +18,6 @@ public class WebConfig implements WebMvcConfigurer { private final AuthenticationArgumentResolver authenticationArgumentResolver; - @Override - public void addCorsMappings(CorsRegistry registry){ - registry.addMapping("/api/v1/**") - .allowedOrigins("http://localhost:3000","http://ec2-52-78-15-107.ap-northeast-2.compute.amazonaws.com") - .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE") - .allowedHeaders("Authorization","X-AUTH-TOKEN") - .allowCredentials(false) - .maxAge(3000); - } - - @Override public void addArgumentResolvers(List resolvers){ resolvers.add(authenticationArgumentResolver); From 3b98e02c92d24ebf9335e02f31a36d356332e3d8 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 15:22:53 +0900 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80=20-=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/auth/jwt/JwtTokenizer.java | 9 ++++-- server/src/main/resources/application.yml | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/JwtTokenizer.java b/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/JwtTokenizer.java index 5c3d4156..904a4d42 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/JwtTokenizer.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/auth/jwt/JwtTokenizer.java @@ -8,6 +8,7 @@ import io.jsonwebtoken.security.Keys; import lombok.Getter; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; import java.nio.charset.StandardCharsets; @@ -18,19 +19,21 @@ public class JwtTokenizer { @Getter + @Value("${User.mail.admin}") private static String ADMIN_SUBJECT = "ADMIN@ADMIN.com"; @Getter + @Value("${User.mail.disable}") private static String USER_DISABLE_MAIL="disable@disable.com"; @Getter - @Value("thisIsTestScretKeythisIsTestScretKeythisIsTestScretKeythisIsTestScretKey") + @Value("${jwt.key.secret}") private String secretKeySting; @Getter - @Value("60") + @Value("${jwt.access-token-expiration-minutes}") private int accessTokenExpirationMinutes; @Getter - @Value("300") + @Value("${jwt.refresh-token-expiration-minutes}") private int refreshTokenExpirationMinutes; //시크릿키로 이용할 무작위 문자열을 바이트배열로 변환 diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 38d82643..1af3263f 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -12,7 +12,16 @@ spring: properties: hibernate: format_sql: true - + security: + oauth2: + client: + registration: + google: + clientId: ${GOOGLE_CLIENTID} + clientSecret: ${GOOGLE_CLIENTSECRET} + scope: + - email + - profile logging: logback: rollingpolicy: @@ -26,4 +35,19 @@ springdoc: default-produces-media-type: application/json;charset=UTF-8 swagger-ui: url: /docs/open-api-3.0.1.json - path: /docs/swagger \ No newline at end of file + path: /docs/swagger + + + +jwt: + key: + secret: ${JWT_SECRET_KEY} + access-token-expiration-minutes: ${ACCESS_EXPIRATION_MINUTES} + refresh-token-expiration-minutes: ${REFRESH_EXPIRATION_MINUTES} + +User: + mail: + admin: ${ADMIN_EMAIL} + disable: ${DISABLE_USER} +##${ADMIN_EMAIL} +##${DISABLE_USER} \ No newline at end of file From b719bfad717961d19d4cb4739dfbc33a2f00af28 Mon Sep 17 00:00:00 2001 From: younghoshin Date: Fri, 23 Jun 2023 16:53:22 +0900 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=9D=91=EB=8B=B5=20=EB=B0=94=EB=94=94=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sof/domain/user/controller/UserController.java | 2 +- .../rainbow/sof/domain/user/dto/singleDto/UserDto.java | 8 ++++---- .../com/rainbow/sof/domain/user/mapper/UserMapper.java | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java b/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java index 26900ff7..d239cded 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/controller/UserController.java @@ -37,7 +37,7 @@ public ResponseEntity postSignup(@Valid @RequestBody UserDto.SignUpPost signU User user = mapper.userSignupPostToUser(signUpPost); User createUser=service.createUser(user); URI location = UriCreator.createUri(USER_DEFAULT_URL.getUri(), createUser.getUserId()); - return ResponseEntity.created(location).build(); + return ResponseEntity.created(location).body(mapper.userToUserUserDtoResponse(user)); } diff --git a/server/src/main/java/com/rainbow/sof/domain/user/dto/singleDto/UserDto.java b/server/src/main/java/com/rainbow/sof/domain/user/dto/singleDto/UserDto.java index d7773eb0..2e91df6c 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/dto/singleDto/UserDto.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/dto/singleDto/UserDto.java @@ -21,9 +21,9 @@ public static class SignUpPost{ private String name; @NotBlank - @Size(min = 8,message = "비밀번호는 최수 8자리 이상이어야합니다.") - @Pattern(regexp="^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$", - message = "비밀번호는 하나이상의 숫자와 문자가 조합 되어야합니다.") + @Size(min = 8,message = "비밀번호는 최소 8자리 이상이어야합니다.") +// @Pattern(regexp="^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$", +// message = "비밀번호는 하나이상의 숫자와 문자가 조합 되어야합니다.") private String password; @NotBlank @@ -58,7 +58,7 @@ public Patch(String name) { @Getter @Builder public static class Response{ - private long memberId; + private long userId; private String name; private String email; private LocalDateTime createdAt; diff --git a/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java b/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java index 30ad319f..95ca7be6 100644 --- a/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java +++ b/server/src/main/java/com/rainbow/sof/domain/user/mapper/UserMapper.java @@ -14,6 +14,7 @@ @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface UserMapper { User userSignupPostToUser(UserDto.SignUpPost signUpPost); + UserDto.Response userToUserUserDtoResponse(User user); User userLoginPostTouser(UserDto.CreationLoginDto creationLoginDto); UserDto.LoginResponse userToLoginDto(User user);