Skip to content

Commit

Permalink
1.8 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjie committed May 11, 2019
1 parent 61a9b45 commit a42e1ca
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 58 deletions.
2 changes: 1 addition & 1 deletion eladmin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -41,6 +44,7 @@ public Docket createRestApi() {
.build();
pars.add(ticketPar.build());
return new Docket(DocumentationType.SWAGGER_2)
.enable(enabled)
.apiInfo(apiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/error.*")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,4 @@ public static String desDecrypt(String source) throws Exception {
public static String encryptPassword(String password){
return DigestUtils.md5DigestAsHex(password.getBytes());
}

public static void main(String[] args) {
System.out.println(encryptPassword("123456"));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,4 +21,24 @@ public static UserDetails getUserDetails() {
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
4 changes: 2 additions & 2 deletions eladmin-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>

<!--模板引擎-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;

Expand All @@ -23,6 +24,6 @@ public interface GenConfigService {
* update
* @param genConfig
*/
@CachePut(key = "'1'")
@CacheEvict(allEntries = true)
GenConfig update(GenConfig genConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,4 @@ public static void genFile(File file,Template template,Map<String,Object> map) t
writer.close();
}
}

public static void main(String[] args){
System.out.println(FileUtil.exist("E:\\1.5.txt"));
}
}
4 changes: 2 additions & 2 deletions eladmin-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-common</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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;
Expand Down Expand Up @@ -33,7 +33,7 @@ public ResponseEntity getLogs(Log log, Pageable pageable){
@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
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;
Expand Down Expand Up @@ -66,8 +65,7 @@ public void save(ProceedingJoinPoint joinPoint, Log log){
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]);
Expand Down
6 changes: 3 additions & 3 deletions eladmin-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-tools</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>

<!--jwt-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
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;
Expand Down Expand Up @@ -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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
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.*;
Expand Down Expand Up @@ -70,8 +69,7 @@ public ResponseEntity login(@Validated @RequestBody AuthorizationUser authorizat
*/
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ResponseEntity delete(@PathVariable Long id){
*/
@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))){
Expand All @@ -138,7 +138,7 @@ public ResponseEntity validPass(@PathVariable String pass){
*/
@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("新密码不能与旧密码相同");
}
Expand All @@ -153,9 +153,8 @@ public ResponseEntity updatePass(@PathVariable String pass){
*/
@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);
}

Expand All @@ -168,7 +167,7 @@ public ResponseEntity updateAvatar(@RequestParam MultipartFile file){
@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("密码错误");
}
Expand Down
4 changes: 4 additions & 0 deletions eladmin-system/src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ jwt:

#是否允许生成代码,生产环境设置为false
generator:
enabled: true

#是否开启 swagger-ui
swagger:
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ generator:
# documentation:
# swagger:
# v2:
# host: # 接口域名或外网ip
# host: # 接口域名或外网ip

#是否开启 swagger-ui
swagger:
enabled: false
4 changes: 2 additions & 2 deletions eladmin-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-logging</artifactId>
<version>1.5</version>
<version>1.8</version>
</dependency>

<!--邮件依赖-->
Expand Down
Loading

0 comments on commit a42e1ca

Please sign in to comment.