Answer the question
In order to leave comments, you need to log in
Why is the request not reaching the controller?
I have a problem with requests and their processing.
There is a ManagerController that accepts various requests. There he is:
@Controller
@RequestMapping("/managerToolsService")
public class ManagerController {
@Autowired
private ScheduleService scheduleService;
@Autowired
private TrainService trainService;
@Autowired
private TicketService ticketService;
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MANAGER')")
@GetMapping("/viewBookingTrains")
public String viewBookingTrains(Model model) {
//List<TrainDTO> bookingTrains = trainService.getAll();
List<Train> bookingTrains = trainService.getAllValidTrains();
model.addAttribute("bookingTrains", bookingTrains);
return "booking-train-users-list";
}
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MANAGER')")
@RequestMapping(name = "/viewSchedules", params = "trainId")
public String viewBookingTrains(@RequestParam(value = "trainId") Long trainId, Model model) {
List<Schedule> selectedScheduleByTrain = scheduleService.getByTrain(
trainService.getById(trainId)
);
model.addAttribute("selectedSchedulesByTrain", selectedScheduleByTrain);
return "schedule-list";
}
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MANAGER')")
@RequestMapping(name = "/viewBookingUsersInfo", params = "scheduleId")
public String viewBookingUsersInfo(@RequestParam(value = "scheduleId") Long scheduleId, Model model) {
// List<Seat> bookingSeats = ticketService.getBookingSeatsBySchedule(
// scheduleService.getById(scheduleId)
// );
List<Ticket> tickets = ticketService.getBySchedules(
scheduleService.getById(scheduleId)
);
model.addAttribute("tickets", tickets);
return "booking-users-in-train";
}
}
/viewBookingTrains
<!-- Add HTML table -->
<table class="table table-striped">
<tr>
<th>Train name</th>
</tr>
<!-- Loop over and print stations -->
<c:forEach var="tmpTrain" items="${bookingTrains}">
<tr>
<td>${tmpTrain.name}</td>
<td><a href="/managerToolsService/viewSchedules?trainId=${tmpTrain.id}">Watch</a> </td>
</tr>
</c:forEach>
a href="/managerToolsService/viewSchedules?trainId=${tmpTrain.id}
I getHTTP Status 404 – Not Found
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
http://localhost:8080/managerToolsService/viewSchedules?trainId=4
). @Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan(basePackageClasses = UserDetailServiceImpl.class)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(new BCryptPasswordEncoder());
}
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("http://localhost:8080");
}
};
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.setAllowedOrigins(Collections.singletonList("*"));
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/registration",
"/login",
"/",
"/static/**",
"/home",
"/stations/list",
"/schedule/scheduleList",
"/schedule/scheduleByStationsAndDate")
.permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("login")
.passwordParameter("password")
.defaultSuccessUrl("/home")
.failureUrl("/login?error=true")
.and()
.cors()
.and()
.csrf().disable()
.logout().permitAll();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean()
throws Exception {
return super.authenticationManagerBean();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question