Skip to content

Commit

Permalink
feat: config파일에 작성한 속성을 가져와서 객체로 생성하기 위한 클래스 파일 작성 (#35)
Browse files Browse the repository at this point in the history
- @ConfigurationProperties를 이용해서 yml config 파일에서 읽은 속성을 객체로 생성
- @EnableConfigurationProperties를 이용해서 위에서 객체로 생성한 것을 속성으로 사용하고,
- @configuration을 통해서 해당 속성을 사용한 repository를 스프링 빈으로 등록한다.
  • Loading branch information
mybloom committed Jun 7, 2022
1 parent 94eaa61 commit d315903
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions BE/src/main/java/org/team4/airbnb/auth/config/OauthConfig.java
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 BE/src/main/java/org/team4/airbnb/auth/config/OauthProperties.java
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;
}
}

0 comments on commit d315903

Please sign in to comment.