Eric B.
Eric B.

Reputation: 24411

Custom filter position in spring security

How can I insert multiple custom filters in the Spring Security chain at the top of the chain?

I can insert one by using position="FIRST" and after="FIRST" but how can I add two or three at the top of the chain? If I try multiple after="FIRST" I get conflict errors that I cannot put multiple filters in the same position.

    <custom-filter ref="customExceptionJSONFilter" position="FIRST"/>
    <custom-filter ref="logHeadersFilter" after="FIRST"/>
    <custom-filter ref="thirdCustomFilter" after="FIRST"/>       <---- this causes a conflict

Is there any way of positioning based on another filter? Or some way of saying "FIRST+1", "FIRST+2", etc?

Upvotes: 1

Views: 4210

Answers (1)

Dave Syer
Dave Syer

Reputation: 58094

The best way to do that is probably to wrap the filters you want to insert into a single Filter. You can copy the code from VirtualFilterChain in Spring Security to implement it: https://github.com/spring-projects/spring-security/blob/6be4e3a9fc99d676f367a5e9eed3ea61fbba122c/web/src/main/java/org/springframework/security/web/FilterChainProxy.java#L306

Upvotes: 1

Related Questions