🎉 2.1.0.RELEASE

This commit is contained in:
smallchill 2019-03-09 10:58:48 +08:00
parent ae17db974f
commit f4bde35ff6
23 changed files with 420 additions and 23 deletions

View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-tool</artifactId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.mp.BladeMetaObjectHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@ -36,6 +37,7 @@ import org.springframework.context.annotation.Profile;
public class MybatisPlusConfiguration {
@Bean
@ConditionalOnMissingBean(PaginationInterceptor.class)
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -31,10 +31,15 @@ public class BladeUser implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
* 用户id
*/
@ApiModelProperty(hidden = true)
private Integer userId;
/**
* 租户编号
*/
@ApiModelProperty(hidden = true)
private String tenantCode;
/**
* 昵称
*/

View File

@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.api.ResultCode;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.WebUtil;
@ -46,7 +47,7 @@ public class SecureInterceptor extends HandlerInterceptorAdapter {
log.warn("签名认证失败,请求接口:{}请求IP{},请求参数:{}", request.getRequestURI(), WebUtil.getIP(request), JsonUtil.toJson(request.getParameterMap()));
R result = R.fail(ResultCode.UN_AUTHORIZED);
response.setCharacterEncoding(StringPool.UTF_8);
response.setHeader("Content-type", MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setStatus(HttpServletResponse.SC_OK);
try {
response.getWriter().write(Objects.requireNonNull(JsonUtil.toJson(result)));

View File

@ -42,8 +42,10 @@ public class SecureRegistry {
this.defaultExcludePatterns.add("/auth/**");
this.defaultExcludePatterns.add("/token/**");
this.defaultExcludePatterns.add("/log/**");
this.defaultExcludePatterns.add("/user/userInfo");
this.defaultExcludePatterns.add("/user/user-info");
this.defaultExcludePatterns.add("/menu/auth-routes");
this.defaultExcludePatterns.add("/error/**");
this.defaultExcludePatterns.add("/assets/**");
}
/**

View File

@ -28,7 +28,10 @@ import org.springblade.core.tool.utils.WebUtil;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.security.Key;
import java.util.*;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
/**
* Secure工具类
@ -45,8 +48,9 @@ public class SecureUtil {
public final static String ROLE_ID = "roleId";
public final static String USER_NAME = "userName";
public final static String ROLE_NAME = "roleName";
public final static String TENANT_CODE = "tenantCode";
public final static Integer AUTH_LENGTH = 7;
private static String BASE64_SECURITY = Base64.getEncoder().encodeToString("SpringBlade".getBytes(Charsets.UTF_8));
public static String BASE64_SECURITY = Base64.getEncoder().encodeToString("BladeX".getBytes(Charsets.UTF_8));
/**
* 获取用户信息
@ -79,14 +83,18 @@ public class SecureUtil {
return null;
}
Integer userId = Func.toInt(claims.get(SecureUtil.USER_ID));
String tenantCode = Func.toStr(claims.get(SecureUtil.TENANT_CODE));
String roleId = Func.toStr(claims.get(SecureUtil.ROLE_ID));
String account = Func.toStr(claims.get(SecureUtil.ACCOUNT));
String roleName = Func.toStr(claims.get(SecureUtil.ROLE_NAME));
String userName = Func.toStr(claims.get(SecureUtil.USER_NAME));
BladeUser bladeUser = new BladeUser();
bladeUser.setAccount(account);
bladeUser.setUserId(userId);
bladeUser.setTenantCode(tenantCode);
bladeUser.setAccount(account);
bladeUser.setRoleId(roleId);
bladeUser.setRoleName(roleName);
bladeUser.setUserName(userName);
return bladeUser;
}
@ -133,6 +141,48 @@ public class SecureUtil {
return (null == user) ? StringPool.EMPTY : user.getAccount();
}
/**
* 获取用户名
*
* @return userName
*/
public static String getUserName() {
BladeUser user = getUser();
return (null == user) ? StringPool.EMPTY : user.getUserName();
}
/**
* 获取用户名
*
* @param request request
* @return userName
*/
public static String getUserName(HttpServletRequest request) {
BladeUser user = getUser(request);
return (null == user) ? StringPool.EMPTY : user.getUserName();
}
/**
* 获取租户编号
*
* @return tenantCode
*/
public static String getTenantCode() {
BladeUser user = getUser();
return (null == user) ? StringPool.EMPTY : user.getTenantCode();
}
/**
* 获取租户编号
*
* @param request request
* @return tenantCode
*/
public static String getTenantCode(HttpServletRequest request) {
BladeUser user = getUser(request);
return (null == user) ? StringPool.EMPTY : user.getTenantCode();
}
/**
* 获取Claims
*
@ -157,7 +207,7 @@ public class SecureUtil {
* @return header
*/
public static String getHeader() {
return getHeader(Objects.requireNonNull(WebUtil.getRequest()));
return getHeader(WebUtil.getRequest());
}
/**

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

25
blade-core-tenant/pom.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>blade-tool</artifactId>
<groupId>org.springblade</groupId>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-core-tenant</artifactId>
<name>${project.artifactId}</name>
<version>${blade.tool.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-mybatis</artifactId>
<version>${blade.tool.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,67 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.utils.StringUtil;
/**
* 租户信息处理器
*
* @author Chill
*/
@Slf4j
@AllArgsConstructor
public class BladeTenantHandler implements TenantHandler {
private final BladeTenantProperties properties;
/**
* 获取租户编号
*
* @return 租户编号
*/
@Override
public Expression getTenantId() {
return new StringValue(SecureUtil.getTenantCode());
}
/**
* 获取租户字段名称
*
* @return 租户字段名称
*/
@Override
public String getTenantIdColumn() {
return properties.getColumn();
}
/**
* 过滤租户表
*
* @param tableName 表名
* @return 是否进行过滤
*/
@Override
public boolean doTableFilter(String tableName) {
return (properties.getTables().size() > 0 && !properties.getTables().contains(tableName)) || !properties.getBladeTables().contains(tableName) || StringUtil.isBlank(SecureUtil.getTenantCode());
}
}

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant;
import org.springblade.core.tool.utils.RandomType;
import org.springblade.core.tool.utils.StringUtil;
/**
* blade租户id生成器
*
* @author Chill
*/
public class BladeTenantId implements TenantId {
@Override
public String generate() {
return StringUtil.random(6, RandomType.INT);
}
}

View File

@ -0,0 +1,50 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 多租户配置
*
* @author Chill
*/
@Getter
@Setter
@ConfigurationProperties(prefix = "blade.tenant")
public class BladeTenantProperties {
/**
* 多租户字段名称
*/
private String column = "tenant_code";
/**
* 多租户数据表
*/
private List<String> tables = new ArrayList<>();
/**
* 多租户系统数据表
*/
private List<String> bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual");
}

View File

@ -0,0 +1,88 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* 多租户配置类
*
* @author Chill
*/
@Configuration
@AllArgsConstructor
@AutoConfigureBefore(MybatisConfiguration.class)
@EnableConfigurationProperties(BladeTenantProperties.class)
public class TenantConfiguration {
/**
* 多租户配置类
*/
private final BladeTenantProperties properties;
/**
* 自定义租户处理器
*
* @return TenantHandler
*/
@Bean
@ConditionalOnMissingBean(TenantHandler.class)
public TenantHandler bladeTenantHandler() {
return new BladeTenantHandler(properties);
}
/**
* 自定义租户id生成器
*
* @return TenantId
*/
@Bean
@ConditionalOnMissingBean(TenantId.class)
public TenantId tenantId() {
return new BladeTenantId();
}
/**
* 分页插件
*
* @param tenantHandler 自定义租户处理器
* @return PaginationInterceptor
*/
@Bean
public PaginationInterceptor paginationInterceptor(TenantHandler tenantHandler) {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
List<ISqlParser> sqlParserList = new ArrayList<>();
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(tenantHandler);
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
return paginationInterceptor;
}
}

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant;
/**
* 租户id生成器
*
* @author Chill
*/
public interface TenantId {
/**
* 生成自定义租户id
* @return
*/
String generate();
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.tenant.mp;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
/**
* 租户基础实体类
*
* @author Chill
*/
@Data
public class TenantEntity extends BaseEntity {
/**
* 租户编号
*/
@ApiModelProperty(value = "租户编号")
private String tenantCode;
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-tool</artifactId>
<version>2.0.8</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -27,6 +27,11 @@ public interface BladeConstant {
*/
String UTF_8 = "UTF-8";
/**
* contentType
*/
String CONTENT_TYPE_NAME = "Content-type";
/**
* JSON 资源
*/
@ -47,10 +52,7 @@ public interface BladeConstant {
*/
int DB_STATUS_NORMAL = 1;
/**
* 是否删除字段名
*/
String IS_DELETED_FIELD = "is_deleted";
/**
* 删除状态[0:正常,1:删除]
*/
@ -63,6 +65,11 @@ public interface BladeConstant {
int DB_ADMIN_NON_LOCKED = 0;
int DB_ADMIN_LOCKED = 1;
/**
* 管理员对应的租户编号
*/
String ADMIN_TENANT_CODE = "000000";
/**
* 日志默认状态
*/

View File

@ -22,7 +22,7 @@ package org.springblade.core.tool.constant;
*/
public class RoleConstant {
public static final String ADMIN = "admin";
public static final String ADMIN = "administrator";
public static final String HAS_ROLE_ADMIN = "hasRole('" + ADMIN + "')";

View File

@ -5,7 +5,7 @@
<groupId>org.springblade</groupId>
<artifactId>blade-tool</artifactId>
<version>2.0.8</version>
<version>2.1.0</version>
<packaging>pom</packaging>
<name>blade-tool</name>
<description>
@ -36,7 +36,7 @@
</scm>
<properties>
<blade.tool.version>2.0.8</blade.tool.version>
<blade.tool.version>2.1.0</blade.tool.version>
<java.version>1.8</java.version>
<maven.plugin.version>3.8.0</maven.plugin.version>
@ -68,6 +68,7 @@
<module>blade-core-mybatis</module>
<module>blade-core-swagger</module>
<module>blade-core-cloud</module>
<module>blade-core-tenant</module>
</modules>
<dependencyManagement>