• Register
0 votes
537 views

Problem :

I am using the spring security along with java config.

I am using the PostMan for testing my REST services. I get a 'csrf token' successfully and I am able to login by using a X-CSRF-TOKEN in request header. But after login when I hit a post request(Note:I am including same token in a request header that I used for login post request) I get the below error message:

“HTTP Status 403 - Could not verify the provided CSRF token because your session was not found.”

Can some one guide me what I am doing wrong?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

According to the spring.io:

When should you use a CSRF protection? Our recommendation is to use a CSRF protection for any request that could be processed by the browser by normal users. If you are only creating the service that is used by the non-browser clients, you will likely want to disable a CSRF protection.

So to disable CSRF protection you can refer the below code :

@Configuration
public class RestSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
  }
}

Note: The CSRF protection is enabled by default with a Java Configuration

Hope it will help you in fixing your error.

9 7 4
38,600 points
It is the bad idea as if when i want to hit the api with postman and want cors to work in that case then what should to be done

Related questions

0 votes
1 answer 92 views
92 views
I have been stuck to sort out this issue for a long time and even after reading a number of posts. Can some one help to sort out this issue and give me the reason why this is happening in this case?
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 41 views
41 views
Problem: I am having basic knowledge of CodeIgniter.I tried to enable the csrf_protection option in my codeigniter's config file and then tried using the form_open() function to create my required forms. But when I try to submit my form below error occurs: The action ... the answers available online related to this error but they simply did not work for me and my problem still remains as it is.
asked Sep 2, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 211 views
211 views
Problem : Facing following issue with Google Calender could not upload your events because you do not have sufficient access on the target calendar.
asked Nov 13, 2019 peterlaw 6.9k points
0 votes
1 answer 11 views
11 views
When i am applying Google OBB downloader this problems happens. I am browsing serveral forums however didn’t get the desired result. Anyone here give me the specific solution.
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
0 answers 48 views
48 views
Problem: I have fundamental knowledge related to android and apk-expansion-files. Currently my obb files download in my projects stopped working suddenly for all of my unpublished applications. Please find the error as shown below. Download failed because the resources ... it actually means. Any suggestions from any expert on android on how to make obb files download work will be appreciated!
asked Jun 16, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 748 views
748 views
Problem : I am implementing kerberos Authentication in my existing java spring application.My unix team has provided me SPN, krb5.conf and keytab file. I am trying hard but getting unable to obtain password from user exception
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 3.1K views
3.1K views
Problem : As I am allowing the USB debugging, when I tap on OK button, the Messaging pops up as follows: Because an app is obscuring a permissions request, Settings can't verify your response The above error is coming in allowing USB debugging.
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 18 views
18 views
I need to find frequency of charts in a string? can anyone here help me?
asked Sep 22, 2020 Daniel Anderson 4k points
1 vote
1 answer 73 views
73 views
Problem : I am a Computer Science student. I am trying to learn Java Programming in this Covid19 lockdown period. I want to write a program which should perform the below task. “Write a java program to count number of characters in given string”. Please let me know the exact procedure to write the above mentioned program.
asked May 19, 2020 Martin K 6.6k points