I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.
Solution :
First of all, I would like to say a Big thank you all for your support and patience, I appreciate that very much, we love working with Azure and collaborating with this community!
The genuine error code was 403 but it was converted to 405 for the reason I will provide below.
I solved the problem and would like to share details so it will be helpful for others in the community. The problem was related to csrf protection that I accidentally enabled in my server codes by using @EnableWebSecurity annotation in spring boot that automatically enables csrf(
SQLCopy
.csrf(AbstractHttpConfigurer::disable)
), so In my codes for some reason, I had @EnableWebSecurity over TWO classes, in one of them I was disabling csrf, but since I had a second class with @EnableWebSecurity that was overriding the disabling of the first one and turning it on.
So when post/put was sent to the server without csrf token it was throwing 403 error(forbidden) and since I had error controller (
SQLCopy
ErrorControllerImpl implements ErrorController
)it was trying to redirect that issue to that controller, but there I had only handling for GET and not for post/put, si I went ahead and added there handling for post/put and at that point I was able to get 403 error back not 405.
SQLCopy
@RequestMapping(
value = PATH,
method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public String handleError(HttpServletRequest request) {...}
so at the end I merged the codes om my two classes annotated with @EnableWebSecurity annotation into one and at that class disabled csrf and that fixed the problem.
tl:dr
- added post/put handling to my spring boot error controller
- use @EnableWebSecurity annotation only once in your code, if you want to disable csrf, do it there or enable it (use token repo and send token from UI to the server when requesting)
- enable security logs to see more in logs
SQLCopy
logging.level.org.springframework.security=DEBUG
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.