forked from codesquad-members-2022/airbnb
-
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: config파일에 작성한 속성을 가져와서 객체로 생성하기 위한 클래스 파일 작성 (#35)
- @ConfigurationProperties를 이용해서 yml config 파일에서 읽은 속성을 객체로 생성 - @EnableConfigurationProperties를 이용해서 위에서 객체로 생성한 것을 속성으로 사용하고, - @configuration을 통해서 해당 속성을 사용한 repository를 스프링 빈으로 등록한다.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
BE/src/main/java/org/team4/airbnb/auth/config/OauthConfig.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,21 @@ | ||
package org.team4.airbnb.auth.config; | ||
|
||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
@EnableConfigurationProperties(OauthProperties.class) | ||
public class OauthConfig { | ||
|
||
private final OauthProperties properties; | ||
|
||
@Bean | ||
public MemoryProviderRepository memoryProviderRepository() { | ||
Map<String, OauthProvider> providers = OauthAdapter.getOauthProviders(properties); | ||
return new MemoryProviderRepository(providers); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
BE/src/main/java/org/team4/airbnb/auth/config/OauthProperties.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,30 @@ | ||
package org.team4.airbnb.auth.config; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Getter | ||
@ConfigurationProperties(prefix = "oauth") | ||
public class OauthProperties { | ||
private final Map<String, User> users = new HashMap<>(); | ||
|
||
private final Map<String, Provider> providers = new HashMap<>(); | ||
|
||
@Getter | ||
@Setter | ||
public static class User { | ||
private String clientId; | ||
private String clientSecret; | ||
private String redirectUri; | ||
} | ||
|
||
@Getter | ||
@Setter | ||
public static class Provider { | ||
private String tokenUri; | ||
private String userInfoUri; | ||
} | ||
} |