Search code examples
spring-securitygrails-3.0

filterInterceptor.handlers after upgrade to spring 3.1.2


I upgraded to Grails 3.0.17 and Spring 3.1.2. I am having these errors

ERROR grails.boot.GrailsApp - Application startup failed
java.lang.ArrayIndexOutOfBoundsException: -1
        at java.util.ArrayList.elementData(ArrayList.java:422) ~[na:1.8.0_241]
        at java.util.ArrayList.remove(ArrayList.java:499) ~[na:1.8.0_241]
        at java_util_List$remove$7.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.5.jar:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.5.jar:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) [groovy-2.4.5.jar:2.4.5]
 at BootStrap.renderResponseFiltersMustBeLastInPipeLine(BootStrap.groovy:34) ~[main/:na]

part of the code BootStrap.groovy

 def filterInterceptor

    def init = { servletContext ->

        println "Initializing iMedCom client server"

        def applicationContext = grailsApplication.mainContext
        configureDatasource(applicationContext)
        renderResponseFiltersMustBeLastInPipeLine(filterInterceptor.handlers)

    }

    private renderResponseFiltersMustBeLastInPipeLine(allFilters) {
        def index = allFilters.findIndexOf {it.filterConfig.name == 'renderResponse'}
        def filter = allFilters.remove(index)
        allFilters.add(0, filter)
    }

and in my application.groovy

grails.plugin.springsecurity.filterChain.chainMap = [
        [pattern: '/currentVersion',            filters: 'nonAuthFilter'],
        [pattern: '/patient-api.html',            filters: 'nonAuthFilter'],
        [pattern: '/isAlive',            filters: 'nonAuthFilter'],
        [pattern: '/isAlive/json',            filters: 'nonAuthFilter'],
        [pattern: '/isAlive/html',            filters: 'nonAuthFilter'],
        [pattern: '/**',            filters: 'JOINED_FILTERS,-exceptionTranslationFilter,-sessionManagementFilter,-rememberMeAuthenticationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter']
]

any ideas?


Solution

  • Here is what helped me solve this issue:

    I replaced def index = allFilters.findIndexOf {it.filterConfig.name == 'renderResponse'} with def index = allFilters.findAll{it.filterConfig.name == 'renderResponse'} Hope this helps someone in the community.