Skip to content
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

Build against Spring Security #49

Merged
merged 52 commits into from
Nov 17, 2020
Merged

Conversation

jglick
Copy link
Member

@jglick jglick commented Jul 31, 2020

Following up #48 but now trying to build against jenkinsci/jenkins#4848 and use only Spring Security.

Managed to make everything compile & pass tests. @rwinch I will likely need your help here. There seem to have been quite substantial changes between Acegi Security and Spring Security in the LDAP support, and I have not managed to find a migration guide. Most (though not all) of the problems center around some change from using LdapUserDetails, which used to have a getAttributes method, to DirContextOperations (which has this method) plus a String username but which is not an Authentication or UserDetails. I am feeling my way around in the dark, knowing next to nothing about LDAP, JNDI, etc.

src/main/java/hudson/security/LDAPSecurityRealm.java Outdated Show resolved Hide resolved
src/main/java/hudson/security/LDAPSecurityRealm.java Outdated Show resolved Hide resolved
src/main/java/hudson/security/LDAPSecurityRealm.java Outdated Show resolved Hide resolved
Comment on lines -581 to +579
DefaultInitialDirContextFactory initialDirContextFactory = new DefaultInitialDirContextFactory(getLDAPURL());
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(getLDAPURL());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just guessing.

Comment on lines -583 to +582
initialDirContextFactory.setManagerDn(getManagerDN());
initialDirContextFactory.setManagerPassword(getManagerPassword());
contextSource.setUserDn(getManagerDN());
contextSource.setPassword(getManagerPassword());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inferred from LdapAuthenticationProviderConfigurer that this is the equivalent.

import org.springframework.ldap.core.support.AbstractContextMapper;

/**
* Sort of like {@link AttributesMapper} but with a DN; also sort of like {@link AbstractContextMapper}.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could find no exact equivalent of this Acegi Security type, but anyway it is only being used internally here.

jglick added a commit to jglick/jep that referenced this pull request Jul 31, 2020
…tiesPopulatorImpl so its constructor should not do so redundantly; unclear how tests pass in jenkinsci#46 without this
@rsandell
Copy link
Member

Since this will be a major version change with long sought after upgrades, I think removing some of the small obscure features is OK.

@jglick
Copy link
Member Author

jglick commented Aug 26, 2020

I think removing some of the small obscure features is OK.

Probably so, but I do not know enough about this plugin’s usage to even know which features are “small” or “obscure”.

Currently there are still quite a few test failures that are beyond the limits of my knowledge. For example: ou=umich,ou.edu is apparently an “invalid name” according to JNDI. This is just the search string (or “URL” or something?) configured in the test, but apparently it is supposed to be processed somehow?

@jglick jglick requested a review from stephenc September 3, 2020 22:24
rtyler pushed a commit to jglick/jep that referenced this pull request Sep 7, 2020
@@ -1765,7 +1770,7 @@ public FormValidation validate(LDAPSecurityRealm realm, String user, String pass
.LDAPSecurityRealm_UserLookupManagerDnPermissions(),
jenkins.security.plugins.ldap.Messages.LDAPSecurityRealm_UserLookupSettingsCorrect());
// we do not flag these errors as could be probing user accounts
} catch (LdapDataAccessException e) {
} catch (AuthenticationException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old LdapDataAccessException meant that there was problems communicating with the ldap server, or your query was wrong or similar. Is the new AuthenticationException equivalent? By the name it sounds to me like it's a different exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no more org.springframework.dao.DataAccessException or its subtypes, so in the core PR as well as here I have converted these to the more generic AuthenticationException. Whether this is the most appropriate type or not, I do not know, and I am not sure we really care.

* Creates security components.
* @return Created {@link SecurityComponents}
* @throws IllegalStateException Execution error
*/
@Override @Nonnull
public SecurityComponents createSecurityComponents() {
if (configurations.size() > 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

History lesson for context;
When we implemented the multiple ldap server support we were a bit paranoid of changing the behavior in any way for configurations with only one server configured. That's why you see all of these if (configurations.size() > 1) all over the place. It was also the reason for the DelegatedLdapUserDetails class that I see you have changed to always be used instead of before; only when multiple configurations are in effect.

Since the behavior (both user wise but also in binary compatibility) is changing now and DelegatedLdapUserDetails is used all the time, I believe it's now possible to remove all this semi redundant code that has separate treatments for the single server configuration scenario.

But I won't block this PR if you don't want to include that cleanup work here ;).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying this in #52.

@jglick jglick mentioned this pull request Sep 28, 2020
jglick added a commit to jglick/reverse-proxy-auth-plugin that referenced this pull request Oct 7, 2020
pom.xml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants