From 110bdc5a84edb9374eaacc46c9749527920b63a1 Mon Sep 17 00:00:00 2001 From: zlt Date: Mon, 4 Feb 2019 14:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sonar=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8Dsonar=E6=B5=8B=E8=AF=95=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- README.md | 2 +- pom.xml | 11 +++++ .../controller/SysGeneratorController.java | 15 +++--- .../com/central/generator/utils/GenUtils.java | 32 ++++++++----- .../central/file/config/AliyunOSSConfig.java | 1 - .../file/config/OssServiceFactory.java | 3 +- .../service/impl/AbstractIFileService.java | 1 - .../service/impl/AliyunOssServiceImplI.java | 1 - .../service/impl/QiniuOssServiceImplI.java | 9 ---- .../java/com/central/file/utils/FileUtil.java | 9 +++- .../user/controller/SysMenuController.java | 8 ++-- .../user/controller/SysUserController.java | 10 ++-- .../user/service/impl/SysMenuServiceImpl.java | 4 +- .../user/service/impl/SysRoleServiceImpl.java | 1 + .../user/service/impl/SysUserServiceImpl.java | 18 +++----- .../config/DefaultSecurityHandlerConfig.java | 4 +- .../common/store/RedisTemplateTokenStore.java | 20 ++++---- .../oauth2/common/store/ResJwtTokenStore.java | 4 +- .../central/oauth2/common/util/AuthUtils.java | 13 ++++-- .../common/constant/CommonConstant.java | 5 -- .../com/central/common/model/CodeEnum.java | 4 -- .../central/common/model/LoginAppUser.java | 4 +- .../java/com/central/common/model/Result.java | 4 +- .../com/central/common/utils/DateUtils.java | 4 ++ .../com/central/common/utils/ExcelUtil.java | 15 +++--- .../com/central/common/utils/PhoneUtil.java | 4 ++ .../central/common/utils/ResponseUtil.java | 3 ++ .../com/central/common/utils/SpringUtil.java | 3 +- .../com/central/common/utils/SysUserUtil.java | 12 ++--- .../com/central/common/utils/UUIDUtil.java | 9 ++-- .../db/config/DateMetaObjectHandler.java | 12 +++-- .../db/config/DefaultMybatisPlusConfig.java | 3 +- .../com/central/log/monitor/PointUtil.java | 4 ++ .../common/redis/RedisAutoConfigure.java | 3 +- .../redis/constant/RedisToolsConstant.java | 4 +- .../redis/lock/RedisDistributedLock.java | 3 +- .../redis/template/RedisRepository.java | 3 +- .../redis/util/RedisObjectSerializer.java | 16 ++++--- .../swagger2/SwaggerAutoConfiguration.java | 7 +-- .../common/swagger2/SwaggerProperties.java | 46 ++----------------- .../fallback/MenuServiceFallbackFactory.java | 6 --- .../oauth/config/SecurityHandlerConfig.java | 1 - .../oauth/controller/OAuth2Controller.java | 2 +- .../controller/ValidateCodeController.java | 3 +- .../oauth/filter/ValidateCodeFilter.java | 2 +- .../oauth/handler/OauthLogoutHandler.java | 1 - .../central/oauth/mapper/ClientMapper.java | 8 ---- .../mobile/MobileAuthenticationProvider.java | 2 +- .../mobile/MobileAuthenticationToken.java | 2 +- .../openid/OpenIdAuthenticationProvider.java | 2 +- .../openid/OpenIdAuthenticationToken.java | 5 +- .../oauth/service/ZltUserDetailsService.java | 8 +++- .../oauth/service/impl/ClientServiceImpl.java | 1 - .../impl/RedisClientDetailsService.java | 12 ++--- .../service/impl/UserDetailServiceImpl.java | 6 +-- .../service/impl/ValidateCodeServiceImpl.java | 2 +- .../static/pages/generator/list.html | 14 ------ 58 files changed, 181 insertions(+), 233 deletions(-) diff --git a/.gitignore b/.gitignore index 05a9af41..dbecfca7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea/ -/logs/ \ No newline at end of file +/logs/ +/target/ \ No newline at end of file diff --git a/README.md b/README.md index 98cb0f19..42622d60 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ central-platform -- 父项目,公共依赖 - + diff --git a/pom.xml b/pom.xml index f9b6b0f0..5f2d71a6 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ 2.0.8.RELEASEFinchley.SR22.1.1.RELEASE + zlt-job/**/*, zlt-register/**/*, zlt-web/**/* @@ -301,6 +302,16 @@ + + + aliyun-repos + http://maven.aliyun.com/nexus/content/groups/public/ + + false + + + + zlt-commons diff --git a/zlt-business/code-generator/src/main/java/com/central/generator/controller/SysGeneratorController.java b/zlt-business/code-generator/src/main/java/com/central/generator/controller/SysGeneratorController.java index 7d8037d4..4f53ce01 100644 --- a/zlt-business/code-generator/src/main/java/com/central/generator/controller/SysGeneratorController.java +++ b/zlt-business/code-generator/src/main/java/com/central/generator/controller/SysGeneratorController.java @@ -9,10 +9,7 @@ import com.central.common.model.PageResult; import com.central.generator.service.SysGeneratorService; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; @@ -30,16 +27,16 @@ public class SysGeneratorController { * 列表 */ @ResponseBody - @RequestMapping("/list") - public PageResult list(@RequestParam Map params) { + @GetMapping("/list") + public PageResult getTableList(@RequestParam Map params) { return sysGeneratorService.queryList(params); } /** - * 生成代码 + * 生成代码FileUtil */ - @RequestMapping("/code") - public void code(String tables, HttpServletResponse response) throws IOException { + @GetMapping("/code") + public void makeCode(String tables, HttpServletResponse response) throws IOException { byte[] data = sysGeneratorService.generatorCode(tables.split(",")); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"generator.zip\""); diff --git a/zlt-business/code-generator/src/main/java/com/central/generator/utils/GenUtils.java b/zlt-business/code-generator/src/main/java/com/central/generator/utils/GenUtils.java index e8fff3ff..43cfbeb0 100644 --- a/zlt-business/code-generator/src/main/java/com/central/generator/utils/GenUtils.java +++ b/zlt-business/code-generator/src/main/java/com/central/generator/utils/GenUtils.java @@ -3,6 +3,7 @@ package com.central.generator.utils; import java.io.File; import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -33,6 +34,10 @@ import org.apache.velocity.app.Velocity; */ @Slf4j public class GenUtils { + private GenUtils() { + throw new IllegalStateException("Utility class"); + } + private final static String FILE_NAME_MODEL = "Model.java.vm"; private final static String FILE_NAME_MAPPER = "Mapper.java.vm"; private final static String FILE_NAME_MAPPERXML = "Mapper.xml.vm"; @@ -40,17 +45,20 @@ public class GenUtils { private final static String FILE_NAME_SERVICEIMPL = "ServiceImpl.java.vm"; private final static String FILE_NAME_CONTROLLER = "Controller.java.vm"; private final static String FILE_NAME_PAGE = "index.html.vm"; + private final static String TEMPLATE_PATH = "template/"; + private final static String PACKAGE = "package"; + private final static String MODULE_NAME = "moduleName"; public static List getTemplates() { - List templates = new ArrayList(); - templates.add("template/"+FILE_NAME_MODEL); - templates.add("template/"+FILE_NAME_MAPPER); - templates.add("template/"+FILE_NAME_MAPPERXML); - templates.add("template/"+FILE_NAME_SERVICE); - templates.add("template/"+FILE_NAME_SERVICEIMPL); - templates.add("template/"+FILE_NAME_CONTROLLER); + List templates = new ArrayList<>(); + templates.add(TEMPLATE_PATH+FILE_NAME_MODEL); + templates.add(TEMPLATE_PATH+FILE_NAME_MAPPER); + templates.add(TEMPLATE_PATH+FILE_NAME_MAPPERXML); + templates.add(TEMPLATE_PATH+FILE_NAME_SERVICE); + templates.add(TEMPLATE_PATH+FILE_NAME_SERVICEIMPL); + templates.add(TEMPLATE_PATH+FILE_NAME_CONTROLLER); - templates.add("template/"+FILE_NAME_PAGE); + templates.add(TEMPLATE_PATH+FILE_NAME_PAGE); return templates; } @@ -123,8 +131,8 @@ public class GenUtils { map.put("columns", tableEntity.getColumns()); map.put("hasBigDecimal", hasBigDecimal); map.put("mainPath", mainPath); - map.put("package", config.getString("package")); - map.put("moduleName", config.getString("moduleName")); + map.put(PACKAGE, config.getString(PACKAGE)); + map.put(MODULE_NAME, config.getString(MODULE_NAME)); map.put("author", config.getString("author")); map.put("email", config.getString("email")); map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN)); @@ -141,8 +149,8 @@ public class GenUtils { tpl.merge(context, sw); //添加到zip - zip.putNextEntry(new ZipEntry(getFileName(template, tableEntity.getClassName(), config.getString("package"), config.getString("moduleName")))); - IOUtils.write(sw.toString(), zip, "UTF-8"); + zip.putNextEntry(new ZipEntry(getFileName(template, tableEntity.getClassName(), config.getString(PACKAGE), config.getString(MODULE_NAME)))); + IOUtils.write(sw.toString(), zip, StandardCharsets.UTF_8); zip.closeEntry(); } catch (IOException e) { log.error("generatorCode-error", e); diff --git a/zlt-business/file-center/src/main/java/com/central/file/config/AliyunOSSConfig.java b/zlt-business/file-center/src/main/java/com/central/file/config/AliyunOSSConfig.java index 1e291d82..03d81f26 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/config/AliyunOSSConfig.java +++ b/zlt-business/file-center/src/main/java/com/central/file/config/AliyunOSSConfig.java @@ -1,7 +1,6 @@ package com.central.file.config; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/zlt-business/file-center/src/main/java/com/central/file/config/OssServiceFactory.java b/zlt-business/file-center/src/main/java/com/central/file/config/OssServiceFactory.java index 1fe96b15..5205b4e9 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/config/OssServiceFactory.java +++ b/zlt-business/file-center/src/main/java/com/central/file/config/OssServiceFactory.java @@ -1,5 +1,6 @@ package com.central.file.config; +import java.util.EnumMap; import java.util.HashMap; import java.util.Map; @@ -19,7 +20,7 @@ import com.central.file.model.FileType; @Configuration public class OssServiceFactory { - private Map map = new HashMap<>(); + private Map map = new EnumMap<>(FileType.class); @Autowired private IFileService aliyunOssServiceImpl; diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java index fa77cc80..6312214b 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java @@ -5,7 +5,6 @@ import java.util.Map; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.central.common.model.SysUser; import org.apache.commons.collections4.MapUtils; import org.springframework.web.multipart.MultipartFile; diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AliyunOssServiceImplI.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AliyunOssServiceImplI.java index 6ddafbee..d7ad9f77 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AliyunOssServiceImplI.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AliyunOssServiceImplI.java @@ -6,7 +6,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import com.aliyun.oss.OSSClient; -import com.central.file.mapper.FileMapper; import com.central.file.model.FileInfo; import com.central.file.model.FileType; diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/QiniuOssServiceImplI.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/QiniuOssServiceImplI.java index 993cb583..a866f0d7 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/QiniuOssServiceImplI.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/QiniuOssServiceImplI.java @@ -40,15 +40,6 @@ public class QiniuOssServiceImplI extends AbstractIFileService implements Initia return FileType.QINIU; } - /** - * 获取上传凭证 - * - * @return - */ - private String getUploadToken() { - return this.auth.uploadToken(bucket, null, 3600, putPolicy); - } - @Override protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception { // 调用put方法上传 diff --git a/zlt-business/file-center/src/main/java/com/central/file/utils/FileUtil.java b/zlt-business/file-center/src/main/java/com/central/file/utils/FileUtil.java index 6cfb9fe3..0387b34c 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/utils/FileUtil.java +++ b/zlt-business/file-center/src/main/java/com/central/file/utils/FileUtil.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.Date; import com.central.file.model.FileInfo; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.web.multipart.MultipartFile; @@ -13,7 +14,11 @@ import org.springframework.web.multipart.MultipartFile; * @author zlt * 文件工具类 */ +@Slf4j public class FileUtil { + private FileUtil() { + throw new IllegalStateException("Utility class"); + } public static FileInfo getFileInfo(MultipartFile file) throws Exception { String md5 = fileMd5(file.getInputStream()); @@ -37,7 +42,7 @@ public class FileUtil { try { return DigestUtils.md5Hex(inputStream); } catch (IOException e) { - e.printStackTrace(); + log.error("fileMd5-error", e); } return null; } @@ -54,7 +59,7 @@ public class FileUtil { file.transferTo(targetFile); return path; } catch (Exception e) { - e.printStackTrace(); + log.error("saveFile-error", e); } return null; } diff --git a/zlt-business/user-center/src/main/java/com/central/user/controller/SysMenuController.java b/zlt-business/user-center/src/main/java/com/central/user/controller/SysMenuController.java index 37b2913d..01078fd9 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/controller/SysMenuController.java +++ b/zlt-business/user-center/src/main/java/com/central/user/controller/SysMenuController.java @@ -75,9 +75,8 @@ public class SysMenuController { @ApiOperation(value = "根据roleId获取对应的菜单") @GetMapping("/{roleId}/menus") public List> findMenusByRoleId(@PathVariable Long roleId) { - Set roleIds = new HashSet() {{ - add(roleId); - }}; + Set roleIds = new HashSet<>(); + roleIds.add(roleId); //获取该角色对应的菜单 List roleMenus = menuService.findByRoles(roleIds); //全部的菜单列表 @@ -169,7 +168,6 @@ public class SysMenuController { return Collections.emptyList(); } List menus = menuService.findByRoleCodes(roles.parallelStream().map(SysRole::getCode).collect(Collectors.toSet()), CommonConstant.MENU); - List sysMenus = treeBuilder(menus); - return sysMenus; + return treeBuilder(menus); } } diff --git a/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java b/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java index d14975ca..02461b2a 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java +++ b/zlt-business/user-center/src/main/java/com/central/user/controller/SysUserController.java @@ -39,6 +39,8 @@ import javax.servlet.http.HttpServletResponse; @RestController @Api(tags = "用户模块api") public class SysUserController { + private static final String ADMIN_CHANGE_MSG = "超级管理员不给予修改"; + @Autowired private ISysUserService appUserService; @@ -163,7 +165,7 @@ public class SysUserController { public Result updateEnabled(@RequestParam Map params) { Long id = MapUtils.getLong(params, "id"); if (checkAdmin(id)) { - return Result.failed("超级管理员不给予修改"); + return Result.failed(ADMIN_CHANGE_MSG); } return appUserService.updateEnabled(params); } @@ -176,7 +178,7 @@ public class SysUserController { @PutMapping(value = "/users/{id}/password") public Result resetPassword(@PathVariable Long id) { if (checkAdmin(id)) { - return Result.failed("超级管理员不给予修改"); + return Result.failed(ADMIN_CHANGE_MSG); } appUserService.updatePassword(id, null, null); return Result.succeed("重置成功"); @@ -188,7 +190,7 @@ public class SysUserController { @PutMapping(value = "/users/password") public Result resetPassword(@RequestBody SysUser sysUser) { if (checkAdmin(sysUser.getId())) { - return Result.failed("超级管理员不给予修改"); + return Result.failed(ADMIN_CHANGE_MSG); } appUserService.updatePassword(sysUser.getId(), sysUser.getOldPassword(), sysUser.getNewPassword()); return Result.succeed("重置成功"); @@ -202,7 +204,7 @@ public class SysUserController { @DeleteMapping(value = "/users/{id}") public Result delete(@PathVariable Long id) { if (checkAdmin(id)) { - return Result.failed("超级管理员不给予修改"); + return Result.failed(ADMIN_CHANGE_MSG); } appUserService.delUser(id); return Result.succeed("删除成功"); diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysMenuServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysMenuServiceImpl.java index c0d73bd9..0f4f60fe 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysMenuServiceImpl.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysMenuServiceImpl.java @@ -33,9 +33,7 @@ public class SysMenuServiceImpl extends SuperServiceImpl sysRoleMenuMapper.delete(roleId, null); if (!CollectionUtils.isEmpty(menuIds)) { - menuIds.forEach(menuId -> { - sysRoleMenuMapper.save(roleId, menuId); - }); + menuIds.forEach(menuId -> sysRoleMenuMapper.save(roleId, menuId)); } } diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java index 4c180fff..c22119e4 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysRoleServiceImpl.java @@ -66,6 +66,7 @@ public class SysRoleServiceImpl extends SuperServiceImpl } @Override + @Transactional public Result saveOrUpdateRole(SysRole sysRole) { if (sysRole.getId() == null) { this.saveRole(sysRole); diff --git a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java index e3b4942a..1983495a 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java +++ b/zlt-business/user-center/src/main/java/com/central/user/service/impl/SysUserServiceImpl.java @@ -80,7 +80,7 @@ public class SysUserServiceImpl extends SuperServiceImpl loginAppUser.setRoles(sysRoles); if (!CollectionUtils.isEmpty(sysRoles)) { - Set roleIds = sysRoles.parallelStream().map(r -> r.getId()).collect(Collectors.toSet()); + Set roleIds = sysRoles.parallelStream().map(SuperEntity::getId).collect(Collectors.toSet()); List menus = roleMenuMapper.findMenusByRoleIds(roleIds, CommonConstant.PERMISSION); if (!CollectionUtils.isEmpty(menus)) { Set permissions = menus.parallelStream().map(p -> p.getPathMethod()+":"+p.getPath()) @@ -154,9 +154,7 @@ public class SysUserServiceImpl extends SuperServiceImpl userRoleMapper.deleteUserRole(id, null); if (!CollectionUtils.isEmpty(roleIds)) { - roleIds.forEach(roleId -> { - userRoleMapper.saveUserRoles(id, roleId); - }); + roleIds.forEach(roleId -> userRoleMapper.saveUserRoles(id, roleId)); } } @@ -188,10 +186,8 @@ public class SysUserServiceImpl extends SuperServiceImpl List userIds = list.stream().map(SysUser::getId).collect(Collectors.toList()); List sysRoles = userRoleMapper.findRolesByUserIds(userIds); - list.forEach(u -> { - u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId())) - .collect(Collectors.toList())); - }); + list.forEach(u -> u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId())) + .collect(Collectors.toList()))); } return PageResult.builder().data(list).code(0).count(total).build(); } @@ -238,9 +234,7 @@ public class SysUserServiceImpl extends SuperServiceImpl userRoleMapper.deleteUserRole(sysUser.getId(), null); List roleIds = Arrays.asList(sysUser.getRoleId().split(",")); if (!CollectionUtils.isEmpty(roleIds)) { - roleIds.forEach(roleId -> { - userRoleMapper.saveUserRoles(sysUser.getId(), Long.parseLong(roleId.toString())); - }); + roleIds.forEach(roleId -> userRoleMapper.saveUserRoles(sysUser.getId(), Long.parseLong(roleId.toString()))); } } return result ? Result.succeed(sysUser, "操作成功") : Result.failed("操作失败"); @@ -250,7 +244,7 @@ public class SysUserServiceImpl extends SuperServiceImpl @Override public boolean delUser(Long id) { userRoleMapper.deleteUserRole(id, null); - return baseMapper.deleteById(id) > 0 ? true : false; + return baseMapper.deleteById(id) > 0; } @Override diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultSecurityHandlerConfig.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultSecurityHandlerConfig.java index 96905d3d..37c31364 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultSecurityHandlerConfig.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/DefaultSecurityHandlerConfig.java @@ -30,9 +30,7 @@ public class DefaultSecurityHandlerConfig { */ @Bean public AuthenticationEntryPoint authenticationEntryPoint() { - return (request, response, authException) -> { - ResponseUtil.responseWriter(objectMapper, response, authException.getMessage(), HttpStatus.UNAUTHORIZED.value()); - }; + return (request, response, authException) -> ResponseUtil.responseWriter(objectMapper, response, authException.getMessage(), HttpStatus.UNAUTHORIZED.value()); } @Bean diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/RedisTemplateTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/RedisTemplateTokenStore.java index 848faf97..02ee3f1a 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/RedisTemplateTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/RedisTemplateTokenStore.java @@ -140,7 +140,7 @@ public class RedisTemplateTokenStore implements TokenStore { ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken; Date expiration = expiringRefreshToken.getExpiration(); if (expiration != null) { - int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue(); + int seconds = (int)((expiration.getTime() - System.currentTimeMillis()) / 1000L); redisTemplate.expire(REFRESH_TO_ACCESS + token.getRefreshToken().getValue(), seconds, TimeUnit.SECONDS); redisTemplate.expire(ACCESS_TO_REFRESH + token.getValue(), seconds, TimeUnit.SECONDS); @@ -221,24 +221,20 @@ public class RedisTemplateTokenStore implements TokenStore { @Override public Collection findTokensByClientIdAndUserName(String clientId, String userName) { List result = redisTemplate.opsForList().range(UNAME_TO_ACCESS + getApprovalKey(clientId, userName), 0, -1); - if (result == null || result.size() == 0) { - return Collections.emptySet(); - } - List accessTokens = new ArrayList(result.size()); - for (Iterator it = result.iterator(); it.hasNext(); ) { - OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next(); - accessTokens.add(accessToken); - } - return Collections.unmodifiableCollection(accessTokens); + return getTokenColl(result); } @Override public Collection findTokensByClientId(String clientId) { List result = redisTemplate.opsForList().range((CLIENT_ID_TO_ACCESS + clientId), 0, -1); - if (result == null || result.size() == 0) { + return getTokenColl(result); + } + + private Collection getTokenColl(List result) { + if (result == null || result.isEmpty()) { return Collections.emptySet(); } - List accessTokens = new ArrayList(result.size()); + List accessTokens = new ArrayList<>(result.size()); for (Iterator it = result.iterator(); it.hasNext(); ) { OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next(); accessTokens.add(accessToken); diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java index ead8b79f..33194974 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java @@ -50,8 +50,8 @@ public class ResJwtTokenStore { * @return 公钥 Key */ private String getPubKey() { - Resource resource = new ClassPathResource(ResJwtTokenStore.PUBLIC_KEY); - try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { + Resource res = new ClassPathResource(ResJwtTokenStore.PUBLIC_KEY); + try (BufferedReader br = new BufferedReader(new InputStreamReader(res.getInputStream()))) { return br.lines().collect(Collectors.joining("\n")); } catch (IOException ioe) { return getKeyFromAuthorizationServer(); diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java index cf94361d..e8494ccf 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java @@ -7,6 +7,7 @@ import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAut import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Enumeration; @@ -18,6 +19,10 @@ import java.util.Enumeration; */ @Slf4j public class AuthUtils { + private AuthUtils() { + throw new IllegalStateException("Utility class"); + } + private static final String BASIC_ = "Basic "; /** @@ -60,7 +65,7 @@ public class AuthUtils { /** * *从header 请求中的clientId:clientSecret */ - public static String[] extractClient(HttpServletRequest request) throws IOException, UnapprovedClientAuthenticationException { + public static String[] extractClient(HttpServletRequest request) { String header = request.getHeader("Authorization"); if (header == null || !header.startsWith(BASIC_)) { throw new UnapprovedClientAuthenticationException("请求头中client信息为空"); @@ -73,10 +78,10 @@ public class AuthUtils { * * @param header header中的参数 */ - public static String[] extractHeaderClient(String header) throws IOException { - byte[] base64Client = header.substring(BASIC_.length()).getBytes(CommonConstant.UTF8); + public static String[] extractHeaderClient(String header) { + byte[] base64Client = header.substring(BASIC_.length()).getBytes(StandardCharsets.UTF_8); byte[] decoded = Base64.getDecoder().decode(base64Client); - String clientStr = new String(decoded, CommonConstant.UTF8); + String clientStr = new String(decoded, StandardCharsets.UTF_8); String[] clientArr = clientStr.split(":"); if (clientArr.length != 2) { throw new RuntimeException("Invalid basic authentication token"); diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java index 0d2d64a8..94b52679 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/constant/CommonConstant.java @@ -72,11 +72,6 @@ public interface CommonConstant { */ String DEL_FLAG = "is_del"; - /** - * 编码 - */ - String UTF8 = "UTF-8"; - /** * 超级管理员用户名 */ diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/CodeEnum.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/CodeEnum.java index e8b8ca75..3c80502d 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/CodeEnum.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/CodeEnum.java @@ -15,8 +15,4 @@ public enum CodeEnum { public Integer getCode() { return code; } - - public void setCode(Integer code) { - this.code = code; - } } diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/LoginAppUser.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/LoginAppUser.java index 80365586..d2bd58c0 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/LoginAppUser.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/LoginAppUser.java @@ -33,9 +33,7 @@ public class LoginAppUser extends SysUser implements SocialUserDetails { public Collection getAuthorities() { Collection collection = new HashSet<>(); if (!CollectionUtils.isEmpty(super.getRoles())) { - super.getRoles().parallelStream().forEach(role -> { - collection.add(new SimpleGrantedAuthority(role.getCode())); - }); + super.getRoles().parallelStream().forEach(role -> collection.add(new SimpleGrantedAuthority(role.getCode()))); } return collection; } diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/Result.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/Result.java index 3eb57a17..24a1e672 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/Result.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/model/Result.java @@ -27,7 +27,7 @@ public class Result implements Serializable { } public static Result succeedWith(T datas, Integer code, String msg) { - return new Result(datas, code, msg); + return new Result<>(datas, code, msg); } public static Result failed(String msg) { @@ -39,7 +39,7 @@ public class Result implements Serializable { } public static Result failedWith(T datas, Integer code, String msg) { - return new Result(datas, code, msg); + return new Result<>(datas, code, msg); } } diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/DateUtils.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/DateUtils.java index 1913ebbd..581b4d83 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/DateUtils.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/DateUtils.java @@ -9,6 +9,10 @@ import java.util.Date; * @author zlt */ public class DateUtils { + private DateUtils() { + throw new IllegalStateException("Utility class"); + } + /** 时间格式(yyyy-MM-dd) */ public final static String DATE_PATTERN = "yyyy-MM-dd"; /** 时间格式(yyyy-MM-dd HH:mm:ss) */ diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ExcelUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ExcelUtil.java index 88196bfd..210a66ab 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ExcelUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ExcelUtil.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.net.URLEncoder; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -23,6 +24,10 @@ import java.util.Map; * @date 2019/1/6 */ public class ExcelUtil { + private ExcelUtil() { + throw new IllegalStateException("Utility class"); + } + /** * 导出 * @@ -95,23 +100,21 @@ public class ExcelUtil { public static List importExcel(String filePath, Integer titleRows, Integer headerRows, Class pojoClass) { if (StringUtils.isBlank(filePath)) { - return null; + return Collections.emptyList(); } ImportParams params = new ImportParams(); params.setTitleRows(titleRows); params.setHeadRows(headerRows); - List list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params); - return list; + return ExcelImportUtil.importExcel(new File(filePath), pojoClass, params); } public static List importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class pojoClass) throws Exception { if (file == null) { - return null; + return Collections.emptyList(); } ImportParams params = new ImportParams(); params.setTitleRows(titleRows); params.setHeadRows(headerRows); - List list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params); - return list; + return ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params); } } diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/PhoneUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/PhoneUtil.java index aa3e6e8f..bbeba187 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/PhoneUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/PhoneUtil.java @@ -8,6 +8,10 @@ import java.util.regex.Pattern; * 正则表达式手机号码校验类 */ public class PhoneUtil { + private PhoneUtil() { + throw new IllegalStateException("Utility class"); + } + private static String REGEX = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$"; private static Pattern P = Pattern.compile(REGEX); diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ResponseUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ResponseUtil.java index 0122f8d8..a13dd624 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ResponseUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/ResponseUtil.java @@ -14,6 +14,9 @@ import java.util.Map; * @date 2018/12/20 */ public class ResponseUtil { + private ResponseUtil() { + throw new IllegalStateException("Utility class"); + } /** * 通过流写到前端 * diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SpringUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SpringUtil.java index 8c0ad2d2..502f36bd 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SpringUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SpringUtil.java @@ -1,6 +1,5 @@ package com.central.common.utils; -import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.env.Environment; @@ -28,7 +27,7 @@ public class SpringUtil implements ApplicationContextAware { } @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) { SpringUtil.applicationContext = applicationContext; } } diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SysUserUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SysUserUtil.java index 418fff20..d123c3f0 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SysUserUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/SysUserUtil.java @@ -1,25 +1,21 @@ package com.central.common.utils; import cn.hutool.core.bean.BeanUtil; -import com.central.common.model.SysRole; import com.central.common.model.SysUser; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.oauth2.provider.OAuth2Authentication; -import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import com.central.common.model.LoginAppUser; -import java.util.*; - /** * 获取用户信息 * * @author zlt */ public class SysUserUtil { + private SysUserUtil() { + throw new IllegalStateException("Utility class"); + } + public static LoginAppUser getLoginAppUser(SysUser user) { LoginAppUser login = new LoginAppUser(); BeanUtil.copyProperties(user, login); diff --git a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/UUIDUtil.java b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/UUIDUtil.java index 674c22fd..d5a9ce07 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/UUIDUtil.java +++ b/zlt-commons/zlt-common-spring-boot-starter/src/main/java/com/central/common/utils/UUIDUtil.java @@ -14,6 +14,10 @@ import java.util.UUID; * @date 2017-3-28 下午1:11:31 */ public class UUIDUtil { + private UUIDUtil() { + throw new IllegalStateException("Utility class"); + } + private static String[] chars = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", @@ -27,7 +31,7 @@ public class UUIDUtil { * @author wangfan */ public static String randomUUID8() { - StringBuffer shortBuffer = new StringBuffer(); + StringBuilder shortBuffer = new StringBuilder(); String uuid = UUID.randomUUID().toString().replace("-", ""); for (int i = 0; i < 8; i++) { String str = uuid.substring(i * 4, i * 4 + 4); @@ -43,8 +47,7 @@ public class UUIDUtil { * @author wangfan */ public static String randomUUID32(){ - String uuid = UUID.randomUUID().toString().replace("-", ""); - return uuid; + return UUID.randomUUID().toString().replace("-", ""); } } diff --git a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DateMetaObjectHandler.java b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DateMetaObjectHandler.java index 929ed437..b131ee21 100644 --- a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DateMetaObjectHandler.java +++ b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DateMetaObjectHandler.java @@ -12,21 +12,23 @@ import java.util.Date; * @date 2018/12/11 */ public class DateMetaObjectHandler implements MetaObjectHandler { + private final static String UPDATE_TIME = "updateTime"; + private final static String CREATE_TIME = "createTime"; /** * 插入填充,字段为空自动填充 */ @Override public void insertFill(MetaObject metaObject) { - Object createTime = getFieldValByName("createTime", metaObject); - Object updateTime = getFieldValByName("updateTime", metaObject); + Object createTime = getFieldValByName(CREATE_TIME, metaObject); + Object updateTime = getFieldValByName(UPDATE_TIME, metaObject); if (createTime == null || updateTime == null) { Date date = new Date(); if (createTime == null) { - setFieldValByName("createTime", date, metaObject); + setFieldValByName(CREATE_TIME, date, metaObject); } if (updateTime == null) { - setFieldValByName("updateTime", date, metaObject); + setFieldValByName(UPDATE_TIME, date, metaObject); } } } @@ -39,6 +41,6 @@ public class DateMetaObjectHandler implements MetaObjectHandler { @Override public void updateFill(MetaObject metaObject) { //mybatis-plus版本2.0.9+ - setFieldValByName("updateTime", new Date(), metaObject); + setFieldValByName(UPDATE_TIME, new Date(), metaObject); } } \ No newline at end of file diff --git a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DefaultMybatisPlusConfig.java b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DefaultMybatisPlusConfig.java index 0fbb3902..50f0097f 100644 --- a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DefaultMybatisPlusConfig.java +++ b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/DefaultMybatisPlusConfig.java @@ -28,7 +28,6 @@ public class DefaultMybatisPlusConfig { @Bean @Profile({"dev","test"}) public PerformanceInterceptor performanceInterceptor() { - PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor(); - return performanceInterceptor; + return new PerformanceInterceptor(); } } diff --git a/zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java b/zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java index b6643768..d06b2eef 100644 --- a/zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java +++ b/zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/monitor/PointUtil.java @@ -9,6 +9,10 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j public class PointUtil { + private PointUtil() { + throw new IllegalStateException("Utility class"); + } + public static final String SPLIT = "|"; /** diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java index 00f7166a..194fe698 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java @@ -101,11 +101,10 @@ public class RedisAutoConfigure { } private RedisCacheConfiguration getDefConf() { - RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + return RedisCacheConfiguration.defaultCacheConfig() .disableCachingNullValues() .computePrefixWith(cacheName -> "cache".concat(":").concat(cacheName).concat(":")) .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new RedisObjectSerializer())); - return cacheConfiguration; } } diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/constant/RedisToolsConstant.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/constant/RedisToolsConstant.java index e55a5ce5..81100acc 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/constant/RedisToolsConstant.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/constant/RedisToolsConstant.java @@ -7,7 +7,9 @@ package com.central.common.redis.constant; * @date 2018/5/21 11:59 */ public class RedisToolsConstant { - + private RedisToolsConstant() { + throw new IllegalStateException("Utility class"); + } /** * single Redis */ diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java index f88c6bd1..a663037f 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java @@ -56,7 +56,8 @@ public class RedisDistributedLock extends AbstractDistributedLock { log.debug("get redisDistributeLock failed, retrying..." + retryTimes); Thread.sleep(sleepMillis); } catch (InterruptedException e) { - return false; + log.warn("Interrupted!", e); + Thread.currentThread().interrupt(); } result = setRedis(key, expire); } diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java index 62417d4b..abdcf2e9 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java @@ -14,6 +14,7 @@ import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.*; /** @@ -27,7 +28,7 @@ public class RedisRepository { /** * 默认编码 */ - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); + private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; /** * key序列化 diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/util/RedisObjectSerializer.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/util/RedisObjectSerializer.java index 98cf455b..3fe888cc 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/util/RedisObjectSerializer.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/util/RedisObjectSerializer.java @@ -12,22 +12,26 @@ import org.springframework.data.redis.serializer.SerializationException; * @author zlt */ public class RedisObjectSerializer implements RedisSerializer { - private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; // 做一个空数组,不是null + // 做一个空数组,不是null + private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; // 为了方便进行对象与字节数组的转换,所以应该首先准备出两个转换器 private Converter serializingConverter = new SerializingConverter(); private Converter deserializingConverter = new DeserializingConverter(); @Override - public byte[] serialize(Object obj) throws SerializationException { - if (obj == null) { // 这个时候没有要序列化的对象出现,所以返回的字节数组应该就是一个空数组 + public byte[] serialize(Object obj) { + // 这个时候没有要序列化的对象出现,所以返回的字节数组应该就是一个空数组 + if (obj == null) { return EMPTY_BYTE_ARRAY; } - return this.serializingConverter.convert(obj); // 将对象变为字节数组 + // 将对象变为字节数组 + return this.serializingConverter.convert(obj); } @Override - public Object deserialize(byte[] data) throws SerializationException { - if (data == null || data.length == 0) { // 此时没有对象的内容信息 + public Object deserialize(byte[] data) { + // 此时没有对象的内容信息 + if (data == null || data.length == 0) { return null; } return this.deserializingConverter.convert(data); diff --git a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java index 3eb6a4c8..09e20d36 100644 --- a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java +++ b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; Swagger2Configuration.class }) public class SwaggerAutoConfiguration implements BeanFactoryAware { + private static final String AUTH_KEY = "Authorization"; private BeanFactory beanFactory; @@ -179,7 +180,7 @@ public class SwaggerAutoConfiguration implements BeanFactoryAware { } @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } @@ -198,13 +199,13 @@ public class SwaggerAutoConfiguration implements BeanFactoryAware { AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; List references = new ArrayList<>(1); - references.add(new SecurityReference("Authorization", authorizationScopes)); + references.add(new SecurityReference(AUTH_KEY, authorizationScopes)); return references; } private List securitySchemes() { List apiKeys = new ArrayList<>(1); - ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header"); + ApiKey apiKey = new ApiKey(AUTH_KEY, AUTH_KEY, "header"); apiKeys.add(apiKey); return apiKeys; } diff --git a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerProperties.java b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerProperties.java index 8b8f91ab..383b968b 100644 --- a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerProperties.java +++ b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerProperties.java @@ -1,6 +1,8 @@ package com.central.common.swagger2; import lombok.Data; +import lombok.Getter; +import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import java.util.ArrayList; @@ -51,7 +53,8 @@ public class SwaggerProperties { /**全局参数配置**/ private List globalOperationParameters; - + @Setter + @Getter public static class GlobalOperationParameter{ /**参数名**/ private String name; @@ -67,46 +70,6 @@ public class SwaggerProperties { /**参数是否必须传**/ private String required; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getModelRef() { - return modelRef; - } - - public void setModelRef(String modelRef) { - this.modelRef = modelRef; - } - - public String getParameterType() { - return parameterType; - } - - public void setParameterType(String parameterType) { - this.parameterType = parameterType; - } - - public String getRequired() { - return required; - } - - public void setRequired(String required) { - this.required = required; - } } @Data @@ -139,7 +102,6 @@ public class SwaggerProperties { @Data public static class Contact { - /**联系人**/ private String name = ""; /**联系人url**/ diff --git a/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/feign/fallback/MenuServiceFallbackFactory.java b/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/feign/fallback/MenuServiceFallbackFactory.java index 990e57fa..7cba08ab 100644 --- a/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/feign/fallback/MenuServiceFallbackFactory.java +++ b/zlt-gateway/zuul-gateway/src/main/java/com/central/gateway/feign/fallback/MenuServiceFallbackFactory.java @@ -1,17 +1,11 @@ package com.central.gateway.feign.fallback; import cn.hutool.core.collection.CollectionUtil; -import com.central.common.feign.UserService; -import com.central.common.model.LoginAppUser; -import com.central.common.model.SysMenu; -import com.central.common.model.SysUser; import com.central.gateway.feign.MenuService; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.List; - /** * menuService降级工场 * diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java index d41aee56..17629925 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java +++ b/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java @@ -4,7 +4,6 @@ import com.central.common.utils.ResponseUtil; import com.central.oauth.handler.OauthLogoutHandler; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; diff --git a/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java b/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java index b31ec32e..c247f1fb 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java +++ b/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java @@ -116,7 +116,7 @@ public class OAuth2Controller { * @return */ @ApiOperation(value = "当前登陆用户信息") - @RequestMapping(value = {"/oauth/userinfo"}, produces = "application/json") // 获取用户信息。/auth/user + @GetMapping(value = {"/oauth/userinfo"}, produces = "application/json") // 获取用户信息。/auth/user public Map getCurrentUserDetail(@LoginUser SysUser user) { Map userInfo = new HashMap<>(); if (user != null) { diff --git a/zlt-uaa/src/main/java/com/central/oauth/controller/ValidateCodeController.java b/zlt-uaa/src/main/java/com/central/oauth/controller/ValidateCodeController.java index 127306ce..bd394c5e 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/controller/ValidateCodeController.java +++ b/zlt-uaa/src/main/java/com/central/oauth/controller/ValidateCodeController.java @@ -35,8 +35,7 @@ public class ValidateCodeController { * @throws Exception */ @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{deviceId}") - public void createCode(@PathVariable String deviceId, HttpServletResponse response) - throws Exception { + public void createCode(@PathVariable String deviceId, HttpServletResponse response) throws Exception { Assert.notNull(deviceId, "机器码不能为空"); response.setHeader("Cache-Control", "no-store, no-cache"); response.setContentType("image/jpeg"); diff --git a/zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java b/zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java index 87b46ad2..e6729ea3 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java +++ b/zlt-uaa/src/main/java/com/central/oauth/filter/ValidateCodeFilter.java @@ -59,7 +59,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter { return true; } } - } catch (IOException e) { + } catch (Exception e) { log.error("解析client信息失败", e); } } diff --git a/zlt-uaa/src/main/java/com/central/oauth/handler/OauthLogoutHandler.java b/zlt-uaa/src/main/java/com/central/oauth/handler/OauthLogoutHandler.java index f01332ca..f15a7ceb 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/handler/OauthLogoutHandler.java +++ b/zlt-uaa/src/main/java/com/central/oauth/handler/OauthLogoutHandler.java @@ -39,7 +39,6 @@ public class OauthLogoutHandler implements LogoutHandler { log.info("remove existingAccessToken!", existingAccessToken); tokenStore.removeAccessToken(existingAccessToken); } - return; } } } diff --git a/zlt-uaa/src/main/java/com/central/oauth/mapper/ClientMapper.java b/zlt-uaa/src/main/java/com/central/oauth/mapper/ClientMapper.java index ee764b41..90c6c168 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/mapper/ClientMapper.java +++ b/zlt-uaa/src/main/java/com/central/oauth/mapper/ClientMapper.java @@ -13,13 +13,5 @@ import com.central.oauth.model.Client; * @author zlt */ public interface ClientMapper extends SuperMapper { - //int count(@Param("params") Map params); - List findList(Page page, @Param("params") Map params ); - - /*@Select("select * from oauth_client_details t where t.client_id = #{clientId}") - Client getClient(String clientId);*/ - - /*@Update("update oauth_client_details t set t.client_secret = #{clientSecret},t.client_secret_str = #{clientSecretStr} where t.id = #{id}") - int update(Client client);*/ } diff --git a/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationProvider.java b/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationProvider.java index bf03dc35..328ee11b 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationProvider.java +++ b/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationProvider.java @@ -19,7 +19,7 @@ public class MobileAuthenticationProvider implements AuthenticationProvider { private PasswordEncoder passwordEncoder; @Override - public Authentication authenticate(Authentication authentication) throws AuthenticationException { + public Authentication authenticate(Authentication authentication) { MobileAuthenticationToken authenticationToken = (MobileAuthenticationToken) authentication; String mobile = (String) authenticationToken.getPrincipal(); String password = (String) authenticationToken.getCredentials(); diff --git a/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationToken.java b/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationToken.java index 55c149b8..8911187e 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationToken.java +++ b/zlt-uaa/src/main/java/com/central/oauth/mobile/MobileAuthenticationToken.java @@ -69,7 +69,7 @@ public class MobileAuthenticationToken extends AbstractAuthenticationToken { } @Override - public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { + public void setAuthenticated(boolean isAuthenticated) { if (isAuthenticated) { throw new IllegalArgumentException( "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead"); diff --git a/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationProvider.java b/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationProvider.java index 5c1055c5..96ee49a6 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationProvider.java +++ b/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationProvider.java @@ -15,7 +15,7 @@ public class OpenIdAuthenticationProvider implements AuthenticationProvider { private SocialUserDetailsService userDetailsService; @Override - public Authentication authenticate(Authentication authentication) throws AuthenticationException { + public Authentication authenticate(Authentication authentication) { OpenIdAuthenticationToken authenticationToken = (OpenIdAuthenticationToken) authentication; String openId = (String) authenticationToken.getPrincipal(); UserDetails user = userDetailsService.loadUserByUserId(openId); diff --git a/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationToken.java b/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationToken.java index 41303e0e..7c342fa2 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationToken.java +++ b/zlt-uaa/src/main/java/com/central/oauth/openid/OpenIdAuthenticationToken.java @@ -1,6 +1,3 @@ -/** - * - */ package com.central.oauth.openid; import org.springframework.security.authentication.AbstractAuthenticationToken; @@ -66,7 +63,7 @@ public class OpenIdAuthenticationToken extends AbstractAuthenticationToken { } @Override - public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { + public void setAuthenticated(boolean isAuthenticated) { if (isAuthenticated) { throw new IllegalArgumentException( "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead"); diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/ZltUserDetailsService.java b/zlt-uaa/src/main/java/com/central/oauth/service/ZltUserDetailsService.java index 235539fd..5fbb2942 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/ZltUserDetailsService.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/ZltUserDetailsService.java @@ -9,5 +9,11 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; * @date 2018/12/28 */ public interface ZltUserDetailsService extends UserDetailsService { - UserDetails loadUserByMobile(String mobile) throws UsernameNotFoundException; + /** + * 根据电话号码查询用户 + * + * @param mobile + * @return + */ + UserDetails loadUserByMobile(String mobile); } diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/impl/ClientServiceImpl.java b/zlt-uaa/src/main/java/com/central/oauth/service/impl/ClientServiceImpl.java index 34543c27..acc4e0cc 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/impl/ClientServiceImpl.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/impl/ClientServiceImpl.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.central.common.constant.CommonConstant; import com.central.common.lock.DistributedLock; -import com.central.common.model.SysUser; import com.central.common.redis.template.RedisRepository; import com.central.common.constant.SecurityConstants; import com.central.common.model.PageResult; diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisClientDetailsService.java b/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisClientDetailsService.java index 44920caa..6d8655f9 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisClientDetailsService.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisClientDetailsService.java @@ -37,7 +37,7 @@ public class RedisClientDetailsService extends JdbcClientDetailsService { } @Override - public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException { + public ClientDetails loadClientByClientId(String clientId) { // 先从redis获取 ClientDetails clientDetails = (ClientDetails) redisTemplate.opsForValue().get(clientRedisKey(clientId)); if (clientDetails == null) { @@ -70,19 +70,19 @@ public class RedisClientDetailsService extends JdbcClientDetailsService { } @Override - public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { + public void updateClientDetails(ClientDetails clientDetails) { super.updateClientDetails(clientDetails); cacheAndGetClient(clientDetails.getClientId()); } @Override - public void updateClientSecret(String clientId, String secret) throws NoSuchClientException { + public void updateClientSecret(String clientId, String secret) { super.updateClientSecret(clientId, secret); cacheAndGetClient(clientId); } @Override - public void removeClientDetails(String clientId) throws NoSuchClientException { + public void removeClientDetails(String clientId) { super.removeClientDetails(clientId); removeRedisCache(clientId); } @@ -106,9 +106,7 @@ public class RedisClientDetailsService extends JdbcClientDetailsService { return; } - list.parallelStream().forEach(client -> { - redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client); - }); + list.parallelStream().forEach(client -> redisTemplate.opsForValue().set(clientRedisKey(client.getClientId()), client)); } private String clientRedisKey(String clientId) { diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/impl/UserDetailServiceImpl.java b/zlt-uaa/src/main/java/com/central/oauth/service/impl/UserDetailServiceImpl.java index 3c8e02a9..a790dfd3 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/impl/UserDetailServiceImpl.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/impl/UserDetailServiceImpl.java @@ -26,7 +26,7 @@ public class UserDetailServiceImpl implements ZltUserDetailsService, SocialUserD private UserService userService; @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + public UserDetails loadUserByUsername(String username) { LoginAppUser loginAppUser = userService.findByUsername(username); if (loginAppUser == null) { throw new InternalAuthenticationServiceException("用户名或密码错误"); @@ -35,13 +35,13 @@ public class UserDetailServiceImpl implements ZltUserDetailsService, SocialUserD } @Override - public SocialUserDetails loadUserByUserId(String openId) throws UsernameNotFoundException { + public SocialUserDetails loadUserByUserId(String openId) { LoginAppUser loginAppUser = userService.findByOpenId(openId); return checkUser(loginAppUser); } @Override - public UserDetails loadUserByMobile(String mobile) throws UsernameNotFoundException { + public UserDetails loadUserByMobile(String mobile) { LoginAppUser loginAppUser = userService.findByMobile(mobile); return checkUser(loginAppUser); } diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/impl/ValidateCodeServiceImpl.java b/zlt-uaa/src/main/java/com/central/oauth/service/impl/ValidateCodeServiceImpl.java index 5ec86a66..5076f56f 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/impl/ValidateCodeServiceImpl.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/impl/ValidateCodeServiceImpl.java @@ -95,7 +95,7 @@ public class ValidateCodeServiceImpl implements IValidateCodeService { * 验证验证码 */ @Override - public void validate(HttpServletRequest request) throws ValidateCodeException { + public void validate(HttpServletRequest request) { String deviceId = request.getParameter("deviceId"); if (StringUtils.isBlank(deviceId)) { throw new ValidateCodeException("请在请求参数中携带deviceId参数"); diff --git a/zlt-web/back-web/src/main/resources/static/pages/generator/list.html b/zlt-web/back-web/src/main/resources/static/pages/generator/list.html index 6192688b..753cf53a 100644 --- a/zlt-web/back-web/src/main/resources/static/pages/generator/list.html +++ b/zlt-web/back-web/src/main/resources/static/pages/generator/list.html @@ -75,20 +75,6 @@ // layer.msg("演示阶段", {icon: 1}); var url = config.base_server + 'api-generator/generator/code?access_token=' + config.getToken().access_token + "&tables=" + obj.data.tableName; window.location.href = url; - - // var xhr = new XMLHttpRequest(); - // xhr.open('GET', url, true); - // xhr.responseType = "blob"; - // xhr.setRequestHeader("client_type", "DESKTOP_WEB"); - // xhr.onload = function() { - // if (this.status == 200) { - // var blob = this.response; - // var objecturl = URL.createObjectURL(blob); - // window.location.href = objecturl; - // } - // } - // xhr.send(); - }; }); \ No newline at end of file