Skip to content

Commit

Permalink
Allow setting of FilterRegistrationBean according to documentation. F…
Browse files Browse the repository at this point in the history
…ixes #1027
  • Loading branch information
codeconsole committed Oct 8, 2024
1 parent 0b8ef6d commit 523bd56
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.apache.commons.lang.StringEscapeUtils
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.ApplicationContext
import org.springframework.security.access.hierarchicalroles.RoleHierarchy
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
Expand Down Expand Up @@ -420,11 +421,14 @@ final class SpringSecurityUtils {
assert !oldFilter,
"Cannot register filter '$beanName' at position $order; '$oldFilter' is already registered in that position"

Filter filter = getBean(beanName)
configuredOrderedFilters[order] = filter
def filter = getBean(beanName)
if (filter instanceof FilterRegistrationBean) {
filter = ((FilterRegistrationBean) filter).filter
}
configuredOrderedFilters[order] = (Filter) filter

List<GrailsSecurityFilterChain> filterChains = getBean('securityFilterChains', List)
mergeFilterChains configuredOrderedFilters, filter, beanName, order, filterChains
mergeFilterChains configuredOrderedFilters, (Filter) filter, beanName, order, filterChains

log.trace 'Client registered bean "{}" as a filter at order {}', beanName, order
log.trace 'Updated filter chain: {}', filterChains
Expand Down

0 comments on commit 523bd56

Please sign in to comment.