Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
notes2.0
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zjm
notes2.0
Commits
114229d4
提交
114229d4
authored
3月 05, 2020
作者:
gongwenjie
浏览文件
操作
浏览文件
下载
差异文件
合并分支 'gwj' 到 'master'
登录 查看合并请求
!11
上级
7e532bbc
b9065143
流水线
#17
已失败 于阶段
变更
2
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
4 行删除
+51
-4
SecurityConfig.java
...main/java/com/zjty/tynotes/pas/config/SecurityConfig.java
+6
-0
MySuccessHandler.java
...com/zjty/tynotes/pas/config/handler/MySuccessHandler.java
+45
-4
没有找到文件。
notes-pas/src/main/java/com/zjty/tynotes/pas/config/SecurityConfig.java
浏览文件 @
114229d4
...
...
@@ -3,6 +3,7 @@ package com.zjty.tynotes.pas.config;
import
com.zjty.tynotes.pas.config.handler.MyAccessHandler
;
import
com.zjty.tynotes.pas.config.handler.MyFailHandler
;
import
com.zjty.tynotes.pas.config.handler.MyLogoutHandler
;
import
com.zjty.tynotes.pas.config.handler.MySuccessHandler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -46,6 +47,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private
MyFailHandler
failHandler
;
@Autowired
private
MySuccessHandler
successHandler
;
@Override
public
void
configure
(
HttpSecurity
httpSecurity
)
throws
Exception
{
httpSecurity
...
...
@@ -90,6 +95,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public
MyFilter
myFilter
()
throws
Exception
{
MyFilter
filter
=
new
MyFilter
();
filter
.
setAuthenticationSuccessHandler
(
successHandler
);
filter
.
setAuthenticationFailureHandler
(
failHandler
);
filter
.
setFilterProcessesUrl
(
"/userLogin"
);
filter
.
setAuthenticationManager
(
this
.
authenticationManager
());
...
...
notes-pas/src/main/java/com/zjty/tynotes/pas/config/handler/MySuccessHandler.java
浏览文件 @
114229d4
...
...
@@ -3,10 +3,17 @@ package com.zjty.tynotes.pas.config.handler;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.zjty.tynotes.pas.entity.Authority
;
import
com.zjty.tynotes.pas.entity.Role
;
import
com.zjty.tynotes.pas.dao.AuthorityDao
;
import
com.zjty.tynotes.pas.dao.RoleAuthorityDao
;
import
com.zjty.tynotes.pas.dao.RoleDao
;
import
com.zjty.tynotes.pas.dao.UserRoleDao
;
import
com.zjty.tynotes.pas.entity.*
;
import
com.zjty.tynotes.pas.entity.User
;
import
com.zjty.tynotes.pas.service.IAuthorityService
;
import
com.zjty.tynotes.pas.service.IRoleService
;
import
com.zjty.tynotes.pas.service.IUserService
;
import
com.zjty.tynotes.pas.task.Init
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
...
@@ -27,7 +34,9 @@ import javax.servlet.http.Cookie;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
/**
* @author mcj
...
...
@@ -49,6 +58,18 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
@Autowired
IUserService
iUserService
;
RoleDao
roleDao
;
@Autowired
private
UserRoleDao
userRoleDao
;
@Autowired
private
RoleAuthorityDao
roleAuthorityDao
;
@Autowired
private
AuthorityDao
authorityDao
;
@Autowired
private
Init
init
;
@Autowired
RedisTemplate
redisTemplate
;
...
...
@@ -74,13 +95,33 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
}
}
redisTemplate
.
opsForValue
().
set
(
user
.
getUsername
(),
0
);
// redisTemplate.opsForValue().set(user.getUsername(),0);
if
((
"root"
).
equals
(
user
.
getUsername
())){
user
=
init
.
root
;
}
else
{
List
<
UserRole
>
userRoles
=
userRoleDao
.
findAllByUserId
(
user
.
getId
());
List
<
Role
>
roles
=
new
ArrayList
<>();
for
(
UserRole
userRole
:
userRoles
)
{
String
roleId
=
userRole
.
getRoleId
();
Optional
<
Role
>
op
=
roleDao
.
findById
(
userRole
.
getRoleId
());
if
(
op
.
isPresent
()){
Role
role
=
op
.
get
();
List
<
RoleAuthority
>
roleAuthorities
=
roleAuthorityDao
.
findAllByRoleId
(
roleId
);
List
<
String
>
authorityIds
=
new
ArrayList
<>();
for
(
RoleAuthority
roleAuthority
:
roleAuthorities
)
{
authorityIds
.
add
(
roleAuthority
.
getAuthorityId
());
}
List
<
Authority
>
authorities
=
authorityDao
.
findAllByIdIn
(
authorityIds
);
role
.
setAuthorities
(
authorities
);
roles
.
add
(
role
);
}
}
user
.
setRoles
(
roles
);
}
sessionRegistry
.
registerNewSession
(
value
,
authentication
.
getPrincipal
());
httpServletResponse
.
setStatus
(
200
);
httpServletResponse
.
setContentType
(
"application/json; charset=utf-8"
);
httpServletResponse
.
getWriter
().
println
(
new
ObjectMapper
().
writeValueAsString
(
"登陆成功"
));
httpServletResponse
.
getWriter
().
println
(
new
ObjectMapper
().
writeValueAsString
(
user
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论