Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
ruoyi-bs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
过峰
ruoyi-bs
Commits
1a560350
提交
1a560350
authored
12月 13, 2024
作者:
陈柏江
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
LoginNew 添加匿名访问权限
上级
c34f92d1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
9 行增加
和
13 行删除
+9
-13
SecurityConfig.java
.../main/java/com/ruoyi/framework/config/SecurityConfig.java
+9
-13
没有找到文件。
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
浏览文件 @
1a560350
package
com
.
ruoyi
.
framework
.
config
;
package
com
.
ruoyi
.
framework
.
config
;
import
com.ruoyi.framework.config.properties.PermitAllUrlProperties
;
import
com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter
;
import
com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl
;
import
com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl
;
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.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -16,10 +20,6 @@ import org.springframework.security.web.SecurityFilterChain;
...
@@ -16,10 +20,6 @@ import org.springframework.security.web.SecurityFilterChain;
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.security.web.authentication.logout.LogoutFilter
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.filter.CorsFilter
;
import
com.ruoyi.framework.config.properties.PermitAllUrlProperties
;
import
com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter
;
import
com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl
;
import
com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl
;
/**
/**
* spring security配置
* spring security配置
...
@@ -28,8 +28,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
...
@@ -28,8 +28,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
*/
*/
@EnableMethodSecurity
(
prePostEnabled
=
true
,
securedEnabled
=
true
)
@EnableMethodSecurity
(
prePostEnabled
=
true
,
securedEnabled
=
true
)
@Configuration
@Configuration
public
class
SecurityConfig
public
class
SecurityConfig
{
{
/**
/**
* 自定义用户认证逻辑
* 自定义用户认证逻辑
*/
*/
...
@@ -70,8 +69,7 @@ public class SecurityConfig
...
@@ -70,8 +69,7 @@ public class SecurityConfig
* 身份验证实现
* 身份验证实现
*/
*/
@Bean
@Bean
public
AuthenticationManager
authenticationManager
()
public
AuthenticationManager
authenticationManager
()
{
{
DaoAuthenticationProvider
daoAuthenticationProvider
=
new
DaoAuthenticationProvider
();
DaoAuthenticationProvider
daoAuthenticationProvider
=
new
DaoAuthenticationProvider
();
daoAuthenticationProvider
.
setUserDetailsService
(
userDetailsService
);
daoAuthenticationProvider
.
setUserDetailsService
(
userDetailsService
);
daoAuthenticationProvider
.
setPasswordEncoder
(
bCryptPasswordEncoder
());
daoAuthenticationProvider
.
setPasswordEncoder
(
bCryptPasswordEncoder
());
...
@@ -94,8 +92,7 @@ public class SecurityConfig
...
@@ -94,8 +92,7 @@ public class SecurityConfig
* authenticated | 用户登录后可访问
* authenticated | 用户登录后可访问
*/
*/
@Bean
@Bean
protected
SecurityFilterChain
filterChain
(
HttpSecurity
httpSecurity
)
throws
Exception
protected
SecurityFilterChain
filterChain
(
HttpSecurity
httpSecurity
)
throws
Exception
{
{
return
httpSecurity
return
httpSecurity
// CSRF禁用,因为不使用session
// CSRF禁用,因为不使用session
.
csrf
(
csrf
->
csrf
.
disable
())
.
csrf
(
csrf
->
csrf
.
disable
())
...
@@ -111,7 +108,7 @@ public class SecurityConfig
...
@@ -111,7 +108,7 @@ public class SecurityConfig
.
authorizeHttpRequests
((
requests
)
->
{
.
authorizeHttpRequests
((
requests
)
->
{
permitAllUrl
.
getUrls
().
forEach
(
url
->
requests
.
antMatchers
(
url
).
permitAll
());
permitAllUrl
.
getUrls
().
forEach
(
url
->
requests
.
antMatchers
(
url
).
permitAll
());
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
requests
.
antMatchers
(
"/login
"
,
"/register"
,
"/captchaImage"
).
permitAll
()
requests
.
antMatchers
(
"/login"
,
"/loginNew
"
,
"/register"
,
"/captchaImage"
).
permitAll
()
// 静态资源,可匿名访问
// 静态资源,可匿名访问
.
antMatchers
(
HttpMethod
.
GET
,
"/"
,
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/profile/**"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
GET
,
"/"
,
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/profile/**"
).
permitAll
()
.
antMatchers
(
"/swagger-ui.html"
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/*/api-docs"
,
"/druid/**"
).
permitAll
()
.
antMatchers
(
"/swagger-ui.html"
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/*/api-docs"
,
"/druid/**"
).
permitAll
()
...
@@ -132,8 +129,7 @@ public class SecurityConfig
...
@@ -132,8 +129,7 @@ public class SecurityConfig
* 强散列哈希加密实现
* 强散列哈希加密实现
*/
*/
@Bean
@Bean
public
BCryptPasswordEncoder
bCryptPasswordEncoder
()
public
BCryptPasswordEncoder
bCryptPasswordEncoder
()
{
{
return
new
BCryptPasswordEncoder
();
return
new
BCryptPasswordEncoder
();
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论