-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Allow port=0 for ApacheDSContainer #8416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I think there might be some confusion as to what we are looking for. Please see my comment inline.
@@ -143,6 +148,9 @@ public void afterPropertiesSet() throws Exception { | |||
server.setDirectoryService(service); | |||
// AbstractLdapIntegrationTests assume IPv4, so we specify the same here | |||
|
|||
if (this.port == 0) { | |||
this.port = getRandomPort(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. We are already finding a random port in this way within our configuration support.
The problem is sometimes the port gets resolved to an open port and assigned, the port is then taken up by another process or thread, and then this code tries to use the now taken port.
To fix this we want to be able to pass in 0
to TcpTransport
to avoid a race condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. Do I understand correctly that we should also add an accessor to ApacheDSContainer
for configured port value i.e 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not for the configured value, but for the actual port that is resolved by TcpTransport
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be getLocalPort
for the actual port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we want the name of the method to be getLocalPort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick turnaround. I have provided some feedback inline.
|
||
SocketAcceptor socketAcceptor = server.getSocketAcceptor(transport); | ||
InetSocketAddress localAddress = socketAcceptor.getLocalAddress(); | ||
this.localPort = localAddress.getPort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic should probably be moved to the start
method since a user could invoke start
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also move the server
initialization to the start
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try and make as little changes in this PR as possible. If we see additional room for improvement, let's create separate tickets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This looks good. The last changes are to have the code take advantage of these changes. For example, LdapAuthenticationProviderConfigurer
can now be updated to use the fact that 0 works.
I'm also wondering if it is actually better to use getPort() to return the used port if 0 is passed in since if the DLS or XML config passes 0, then the port returns the randomly selected port.
@rwinch I made changes to |
5c060c6
to
ec8cf95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. We still need changes in LdapServerBeanDefinitionParser. We should also make sure our integration tests are always using port 0 and not use new ServerSocket(0).getLocalPort()
anymore.
a79cbd8
to
56d154f
Compare
@rwinch I made changes to |
62586fe
to
358251b
Compare
@rwinch Could you please take a look at the latest changes when you have a moment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. I've provided feedback inline
* @param container the embedded DS container | ||
* @return an instance which will connect to the embedded LDAP server | ||
*/ | ||
public static DefaultSpringSecurityContextSource createEmbeddedContextSource(EmbeddedDsContainer container) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should need to add this method. I'd prefer to keep as many things private scope as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this factory method for XML config because we need to create and post process a bean of the embedded container first and then use the actual port value to build a url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can likely be done with a package private method within the config itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please provide some example of how this can be done in BeanDefinitionParser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Added EmbeddedLdapServerConfigBean
with factory method.
* @see ApacheDSContainer | ||
* @see UnboundIdContainer | ||
*/ | ||
public interface EmbeddedDsContainer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should need to add a new public interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Thanks for the Pull Request and your patience as we worked on finding the best solution! This is now merged into master via 0fa339f 😄 |
Fixes gh-8144