Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
notes2.0
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zjm
notes2.0
Commits
30064e3b
提交
30064e3b
authored
3月 05, 2020
作者:
gongwenjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
撤销 "合并分支 'gwj' 到 'master'"
这将还原合并请求
!8
上级
37a59a26
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
14 行增加
和
62 行删除
+14
-62
pom.xml
notes-pas/pom.xml
+2
-4
SecurityConfig.java
...main/java/com/zjty/tynotes/pas/config/SecurityConfig.java
+0
-5
MySuccessHandler.java
...com/zjty/tynotes/pas/config/handler/MySuccessHandler.java
+9
-42
LoginController.java
...java/com/zjty/tynotes/pas/controller/LoginController.java
+1
-8
application-prod.properties
notes-union/src/main/resources/application-prod.properties
+1
-1
application.properties
notes-union/src/main/resources/application.properties
+1
-2
没有找到文件。
notes-pas/pom.xml
浏览文件 @
30064e3b
...
...
@@ -52,10 +52,7 @@
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
notes-pas/src/main/java/com/zjty/tynotes/pas/config/SecurityConfig.java
浏览文件 @
30064e3b
...
...
@@ -3,7 +3,6 @@ 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
;
...
...
@@ -37,8 +36,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private
MyAccessHandler
accessHandler
;
@Autowired
private
MyEntryPoint
myEntryPoint
;
@Autowired
private
MySuccessHandler
successHandler
;
@Autowired
private
MyUserDetailsServiceImpl
myUserDetailsServiceImpl
;
...
...
@@ -81,7 +78,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
addFilterAt
(
myFilter
(),
UsernamePasswordAuthenticationFilter
.
class
)
.
addFilterBefore
(
corsFilter
(),
ChannelProcessingFilter
.
class
)
.
csrf
().
csrfTokenRepository
(
CookieCsrfTokenRepository
.
withHttpOnlyFalse
()).
disable
().
sessionManagement
().
maximumSessions
(
1
).
expiredUrl
(
"/userLogout"
).
sessionRegistry
(
sessionRegistry
())
;
}
...
...
@@ -94,7 +90,6 @@ 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
浏览文件 @
30064e3b
package
com
.
zjty
.
tynotes
.
pas
.
config
.
handler
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
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.Authority
;
import
com.zjty.tynotes.pas.entity.Role
;
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
;
...
...
@@ -29,11 +26,8 @@ import javax.servlet.ServletException;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.constraints.NotNull
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
/**
* @author mcj
...
...
@@ -48,13 +42,7 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
private
IAuthorityService
iAuthorityService
;
@Autowired
RoleDao
roleDao
;
@Autowired
private
UserRoleDao
userRoleDao
;
@Autowired
private
RoleAuthorityDao
roleAuthorityDao
;
@Autowired
private
AuthorityDao
authorityDao
;
IRoleService
iRoleService
;
private
BCryptPasswordEncoder
bCryptPasswordEncoder
=
new
BCryptPasswordEncoder
();
...
...
@@ -63,8 +51,6 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
@Autowired
RedisTemplate
redisTemplate
;
@Autowired
private
Init
init
;
@Override
public
void
onAuthenticationSuccess
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
Authentication
authentication
)
throws
IOException
,
ServletException
{
...
...
@@ -88,32 +74,13 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
}
}
// 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
);
}
redisTemplate
.
opsForValue
().
set
(
user
.
getUsername
(),
0
);
sessionRegistry
.
registerNewSession
(
value
,
authentication
.
getPrincipal
());
httpServletResponse
.
setStatus
(
200
);
httpServletResponse
.
setContentType
(
"application/json; charset=utf-8"
);
httpServletResponse
.
getWriter
().
println
(
new
ObjectMapper
().
writeValueAsString
(
user
));
httpServletResponse
.
getWriter
().
println
(
new
ObjectMapper
().
writeValueAsString
(
"登陆成功"
));
}
}
notes-pas/src/main/java/com/zjty/tynotes/pas/controller/LoginController.java
浏览文件 @
30064e3b
...
...
@@ -7,7 +7,6 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
...
...
@@ -18,9 +17,9 @@ import java.util.HashMap;
* @Version 1.0
*/
@Api
(
tags
=
"用户管理权限管理模块"
,
protocols
=
"http"
)
@RestController
@RequestMapping
(
"/pas/count"
)
@AutoDocument
@Controller
public
class
LoginController
{
@Autowired
...
...
@@ -28,16 +27,10 @@ public class LoginController {
@ApiOperation
(
value
=
"登陆失败计数"
,
response
=
String
.
class
)
@PostMapping
@ResponseBody
public
ResponseEntity
login
(
@RequestBody
String
username
){
String
s
=
iUserService
.
addUserCount
(
username
);
HashMap
<
Object
,
Object
>
map
=
new
HashMap
<>(
16
);
map
.
put
(
"msg"
,
s
);
return
ResponseEntity
.
ok
(
map
);
}
@GetMapping
(
"/login"
)
public
String
login2
(){
return
"login"
;
}
}
notes-union/src/main/resources/application-prod.properties
浏览文件 @
30064e3b
...
...
@@ -18,7 +18,7 @@ spring.data.mongodb.uri=mongodb://localhost:27017/notes
spring.servlet.multipart.max-file-size
=
100MB
spring.servlet.multipart.max-request-size
=
1000MB
spring.redis.host
=
127.0.0.1
spring.redis.host
=
localhost
spring.redis.port
=
6379
spring.redis.timeout
=
5000ms
...
...
notes-union/src/main/resources/application.properties
浏览文件 @
30064e3b
...
...
@@ -13,9 +13,8 @@ server.port=8289
## 证书别名
#server.ssl.keyAlias= alias
#mongodb configuration
spring.data.mongodb.uri
=
mongodb://localhost:27017/note
spring.data.mongodb.uri
=
mongodb://localhost:27017/note
s
# servlet configuration
spring.servlet.multipart.max-file-size
=
100MB
spring.servlet.multipart.max-request-size
=
1000MB
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论