Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
8c4f2a92
"src/main/java/net/mingsoft/config/ShiroConfig.java" did not exist on "da21280bb35139c3203936023e334b7ff67c797c"
Commit
8c4f2a92
authored
Jul 27, 2019
by
macro
Browse files
cors config update
parent
3b3882a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
mall-admin/src/main/java/com/macro/mall/config/GlobalCorsConfig.java
0 → 100644
View file @
8c4f2a92
package
com.macro.mall.config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
/**
* 全局跨域配置
* Created by macro on 2019/7/27.
*/
@Configuration
public
class
GlobalCorsConfig
{
/**
* 允许跨域调用的过滤器
*/
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
//允许所有域名进行跨域调用
config
.
addAllowedOrigin
(
"*"
);
//允许跨越发送cookie
config
.
setAllowCredentials
(
true
);
//放行全部原始头信息
config
.
addAllowedHeader
(
"*"
);
//允许所有请求方法跨域调用
config
.
addAllowedMethod
(
"*"
);
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
}
mall-admin/src/main/java/com/macro/mall/config/SecurityConfig.java
View file @
8c4f2a92
...
@@ -69,8 +69,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -69,8 +69,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
permitAll
()
.
permitAll
()
.
antMatchers
(
HttpMethod
.
OPTIONS
)
//跨域请求会先进行一次options请求
.
antMatchers
(
HttpMethod
.
OPTIONS
)
//跨域请求会先进行一次options请求
.
permitAll
()
.
permitAll
()
.
antMatchers
(
"/**"
)
//测试时全部运行访问
//
.antMatchers("/**")//测试时全部运行访问
.
permitAll
()
//
.permitAll()
.
anyRequest
()
// 除上面外的所有请求全部需要鉴权认证
.
anyRequest
()
// 除上面外的所有请求全部需要鉴权认证
.
authenticated
();
.
authenticated
();
// 禁用缓存
// 禁用缓存
...
@@ -112,23 +112,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -112,23 +112,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return
new
JwtAuthenticationTokenFilter
();
return
new
JwtAuthenticationTokenFilter
();
}
}
/**
* 允许跨域调用的过滤器
*/
@Bean
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
addAllowedOrigin
(
"*"
);
config
.
setAllowCredentials
(
true
);
config
.
addAllowedHeader
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
source
.
registerCorsConfiguration
(
"/**"
,
config
);
FilterRegistrationBean
bean
=
new
FilterRegistrationBean
(
new
CorsFilter
(
source
));
bean
.
setOrder
(
0
);
return
new
CorsFilter
(
source
);
}
@Bean
@Bean
@Override
@Override
public
AuthenticationManager
authenticationManagerBean
()
throws
Exception
{
public
AuthenticationManager
authenticationManagerBean
()
throws
Exception
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment