Add cors configuration support.

main
Paulo Gustavo Veiga 2024-02-17 18:16:46 -08:00
parent a829844c1a
commit 3106b3e94a
5 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,24 @@
package com.wisemapping.config.rest;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Value("${app.security.corsAllowedOrigins:}")
private String corsAllowedOrigins;
@Override
public void addCorsMappings(@NotNull CorsRegistry registry) {
if (!corsAllowedOrigins.isEmpty()) {
registry.addMapping("/api/**")
.allowedOrigins(corsAllowedOrigins).
maxAge(3600);
}
}
}

View File

@ -40,7 +40,6 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/api/restful/account") @RequestMapping("/api/restful/account")
@PreAuthorize("isAuthenticated() and hasRole('ROLE_USER')") @PreAuthorize("isAuthenticated() and hasRole('ROLE_USER')")
@CrossOrigin
public class AccountController extends BaseController { public class AccountController extends BaseController {
@Qualifier("userService") @Qualifier("userService")
@Autowired @Autowired

View File

@ -32,7 +32,6 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController
@CrossOrigin
@RequestMapping("/api/restful") @RequestMapping("/api/restful")
public class JwtAuthController { public class JwtAuthController {

View File

@ -48,7 +48,6 @@ import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/api/restful/maps") @RequestMapping("/api/restful/maps")
@CrossOrigin
public class MindmapController extends BaseController { public class MindmapController extends BaseController {
private final Logger logger = LogManager.getLogger(); private final Logger logger = LogManager.getLogger();

View File

@ -71,6 +71,7 @@ app:
# Redirect to this url, this url must be configured in the google app {baseurl}/c/registration-google # Redirect to this url, this url must be configured in the google app {baseurl}/c/registration-google
#security.oauth2.google.callbackUrl=<oauth callback url> #security.oauth2.google.callbackUrl=<oauth callback url>
security: security:
corsAllowedOrigins: https://dev.wisemapping.com
oauth2: oauth2:
google: google:
confirmUrl: https://oauth2.googleapis.com/token confirmUrl: https://oauth2.googleapis.com/token