Auto-exclude conflicting Spring Boot security auto-configurations#1205
Open
jamesfredley wants to merge 1 commit intoapache:7.0.xfrom
Open
Auto-exclude conflicting Spring Boot security auto-configurations#1205jamesfredley wants to merge 1 commit intoapache:7.0.xfrom
jamesfredley wants to merge 1 commit intoapache:7.0.xfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an AutoConfigurationImportFilter to the plugin so Spring Boot security auto-configurations that conflict with the Grails Spring Security plugin are automatically excluded, removing the need for users to manually maintain spring.autoconfigure.exclude entries.
Changes:
- Introduces
SecurityAutoConfigurationExcluderimplementingAutoConfigurationImportFilterto filter 7 known conflicting Spring Boot auto-configurations. - Registers the filter via
META-INF/spring.factories. - Adds Spock coverage for exclusion behavior and filter registration; adds
spring-boot-autoconfigureascompileOnlyfor the SPI type.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
plugin-core/plugin/src/main/groovy/grails/plugin/springsecurity/SecurityAutoConfigurationExcluder.groovy |
New import filter that excludes conflicting Spring Boot security auto-configurations. |
plugin-core/plugin/src/main/resources/META-INF/spring.factories |
SPI registration for the new auto-config import filter. |
plugin-core/plugin/build.gradle |
Adds spring-boot-autoconfigure as compileOnly to compile against the SPI. |
plugin-core/plugin/src/test/groovy/grails/plugin/springsecurity/SecurityAutoConfigurationExcluderSpec.groovy |
New Spock spec validating filtering behavior and SPI registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...in/src/test/groovy/grails/plugin/springsecurity/SecurityAutoConfigurationExcluderSpec.groovy
Outdated
Show resolved
Hide resolved
...plugin/src/main/groovy/grails/plugin/springsecurity/SecurityAutoConfigurationExcluder.groovy
Show resolved
Hide resolved
Add SecurityAutoConfigurationExcluder implementing AutoConfigurationImportFilter to automatically exclude 7 Spring Boot security auto-configuration classes that conflict with the Grails Spring Security plugin. Previously, every Grails 7 user had to manually add spring.autoconfigure.exclude entries to application.yml (documented in README). This filter eliminates that requirement by filtering them out during Spring Boot's auto-configuration discovery phase, before bytecode is loaded. Excluded auto-configurations: - SecurityAutoConfiguration - SecurityFilterAutoConfiguration - UserDetailsServiceAutoConfiguration - OAuth2ClientAutoConfiguration (2 packages) - OAuth2ResourceServerAutoConfiguration - ManagementWebSecurityAutoConfiguration Implementation: - SecurityAutoConfigurationExcluder.groovy — the filter - META-INF/spring.factories — SPI registration - build.gradle — compileOnly spring-boot-autoconfigure - SecurityAutoConfigurationExcluderSpec — 18 Spock tests
5dc44fb to
a783a42
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
SecurityAutoConfigurationExcluderimplementingAutoConfigurationImportFilterto automatically exclude 7 Spring Boot security auto-configuration classes that conflict with the Grails Spring Security plugin. This eliminates the manualspring.autoconfigure.excludeentries that every Grails 7 user currently must add toapplication.yml.Feature Description
The plugin README documents that Grails 7 requires 7 manual
spring.autoconfigure.excludeentries:These exclusions are always required — not conditional or environment-specific. This boilerplate is easy to miss, hard to debug when forgotten, and should be handled automatically by the plugin.
Implementation
Approach:
AutoConfigurationImportFilterSPI (stable since Spring Boot 1.5.0, used in 3.x)Why
AutoConfigurationImportFilterover alternativesEnvironmentPostProcessorspring.autoconfigure.excludeis aList— property sources cannot merge lists reliably (Spring Boot #41669). User's own exclusions would be overwritten.@EnableAutoConfiguration(exclude=...)on plugin class@Grailsannotation, can't also use@EnableAutoConfigurationAutoConfigurationImportFilter✓ Cannot be overridden by user config
✓ No property merging issues
✓ Used by established libraries (Redis OM Spring, TCC Transaction)
Files Changed
SecurityAutoConfigurationExcluder.groovyAutoConfigurationImportFilterimplementation that returnsfalsefor the 7 conflicting auto-configurationsMETA-INF/spring.factoriesspring.factoriesin Spring Boot 3.x, not.imports)build.gradlecompileOnly 'org.springframework.boot:spring-boot-autoconfigure'— always available at runtime in any Grails appSecurityAutoConfigurationExcluderSpec.groovyspring.factoriesregistrationTest Coverage (18 tests, all pass)
spring.factoriesregistration is correctBackward Compatibility
application.ymlare unaffected — the filter and manual exclusions are independent mechanismsspring-boot-autoconfigureis added ascompileOnlyonly — no new runtime dependency (it's always already present via Spring Boot starter)Example Application
https://github.com/jamesfredley/grails-spring-security-autoconfig-exclusion
A minimal Grails 7.0.7 app with spring-security configured (User/Role/UserRole domains, annotation-based security) that intentionally does NOT include the manual exclusions. The
/bugDemo/indexendpoint shows which auto-configuration classes are on the classpath and which beans are registered.Environment Information
Version
7.0.x