#spring 401
30 messages · Page 1 of 1 (latest)
Hey, @azure orchid!
Please remember to /close this post once your question has been answered!
Your RequestMapping("/api/v1/users/") should be match with
antMatchers("/auth/**")
.permitAll()
U are allowing auth path without authentication and authorisation but trying to access other which will result to unauthorised access error
i edited it, but now i get from the login method 500 error
@PostMapping("/login")
Authentication authentication = this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authRequest.getEmail(), authRequest.getPassword()));
error line
Maybe missing: SecurityContextHolder.getContext().setAuthentication(authentication); ?
where
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
See here I have an example in a side project: https://github.com/carlos-molero/fundebt/blob/master/src/main/java/dev/carlosmolero/fundebt/filters/JWTAuthorizationFilter.java
nope i'm doing that already
i found out that this is null
String token = request.getHeader("Authorization");
That’s problematic then 😂
yes
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() ...
🎉