<<<< 학습 필요!!!!! >>>>
외부 설정 : application.properties 다른 설정 파일 읽어와서 bean으로 만들 순 없을까???
기본 유저 만들기
● ApplicationRunner
○ Admin
○ User외부 설정으로 기본 유저와 클라이언트 정보 빼내기
● @ConfigurationProperties
라이브러리 추가 (properties 객체를 만들 때 필요)
<!-- Configuration Metadata는 IDE에서 yml 혹은 properties에서 사용하는 Configuration의 자동완성을 도와주는 메타데이터이다. (소스코드에는 영향을 1도 안 미친다.) --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
Application.properties 정보 추가
###############################
# 문자열을 외부 설정으로 명시
# AppProperties 객체에 아래 정보 바인딩 됨
# @Component
# @ConfigurationProperties(prefix="my-app")
###############################
my-app.admin-username=admin@email.com
my-app.admin-password=admin
my-app.user-username=user@email.com
my-app.user-password=user
my-app.client-id=myApp
my-app.client-secret=pass
AppProperties 파일
@Component @ConfigurationProperties(prefix="my-app") @Getter @Setter public class AppProperties { @NotEmpty private String adminUsername; @NotEmpty private String adminPassword; @NotEmpty private String userUsername; @NotEmpty private String userPassword; @NotEmpty private String clientId; @NotEmpty private String clientSecret; }
> properties bean 사용하기
@Autowired
AppProperties appProperties;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
//테스트 이므로 inmemory db를 사용 , 나중에 적절한 db화가 필요
clients.inMemory().withClient(appProperties.getClientId()) // client id 설정
.authorizedGrantTypes("password" , "refresh_token") // 허용 할 Grant type 설정
.scopes("read","write") //
.secret(passwordEncoder.encode(appProperties.getClientSecret())) //client secret 설정
.accessTokenValiditySeconds(10*60) //acess token 유효시간 설정
.refreshTokenValiditySeconds(60*60); //refresh token 유효시간 설정
}