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
a42e1ca7
Commit
a42e1ca7
authored
May 11, 2019
by
zhengjie
Browse files
1.8 版本
parent
61a9b45a
Changes
23
Hide whitespace changes
Inline
Side-by-side
eladmin-common/pom.xml
View file @
a42e1ca7
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
eladmin-common/src/main/java/me/zhengjie/swagger2/SwaggerConfig.java
View file @
a42e1ca7
...
...
@@ -29,6 +29,9 @@ public class SwaggerConfig {
@Value
(
"${jwt.header}"
)
private
String
tokenHeader
;
@Value
(
"${swagger.enabled}"
)
private
Boolean
enabled
;
@Bean
public
Docket
createRestApi
()
{
ParameterBuilder
ticketPar
=
new
ParameterBuilder
();
...
...
@@ -41,6 +44,7 @@ public class SwaggerConfig {
.
build
();
pars
.
add
(
ticketPar
.
build
());
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
enable
(
enabled
)
.
apiInfo
(
apiInfo
())
.
select
()
.
paths
(
Predicates
.
not
(
PathSelectors
.
regex
(
"/error.*"
)))
...
...
eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java
View file @
a42e1ca7
...
...
@@ -93,8 +93,4 @@ public class EncryptUtils {
public
static
String
encryptPassword
(
String
password
){
return
DigestUtils
.
md5DigestAsHex
(
password
.
getBytes
());
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
encryptPassword
(
"123456"
));
}
}
eladmin-common/src/main/java/me/zhengjie/utils/Security
ContextHolder
.java
→
eladmin-common/src/main/java/me/zhengjie/utils/Security
Utils
.java
View file @
a42e1ca7
package
me.zhengjie.utils
;
import
cn.hutool.json.JSONObject
;
import
me.zhengjie.exception.BadRequestException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.core.userdetails.UserDetails
;
/**
* 获取当前登录的用户名
*
* 获取当前登录的用户
* @author jie
* @date 2019-01-17
*/
public
class
Security
ContextHolder
{
public
class
Security
Utils
{
public
static
UserDetails
getUserDetails
()
{
UserDetails
userDetails
=
null
;
...
...
@@ -21,4 +21,24 @@ public class SecurityContextHolder {
}
return
userDetails
;
}
/**
* 获取系统用户名称
* @return 系统用户名称
*/
public
static
String
getUsername
(){
Object
obj
=
getUserDetails
();
JSONObject
json
=
new
JSONObject
(
obj
);
return
json
.
get
(
"username"
,
String
.
class
);
}
/**
* 获取系统用户id
* @return 系统用户id
*/
public
static
Long
getUserId
(){
Object
obj
=
getUserDetails
();
JSONObject
json
=
new
JSONObject
(
obj
);
return
json
.
get
(
"id"
,
Long
.
class
);
}
}
eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java
0 → 100644
View file @
a42e1ca7
package
me.zhengjie.utils
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
me
.
zhengjie
.
utils
.
EncryptUtils
.*;
public
class
EncryptUtilsTest
{
/**
* 对称加密
*/
@Test
public
void
testDesEncrypt
()
{
try
{
assertEquals
(
"7772841DC6099402"
,
desEncrypt
(
"123456"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 对称解密
*/
@Test
public
void
testDesDecrypt
()
{
try
{
assertEquals
(
"123456"
,
desDecrypt
(
"7772841DC6099402"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
eladmin-generator/pom.xml
View file @
a42e1ca7
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -19,7 +19,7 @@
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</dependency>
<!--模板引擎-->
...
...
eladmin-generator/src/main/java/me/zhengjie/service/GenConfigService.java
View file @
a42e1ca7
...
...
@@ -2,6 +2,7 @@ package me.zhengjie.service;
import
me.zhengjie.domain.GenConfig
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
...
...
@@ -23,6 +24,6 @@ public interface GenConfigService {
* update
* @param genConfig
*/
@Cache
Put
(
key
=
"'1'"
)
@Cache
Evict
(
allEntries
=
true
)
GenConfig
update
(
GenConfig
genConfig
);
}
eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java
View file @
a42e1ca7
...
...
@@ -239,8 +239,4 @@ public class GenUtil {
writer
.
close
();
}
}
public
static
void
main
(
String
[]
args
){
System
.
out
.
println
(
FileUtil
.
exist
(
"E:\\1.5.txt"
));
}
}
eladmin-logging/pom.xml
View file @
a42e1ca7
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -15,7 +15,7 @@
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-common
</artifactId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
eladmin-logging/src/main/java/me/zhengjie/rest/LogController.java
View file @
a42e1ca7
...
...
@@ -2,7 +2,7 @@ package me.zhengjie.rest;
import
me.zhengjie.domain.Log
;
import
me.zhengjie.service.query.LogQueryService
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -33,7 +33,7 @@ public class LogController {
@GetMapping
(
value
=
"/logs/user"
)
public
ResponseEntity
getUserLogs
(
Log
log
,
Pageable
pageable
){
log
.
setLogType
(
"INFO"
);
log
.
setUsername
(
Security
ContextHolder
.
getUserDeta
ils
()
.
getUsername
());
log
.
setUsername
(
Security
Ut
ils
.
getUsername
());
return
new
ResponseEntity
(
logQueryService
.
queryAll
(
log
,
pageable
),
HttpStatus
.
OK
);
}
...
...
eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java
View file @
a42e1ca7
...
...
@@ -5,12 +5,11 @@ import me.zhengjie.domain.Log;
import
me.zhengjie.repository.LogRepository
;
import
me.zhengjie.service.LogService
;
import
me.zhengjie.utils.RequestHolder
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
me.zhengjie.utils.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -66,8 +65,7 @@ public class LogServiceImpl implements LogService {
log
.
setRequestIp
(
StringUtils
.
getIP
(
request
));
if
(!
LOGINPATH
.
equals
(
signature
.
getName
())){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
username
=
userDetails
.
getUsername
();
username
=
SecurityUtils
.
getUsername
();
}
else
{
try
{
JSONObject
jsonObject
=
new
JSONObject
(
argValues
[
0
]);
...
...
eladmin-system/pom.xml
View file @
a42e1ca7
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -20,7 +20,7 @@
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-generator
</artifactId>
<version>
1.
5
</version>
<version>
1.
8
</version>
<exclusions>
<exclusion>
<groupId>
me.zhengjie
</groupId>
...
...
@@ -32,7 +32,7 @@
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-tools
</artifactId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</dependency>
<!--jwt-->
...
...
eladmin-system/src/main/java/me/zhengjie/config/DataScope.java
View file @
a42e1ca7
...
...
@@ -6,9 +6,8 @@ import me.zhengjie.modules.system.domain.User;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
...
...
@@ -36,7 +35,7 @@ public class DataScope {
public
Set
<
Long
>
getDeptIds
()
{
User
user
=
userService
.
findByName
(
Security
ContextHolder
.
getUserDeta
ils
()
.
getUsername
());
User
user
=
userService
.
findByName
(
Security
Ut
ils
.
getUsername
());
// 用于存储部门id
Set
<
Long
>
deptIds
=
new
HashSet
<>();
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java
View file @
a42e1ca7
...
...
@@ -7,13 +7,12 @@ import me.zhengjie.modules.security.security.AuthorizationUser;
import
me.zhengjie.modules.security.security.JwtUser
;
import
me.zhengjie.utils.EncryptUtils
;
import
me.zhengjie.modules.security.utils.JwtTokenUtil
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.authentication.AccountExpiredException
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -70,8 +69,7 @@ public class AuthenticationController {
*/
@GetMapping
(
value
=
"${jwt.auth.account}"
)
public
ResponseEntity
getUserInfo
(){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
SecurityUtils
.
getUsername
());
return
ResponseEntity
.
ok
(
jwtUser
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/MenuController.java
View file @
a42e1ca7
...
...
@@ -10,12 +10,11 @@ import me.zhengjie.modules.system.service.UserService;
import
me.zhengjie.modules.system.service.dto.MenuDTO
;
import
me.zhengjie.modules.system.service.mapper.MenuMapper
;
import
me.zhengjie.modules.system.service.query.MenuQueryService
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
...
...
@@ -51,8 +50,7 @@ public class MenuController {
*/
@GetMapping
(
value
=
"/menus/build"
)
public
ResponseEntity
buildMenus
(){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
User
user
=
userService
.
findByName
(
userDetails
.
getUsername
());
User
user
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
List
<
MenuDTO
>
menuDTOList
=
menuService
.
findByRoles
(
roleService
.
findByUsers_Id
(
user
.
getId
()));
List
<
MenuDTO
>
menuDTOTree
=
(
List
<
MenuDTO
>)
menuService
.
buildTree
(
menuDTOList
).
get
(
"content"
);
return
new
ResponseEntity
(
menuService
.
buildMenus
(
menuDTOTree
),
HttpStatus
.
OK
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
View file @
a42e1ca7
...
...
@@ -122,7 +122,7 @@ public class UserController {
*/
@GetMapping
(
value
=
"/users/validPass/{pass}"
)
public
ResponseEntity
validPass
(
@PathVariable
String
pass
){
UserDetails
userDetails
=
Security
ContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
Security
Utils
.
getUserDetails
();
Map
map
=
new
HashMap
();
map
.
put
(
"status"
,
200
);
if
(!
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
...
...
@@ -138,7 +138,7 @@ public class UserController {
*/
@GetMapping
(
value
=
"/users/updatePass/{pass}"
)
public
ResponseEntity
updatePass
(
@PathVariable
String
pass
){
UserDetails
userDetails
=
Security
ContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
Security
Utils
.
getUserDetails
();
if
(
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
throw
new
BadRequestException
(
"新密码不能与旧密码相同"
);
}
...
...
@@ -153,9 +153,8 @@ public class UserController {
*/
@PostMapping
(
value
=
"/users/updateAvatar"
)
public
ResponseEntity
updateAvatar
(
@RequestParam
MultipartFile
file
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
Picture
picture
=
pictureService
.
upload
(
file
,
userDetails
.
getUsername
());
userService
.
updateAvatar
(
userDetails
.
getUsername
(),
picture
.
getUrl
());
Picture
picture
=
pictureService
.
upload
(
file
,
SecurityUtils
.
getUsername
());
userService
.
updateAvatar
(
SecurityUtils
.
getUsername
(),
picture
.
getUrl
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
...
...
@@ -168,7 +167,7 @@ public class UserController {
@Log
(
"修改邮箱"
)
@PostMapping
(
value
=
"/users/updateEmail/{code}"
)
public
ResponseEntity
updateEmail
(
@PathVariable
String
code
,
@RequestBody
User
user
){
UserDetails
userDetails
=
Security
ContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
Security
Utils
.
getUserDetails
();
if
(!
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
user
.
getPassword
()))){
throw
new
BadRequestException
(
"密码错误"
);
}
...
...
eladmin-system/src/main/resources/config/application-dev.yml
View file @
a42e1ca7
...
...
@@ -59,4 +59,8 @@ jwt:
#是否允许生成代码,生产环境设置为false
generator
:
enabled
:
true
#是否开启 swagger-ui
swagger
:
enabled
:
true
\ No newline at end of file
eladmin-system/src/main/resources/config/application-prod.yml
View file @
a42e1ca7
...
...
@@ -66,4 +66,8 @@ generator:
# documentation:
# swagger:
# v2:
# host: # 接口域名或外网ip
\ No newline at end of file
# host: # 接口域名或外网ip
#是否开启 swagger-ui
swagger
:
enabled
:
false
\ No newline at end of file
eladmin-tools/pom.xml
View file @
a42e1ca7
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
eladmin
</artifactId>
<groupId>
me.zhengjie
</groupId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -22,7 +22,7 @@
<dependency>
<groupId>
me.zhengjie
</groupId>
<artifactId>
eladmin-logging
</artifactId>
<version>
1.
5
</version>
<version>
1.
8
</version>
</dependency>
<!--邮件依赖-->
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/PictureController.java
View file @
a42e1ca7
...
...
@@ -4,13 +4,12 @@ import me.zhengjie.aop.log.Log;
import
me.zhengjie.domain.Picture
;
import
me.zhengjie.service.PictureService
;
import
me.zhengjie.service.query.PictureQueryService
;
import
me.zhengjie.utils.Security
ContextHolder
;
import
me.zhengjie.utils.Security
Utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
...
...
@@ -47,8 +46,7 @@ public class PictureController {
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')"
)
@PostMapping
(
value
=
"/pictures"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
String
userName
=
userDetails
.
getUsername
();
String
userName
=
SecurityUtils
.
getUsername
();
Picture
picture
=
pictureService
.
upload
(
file
,
userName
);
Map
map
=
new
HashMap
();
map
.
put
(
"errno"
,
0
);
...
...
Prev
1
2
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