fix: access 설정의 dataSource 가 빈 문자열이면 폴백 대신 기동이 죽는 문제 수정 - #369
Open
wantaekchoi wants to merge 1 commit into
Open
Conversation
EgovAccessConfigReader 는 properties 의 모든 키를 그대로 bean 에 넣는다.
값 검사는 null 뿐이라 egov-access-config.properties 에 `dataSource=` 만
써 두면 기본값 "dataSource" 가 빈 문자열로 덮인다.
DataSourceFactoryBean 은 이 값을 != null 로만 보고 bean 이름으로 쓴다.
그래서 context.getBean("") 에서 NoSuchBeanDefinitionException 이 나고,
바로 아래 containsBean("dataSource") 폴백은 실행되지 않는다. 정작
createDefaultConfig 가 지정하는 기본값이 그 폴백과 같은 이름이라,
값을 비운 설정은 폴백으로 가는 것이 원래 의도다.
같은 패키지의 AuthorityUserFactoryBean·RoleAndUrlFactoryBean 은 같은
자리에서 StringUtils.hasText 로 본다. fdl.security 의 같은 이름 클래스도
ObjectUtils.isEmpty 로 빈 문자열을 값 없음으로 친다. 형제들에 맞춰
hasText 로 바꿨다.
빈 문자열 설정으로 폴백하는지, 그런 설정 파일로 EgovAccessConfiguration
이 기동하는지 확인하는 테스트를 더했다.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
egov-access-config.properties에dataSource=한 줄을 값 없이 두면 애플리케이션이 기동하지 못합니다.EgovAccessConfigReader.mapPropertiesToBean은 properties 의 모든 키를 리플렉션 setter 로 넣고, 값 검사는if (value == null) continue;(EgovAccessConfigReader.java:127) 하나뿐입니다. 그래서 빈 문자열이 그대로setDataSource로 들어가createDefaultConfig가 넣어둔 기본값"dataSource"(:233) 를 덮습니다.DataSourceFactoryBean은 이 값을!= null로만 보고 bean 이름으로 넘겨context.getBean("")을 부릅니다.EgovAccessConfiguration.egovAccessDao(EgovAccessConfiguration.java:94) 가 이 팩토리빈을 부르기 때문에 예외 하나로 끝나지 않고 컨텍스트 기동 자체가 실패합니다. 컨텍스트에 이름이dataSource인 bean 이 멀쩡히 있어도 그렇습니다.값을 비운 설정이 가야 할 곳은 이미 코드 안에 있습니다. 그 아래
else가containsBean(DEF_DATASOURCE_NAME)폴백이 있고DEF_DATASOURCE_NAME은"dataSource"이며,createDefaultConfig가 지정하는 기본값도 같은 이름입니다. 빈 문자열만 그 갈래로 못 갑니다.같은 패키지에서
EgovAccessConfig를 읽어 갈라지는 팩토리빈은 이 클래스를 포함해 셋이고, 나머지 둘은 같은 자리에서StringUtils.hasText를 씁니다.형제 모듈의 같은 이름 클래스인
fdl.security의DataSourceFactoryBean.java:67도!ObjectUtils.isEmpty(config.getDataSource())로 보아 빈 문자열을 같은"dataSource"폴백으로 보냅니다. 표기는 같은 패키지 형제 둘에 맞췄습니다.AS-IS / TO-BE
public DataSource getObject() throws Exception { EgovAccessConfig config = context.getBean(EgovAccessConfig.class); - if (config.getDataSource() != null) { + if (StringUtils.hasText(config.getDataSource())) { return (DataSource) context.getBean(config.getDataSource()); } else { if (context.containsBean(DEF_DATASOURCE_NAME)) {org.springframework.util.StringUtilsimport 한 줄을 함께 더했습니다.영향 범위
동작이 달라지는 입력은 설정의
dataSource가 빈 문자열이거나 공백뿐인 경우입니다. 값이 있으면 종전과 같고,null이면 종전에도 폴백했습니다. 빈 문자열은 앞서 본 대로 예외가 되므로, 새로 폴백을 타는 입력은 이전에 기동을 못 하던 입력입니다.hasText는" "도 값 없음으로 봅니다. 공백을 bean 이름으로 쓰던 설정이라면 동작이 달라지는데, Spring bean 이름 관례상 현실적이지 않다고 보았습니다.fdl.security쪽ObjectUtils.isEmpty는 이 값을 이름으로 쓰므로 두 모듈의 공백 처리가 미세하게 갈리는데, 표기 통일은 이 수정 밖의 일로 보았습니다.JUnit 테스트 JUnit tests
DataSourceFactoryBeanBlankNameTest2건을 더했습니다. 하나는 팩토리빈이 폴백하는지, 하나는dataSource=를 담은 설정 파일로EgovAccessConfiguration이 기동하는지 봅니다. 기동 쪽은config.getDataSource()가 정말 빈 문자열인지도 함께 고정해, 재현 전제가 무너지면 테스트가 알리도록 했습니다.수정을 도로 빼면 둘 다 실패합니다.
수정 후 모듈 전체입니다.
테스트 브라우저 Test Browser
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
화면이 없는 실행환경 모듈이라 첨부하지 않았습니다.