#spring 401

30 messages · Page 1 of 1 (latest)

azure orchid
sharp shadowBOT
#

Hey, @azure orchid!
Please remember to /close this post once your question has been answered!

whole hornet
azure orchid
azure orchid
sharp shadowBOT
#
    @PostMapping("/login")

sharp shadowBOT
lyric sluice
#

Maybe missing: SecurityContextHolder.getContext().setAuthentication(authentication); ?

lyric sluice
#

I think the best approach is creating a OncePerRequestFilter and then adding it to your web security config, inside the filter create the auth and add it to the context

#

Auth must be created before the request reaches the controllers

azure orchid
#

i found out that this is null

String token = request.getHeader("Authorization"); 
lyric sluice
#

That’s problematic then 😂

azure orchid
whole hornet
#

but since it's added in

.antMatchers("/api/**")
.permitAll()
#

that shouldn't be problem

#

ah got it

#

u have overide wrong method

#
    @Bean(BeanIds.AUTHENTICATION_MANAGER)
    @Nullable
    @Override
    public AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManagerBean();
    }
#

it should be

- public AuthenticationManager authenticationManager() ...
+ public AuthenticationManager authenticationManagerBean() ...
azure orchid
#

finally

#

it works

#

thanks

#

love u

whole hornet
#

🎉