mirror of https://github.com/elunez/eladmin
commit
9d9e7b3131
|
@ -26,14 +26,12 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
import springfox.documentation.builders.ParameterBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.schema.AlternateTypeRule;
|
import springfox.documentation.schema.AlternateTypeRule;
|
||||||
import springfox.documentation.schema.AlternateTypeRuleConvention;
|
import springfox.documentation.schema.AlternateTypeRuleConvention;
|
||||||
import springfox.documentation.schema.ModelRef;
|
import springfox.documentation.service.*;
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Parameter;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -53,41 +51,65 @@ public class SwaggerConfig {
|
||||||
@Value("${jwt.header}")
|
@Value("${jwt.header}")
|
||||||
private String tokenHeader;
|
private String tokenHeader;
|
||||||
|
|
||||||
@Value("${jwt.token-start-with}")
|
|
||||||
private String tokenStartWith;
|
|
||||||
|
|
||||||
@Value("${swagger.enabled}")
|
@Value("${swagger.enabled}")
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public Docket createRestApi() {
|
public Docket createRestApi() {
|
||||||
ParameterBuilder ticketPar = new ParameterBuilder();
|
|
||||||
List<Parameter> pars = new ArrayList<>();
|
|
||||||
ticketPar.name(tokenHeader).description("token")
|
|
||||||
.modelRef(new ModelRef("string"))
|
|
||||||
.parameterType("header")
|
|
||||||
.defaultValue(tokenStartWith + " ")
|
|
||||||
.required(true)
|
|
||||||
.build();
|
|
||||||
pars.add(ticketPar.build());
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.enable(enabled)
|
.enable(enabled)
|
||||||
|
.pathMapping("/")
|
||||||
.apiInfo(apiInfo())
|
.apiInfo(apiInfo())
|
||||||
.select()
|
.select()
|
||||||
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
.build()
|
.build()
|
||||||
.globalOperationParameters(pars);
|
//添加登陆认证
|
||||||
|
.securitySchemes(securitySchemes())
|
||||||
|
.securityContexts(securityContexts());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
private ApiInfo apiInfo() {
|
||||||
return new ApiInfoBuilder()
|
return new ApiInfoBuilder()
|
||||||
.description("一个简单且易上手的 Spring boot 后台管理框架")
|
.description("一个简单且易上手的 Spring boot 后台管理框架")
|
||||||
.title("EL-ADMIN 接口文档")
|
.title("EL-ADMIN 接口文档")
|
||||||
.version("2.4")
|
.version("2.6")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SecurityScheme> securitySchemes() {
|
||||||
|
//设置请求头信息
|
||||||
|
List<SecurityScheme> securitySchemes = new ArrayList<>();
|
||||||
|
ApiKey apiKey = new ApiKey(tokenHeader, tokenHeader, "header");
|
||||||
|
securitySchemes.add(apiKey);
|
||||||
|
return securitySchemes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SecurityContext> securityContexts() {
|
||||||
|
//设置需要登录认证的路径
|
||||||
|
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||||
|
// ^(?!auth).*$ 表示所有包含auth的接口不需要使用securitySchemes即不需要带token
|
||||||
|
// ^标识开始 ()里是一子表达式 ?!/auth表示匹配不是/auth的位置,匹配上则添加请求头,注意路径已/开头 .表示任意字符 *表示前面的字符匹配多次 $标识结束
|
||||||
|
securityContexts.add(getContextByPath());
|
||||||
|
return securityContexts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SecurityContext getContextByPath() {
|
||||||
|
return SecurityContext.builder()
|
||||||
|
.securityReferences(defaultAuth())
|
||||||
|
.forPaths(PathSelectors.regex("^(?!/auth).*$"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SecurityReference> defaultAuth() {
|
||||||
|
List<SecurityReference> securityReferences = new ArrayList<>();
|
||||||
|
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||||
|
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||||
|
authorizationScopes[0] = authorizationScope;
|
||||||
|
securityReferences.add(new SecurityReference(tokenHeader, authorizationScopes));
|
||||||
|
return securityReferences;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.springframework.context.annotation.Configuration;
|
||||||
public class ConfigBeanConfiguration {
|
public class ConfigBeanConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "login", ignoreUnknownFields = true)
|
@ConfigurationProperties(prefix = "login")
|
||||||
public LoginProperties loginProperties() {
|
public LoginProperties loginProperties() {
|
||||||
return new LoginProperties();
|
return new LoginProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "jwt", ignoreUnknownFields = true)
|
@ConfigurationProperties(prefix = "jwt")
|
||||||
public SecurityProperties securityProperties() {
|
public SecurityProperties securityProperties() {
|
||||||
return new SecurityProperties();
|
return new SecurityProperties();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ import lombok.Data;
|
||||||
/**
|
/**
|
||||||
* 登录验证码配置信息
|
* 登录验证码配置信息
|
||||||
*
|
*
|
||||||
* @author: liaojinlong
|
* @author liaojinlong
|
||||||
* @date: 2020/6/10 18:53
|
* @date 2020/6/10 18:53
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LoginCode {
|
public class LoginCode {
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class LoginProperties {
|
||||||
private boolean singleLogin = false;
|
private boolean singleLogin = false;
|
||||||
|
|
||||||
private LoginCode loginCode;
|
private LoginCode loginCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录信息缓存
|
* 用户登录信息缓存
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class DeptServiceImpl implements DeptService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeptDto> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<DeptDto> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
Sort sort = new Sort(Sort.Direction.ASC, "deptSort");
|
Sort sort = Sort.by(Sort.Direction.ASC, "deptSort");
|
||||||
String dataScopeType = SecurityUtils.getDataScopeType();
|
String dataScopeType = SecurityUtils.getDataScopeType();
|
||||||
if (isQuery) {
|
if (isQuery) {
|
||||||
if(dataScopeType.equals(DataScopeEnum.ALL.getValue())){
|
if(dataScopeType.equals(DataScopeEnum.ALL.getValue())){
|
||||||
|
@ -278,4 +278,4 @@ public class DeptServiceImpl implements DeptService {
|
||||||
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||||
redisUtils.del(CacheKey.DEPT_ID + id);
|
redisUtils.del(CacheKey.DEPT_ID + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
Sort sort = new Sort(Sort.Direction.ASC, "menuSort");
|
Sort sort = Sort.by(Sort.Direction.ASC, "menuSort");
|
||||||
if(isQuery){
|
if(isQuery){
|
||||||
criteria.setPidIsNull(true);
|
criteria.setPidIsNull(true);
|
||||||
List<Field> fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>());
|
List<Field> fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class RoleServiceImpl implements RoleService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RoleDto> queryAll() {
|
public List<RoleDto> queryAll() {
|
||||||
Sort sort = new Sort(Sort.Direction.ASC, "level");
|
Sort sort = Sort.by(Sort.Direction.ASC, "level");
|
||||||
return roleMapper.toDto(roleRepository.findAll(sort));
|
return roleMapper.toDto(roleRepository.findAll(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ login:
|
||||||
# 验证码高度
|
# 验证码高度
|
||||||
width: 111
|
width: 111
|
||||||
# 验证码宽度
|
# 验证码宽度
|
||||||
heigth: 36
|
height: 36
|
||||||
# 内容长度
|
# 内容长度
|
||||||
length: 2
|
length: 2
|
||||||
# 字体名称,为空则使用默认字体
|
# 字体名称,为空则使用默认字体
|
||||||
|
|
|
@ -65,7 +65,7 @@ login:
|
||||||
# 验证码高度
|
# 验证码高度
|
||||||
width: 111
|
width: 111
|
||||||
# 验证码宽度
|
# 验证码宽度
|
||||||
heigth: 36
|
height: 36
|
||||||
# 内容长度
|
# 内容长度
|
||||||
length: 2
|
length: 2
|
||||||
# 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可
|
# 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<name>工具模块</name>
|
<name>工具模块</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mail.version>1.5.0-b01</mail.version>
|
<mail.version>1.4.7</mail.version>
|
||||||
<qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
|
<qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
|
||||||
<alipay.version>4.9.153.ALL</alipay.version>
|
<alipay.version>4.9.153.ALL</alipay.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -69,7 +69,9 @@ public class EmailServiceImpl implements EmailService {
|
||||||
}
|
}
|
||||||
// 封装
|
// 封装
|
||||||
MailAccount account = new MailAccount();
|
MailAccount account = new MailAccount();
|
||||||
account.setUser(emailConfig.getUser());
|
// 设置用户
|
||||||
|
String user = emailConfig.getFromUser().split("@")[0];
|
||||||
|
account.setUser(user);
|
||||||
account.setHost(emailConfig.getHost());
|
account.setHost(emailConfig.getHost());
|
||||||
account.setPort(Integer.parseInt(emailConfig.getPort()));
|
account.setPort(Integer.parseInt(emailConfig.getPort()));
|
||||||
account.setAuth(true);
|
account.setAuth(true);
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -26,7 +26,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.1.0.RELEASE</version>
|
<version>2.2.10.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -660,7 +660,7 @@ CREATE TABLE `sys_user` (
|
||||||
`is_admin` bit(1) DEFAULT b'0' COMMENT '是否为admin账号',
|
`is_admin` bit(1) DEFAULT b'0' COMMENT '是否为admin账号',
|
||||||
`enabled` bigint(20) DEFAULT NULL COMMENT '状态:1启用、0禁用',
|
`enabled` bigint(20) DEFAULT NULL COMMENT '状态:1启用、0禁用',
|
||||||
`create_by` varchar(255) DEFAULT NULL COMMENT '创建者',
|
`create_by` varchar(255) DEFAULT NULL COMMENT '创建者',
|
||||||
`update_by` varchar(255) DEFAULT NULL COMMENT '更新着',
|
`update_by` varchar(255) DEFAULT NULL COMMENT '更新者',
|
||||||
`pwd_reset_time` datetime DEFAULT NULL COMMENT '修改密码的时间',
|
`pwd_reset_time` datetime DEFAULT NULL COMMENT '修改密码的时间',
|
||||||
`create_time` datetime DEFAULT NULL COMMENT '创建日期',
|
`create_time` datetime DEFAULT NULL COMMENT '创建日期',
|
||||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
|
@ -822,4 +822,4 @@ CREATE TABLE `tool_qiniu_content` (
|
||||||
BEGIN;
|
BEGIN;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
Loading…
Reference in New Issue