-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ced3b3f
commit d3c48f7
Showing
8 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/woowaSisters/woowaSisters/controller/token/JwtTokenController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.woowaSisters.woowaSisters.controller.token; | ||
|
||
import com.woowaSisters.woowaSisters.domain.token.JwtToken; | ||
import com.woowaSisters.woowaSisters.service.token.JwtTokenService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/v1/token") | ||
public class JwtTokenController { | ||
|
||
private final JwtTokenService jwtTokenService; | ||
|
||
@Autowired | ||
public JwtTokenController(JwtTokenService jwtTokenService) { | ||
this.jwtTokenService = jwtTokenService; | ||
} | ||
|
||
@PostMapping("/save") | ||
public ResponseEntity<JwtToken> saveToken(@RequestBody String tokenValue) { | ||
JwtToken jwtToken = jwtTokenService.saveToken(tokenValue); | ||
return ResponseEntity.ok(jwtToken); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/woowaSisters/woowaSisters/domain/token/JwtToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.woowaSisters.woowaSisters.domain.token; | ||
|
||
import lombok.*; | ||
import javax.persistence.*; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "jwt_token") | ||
public class JwtToken { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "token_uuid", columnDefinition = "BINARY(16)") | ||
private UUID tokenUuid; | ||
|
||
@Column(name = "token_value", nullable = false, unique = true, columnDefinition = "TEXT") | ||
private String tokenValue; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/woowaSisters/woowaSisters/domain/token/JwtTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.woowaSisters.woowaSisters.domain.token; | ||
|
||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface JwtTokenRepository extends JpaRepository<JwtToken, UUID> { | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
src/main/java/com/woowaSisters/woowaSisters/service/token/JwtTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.woowaSisters.woowaSisters.service.token; | ||
|
||
|
||
import com.woowaSisters.woowaSisters.domain.token.JwtToken; | ||
import com.woowaSisters.woowaSisters.domain.token.JwtTokenRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@Service | ||
public class JwtTokenService { | ||
|
||
private final JwtTokenRepository jwtTokenRepository; | ||
|
||
@Autowired | ||
public JwtTokenService(JwtTokenRepository jwtTokenRepository) { | ||
this.jwtTokenRepository = jwtTokenRepository; | ||
} | ||
|
||
public JwtToken saveToken(String tokenValue) { | ||
JwtToken jwtToken = JwtToken.builder() | ||
.tokenValue(tokenValue) | ||
.build(); | ||
return jwtTokenRepository.save(jwtToken); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/com/woowaSisters/woowaSisters/OAuthServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.woowaSisters.woowaSisters; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class OAuthServiceTest { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void givenUserLogin_whenRequestGoogleLogin_thenReceiveAuthToken() { | ||
// 로그인 요청 시뮬레이션 | ||
ResponseEntity<String> response = restTemplate.getForEntity("/google/login", String.class); | ||
|
||
// 응답 상태 코드 확인 | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
|
||
// JWT 토큰이 포함되어 있는지 확인 | ||
// 실제 테스트에서는 응답 바디나 헤더에서 JWT 토큰을 찾아야 합니다. | ||
// 이 예시에서는 응답 헤더에 "Authorization" 키로 토큰이 포함되어 있다고 가정합니다. | ||
// 실제로는 이 방식이 아닌, OAuth 프로세스에 따라 토큰이 반환되는 방식을 확인해야 합니다. | ||
// String token = response.getHeaders().getFirst("Authorization"); | ||
// assertThat(token).isNotNull(); | ||
|
||
// 아래는 응답 바디가 JSON 형태로 토큰을 포함하는 경우의 예시입니다. | ||
// 실제로는 응답 형태에 맞춰서 JSON 파싱 로직을 추가해야 합니다. | ||
// 예: JSON 객체에서 "access_token" 필드 값을 추출 | ||
// String body = response.getBody(); | ||
// assertThat(body).contains("access_token"); | ||
} | ||
} |