datdatyul
Active Coder
I have an issue not sending a request from one service to another one through api gateway in my spring cloud example,
Api gateway port number is 8600.
I try to send a request from management service to advertisement service through api gateway, I get the issue in Postman shown below.
Here is my Security Config of management service shown below.
How can I fix the issue?
Here is my project link : [Link][1]
[1]: https://github.com/Rapter1990/SpringBootMicroservices
Here is my controller in Management Service
Api gateway port number is 8600.
I try to send a request from management service to advertisement service through api gateway, I get the issue in Postman shown below.
{
"timestamp": "2022-08-29T11:48:40.168+00:00",
"path": "/api/v1/admin_role/alladvertisements",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "8764de5c-7"
}
Here is my Security Config of management service shown below.
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/api/v1/admin_role/*").hasAnyRole("ROLE_ADMIN")
.antMatchers("/api/v1/user_role/*").hasAnyRole("ROLE_USER")
.antMatchers("/actuator/health").hasAnyRole("ROLE_ADMIN")
.antMatchers("/actuator/circuitbreakerevents").hasAnyRole("ROLE_ADMIN")
.anyRequest()
.permitAll();
}
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider provider = keycloakAuthenticationProvider();
provider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
auth.authenticationProvider(provider);
}
@Override
@Bean
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
}
How can I fix the issue?
Here is my project link : [Link][1]
[1]: https://github.com/Rapter1990/SpringBootMicroservices
Here is my controller in Management Service
@RestController
@RequestMapping("/api/v1/admin_role")
@RequiredArgsConstructor
public class AdminController {
private final AdminService adminService;
@GetMapping("/alladvertisements")
@CircuitBreaker(name = "management", fallbackMethod = "managementFallback")
public ResponseEntity<List<Advertisement>> getAllAdvertisements(){
LOGGER.info("AdminController | getAllAdvertisements is started");
return ResponseEntity.ok(adminService.getAllAdvertisements());
}
}