Skip to content

Is there an easy way to configure Authorization (containing a Bearer token) and X-API-TOKEN headers at the same time? #225

Answered by ch4mpy
ch4mpy asked this question in Q&A
Discussion options

You must be logged in to vote

This duplicates How to use this plugin with alternative authentication at the same time?: spring-addons auto-configures a resource server Security(Web)FilterChain with lowest precedence. This filter chain is designed to authorize requests with an Authorization header containing a Bearer token.

All that is needed is to expose an additional Security(Web)FilterChain bean to handle X-API-TOKEN. Something like:

@Configuration
public class SecurityConfig {

    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    SecurityFilterChain apiTokenFilterChain(HttpSecurity http) throws Exception {
        // Apply this filter-chain only to requests with an X-API-TOKEN header
        http.securityMatcher((H…

Replies: 1 comment

Comment options

ch4mpy
Aug 25, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by ch4mpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant