Add embedded LDAP container interface

Issue gh-10138
This commit is contained in:
Eleftheria Stein 2021-10-04 12:31:00 +02:00
parent dfcd898e06
commit 2894ed318d
3 changed files with 50 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -77,7 +77,8 @@ import org.springframework.util.Assert;
* supported with no GA version to replace it.
*/
@Deprecated
public class ApacheDSContainer implements InitializingBean, DisposableBean, Lifecycle, ApplicationContextAware {
public class ApacheDSContainer
implements EmbeddedLdapServerContainer, InitializingBean, DisposableBean, Lifecycle, ApplicationContextAware {
private final Log logger = LogFactory.getLog(getClass());
@ -177,10 +178,12 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
this.service.setWorkingDirectory(workingDir);
}
@Override
public void setPort(int port) {
this.port = port;
}
@Override
public int getPort() {
return this.port;
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.ldap.server;
/**
* Provides lifecycle services for an embedded LDAP server.
*
* @author Eleftheria Stein
* @since 5.7
*/
public interface EmbeddedLdapServerContainer {
/**
* Returns the embedded LDAP server port.
* @return the embedded LDAP server port
*/
int getPort();
/**
* The embedded LDAP server port to connect to. Supplying 0 as the port indicates that
* a random available port should be selected.
* @param port the port to connect to
*/
void setPort(int port);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,7 +38,8 @@ import org.springframework.util.StringUtils;
/**
* @author Eddú Meléndez
*/
public class UnboundIdContainer implements InitializingBean, DisposableBean, Lifecycle, ApplicationContextAware {
public class UnboundIdContainer
implements EmbeddedLdapServerContainer, InitializingBean, DisposableBean, Lifecycle, ApplicationContextAware {
private InMemoryDirectoryServer directoryServer;
@ -57,10 +58,12 @@ public class UnboundIdContainer implements InitializingBean, DisposableBean, Lif
this.ldif = ldif;
}
@Override
public int getPort() {
return this.port;
}
@Override
public void setPort(int port) {
this.port = port;
}