Merge branch 'master' into feature/gracefullyshutdown

# Conflicts:
#	src/main/java/com/rest/api/config/security/SecurityConfiguration.java
This commit is contained in:
kimyonghwa
2019-05-02 22:48:29 +09:00
5 changed files with 46 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.authorizeRequests() // 다음 리퀘스트에 대한 사용권한 체크
.antMatchers("/*/signin", "/*/signin/**", "/*/signup", "/*/signup/**", "/social/**").permitAll() // 가입 및 인증 주소는 누구나 접근가능
.antMatchers(HttpMethod.GET, "/helloworld/**","/actuator/health").permitAll() // hellowworld로 시작하는 GET요청 리소스는 누구나 접근가능
.anyRequest().hasRole("USER") // 그외 나머지 요청은 모두 인증된 회원만 접근 가능
.anyRequest().hasRole("USER") // 그외 나머지 요청은 모두 인증된 회원만 접근 가능
.and()
.exceptionHandling().accessDeniedHandler(new CustomAccessDeniedHandler())
.and()

View File

@@ -12,7 +12,7 @@ spring:
url: jdbc:mysql://127.0.0.1:33060/daddyprogrammer?useUnicode=true&autoReconnect=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
username: happydaddy
password: daddy!@#1004
password: daddy1004
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
properties.hibernate:

View File

@@ -1,11 +1,15 @@
package com.rest.api.controller.v1;
import com.rest.api.entity.User;
import com.rest.api.repo.UserJpaRepo;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
@@ -14,6 +18,7 @@ import org.springframework.util.MultiValueMap;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collections;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -29,6 +34,17 @@ public class SignControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private UserJpaRepo userJpaRepo;
@Autowired
private PasswordEncoder passwordEncoder;
@Before
public void setUp() throws Exception {
userJpaRepo.save(User.builder().uid("happydaddy@naver.com").name("happydaddy").password(passwordEncoder.encode("1234")).roles(Collections.singletonList("ROLE_USER")).build());
}
@Test
public void signin() throws Exception {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
@@ -95,8 +111,8 @@ public class SignControllerTest {
.andExpect(jsonPath("$.code").value(-1004));
}
@Test
public void signUpProvider() throws Exception {
@Test @Ignore
public void signUpSocial() throws Exception {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("accessToken", "HizF3ir9522bMW3shkO0x0T9zBdXFCW1WsF56Qo9dVsAAAFqMwTqHw");
params.add("name", "kakaoKing!");
@@ -107,8 +123,8 @@ public class SignControllerTest {
.andExpect(jsonPath("$.code").value(0));
}
@Test
public void signInProvider() throws Exception {
@Test @Ignore
public void signInSocial() throws Exception {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("accessToken", "HizF3ir9522bMW3shkO0x0T9zBdXFCW1WsF56Qo9dVsAAAFqMwTqHw");
mockMvc.perform(post("/v1/signin/kakao").params(params))

View File

@@ -1,5 +1,8 @@
package com.rest.api.controller.v1;
import com.rest.api.entity.User;
import com.rest.api.repo.UserJpaRepo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -7,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.JacksonJsonParser;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
@@ -16,6 +20,10 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.Collections;
import java.util.Optional;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -29,10 +37,17 @@ public class UserControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private UserJpaRepo userJpaRepo;
@Autowired
private PasswordEncoder passwordEncoder;
private String token;
@Before
public void setUp() throws Exception {
userJpaRepo.save(User.builder().uid("happydaddy@naver.com").name("happydaddy").password(passwordEncoder.encode("1234")).roles(Collections.singletonList("ROLE_USER")).build());
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("id", "happydaddy@naver.com");
params.add("password", "1234");
@@ -50,6 +65,10 @@ public class UserControllerTest {
token = jsonParser.parseMap(resultString).get("data").toString();
}
@After
public void tearDown() throws Exception {
}
@Test
public void invalidToken() throws Exception {
mockMvc.perform(MockMvcRequestBuilders
@@ -109,8 +128,10 @@ public class UserControllerTest {
@Test
public void delete() throws Exception {
Optional<User> user = userJpaRepo.findByUid("happydaddy@naver.com");
assertTrue(user.isPresent());
mockMvc.perform(MockMvcRequestBuilders
.delete("/v1/user/2")
.delete("/v1/user/" + user.get().getMsrl())
.header("X-AUTH-TOKEN", token))
.andDo(print())
.andExpect(status().isOk())

View File

@@ -1,6 +1,7 @@
package com.rest.api.service.social;
import com.rest.api.model.social.KakaoProfile;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,7 +17,7 @@ public class KakaoServiceTest {
@Autowired
private KakaoService kakaoService;
@Test
@Test @Ignore
public void whenGetKakaoProfile_thenReturnProfile() {
String accessToken = "xjsMzpQtIr4w13FIQvL3R7BW7X4yvm1KmzXCTwopyWAAAAFqMxEcwA";