Commit a42e1ca7 authored by zhengjie's avatar zhengjie
Browse files

1.8 版本

parent 61a9b45a
......@@ -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>
......
......@@ -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.*")))
......
......@@ -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"));
}
}
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 SecurityContextHolder {
public class SecurityUtils {
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);
}
}
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();
}
}
}
......@@ -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>
<!--模板引擎-->
......
......@@ -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
*/
@CachePut(key = "'1'")
@CacheEvict(allEntries = true)
GenConfig update(GenConfig genConfig);
}
......@@ -239,8 +239,4 @@ public class GenUtil {
writer.close();
}
}
public static void main(String[] args){
System.out.println(FileUtil.exist("E:\\1.5.txt"));
}
}
......@@ -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
......@@ -2,7 +2,7 @@ package me.zhengjie.rest;
import me.zhengjie.domain.Log;
import me.zhengjie.service.query.LogQueryService;
import me.zhengjie.utils.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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(SecurityContextHolder.getUserDetails().getUsername());
log.setUsername(SecurityUtils.getUsername());
return new ResponseEntity(logQueryService.queryAll(log,pageable), HttpStatus.OK);
}
......
......@@ -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.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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]);
......
......@@ -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-->
......
......@@ -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.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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(SecurityContextHolder.getUserDetails().getUsername());
User user = userService.findByName(SecurityUtils.getUsername());
// 用于存储部门id
Set<Long> deptIds = new HashSet<>();
......
......@@ -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.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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);
}
}
......@@ -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.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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);
......
......@@ -122,7 +122,7 @@ public class UserController {
*/
@GetMapping(value = "/users/validPass/{pass}")
public ResponseEntity validPass(@PathVariable String pass){
UserDetails userDetails = SecurityContextHolder.getUserDetails();
UserDetails userDetails = SecurityUtils.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 = SecurityContextHolder.getUserDetails();
UserDetails userDetails = SecurityUtils.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 = SecurityContextHolder.getUserDetails();
UserDetails userDetails = SecurityUtils.getUserDetails();
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
throw new BadRequestException("密码错误");
}
......
......@@ -59,4 +59,8 @@ jwt:
#是否允许生成代码,生产环境设置为false
generator:
enabled: true
#是否开启 swagger-ui
swagger:
enabled: true
\ No newline at end of file
......@@ -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
......@@ -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>
<!--邮件依赖-->
......
......@@ -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.SecurityContextHolder;
import me.zhengjie.utils.SecurityUtils;
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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment