org.springframework.web.servlet.config.annotation.CorsRegistry Java Examples

The following examples show how to use org.springframework.web.servlet.config.annotation.CorsRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebConfig.java    From openvsx with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
    if (!Strings.isNullOrEmpty(webuiUrl) && UrlUtil.isAbsolute(webuiUrl)) {
        // The Web UI is given with an absolute URL, so we need to enable CORS with credentials.
        var authorizedEndpoints = new String[] {
            "/user/**",
            "/logout",
            "/api/*/*/review/**"
        };
        for (var endpoint : authorizedEndpoints) {
            registry.addMapping(endpoint)
                    .allowedOrigins(webuiUrl)
                    .allowCredentials(true);
        }
    }
}
 
Example #2
Source File: AdminApplication.java    From mogu_blog_v2 with Apache License 2.0 6 votes vote down vote up
/**
     * 跨域过滤器
     *
     * @return
     */
//    @Bean
//    public CorsFilter corsFilter() {
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        source.registerCorsConfiguration("/**", buildConfig());
//        return new CorsFilter(source);
//    }

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                //配置允许跨域访问的路径
                registry.addMapping("/**/**")
                        .allowedOrigins("*")
                        .allowedMethods("*")
                        .allowedHeaders("*")
                        .allowCredentials(true)
                        .exposedHeaders("")
                        .maxAge(3600);
            }
        };
    }
 
Example #3
Source File: CorsConfig.java    From parker with MIT License 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {

    //设置允许跨域的路径
    registry.addMapping("/**")
            //设置允许跨域请求的域名
            .allowedOrigins("*")
            //是否允许证书 不再默认开启
            .allowCredentials(true)
            //设置允许的方法
            .allowedMethods("*")
            //跨域允许时间
            .maxAge(3600);
}
 
Example #4
Source File: WebMvcConfig.java    From AnyMock with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer crossOriginConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping(URL_PREFIX_API_V2_PATTERN);
        }
    };
}
 
Example #5
Source File: WebConfig.java    From grpc-swagger with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedHeaders("*")
                    .allowedMethods("*")
                    .allowedOrigins("*");
        }
    };
}
 
Example #6
Source File: CouponApplication.java    From kakaopay-coupon with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void addCorsMappings(CorsRegistry registry) {
			registry.addMapping("/api/v1/*").allowedOrigins("http://localhost:8081");
		}
	};
}
 
Example #7
Source File: WebMVCConfiguration.java    From Mahuta with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {

    registry.addMapping(MAPPING_PATH)
            .allowedOrigins(this.allowedOrigin)
            .allowedMethods(this.allowedMethods)
            .allowedHeaders(this.allowedHeaders)
            .allowCredentials(this.allowCredentials)
            .maxAge(this.maxAge);
}
 
Example #8
Source File: SecurityConfiguration.java    From Spring-Boot-2-Fundamentals with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/greeting-javaconfig").allowedOrigins("http://localhost:9000");
        }
    };
}
 
Example #9
Source File: SecurityConfiguration.java    From Spring-Boot-2-Fundamentals with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/greeting-javaconfig").allowedOrigins("http://localhost:9000");
        }
    };
}
 
Example #10
Source File: CorsConfig.java    From synchronizing-doc-convert-results with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedHeaders("*")
            .allowedMethods("*")
            .allowedOrigins("*")
            .allowCredentials(true);
}
 
Example #11
Source File: WebConfig.java    From auth-server with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
  // @formatter:off
  registry
    .addMapping("/**")
    .allowedOrigins(properties.getCorsAllowedOrigins())
    .allowedHeaders("*")
    .allowedMethods("*")
    .allowCredentials(true);
  // @formatter:on
}
 
Example #12
Source File: ServletConfig.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
	return new WebMvcConfigurer() {
		@Override
		public void addCorsMappings(CorsRegistry registry) {
			CorsRegistration reg = registry.addMapping("/api/**");
			reg.allowedOrigins("*");
		}
	};
}
 
Example #13
Source File: CorsConfig.java    From danyuan-application with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
	// 设置允许跨域的路径
	registry.addMapping("/**")
	        // 设置允许跨域请求的域名
	        .allowedOrigins("*")
	        // 是否允许证书 不再默认开启
	        .allowCredentials(true)
	        // 设置允许的方法
	        .allowedMethods("*")
	        // 跨域允许时间
	        .maxAge(3600);
}
 
Example #14
Source File: LdapSecurityConfiguration.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer webConfig() {
  return new WebMvcConfigurer() {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
      registry.addMapping("/**").allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
    }
  };
}
 
Example #15
Source File: WebAppConfigurer.java    From XUpdateService with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowCredentials(true)
            .allowedHeaders("Origin", "X-Requested-With", "Content-Type", "Accept", "X-Token", "X-TimeStamp")
            .allowedMethods("GET", "POST", "PATCH", "DELETE", "PUT")
            .maxAge(3600);
    super.addCorsMappings(registry);
}
 
Example #16
Source File: WebConfig.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * 跨域
 *
 * @param registry
 */
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*") // 1 设置访问源地址
            .allowedHeaders("*") // 2 设置访问源请求头
            .allowedMethods("*") // 3 设置访问源请求方法
            .allowCredentials(true)
            .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
            .maxAge(60*60 * 24 * 7);
}
 
Example #17
Source File: WebConfigCORS.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Cors configurer.
 *
 * @return the web mvc configurer
 */
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            if ("all".equals(allowedOrigions)) {
                registry.addMapping("/**");
            } else {
                registry.addMapping("/**").allowedOrigins(allowedOrigions);
            }
        }
    };
}
 
Example #18
Source File: WebSecurityConfig.java    From uccn with Apache License 2.0 5 votes vote down vote up
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowCredentials(true)
            .allowedMethods("GET", "POST", "DELETE", "PUT")
            .maxAge(3600);
}
 
Example #19
Source File: TxManagerConfiguration.java    From Lottor with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedHeaders("*")
                    .allowedMethods("*")
                    .allowedOrigins("*");
        }
    };
}
 
Example #20
Source File: WebSecurityConfigurer.java    From chvote-protocol-poc with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedMethods("GET", "POST", "OPTIONS")
                    .allowedOrigins("*");
        }
    };
}
 
Example #21
Source File: OpenAPI2SpringBoot.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedOrigins("*").allowedHeaders("Content-Type");
        }
    };
}
 
Example #22
Source File: SpringMvcConfiguration.java    From spring-admin-vue with Apache License 2.0 5 votes vote down vote up
/**
 * 允许跨域配置
 */
@Override
public void addCorsMappings(CorsRegistry registry) {
    log.info("跨域已设置");
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowedMethods("*")
            .allowedHeaders("*")
            .allowCredentials(true)
            .maxAge(3600);
}
 
Example #23
Source File: WebMvcConfig.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 5 votes vote down vote up
public void addCorsMappings(CorsRegistry registry){
	final long MAX_AGE_SECS = 3600;
	
    registry.addMapping("/**")
            .allowedOrigins(allowedOrigins)
            .allowedMethods("GET", "POST", "PUT", "DELETE")
            .allowedHeaders("*")
            .maxAge(MAX_AGE_SECS);
}
 
Example #24
Source File: WebConfig.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addCorsMappings(final CorsRegistry registry)
{
	// FIXME: for now we enable CORS for the whole REST API
	// registry.addMapping(ENDPOINT_ROOT + "/**");

	// NOTE: this seems to not work (i.e. headers are not added), so:
	// pls check de.metas.ui.web.config.CORSFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
	// because we are setting the headers there... and that works!

	registry.addMapping("/**");
}
 
Example #25
Source File: ContainerApplication.java    From tac with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer webMvcConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/api/**");
        }
    };
}
 
Example #26
Source File: CorsConfiguration.java    From java-crud-api with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
	return new WebMvcConfigurer() {
		@Override
		public void addCorsMappings(CorsRegistry registry) {
			registry.addMapping("/**").allowedMethods("OPTIONS", "GET", "PUT", "POST", "DELETE", "PATCH")
					.allowedHeaders("Content-Type", "X-XSRF-TOKEN").allowedOrigins(allowedOrigins)
					.allowCredentials(true).maxAge(1728000);
		}
	};
}
 
Example #27
Source File: MainController.java    From OSTMap with Apache License 2.0 5 votes vote down vote up
/**
 * Global enable CORS for all mappings /api/**
 *
 * @return
 */
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/api/**");
        }
    };
}
 
Example #28
Source File: CorsConfig.java    From SpringBoot-Home with Apache License 2.0 5 votes vote down vote up
public WebMvcConfigurer corsConfigurer()
{
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").
                    allowedOrigins("https://www.dustyblog.cn"). //允许跨域的域名,可以用*表示允许任何域名使用
                    allowedMethods("*"). //允许任何方法(post、get等)
              allowedHeaders("*"). //允许任何请求头
                    allowCredentials(true). //带上cookie信息
                    exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L); //maxAge(3600)表明在3600秒内,不需要再发送预检验请求,可以缓存该结果
        }
    };
}
 
Example #29
Source File: Application.java    From spring-boot-react-maven-starter with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedMethods("*").allowedOrigins("http://localhost:3000");
        }
    };
}
 
Example #30
Source File: CORSConfig.java    From LazyREST with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins(ALL)
                    .allowedMethods(ALL)
                    .allowedHeaders(ALL)
                    .allowCredentials(true);
        }
    };
}