mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 05:22:16 +00:00
Throw exception if specified ldif does not exist
Closes gh-7791 Co-Authored-By: Shay Dratler <dratler@users.noreply.github.com>
This commit is contained in:
parent
b22c50c4a8
commit
7c4a706865
@ -141,4 +141,54 @@ public class UnboundIdContainerLdifTests {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unboundIdContainerWhenMissingLdifThenException() {
|
||||
try {
|
||||
appCtx = new AnnotationConfigApplicationContext(MissingLdifConfig.class);
|
||||
failBecauseExceptionWasNotThrown(IllegalStateException.class);
|
||||
} catch (Exception e) {
|
||||
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("Unable to load LDIF classpath:does-not-exist.ldif");
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class MissingLdifConfig {
|
||||
private UnboundIdContainer container = new UnboundIdContainer("dc=springframework,dc=org",
|
||||
"classpath:does-not-exist.ldif");
|
||||
|
||||
@Bean
|
||||
UnboundIdContainer ldapContainer() {
|
||||
this.container.setPort(0);
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void shutdown() {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unboundIdContainerWhenWildcardLdifNotFoundThenProceeds() {
|
||||
new AnnotationConfigApplicationContext(WildcardNoLdifConfig.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class WildcardNoLdifConfig {
|
||||
private UnboundIdContainer container = new UnboundIdContainer("dc=springframework,dc=org",
|
||||
"classpath*:*.test.ldif");
|
||||
|
||||
@Bean
|
||||
UnboundIdContainer ldapContainer() {
|
||||
this.container.setPort(0);
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void shutdown() {
|
||||
this.container.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,10 @@ public class UnboundIdContainer implements InitializingBean, DisposableBean, Lif
|
||||
if (StringUtils.hasText(this.ldif)) {
|
||||
try {
|
||||
Resource[] resources = this.context.getResources(this.ldif);
|
||||
if (resources.length > 0 && resources[0].exists()) {
|
||||
if (resources.length > 0) {
|
||||
if (!resources[0].exists()) {
|
||||
throw new IllegalArgumentException("Unable to find LDIF resource " + this.ldif);
|
||||
}
|
||||
try (InputStream inputStream = resources[0].getInputStream()) {
|
||||
directoryServer.importFromLDIF(false, new LDIFReader(inputStream));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user