I have the following resource structure in my spring application and I am referring to my files in html like this.
<link rel="stylesheet" th:href="@{/css/style.css}">
<img th:src="@{/images/caleta.png}" alt="logo" class="logo-img">
When I access my application on localhost it works fine but when accessed from a pubic domain I get Bad requests.
I am unable to debug my application to find out the root cause of this issue but it started happening ever since I implemented oauth2 login in my app. When I access from public domain, internally ‘/error’ is being triggered.
@RequestMapping("/error")
public String handleError(HttpServletRequest request) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
String errorMessage = (throwable != null) ? throwable.getMessage() : "N/A";
LOG.info("Error occurred with status code: " + statusCode + " and message: " + errorMessage);
return "pages/error-page-link";
}
My security config implementation
@Configuration
@EnableWebSecurity
public class SecurityConfig implements WebMvcConfigurer {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
.requestMatchers("/**")
.permitAll())
.oauth2Login(oauth2Login -> oauth2Login
.loginPage("/login")
.successHandler((request, response, authentication) -> response.sendRedirect("/login/microsoft")));
return http.build();
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*");
}
}
I tried configuring cors, specifying resource handler and permitting all request but still getting Bad Request.