Replace CrossOrigin annotaion with global configuration

This commit is contained in:
George Kalampokis 2022-04-18 18:32:25 +03:00
parent 1d1226dc5f
commit 85b37dd16d
39 changed files with 16 additions and 48 deletions

View File

@ -1,37 +1,43 @@
package eu.eudat.configurations;
import eu.eudat.controllers.interceptors.RequestInterceptor;
import eu.eudat.logic.handlers.PrincipalArgumentResolver;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@EnableAsync
@Configuration
@EnableScheduling
public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
public class WebMVCConfiguration implements WebMvcConfigurer {
private ApiContext apiContext;
private AuthenticationService verifiedUserAuthenticationService;
private AuthenticationService nonVerifiedUserAuthenticationService;
private final AuthenticationService verifiedUserAuthenticationService;
private final AuthenticationService nonVerifiedUserAuthenticationService;
@Autowired
public WebMVCConfiguration(ApiContext apiContext, AuthenticationService verifiedUserAuthenticationService, AuthenticationService nonVerifiedUserAuthenticationService) {
private final Environment environment;
public WebMVCConfiguration(ApiContext apiContext, AuthenticationService verifiedUserAuthenticationService, AuthenticationService nonVerifiedUserAuthenticationService, Environment environment) {
this.apiContext = apiContext;
this.verifiedUserAuthenticationService = verifiedUserAuthenticationService;
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
this.environment = environment;
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**").allowedOrigins(this.environment.getProperty("dmp.domain"));
}
@Autowired
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new PrincipalArgumentResolver(verifiedUserAuthenticationService, nonVerifiedUserAuthenticationService));

View File

@ -38,7 +38,6 @@ import static eu.eudat.types.Authorities.ADMIN;
import static eu.eudat.types.Authorities.DATASET_PROFILE_MANAGER;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/admin/"})
public class Admin extends BaseController {

View File

@ -18,7 +18,6 @@ import java.util.List;
* Created by ikalyvas on 3/28/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/common"})
public class CommonController {

View File

@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
@RestController
@CrossOrigin
@RequestMapping(value = "api/contactEmail")
public class ContactEmail {
private static final Logger logger = LoggerFactory.getLogger(ContactEmail.class);

View File

@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = "api/currency")
public class CurrencyController {

View File

@ -31,7 +31,6 @@ import static eu.eudat.types.Authorities.ADMIN;
* Created by ikalyvas on 3/21/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/dmpprofile"})
public class DMPProfileController extends BaseController {

View File

@ -62,7 +62,6 @@ import static org.springframework.http.MediaType.*;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/dmps/"})
public class DMPs extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(DMPs.class);

View File

@ -22,11 +22,10 @@ import java.io.IOException;
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class DashBoardController extends BaseController {
private DashBoardManager dashBoardManager;
private final DashBoardManager dashBoardManager;
@Autowired
public DashBoardController(ApiContext apiContext, DashBoardManager dashBoardManager) {
super(apiContext);

View File

@ -19,7 +19,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/datarepos"})
public class DataRepositories extends BaseController {

View File

@ -23,7 +23,6 @@ import java.util.UUID;
import static eu.eudat.types.Authorities.ADMIN;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class DatasetProfileController extends BaseController {

View File

@ -17,7 +17,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class DatasetProfiles extends BaseController {

View File

@ -59,7 +59,6 @@ import static eu.eudat.types.Authorities.ANONYMOUS;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/datasets/"})
public class Datasets extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(Datasets.class);

View File

@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
@RestController
@CrossOrigin
@RequestMapping(value = "api/emailConfirmation")
public class EmailConfirmation {

View File

@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
@RestController
@CrossOrigin
@RequestMapping(value = "api/emailMergeConfirmation")
public class EmailMergeConfirmation {

View File

@ -24,7 +24,6 @@ import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class ExternalDatasets extends BaseController {

View File

@ -40,7 +40,6 @@ import java.util.UUID;
import java.util.stream.Collectors;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/file/"})
public class FileController {
private static final Logger logger = LoggerFactory.getLogger(FileController.class);

View File

@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/funders/"})
public class Funders extends BaseController {
private FunderManager funderManager;

View File

@ -28,7 +28,6 @@ import static eu.eudat.types.Authorities.ANONYMOUS;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/grants/"})
public class Grants extends BaseController {
private GrantManager grantManager;

View File

@ -19,7 +19,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/journals"})
public class JournalsController extends BaseController {

View File

@ -15,7 +15,6 @@ import java.io.*;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/language/"})
public class LanguageController {

View File

@ -17,7 +17,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/licenses"})
public class Licenses extends BaseController {

View File

@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/lock/"})
public class LockController {

View File

@ -50,7 +50,6 @@ import java.security.GeneralSecurityException;
@RestController
@CrossOrigin
@RequestMapping(value = "api/auth")
public class Login {
private static final Logger logger = LoggerFactory.getLogger(Login.class);

View File

@ -20,7 +20,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Organisations extends BaseController {

View File

@ -14,7 +14,6 @@ import java.util.List;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Prefillings {

View File

@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/projects/"})
public class Projects extends BaseController {
private ProjectManager projectManager;

View File

@ -17,7 +17,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/pubrepos"})
public class PubRepositoriesController extends BaseController {

View File

@ -17,7 +17,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/publications"})
public class PublicationsController extends BaseController {

View File

@ -26,7 +26,6 @@ import javax.validation.Valid;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/quick-wizard/"})
public class QuickWizardController extends BaseController {

View File

@ -19,7 +19,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Registries extends BaseController {

View File

@ -21,7 +21,6 @@ import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/researchers"})
public class Researchers extends BaseController {

View File

@ -19,7 +19,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Services extends BaseController {

View File

@ -25,7 +25,6 @@ import java.util.stream.Collectors;
* Created by ikalyvas on 7/5/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class TagController extends BaseController {

View File

@ -17,7 +17,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/external/taxonomies"})
public class TaxonomiesController extends BaseController {

View File

@ -26,7 +26,6 @@ import java.util.stream.Stream;
import static eu.eudat.types.Authorities.ADMIN;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/userguide/"})
public class UserGuideController {

View File

@ -22,7 +22,6 @@ import java.util.UUID;
@RequestMapping("api/invite/")
@RestController
@CrossOrigin
public class UserInvitationController extends BaseController {
private InvitationsManager invitationsManager;

View File

@ -31,7 +31,6 @@ import static eu.eudat.types.Authorities.ADMIN;
@RestController
@CrossOrigin
@RequestMapping(value = "api/user")
public class Users extends BaseController {

View File

@ -20,7 +20,6 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Validation extends BaseController {

View File

@ -11,7 +11,6 @@ import java.net.*;
@RestController
@CrossOrigin
public class Proxy {
private String allowedHost;