When I try to check my spring registration request, it should return the message "it Works," but I get nothing. Does anyone have any ideas what might be wrong?
Asked
Active
Viewed 53 times
0

rayn
- 9
- 2
-
seems like you are using spring security dependency. If you are using maven can you check your pom.xml – Ruchira Nawarathna Dec 06 '22 at 04:24
-
Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Noel Dec 06 '22 at 08:57
-
@RuchiraNawarathna It appears that I lack dependencies. How can I resolve this? – rayn Dec 06 '22 at 10:38
-
@rayn for me it appears that you have included "spring-boot-starter-security" or "spring-security-web" dependency. Check for this in your pom file and remove it if you don't need to include spring security – Ruchira Nawarathna Dec 06 '22 at 11:04
-
@RuchiraNawarathna So, basically, I'm trying to make a login signup with spring boot, so I tried to make a post request but I didn't get any response without any errors, so I'm not sure what the problem is, do you have any ideas? – rayn Dec 06 '22 at 14:29
-
@rayn If you preview your postman response you can see a login form which means you are not authenticated. If your signup request does not need any authentication you can simply exclude your signup api endpoint from spring checks. To do that modify security configuration file. Check here https://stackoverflow.com/a/30366773/11785852 – Ruchira Nawarathna Dec 06 '22 at 16:06
-
@RuchiraNawarathna Thank you very much for your assistance; I had missed an API link in the.antMatchers section of the WebSecurityConfig file. – rayn Dec 06 '22 at 17:09
-
@rayn great. I have added this as a detailed answer – Ruchira Nawarathna Dec 08 '22 at 04:00
2 Answers
0
If you preview your postman response you can see a login form which means you are not authenticated. If your signup request does not need any authentication you can simply exclude your registration api endpoint from spring checks. To do that permit all requests to the particular url in your configuration file
If you are using WebSecurityConfigurerAdapter, add an antMatcher entry to your configure method.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/v1/registration").permitAll()
.anyRequest().authenticated();
}
Since WebSecurityConfigurerAdapter is deprecated now if you want to use SecurityFilterChain you can do it as follows. For more info refer documentation.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/v1/registration").permitAll()
.anyRequest().authenticated();
return http.build();
}

Ruchira Nawarathna
- 1,137
- 17
- 30