Springboot ignoring roles
I am new to springboot and decided to follow a tutorial on how to create a JWT RestApi with it. Upon doing this I noticed that it now completely ignores my
@PreAuthorize
annotations.
In a rest controller class:
My SecurityFilterChain in my securityConfiguration class:
30 Replies
⌛
This post has been reserved for your question.
Hey @harry039804! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
And my only user (which I have created for the test) does not have admin permissions however can see the results from
/admin
Can you enable TRACE or DEBUG logging for Spring Security and show the logs when making the reques?
That's DEBUG ^
And that's shown in the console?
yes
Did you enable logging like https://stackoverflow.com/a/47729991/10871900?
Stack Overflow
How do I enable logging for Spring Security?
I am setting up Spring Security to handle logging users in. I have logged in as a user, and am taken to an Access Denied error page upon successful login. I don't know what roles my user has actually
I just enabled it on my
application.properties
what exactly did you enabled?
debug = true

oh I was specifically asking for Spring Security logging
oh mb
like there
isn't there something before and after?
mainly after it
Nothing after that
Before is just basic startup
Only other debug thing before it is this
And you did
logging.level.org.springframework.security=DEBUG
?2025-01-05T21:44:50.795Z DEBUG 84135 --- [restAPI] [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with filters: DisableEncodeUrlFilter, WebAsyncManagerIntegrationFilter, SecurityContextHolderFilter, HeaderWriterFilter, LogoutFilter, BearerTokenAuthenticationFilter, BasicAuthenticationFilter, RequestCacheAwareFilter, SecurityContextHolderAwareRequestFilter, AnonymousAuthenticationFilter, SessionManagementFilter, ExceptionTranslationFilter, AuthorizationFilter
yesCan you show the full logs?
100% debugging because its giving a different output without
logging.level.org.springframework.security=DEBUG
in application properties.
sure hold onPastebin
2025-01-05T21:50:03.184Z INFO 84270 --- [restAPI] [ main...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
oh
you need to enable annotations like
@PreAuthorize
o
I think
@EnableMethodSecurity
on the main class
or the security configah
How do you know that lmao?
Like you got any links to good documentation
Thank you that sorted it... I did remove that as it was not part of the tutorial I was watching so thought it was useless as the previous tutorial didn't actually explain its purpose... lmao
Post Closed
This post has been closed by <@422471294529962011>.