Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
1e40e60d
提交
1e40e60d
authored
7月 22, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持CORS跨域请求
上级
133a10ec
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
37 行增加
和
0 行删除
+37
-0
ResourcesConfig.java
...main/java/com/ruoyi/framework/config/ResourcesConfig.java
+24
-0
SecurityConfig.java
.../main/java/com/ruoyi/framework/config/SecurityConfig.java
+11
-0
GenController.java
...in/java/com/ruoyi/generator/controller/GenController.java
+2
-0
没有找到文件。
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
浏览文件 @
1e40e60d
package
com
.
ruoyi
.
framework
.
config
;
package
com
.
ruoyi
.
framework
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
@@ -39,4 +43,24 @@ public class ResourcesConfig implements WebMvcConfigurer
...
@@ -39,4 +43,24 @@ public class ResourcesConfig implements WebMvcConfigurer
{
{
registry
.
addInterceptor
(
repeatSubmitInterceptor
).
addPathPatterns
(
"/**"
);
registry
.
addInterceptor
(
repeatSubmitInterceptor
).
addPathPatterns
(
"/**"
);
}
}
/**
* 跨域配置
*/
@Bean
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setAllowCredentials
(
true
);
// 设置访问源地址
config
.
addAllowedOrigin
(
"*"
);
// 设置访问源请求头
config
.
addAllowedHeader
(
"*"
);
// 设置访问源请求方法
config
.
addAllowedMethod
(
"*"
);
// 对接口配置跨域设置
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
}
}
\ No newline at end of file
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
浏览文件 @
1e40e60d
...
@@ -12,6 +12,8 @@ import org.springframework.security.config.http.SessionCreationPolicy;
...
@@ -12,6 +12,8 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.security.web.authentication.logout.LogoutFilter
;
import
org.springframework.web.filter.CorsFilter
;
import
com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter
;
import
com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter
;
import
com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl
;
import
com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl
;
import
com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl
;
import
com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl
;
...
@@ -47,6 +49,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
...
@@ -47,6 +49,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
*/
*/
@Autowired
@Autowired
private
JwtAuthenticationTokenFilter
authenticationTokenFilter
;
private
JwtAuthenticationTokenFilter
authenticationTokenFilter
;
/**
* 跨域过滤器
*/
@Autowired
private
CorsFilter
corsFilter
;
/**
/**
* 解决 无法直接注入 AuthenticationManager
* 解决 无法直接注入 AuthenticationManager
...
@@ -112,6 +120,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
...
@@ -112,6 +120,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
httpSecurity
.
logout
().
logoutUrl
(
"/logout"
).
logoutSuccessHandler
(
logoutSuccessHandler
);
httpSecurity
.
logout
().
logoutUrl
(
"/logout"
).
logoutSuccessHandler
(
logoutSuccessHandler
);
// 添加JWT filter
// 添加JWT filter
httpSecurity
.
addFilterBefore
(
authenticationTokenFilter
,
UsernamePasswordAuthenticationFilter
.
class
);
httpSecurity
.
addFilterBefore
(
authenticationTokenFilter
,
UsernamePasswordAuthenticationFilter
.
class
);
// 添加CORS filter
httpSecurity
.
addFilterBefore
(
corsFilter
,
JwtAuthenticationTokenFilter
.
class
);
httpSecurity
.
addFilterBefore
(
corsFilter
,
LogoutFilter
.
class
);
}
}
...
...
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
浏览文件 @
1e40e60d
...
@@ -178,6 +178,8 @@ public class GenController extends BaseController
...
@@ -178,6 +178,8 @@ public class GenController extends BaseController
private
void
genCode
(
HttpServletResponse
response
,
byte
[]
data
)
throws
IOException
private
void
genCode
(
HttpServletResponse
response
,
byte
[]
data
)
throws
IOException
{
{
response
.
reset
();
response
.
reset
();
response
.
addHeader
(
"Access-Control-Allow-Origin"
,
"*"
);
response
.
addHeader
(
"Access-Control-Expose-Headers"
,
"Content-Disposition"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"ruoyi.zip\""
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"ruoyi.zip\""
);
response
.
addHeader
(
"Content-Length"
,
""
+
data
.
length
);
response
.
addHeader
(
"Content-Length"
,
""
+
data
.
length
);
response
.
setContentType
(
"application/octet-stream; charset=UTF-8"
);
response
.
setContentType
(
"application/octet-stream; charset=UTF-8"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论