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

Migration of various Groovy classes to Java #1663

Merged
merged 22 commits into from
Jun 29, 2023
Merged

Conversation

jvz
Copy link
Contributor

@jvz jvz commented Jun 12, 2023

Broken up into several commits, I've ported over several Groovy classes to Java. Included is a small simplification to how AuthConfig works for setting up the WebSecurity builder object as that can be done via a customizer. An equivalent approach to simplifying the setup for HttpSecurity would require a much larger change as all the authentication configuration classes would need to migrate from WebSecurityConfigurerAdapter to instead define SecurityFilterChain beans which compose more easily than the existing approach (Spring Security doesn't let you use both approaches at the same time).

In the OidRolesExtractor migration, I've also simplified the use of Bouncycastle APIs slightly as they define convenience methods that do the same thing as what was done in the Groovy code but with less verbosity. I did some research into the particular OID from the test and documentation, and amusingly enough, that same OID is already used for some power management authentication standard, but we don't seem to encode role info even remotely similar to that. While there's some RFC about defining roles and such in certificates, these seem to apply to what's known as an "attribute certificate" which is separate from a normal X.509 certificate (Bouncycastle includes ASN.1 classes for that RFC). Anyways, I made the role parsing more explicit there as relying on toString() for implementation details is not ideal (not every ASN.1 class from BC implements a useful toString() here, but we do expect string data).

.registerModule(new JavaTimeModule())

return new JsonHttpMessageConverter(objectMapper)
return new JsonHttpMessageConverter(objectMapperBuilder.build())
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 don't know how many times I have to emphasize this, but Spring Boot offers this super useful builder class for making an ObjectMapper, and you can configure default settings in the Spring properties somewhere. Thus, I've moved the feature flags to application.properties on the classpath which Spring Boot picks up by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

At least in this commit, I don't see anything moving to application.properties. In this other commit I do see read-unknown-enum-values-as-null set to true. I don't see an equivalent of .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) nor .registerModule(new JavaTimeModule() though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disabling fail on unknown properties is a default setting in Jackson2ObjectMapperBuilder. JavaTimeModule is one of the "standard" Jackson modules that class looks for, too. See https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.html for more info.

@@ -210,12 +203,6 @@ class GateConfig extends RedisHttpSessionConfiguration {
createClient "clouddriver", ClouddriverService
}

@Bean
@ConditionalOnProperty("services.keel.enabled")
KeelService keelService(OkHttpClientProvider clientProvider) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a duplicate bean. There's another one defined later in this file without the OkHttpClientProvider argument (which is ignored in this method anyways).

* can be pulled and forwarded in the AuthenticatedRequestFilter.
*/
@Bean
FilterRegistrationBean securityFilterChain(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now handled in application.properties since all it was doing was reordering the spring security filter. That's a supported config property in Spring Boot, so no need to expose internal details of Spring Security!

ASN1OctetString octetString = ASN1OctetString.getInstance(bytes);
var primitive = ASN1Primitive.fromByteArray(octetString.getOctets());
String string;
if (primitive instanceof ASN1String) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the Spinnaker docs say this needs to be a UTF-8 string, ASN.1 does support like a million other string types that Bouncycastle supports, and they all implement this interface. That is what their toString() methods delegate to, though other ASN.1 types in BC don't necessarily print out machine-parseable data.

@dbyron-sf
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Jun 13, 2023

update

✅ Branch has been successfully updated

@jvz jvz requested a review from dbyron-sf June 15, 2023 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants