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

Import refactor for SAML #2689

Merged
merged 10 commits into from
Jan 25, 2024
Merged

Import refactor for SAML #2689

merged 10 commits into from
Jan 25, 2024

Conversation

swalchemist
Copy link
Contributor

@swalchemist swalchemist commented Jan 24, 2024

These refactors will prepare the code for removing the old Spring SAML extension library. There are several libraries that are brought in only as a result of having the SAML extension library. These changes decouple these libraries that aren't directly related to SAML, by declaring them explicitly.

Changes made with the help of @peterhaochen47.

@swalchemist swalchemist requested a review from a team January 24, 2024 22:15
@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/186908994

The labels on this github issue will be updated when the story is started.

@peterhaochen47 peterhaochen47 marked this pull request as ready for review January 25, 2024 00:15
swalchemist and others added 10 commits January 24, 2024 16:18
* Without this, we depend on spring-security-saml2-core to bring in joda-time.

also:
fix: build error on URIUtil.getName
* ExternalOAuthAuthenticationFilter imports org.apache.commons.httpclient.util.URIUtil. We used to get it from a transitive dependency in the SAML extension library.
* Now we list it directly as a dependency.

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
* We're not getting Commons Lang from the SAML extension library any more.
* We already have Commons Lang 3, so just use that.

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
* Replaces the use of the library that we used to get as part of the SAML extension library.

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
* Fixes a compile error in YamlServletProfileInitializerTest

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
- as opposed to relying to springSecuritySaml to
transitively bring it in

[#186822654]

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
- as opposed to relying on springSecuritySaml to
transitively bring it in
- extract common var

[#186822654]

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
- use Java native string split as opposed
to bouncycastle's (which is likely a mistaken import)

[#186822654]

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
[#186822654]

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
- as opposed to relying on springSecuritySaml to
transitively bring it in

[#186822654]

Co-authored-by: Peter Chen <peter-h.chen@broadcom.com>
Copy link
Member

@strehle strehle left a comment

Choose a reason for hiding this comment

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

OK, but some comments

@@ -128,7 +128,9 @@ libraries.zxing = "com.google.zxing:javase:3.5.2"
libraries.nimbusJwt = "com.nimbusds:nimbus-jose-jwt:9.37.3"
libraries.xmlSecurity = "org.apache.santuario:xmlsec:4.0.1"
libraries.orgJson = "org.json:json:20231013"
libraries.spingSamlEsapiDependencyVersion = "org.owasp.esapi:esapi:2.5.3.1"
libraries.owaspEsapi = "org.owasp.esapi:esapi:2.5.3.1"
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add comments to these libraries... because httpClient is not needed finally so we need these libraries only for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you're asking about commons-httpclient:commons-httpclient:3.1 not esapi?

While the develop branch works fine without this explicit dependency, on our branch that has the SAML extension library removed, the code doesn't compile without this httpclient dependency.

Specifically, it's needed in ExternalOAuthAuthenticationFilter.java

import org.apache.commons.httpclient.util.URIUtil;
...
final String origin = URIUtil.getName(String.valueOf(request.getRequestURL()));

And in TokenMvcMockTests.java in the invalidScopeErrorMessageIsNotShowingAllClientScopes and
invalidScopeErrorMessageIsNotShowingAllUserScopes test methods, for the same import.

So unless we decide to change this code to use a different library, the need to declare this dependency is not temporary.

Cc: @peterhaochen47

Copy link
Member

Choose a reason for hiding this comment

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

So you're asking about commons-httpclient:commons-httpclient:3.1 not esapi?

Yes httpclient:3.1 is a very only version of apache http and this wont be needed if we have no opensaml2, so I recommend this to mark with a todo or comment to remove it later...
In our CVE scanners this library is excluded for many years now ...
For esapi I am not sure if newer opensaml4 has it or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our intention was to declare the dependency that the develop branch was already using for this import. I'm trying to double-check what that is.

Copy link
Member

Choose a reason for hiding this comment

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

I know, but this will be obsolete ... however for me it is Ok as it is,

Copy link
Member

Choose a reason for hiding this comment

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

ent (see usage here)

the usage in our code is something we should refactor....
but the other usage cannot be refactored without opensaml upgrade, e.g.
https://github.com/search?q=repo%3Acloudfoundry%2Fuaa%20org.apache.commons.httpclient&type=code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We looked in httpclient 4.5.14, and it doesn't seem to have the same API, and we didn't see a getName() method there at all, which is what we're using from httpclient 3.1. Do you see one there?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this particular case, our best option is to migrate to using java.net.URI to replace URIUtil.getName, which then removes the need for commons-httpclient:3.1. I tried to do that earlier and found that handling the checked exceptions that the library throws was a pain.

https://marc.info/?l=httpclient-users&m=125425095705062&w=2

Copy link
Member

Choose a reason for hiding this comment

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

We are going to plan to merge this PR. Created this issue to track the future work to replace the old httpclient lib: #2691

@peterhaochen47 peterhaochen47 merged commit 806ae16 into develop Jan 25, 2024
20 checks passed
@peterhaochen47 peterhaochen47 deleted the import-refactor-186822654 branch January 25, 2024 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants