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
jinli gu
Eladmin
Commits
784d670c
Commit
784d670c
authored
May 24, 2019
by
zhengjie
Browse files
2.0 抢先版,主要更新了#71 | #IWYE2
parent
90c2bf90
Changes
49
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
784d670c
###
IntelliJ
IDEA ###
### IDEA ###
.idea/*
.idea/*
*.iml
*.iml
*/target/*
*/target/*
...
...
eladmin-common/pom.xml
View file @
784d670c
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
eladmin
</artifactId>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<version>
1.9
</version>
<version>
2.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerConfig.java
View file @
784d670c
...
@@ -54,8 +54,8 @@ public class SwaggerConfig {
...
@@ -54,8 +54,8 @@ public class SwaggerConfig {
private
ApiInfo
apiInfo
()
{
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
return
new
ApiInfoBuilder
()
.
title
(
"el
une
接口文档"
)
.
title
(
"el
admin
接口文档"
)
.
version
(
"
1.7
"
)
.
version
(
"
2.0
"
)
.
build
();
.
build
();
}
}
...
...
eladmin-generator/pom.xml
View file @
784d670c
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
eladmin
</artifactId>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<version>
1.9
</version>
<version>
2.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
<dependency>
<dependency>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
<artifactId>
eladmin-common
</artifactId>
<version>
1.9
</version>
<version>
2.0
</version>
</dependency>
</dependency>
<!--模板引擎-->
<!--模板引擎-->
...
...
eladmin-generator/src/main/java/me/zhengjie/domain/GenConfig.java
View file @
784d670c
...
@@ -34,6 +34,9 @@ public class GenConfig {
...
@@ -34,6 +34,9 @@ public class GenConfig {
/** 作者 **/
/** 作者 **/
private
String
author
;
private
String
author
;
/** 表前缀 **/
private
String
prefix
;
/** 是否覆盖 **/
/** 是否覆盖 **/
private
Boolean
cover
;
private
Boolean
cover
;
}
}
eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
View file @
784d670c
package
me.zhengjie.utils
;
package
me.zhengjie.utils
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.template.*
;
import
cn.hutool.extra.template.*
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
...
@@ -75,9 +76,16 @@ public class GenUtil {
...
@@ -75,9 +76,16 @@ public class GenUtil {
map
.
put
(
"date"
,
LocalDate
.
now
().
toString
());
map
.
put
(
"date"
,
LocalDate
.
now
().
toString
());
map
.
put
(
"tableName"
,
tableName
);
map
.
put
(
"tableName"
,
tableName
);
String
className
=
StringUtils
.
toCapitalizeCamelCase
(
tableName
);
String
className
=
StringUtils
.
toCapitalizeCamelCase
(
tableName
);
String
changeClassName
=
StringUtils
.
toCamelCase
(
tableName
);
// 判断是否去除表前缀
if
(
StringUtils
.
isNotEmpty
(
genConfig
.
getPrefix
()))
{
className
=
StringUtils
.
toCapitalizeCamelCase
(
StrUtil
.
removePrefix
(
tableName
,
genConfig
.
getPrefix
()));
changeClassName
=
StringUtils
.
toCamelCase
(
StrUtil
.
removePrefix
(
tableName
,
genConfig
.
getPrefix
()));
}
map
.
put
(
"className"
,
className
);
map
.
put
(
"className"
,
className
);
map
.
put
(
"upperCaseClassName"
,
className
.
toUpperCase
());
map
.
put
(
"upperCaseClassName"
,
className
.
toUpperCase
());
map
.
put
(
"changeClassName"
,
StringUtils
.
toCamelCase
(
table
Name
)
)
;
map
.
put
(
"changeClassName"
,
changeClass
Name
);
map
.
put
(
"hasTimestamp"
,
false
);
map
.
put
(
"hasTimestamp"
,
false
);
map
.
put
(
"hasBigDecimal"
,
false
);
map
.
put
(
"hasBigDecimal"
,
false
);
map
.
put
(
"hasQuery"
,
false
);
map
.
put
(
"hasQuery"
,
false
);
...
...
eladmin-logging/pom.xml
View file @
784d670c
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
eladmin
</artifactId>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<version>
1.9
</version>
<version>
2.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<dependency>
<dependency>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
<artifactId>
eladmin-common
</artifactId>
<version>
1.9
</version>
<version>
2.0
</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/domain/Log.java
View file @
784d670c
...
@@ -4,6 +4,7 @@ import lombok.Data;
...
@@ -4,6 +4,7 @@ import lombok.Data;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
org.hibernate.annotations.CreationTimestamp
;
import
org.hibernate.annotations.CreationTimestamp
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
/**
/**
...
@@ -14,7 +15,7 @@ import java.sql.Timestamp;
...
@@ -14,7 +15,7 @@ import java.sql.Timestamp;
@Data
@Data
@Table
(
name
=
"log"
)
@Table
(
name
=
"log"
)
@NoArgsConstructor
@NoArgsConstructor
public
class
Log
{
public
class
Log
implements
Serializable
{
@Id
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
...
...
eladmin-logging/src/main/java/me/zhengjie/repository/LogRepository.java
View file @
784d670c
...
@@ -21,4 +21,7 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
...
@@ -21,4 +21,7 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
*/
*/
@Query
(
value
=
"select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s"
,
nativeQuery
=
true
)
@Query
(
value
=
"select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s"
,
nativeQuery
=
true
)
Long
findIp
(
String
date1
,
String
date2
);
Long
findIp
(
String
date1
,
String
date2
);
@Query
(
value
=
"select exception_detail FROM log where id = ?1"
,
nativeQuery
=
true
)
String
findExceptionById
(
Long
id
);
}
}
eladmin-logging/src/main/java/me/zhengjie/rest/LogController.java
View file @
784d670c
package
me.zhengjie.rest
;
package
me.zhengjie.rest
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.service.query.LogQueryService
;
import
me.zhengjie.service.query.LogQueryService
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -9,6 +10,7 @@ import org.springframework.http.HttpStatus;
...
@@ -9,6 +10,7 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -23,6 +25,9 @@ public class LogController {
...
@@ -23,6 +25,9 @@ public class LogController {
@Autowired
@Autowired
private
LogQueryService
logQueryService
;
private
LogQueryService
logQueryService
;
@Autowired
private
LogService
logService
;
@GetMapping
(
value
=
"/logs"
)
@GetMapping
(
value
=
"/logs"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
public
ResponseEntity
getLogs
(
Log
log
,
Pageable
pageable
){
public
ResponseEntity
getLogs
(
Log
log
,
Pageable
pageable
){
...
@@ -43,4 +48,10 @@ public class LogController {
...
@@ -43,4 +48,10 @@ public class LogController {
log
.
setLogType
(
"ERROR"
);
log
.
setLogType
(
"ERROR"
);
return
new
ResponseEntity
(
logQueryService
.
queryAll
(
log
,
pageable
),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
logQueryService
.
queryAll
(
log
,
pageable
),
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/logs/error/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
public
ResponseEntity
getErrorLogs
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
logService
.
findByErrDetail
(
id
),
HttpStatus
.
OK
);
}
}
}
eladmin-logging/src/main/java/me/zhengjie/service/LogService.java
View file @
784d670c
...
@@ -17,4 +17,11 @@ public interface LogService {
...
@@ -17,4 +17,11 @@ public interface LogService {
*/
*/
@Async
@Async
void
save
(
ProceedingJoinPoint
joinPoint
,
Log
log
);
void
save
(
ProceedingJoinPoint
joinPoint
,
Log
log
);
/**
* 查询异常详情
* @param id
* @return
*/
Object
findByErrDetail
(
Long
id
);
}
}
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogErrorDTO.java
0 → 100644
View file @
784d670c
package
me.zhengjie.service.dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author jie
* @date 2019-5-22
*/
@Data
public
class
LogErrorDTO
implements
Serializable
{
private
Long
id
;
/**
* 操作用户
*/
private
String
username
;
/**
* 描述
*/
private
String
description
;
/**
* 方法名
*/
private
String
method
;
/**
* 参数
*/
private
String
params
;
/**
* 请求ip
*/
private
String
requestIp
;
/**
* 创建日期
*/
private
Timestamp
createTime
;
}
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/service/dto/LogSmallDTO.java
0 → 100644
View file @
784d670c
package
me.zhengjie.service.dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author jie
* @date 2019-5-22
*/
@Data
public
class
LogSmallDTO
implements
Serializable
{
/**
* 描述
*/
private
String
description
;
/**
* 请求ip
*/
private
String
requestIp
;
/**
* 请求耗时
*/
private
Long
time
;
/**
* 创建日期
*/
private
Timestamp
createTime
;
}
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
View file @
784d670c
package
me.zhengjie.service.impl
;
package
me.zhengjie.service.impl
;
import
cn.hutool.core.lang.Dict
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.repository.LogRepository
;
...
@@ -79,4 +80,9 @@ public class LogServiceImpl implements LogService {
...
@@ -79,4 +80,9 @@ public class LogServiceImpl implements LogService {
log
.
setParams
(
params
+
" }"
);
log
.
setParams
(
params
+
" }"
);
logRepository
.
save
(
log
);
logRepository
.
save
(
log
);
}
}
@Override
public
Object
findByErrDetail
(
Long
id
)
{
return
Dict
.
create
().
set
(
"exception"
,
logRepository
.
findExceptionById
(
id
));
}
}
}
eladmin-logging/src/main/java/me/zhengjie/service/mapper/LogErrorMapper.java
0 → 100644
View file @
784d670c
package
me.zhengjie.service.mapper
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.mapper.EntityMapper
;
import
me.zhengjie.service.dto.LogErrorDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author jie
* @date 2019-5-22
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
LogErrorMapper
extends
EntityMapper
<
LogErrorDTO
,
Log
>
{
}
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/service/mapper/LogSmallMapper.java
0 → 100644
View file @
784d670c
package
me.zhengjie.service.mapper
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.mapper.EntityMapper
;
import
me.zhengjie.service.dto.LogSmallDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author jie
* @date 2019-5-22
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
LogSmallMapper
extends
EntityMapper
<
LogSmallDTO
,
Log
>
{
}
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/service/query/LogQueryService.java
View file @
784d670c
...
@@ -2,6 +2,9 @@ package me.zhengjie.service.query;
...
@@ -2,6 +2,9 @@ package me.zhengjie.service.query;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.service.mapper.LogErrorMapper
;
import
me.zhengjie.service.mapper.LogSmallMapper
;
import
me.zhengjie.utils.PageUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
...
@@ -16,6 +19,7 @@ import javax.persistence.criteria.Predicate;
...
@@ -16,6 +19,7 @@ import javax.persistence.criteria.Predicate;
import
javax.persistence.criteria.Root
;
import
javax.persistence.criteria.Root
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* @author jie
* @author jie
...
@@ -28,7 +32,20 @@ public class LogQueryService {
...
@@ -28,7 +32,20 @@ public class LogQueryService {
@Autowired
@Autowired
private
LogRepository
logRepository
;
private
LogRepository
logRepository
;
public
Page
queryAll
(
Log
log
,
Pageable
pageable
){
@Autowired
private
LogErrorMapper
logErrorMapper
;
@Autowired
private
LogSmallMapper
logSmallMapper
;
public
Object
queryAll
(
Log
log
,
Pageable
pageable
){
Page
<
Log
>
page
=
logRepository
.
findAll
(
new
Spec
(
log
),
pageable
);
if
(!
ObjectUtils
.
isEmpty
(
log
.
getUsername
()))
{
return
PageUtil
.
toPage
(
page
.
map
(
logSmallMapper:
:
toDto
));
}
if
(
log
.
getLogType
().
equals
(
"ERROR"
))
{
return
PageUtil
.
toPage
(
page
.
map
(
logErrorMapper:
:
toDto
));
}
return
logRepository
.
findAll
(
new
Spec
(
log
),
pageable
);
return
logRepository
.
findAll
(
new
Spec
(
log
),
pageable
);
}
}
...
...
eladmin-system/pom.xml
View file @
784d670c
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
eladmin
</artifactId>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<version>
1.9
</version>
<version>
2.0
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
<dependency>
<dependency>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-generator
</artifactId>
<artifactId>
eladmin-generator
</artifactId>
<version>
1.9
</version>
<version>
2.0
</version>
<exclusions>
<exclusions>
<exclusion>
<exclusion>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
<dependency>
<dependency>
<groupId>
me.zhengjie
</groupId>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-tools
</artifactId>
<artifactId>
eladmin-tools
</artifactId>
<version>
1.9
</version>
<version>
2.0
</version>
</dependency>
</dependency>
<!--jwt-->
<!--jwt-->
...
@@ -53,6 +53,7 @@
...
@@ -53,6 +53,7 @@
<groupId>
org.quartz-scheduler
</groupId>
<groupId>
org.quartz-scheduler
</groupId>
<artifactId>
quartz
</artifactId>
<artifactId>
quartz
</artifactId>
</dependency>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
eladmin-system/src/main/java/me/zhengjie/config/DataScope.java
View file @
784d670c
package
me.zhengjie.config
;
package
me.zhengjie.config
;
import
me.zhengjie.modules.system.domain.Dept
;
import
me.zhengjie.modules.system.domain.Dept
;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.dto.DeptDTO
;
import
me.zhengjie.modules.system.service.dto.RoleSmallDTO
;
import
me.zhengjie.modules.system.service.dto.UserDTO
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.SecurityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -35,15 +36,15 @@ public class DataScope {
...
@@ -35,15 +36,15 @@ public class DataScope {
public
Set
<
Long
>
getDeptIds
()
{
public
Set
<
Long
>
getDeptIds
()
{
User
user
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
User
DTO
user
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
// 用于存储部门id
// 用于存储部门id
Set
<
Long
>
deptIds
=
new
HashSet
<>();
Set
<
Long
>
deptIds
=
new
HashSet
<>();
// 查询用户角色
// 查询用户角色
List
<
Role
>
roleSet
=
roleService
.
findByUsers_Id
(
user
.
getId
());
List
<
Role
SmallDTO
>
roleSet
=
roleService
.
findByUsers_Id
(
user
.
getId
());
for
(
Role
role
:
roleSet
)
{
for
(
Role
SmallDTO
role
:
roleSet
)
{
if
(
scopeType
[
0
].
equals
(
role
.
getDataScope
()))
{
if
(
scopeType
[
0
].
equals
(
role
.
getDataScope
()))
{
return
new
HashSet
<>()
;
return
new
HashSet
<>()
;
...
@@ -56,8 +57,8 @@ public class DataScope {
...
@@ -56,8 +57,8 @@ public class DataScope {
// 存储自定义的数据权限
// 存储自定义的数据权限
if
(
scopeType
[
2
].
equals
(
role
.
getDataScope
()))
{
if
(
scopeType
[
2
].
equals
(
role
.
getDataScope
()))
{
Set
<
Dept
>
dept
List
=
role
.
get
Depts
(
);
Set
<
Dept
>
dept
s
=
deptService
.
findByRoleIds
(
role
.
get
Id
()
);
for
(
Dept
dept
:
dept
List
)
{
for
(
Dept
dept
:
dept
s
)
{
deptIds
.
add
(
dept
.
getId
());
deptIds
.
add
(
dept
.
getId
());
List
<
Dept
>
deptChildren
=
deptService
.
findByPid
(
dept
.
getId
());
List
<
Dept
>
deptChildren
=
deptService
.
findByPid
(
dept
.
getId
());
if
(
deptChildren
!=
null
&&
deptChildren
.
size
()
!=
0
)
{
if
(
deptChildren
!=
null
&&
deptChildren
.
size
()
!=
0
)
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/JwtAuthorizationTokenFilter.java
View file @
784d670c
...
@@ -52,14 +52,13 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
...
@@ -52,14 +52,13 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
// It is not compelling necessary to load the use details from the database. You could also store the information
// It is not compelling necessary to load the use details from the database. You could also store the information
// in the token and read it from it. It's up to you ;)
// in the token and read it from it. It's up to you ;)
User
Details
userDetails
=
this
.
userDetailsService
.
loadUserByUsername
(
username
);
Jwt
User
userDetails
=
(
JwtUser
)
this
.
userDetailsService
.
loadUserByUsername
(
username
);
// For simple validation it is completely sufficient to just check the token integrity. You don't have to call
// For simple validation it is completely sufficient to just check the token integrity. You don't have to call
// the database compellingly. Again it's up to you ;)
// the database compellingly. Again it's up to you ;)
if
(
jwtTokenUtil
.
validateToken
(
authToken
,
userDetails
))
{
if
(
jwtTokenUtil
.
validateToken
(
authToken
,
userDetails
))
{
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
null
,
userDetails
.
getAuthorities
());
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
null
,
userDetails
.
getAuthorities
());
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
log
.
info
(
"authorizated user '{}', setting security context"
,
username
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
}
}
}
}
...
...
Prev
1
2
3
Next
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