增加sonar测试并修复sonar测试的问题
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
||||
/.idea/
|
||||
/logs/
|
||||
/logs/
|
||||
/target/
|
||||
@@ -103,7 +103,7 @@ central-platform -- 父项目,公共依赖
|
||||
<table>
|
||||
<tr>
|
||||
<td><img src="https://gitee.com/zlt2000/images/raw/master/持续集成2.png"/></td>
|
||||
<td><img src="https://gitee.com/zlt2000/images/raw/master/持续集成.png"/></td>
|
||||
<td><img src="https://gitee.com/zlt2000/images/raw/master/sonar结果.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="https://gitee.com/zlt2000/images/raw/master/elk.png"/></td>
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<spring-boot-dependencies.version>2.0.8.RELEASE</spring-boot-dependencies.version>
|
||||
<spring-cloud-dependencies.version>Finchley.SR2</spring-cloud-dependencies.version>
|
||||
<spring-boot-maven-plugin.version>2.1.1.RELEASE</spring-boot-maven-plugin.version>
|
||||
<sonar.exclusions>zlt-job/**/*, zlt-register/**/*, zlt-web/**/*</sonar.exclusions>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -301,6 +302,16 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliyun-repos</id>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<modules>
|
||||
<!-- 公共 -->
|
||||
<module>zlt-commons</module>
|
||||
|
||||
+6
-9
@@ -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<String, Object> params) {
|
||||
@GetMapping("/list")
|
||||
public PageResult getTableList(@RequestParam Map<String, Object> 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\"");
|
||||
|
||||
+20
-12
@@ -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<String> getTemplates() {
|
||||
List<String> templates = new ArrayList<String>();
|
||||
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<String> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-1
@@ -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<FileType, IFileService> map = new HashMap<>();
|
||||
private Map<FileType, IFileService> map = new EnumMap<>(FileType.class);
|
||||
@Autowired
|
||||
private IFileService aliyunOssServiceImpl;
|
||||
|
||||
|
||||
-1
@@ -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;
|
||||
|
||||
|
||||
-1
@@ -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;
|
||||
|
||||
|
||||
-9
@@ -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方法上传
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+3
-5
@@ -75,9 +75,8 @@ public class SysMenuController {
|
||||
@ApiOperation(value = "根据roleId获取对应的菜单")
|
||||
@GetMapping("/{roleId}/menus")
|
||||
public List<Map<String, Object>> findMenusByRoleId(@PathVariable Long roleId) {
|
||||
Set<Long> roleIds = new HashSet<Long>() {{
|
||||
add(roleId);
|
||||
}};
|
||||
Set<Long> roleIds = new HashSet<>();
|
||||
roleIds.add(roleId);
|
||||
//获取该角色对应的菜单
|
||||
List<SysMenu> roleMenus = menuService.findByRoles(roleIds);
|
||||
//全部的菜单列表
|
||||
@@ -169,7 +168,6 @@ public class SysMenuController {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<SysMenu> menus = menuService.findByRoleCodes(roles.parallelStream().map(SysRole::getCode).collect(Collectors.toSet()), CommonConstant.MENU);
|
||||
List<SysMenu> sysMenus = treeBuilder(menus);
|
||||
return sysMenus;
|
||||
return treeBuilder(menus);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -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<String, Object> 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("删除成功");
|
||||
|
||||
+1
-3
@@ -33,9 +33,7 @@ public class SysMenuServiceImpl extends SuperServiceImpl<SysMenuMapper, SysMenu>
|
||||
sysRoleMenuMapper.delete(roleId, null);
|
||||
|
||||
if (!CollectionUtils.isEmpty(menuIds)) {
|
||||
menuIds.forEach(menuId -> {
|
||||
sysRoleMenuMapper.save(roleId, menuId);
|
||||
});
|
||||
menuIds.forEach(menuId -> sysRoleMenuMapper.save(roleId, menuId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -66,6 +66,7 @@ public class SysRoleServiceImpl extends SuperServiceImpl<SysRoleMapper, SysRole>
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result saveOrUpdateRole(SysRole sysRole) {
|
||||
if (sysRole.getId() == null) {
|
||||
this.saveRole(sysRole);
|
||||
|
||||
+6
-12
@@ -80,7 +80,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
loginAppUser.setRoles(sysRoles);
|
||||
|
||||
if (!CollectionUtils.isEmpty(sysRoles)) {
|
||||
Set<Long> roleIds = sysRoles.parallelStream().map(r -> r.getId()).collect(Collectors.toSet());
|
||||
Set<Long> roleIds = sysRoles.parallelStream().map(SuperEntity::getId).collect(Collectors.toSet());
|
||||
List<SysMenu> menus = roleMenuMapper.findMenusByRoleIds(roleIds, CommonConstant.PERMISSION);
|
||||
if (!CollectionUtils.isEmpty(menus)) {
|
||||
Set<String> permissions = menus.parallelStream().map(p -> p.getPathMethod()+":"+p.getPath())
|
||||
@@ -154,9 +154,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
|
||||
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<SysUserMapper, SysUser>
|
||||
List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList());
|
||||
|
||||
List<SysRole> 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.<SysUser>builder().data(list).code(0).count(total).build();
|
||||
}
|
||||
@@ -238,9 +234,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
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<SysUserMapper, SysUser>
|
||||
@Override
|
||||
public boolean delUser(Long id) {
|
||||
userRoleMapper.deleteUserRole(id, null);
|
||||
return baseMapper.deleteById(id) > 0 ? true : false;
|
||||
return baseMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-3
@@ -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
|
||||
|
||||
+8
-12
@@ -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<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
|
||||
List<Object> result = redisTemplate.opsForList().range(UNAME_TO_ACCESS + getApprovalKey(clientId, userName), 0, -1);
|
||||
if (result == null || result.size() == 0) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(result.size());
|
||||
for (Iterator<Object> it = result.iterator(); it.hasNext(); ) {
|
||||
OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next();
|
||||
accessTokens.add(accessToken);
|
||||
}
|
||||
return Collections.unmodifiableCollection(accessTokens);
|
||||
return getTokenColl(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
|
||||
List<Object> result = redisTemplate.opsForList().range((CLIENT_ID_TO_ACCESS + clientId), 0, -1);
|
||||
if (result == null || result.size() == 0) {
|
||||
return getTokenColl(result);
|
||||
}
|
||||
|
||||
private Collection<OAuth2AccessToken> getTokenColl(List<Object> result) {
|
||||
if (result == null || result.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(result.size());
|
||||
List<OAuth2AccessToken> accessTokens = new ArrayList<>(result.size());
|
||||
for (Iterator<Object> it = result.iterator(); it.hasNext(); ) {
|
||||
OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next();
|
||||
accessTokens.add(accessToken);
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
+9
-4
@@ -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");
|
||||
|
||||
-5
@@ -72,11 +72,6 @@ public interface CommonConstant {
|
||||
*/
|
||||
String DEL_FLAG = "is_del";
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
String UTF8 = "UTF-8";
|
||||
|
||||
/**
|
||||
* 超级管理员用户名
|
||||
*/
|
||||
|
||||
-4
@@ -15,8 +15,4 @@ public enum CodeEnum {
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -33,9 +33,7 @@ public class LoginAppUser extends SysUser implements SocialUserDetails {
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
Collection<GrantedAuthority> 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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ public class Result<T> implements Serializable {
|
||||
}
|
||||
|
||||
public static <T> Result<T> succeedWith(T datas, Integer code, String msg) {
|
||||
return new Result<T>(datas, code, msg);
|
||||
return new Result<>(datas, code, msg);
|
||||
}
|
||||
|
||||
public static <T> Result<T> failed(String msg) {
|
||||
@@ -39,7 +39,7 @@ public class Result<T> implements Serializable {
|
||||
}
|
||||
|
||||
public static <T> Result<T> failedWith(T datas, Integer code, String msg) {
|
||||
return new Result<T>(datas, code, msg);
|
||||
return new Result<>(datas, code, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -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) */
|
||||
|
||||
+9
-6
@@ -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 <T> List<T> importExcel(String filePath, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
|
||||
return list;
|
||||
return ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
|
||||
}
|
||||
|
||||
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass) throws Exception {
|
||||
if (file == null) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
|
||||
return list;
|
||||
return ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -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);
|
||||
|
||||
|
||||
+3
@@ -14,6 +14,9 @@ import java.util.Map;
|
||||
* @date 2018/12/20
|
||||
*/
|
||||
public class ResponseUtil {
|
||||
private ResponseUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
/**
|
||||
* 通过流写到前端
|
||||
*
|
||||
|
||||
+1
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -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);
|
||||
|
||||
+6
-3
@@ -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("-", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -28,7 +28,6 @@ public class DefaultMybatisPlusConfig {
|
||||
@Bean
|
||||
@Profile({"dev","test"})
|
||||
public PerformanceInterceptor performanceInterceptor() {
|
||||
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
|
||||
return performanceInterceptor;
|
||||
return new PerformanceInterceptor();
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -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 = "|";
|
||||
|
||||
/**
|
||||
|
||||
+1
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -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
|
||||
*/
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
|
||||
+2
-1
@@ -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序列化
|
||||
|
||||
+10
-6
@@ -12,22 +12,26 @@ import org.springframework.data.redis.serializer.SerializationException;
|
||||
* @author zlt
|
||||
*/
|
||||
public class RedisObjectSerializer implements RedisSerializer<Object> {
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; // 做一个空数组,不是null
|
||||
// 做一个空数组,不是null
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
// 为了方便进行对象与字节数组的转换,所以应该首先准备出两个转换器
|
||||
private Converter<Object, byte[]> serializingConverter = new SerializingConverter();
|
||||
private Converter<byte[], Object> 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);
|
||||
|
||||
+4
-3
@@ -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<SecurityReference> references = new ArrayList<>(1);
|
||||
references.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
references.add(new SecurityReference(AUTH_KEY, authorizationScopes));
|
||||
return references;
|
||||
}
|
||||
|
||||
private List<ApiKey> securitySchemes() {
|
||||
List<ApiKey> 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;
|
||||
}
|
||||
|
||||
+4
-42
@@ -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<GlobalOperationParameter> 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**/
|
||||
|
||||
-6
@@ -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降级工场
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String, Object> getCurrentUserDetail(@LoginUser SysUser user) {
|
||||
Map<String, Object> userInfo = new HashMap<>();
|
||||
if (user != null) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("解析client信息失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ public class OauthLogoutHandler implements LogoutHandler {
|
||||
log.info("remove existingAccessToken!", existingAccessToken);
|
||||
tokenStore.removeAccessToken(existingAccessToken);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,5 @@ import com.central.oauth.model.Client;
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ClientMapper extends SuperMapper<Client> {
|
||||
//int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<Client> findList(Page<Client> page, @Param("params") Map<String, Object> 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);*/
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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参数");
|
||||
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user