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

fix(test/core): refactor constructor by passing context to HttpSecurity instance updated with spring boot 2.6.x #1765

Closed
wants to merge 3 commits into from

Conversation

j-sandy
Copy link
Contributor

@j-sandy j-sandy commented Feb 15, 2024

While upgrading spring boot 2.6.15 and spring cloud 2021.0.8, encounter below errors during execution of tests under gate-core modules:

Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
java.lang.NullPointerException: Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
	at org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.<init>(ExpressionUrlAuthorizationConfigurer.java:109)
	at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeRequests(HttpSecurity.java:1265)
	at com.netflix.spinnaker.gate.config.AuthConfig.configure(AuthConfig.java:76)
	at com.netflix.spinnaker.gate.config.AuthConfigTest.test webhooks are unauthenticated by default(AuthConfigTest.groovy:51)

Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
java.lang.NullPointerException: Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
	at org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.<init>(ExpressionUrlAuthorizationConfigurer.java:109)
	at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeRequests(HttpSecurity.java:1265)
	at com.netflix.spinnaker.gate.config.AuthConfig.configure(AuthConfig.java:76)
	at com.netflix.spinnaker.gate.config.AuthConfigTest.test webhooks can be configured to be authenticated(AuthConfigTest.groovy:86)

As per the reference given here, the implementation of spring-security-config got changed from 5.5.x to 5.6.x and it must require the ApplicationContext object. So, in order to fix this issue added a map containing ApplicationContext.class and its object to the constructor.

…ty instance updated with spring boot 2.6.x

While upgrading spring boot 2.6.15 and spring cloud 2021.0.8, encounter below errors during execution of tests under gate-core modules:
```
Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
java.lang.NullPointerException: Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
	at org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.<init>(ExpressionUrlAuthorizationConfigurer.java:109)
	at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeRequests(HttpSecurity.java:1265)
	at com.netflix.spinnaker.gate.config.AuthConfig.configure(AuthConfig.java:76)
	at com.netflix.spinnaker.gate.config.AuthConfigTest.test webhooks are unauthenticated by default(AuthConfigTest.groovy:51)

Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
java.lang.NullPointerException: Cannot invoke "org.springframework.context.ApplicationContext.getBeanNamesForType(java.lang.Class)" because "context" is null
	at org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.<init>(ExpressionUrlAuthorizationConfigurer.java:109)
	at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeRequests(HttpSecurity.java:1265)
	at com.netflix.spinnaker.gate.config.AuthConfig.configure(AuthConfig.java:76)
	at com.netflix.spinnaker.gate.config.AuthConfigTest.test webhooks can be configured to be authenticated(AuthConfigTest.groovy:86)
```
As per the reference given [here](https://stackoverflow.com/questions/71322261/nullpointerexception-at-org-springframework-security-config-annotation-web-confi), the implementation of spring-security-config got changed from 5.5.x to 5.6.x and it must require the ApplicationContext object. So, in order to fix this issue added a map containing ApplicationContext.class and its object to the constructor.
@@ -95,4 +100,11 @@ class AuthConfigTest extends Specification {
.collect(Collectors.toList())
filtered.size() == 1
}

private HashMap<Class<?>, Object> getSharedObjects(){
Copy link
Contributor

Choose a reason for hiding this comment

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

javadoc please, not only of what this does, but why...and ideally a link to some spring docs that help explain this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation difference comes in constructor of ExpressionUrlAuthorizationConfigurer class in version 5.6.x and 5.5.x.

@j-sandy
Copy link
Contributor Author

j-sandy commented Feb 27, 2024

@Mergifyio update

Copy link
Contributor

mergify bot commented Feb 27, 2024

update

✅ Branch has been successfully updated

@j-sandy j-sandy marked this pull request as ready for review February 27, 2024 18:41
@j-sandy
Copy link
Contributor Author

j-sandy commented Mar 11, 2024

@Mergifyio update

Copy link
Contributor

mergify bot commented Mar 11, 2024

update

✅ Branch has been successfully updated

@dbyron-sf
Copy link
Contributor

included in #1776.

@dbyron-sf dbyron-sf closed this Mar 12, 2024
@j-sandy j-sandy deleted the httpsec-fix branch March 15, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants