403 error issue

@RestController
@RequestMapping("/api/auth")
public class SignUpAndLoginController {

@Autowired
private UserService userService;
@Autowired
private AuthenticationManager authenticationManager;

@PostMapping("/signup")
public ResponseEntity<User> signUp(@RequestBody User user) {
User user2 = userService.addUser(user);
return ResponseEntity.status(HttpStatus.CREATED).body(user2);
}
@RestController
@RequestMapping("/api/auth")
public class SignUpAndLoginController {

@Autowired
private UserService userService;
@Autowired
private AuthenticationManager authenticationManager;

@PostMapping("/signup")
public ResponseEntity<User> signUp(@RequestBody User user) {
User user2 = userService.addUser(user);
return ResponseEntity.status(HttpStatus.CREATED).body(user2);
}
@RestController
public class Controller {

@GetMapping("/hi")
public String getResponse() {
return "The response is shit";
}
}
@RestController
public class Controller {

@GetMapping("/hi")
public String getResponse() {
return "The response is shit";
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

@Bean
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").permitAll()
.anyRequest().authenticated());
return httpSecurity.build();
}

@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

@Bean
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").permitAll()
.anyRequest().authenticated());
return httpSecurity.build();
}

@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
I am trying to access the /hi endpoint but instead of getting a login page to get log in instead i am getting 403 error ! Can someone help me
No description
7 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st2w ago
for testing, can you replace the RestController with Controller?
dan1st
dan1st2w ago
try enabling DEBUG or TRACE logging for Spring Security and show the logs when making a request: 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
ayylmao123xdd
ayylmao123xdd2w ago
sigma sigma boy might be because you dont have request mapping for the hi endpoint nvm
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Suika
Suika6d ago
yu dont permit access to /hi 403 is forbidden
JavaBot
JavaBot5d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?