-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 응답을 위한 TokenResponse 구현 및 기타 구현 (#17)
- Loading branch information
1 parent
4e27f1a
commit 9d19b7e
Showing
14 changed files
with
142 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package net.teumteum.core.security; | ||
|
||
/* 소셜 OAuth 로그인 타입 */ | ||
public enum Authenticated { | ||
카카오,네이버; | ||
} |
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
25 changes: 0 additions & 25 deletions
25
src/main/java/net/teumteum/core/security/SecurityUtil.java
This file was deleted.
Oops, something went wrong.
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
18 changes: 18 additions & 0 deletions
18
src/main/java/net/teumteum/core/security/dto/TokenResponse.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,18 @@ | ||
package net.teumteum.core.security.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class TokenResponse { | ||
private String accessToken; | ||
private String refreshToken; | ||
|
||
@Builder | ||
public TokenResponse(String accessToken, String refreshToken) { | ||
this.accessToken = accessToken; | ||
this.refreshToken = refreshToken; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/net/teumteum/core/security/service/AuthService.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,19 @@ | ||
package net.teumteum.core.security.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.teumteum.user.domain.User; | ||
import net.teumteum.user.domain.UserConnector; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthService { | ||
private final JwtService jwtService; | ||
private final UserConnector userConnector; | ||
public Optional<User> findUserByToken(String accessToken) { | ||
Long id = Long.parseLong(jwtService.getUserIdFromToken(accessToken)); | ||
return userConnector.findUserById(id); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/test/java/net/teumteum/core/property/PropertyTest.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,49 @@ | ||
package net.teumteum.core.property; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
@DisplayName("property 관련 테스트의 ") | ||
@TestPropertySource(locations = { | ||
"classpath:application-auth.yml", | ||
"classpath:application-redis.yml" | ||
}) | ||
@SpringBootTest | ||
class PropertyTest { | ||
|
||
@Autowired | ||
private JwtProperty jwtProperty; | ||
|
||
@Autowired | ||
private RedisProperty redisProperty; | ||
|
||
@Nested | ||
@DisplayName("jwtProperty 주입 테스트가") | ||
class JwtPropertyTest { | ||
|
||
@Test | ||
@DisplayName("정상적으로 성공한다.") | ||
void test(){ | ||
String bearer = jwtProperty.getBearer(); | ||
System.out.println(bearer); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
@DisplayName("redisProperty 주입 테스트가") | ||
class RedisPropertyTest { | ||
@Test | ||
@DisplayName("정상적으로 성공한다.") | ||
void test(){ | ||
String host = redisProperty.getHost(); | ||
System.out.println(host); | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.teumteum.integration; | ||
|
||
import net.teumteum.core.security.UserAuthentication; | ||
import org.springframework.boot.test.context.TestComponent; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import javax.security.auth.login.LoginContext; | ||
|
||
@TestComponent | ||
public class SecurityUtil { | ||
|
||
public void clearSecurityContext() { | ||
SecurityContextHolder.clearContext(); | ||
} | ||
|
||
/* 해당 요청에서 로그인한 회원 id 반환 */ | ||
public Long getCurrentUserId() { | ||
UserAuthentication userAuthentication = getUserAuthentication(); | ||
return userAuthentication.getId(); | ||
} | ||
|
||
/* 해당 요청에서 로그인한 회원 OAuth id 반환 */ | ||
public String getCurrentUserOAuthId() { | ||
UserAuthentication userAuthentication = getUserAuthentication(); | ||
return userAuthentication.getOauthId(); | ||
} | ||
|
||
public void setUserId(Long userId) { | ||
UserAuthentication userAuthentication = getUserAuthentication(); | ||
userAuthentication.setUserId(userId); | ||
} | ||
|
||
private static UserAuthentication getUserAuthentication() { | ||
return (UserAuthentication) SecurityContextHolder.getContext().getAuthentication(); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/test/java/net/teumteum/integration/TestLoginContext.java
This file was deleted.
Oops, something went wrong.
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