1.8 版本

pull/62/head
zhengjie 2019-05-11 14:11:35 +08:00
parent 61a9b45a63
commit a42e1ca732
23 changed files with 109 additions and 58 deletions

View 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>

View File

@ -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.*")))

View File

@ -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"));
}
}

View File

@ -1,16 +1,16 @@
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);
}
}

View File

@ -0,0 +1,32 @@
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();
}
}
}

View 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>
@ -19,7 +19,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>
<!--模板引擎-->

View File

@ -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);
}

View File

@ -239,8 +239,4 @@ public class GenUtil {
writer.close();
}
}
public static void main(String[] args){
System.out.println(FileUtil.exist("E:\\1.5.txt"));
}
}

View 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>
@ -15,7 +15,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>
</dependencies>
</project>

View 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);
}

View File

@ -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]);

View 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>
@ -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-->

View File

@ -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<>();

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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("密码错误");
}

View File

@ -60,3 +60,7 @@ jwt:
#是否允许生成代码生产环境设置为false
generator:
enabled: true
#是否开启 swagger-ui
swagger:
enabled: true

View File

@ -67,3 +67,7 @@ generator:
# swagger:
# v2:
# host: # 接口域名或外网ip
#是否开启 swagger-ui
swagger:
enabled: false

View 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>
<!--邮件依赖-->

View File

@ -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);

View File

@ -19,7 +19,7 @@ public interface QiNiuService {
*
* @return
*/
@Cacheable(key = "'1'")
@Cacheable(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig find();
/**
@ -27,7 +27,7 @@ public interface QiNiuService {
* @param qiniuConfig
* @return
*/
@CachePut(key = "'1'")
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig update(QiniuConfig qiniuConfig);
/**

View File

@ -1,5 +1,6 @@
package me.zhengjie.service.impl;
import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import me.zhengjie.domain.EmailConfig;
@ -76,12 +77,15 @@ public class EmailServiceImpl implements EmailService {
/**
*
*/
new MailAccount();
try {
MailUtil.send(account,
emailVo.getTos(),
emailVo.getSubject(),
content,
true);
Mail.create(account)
.setTos(String.valueOf(emailVo.getTos()))
.setTitle(emailVo.getSubject())
.setContent(content)
.setHtml(true)
.setUseGlobalSession(false)//关闭session
.send();
}catch (Exception e){
throw new BadRequestException(e.getMessage());
}

View File

@ -7,7 +7,7 @@
<groupId>me.zhengjie</groupId>
<artifactId>eladmin</artifactId>
<packaging>pom</packaging>
<version>1.5</version>
<version>1.8</version>
<modules>
<module>eladmin-common</module>