Merge branch 'develop' of https://github.com/dibo-software/diboot-v2 into develop
This commit is contained in:
commit
59265cdc2d
|
@ -48,7 +48,7 @@ public @interface BindQuery {
|
|||
Class entity() default NullType.class;
|
||||
|
||||
/***
|
||||
* JOIN连接条件
|
||||
* JOIN连接条件,支持动态的跨表JOIN查询
|
||||
* @return
|
||||
*/
|
||||
String condition() default "";
|
||||
|
|
|
@ -65,7 +65,15 @@ public class Cons {
|
|||
/**
|
||||
* 创建时间字段
|
||||
*/
|
||||
createTime
|
||||
createTime,
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
updateTime,
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
createBy
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class BaseController {
|
|||
if(entityOrDto instanceof HttpServletRequest){
|
||||
throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!");
|
||||
}
|
||||
return QueryBuilder.toQueryWrapper(entityOrDto, extractParams());
|
||||
return QueryBuilder.toQueryWrapper(entityOrDto, extractQueryParams());
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -62,7 +62,7 @@ public class BaseController {
|
|||
if(entityOrDto instanceof HttpServletRequest){
|
||||
throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!");
|
||||
}
|
||||
return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractParams());
|
||||
return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams());
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -124,7 +124,7 @@ public class BaseController {
|
|||
* 提取请求参数名集合
|
||||
* @return
|
||||
*/
|
||||
private Set<String> extractParams(){
|
||||
protected Set<String> extractQueryParams(){
|
||||
Map<String, Object> paramValueMap = convertParams2Map();
|
||||
if(V.notEmpty(paramValueMap)){
|
||||
return paramValueMap.keySet();
|
||||
|
@ -136,7 +136,7 @@ public class BaseController {
|
|||
* 将请求参数值转换为Map
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> convertParams2Map(){
|
||||
protected Map<String, Object> convertParams2Map(){
|
||||
Map<String, Object> result = new HashMap<>(8);
|
||||
if(request == null){
|
||||
return result;
|
||||
|
@ -196,7 +196,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public Long getLong(String param){
|
||||
protected Long getLong(String param){
|
||||
return S.toLong(request.getParameter(param));
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ public class BaseController {
|
|||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public long getLong(String param, Long defaultValue){
|
||||
protected long getLong(String param, Long defaultValue){
|
||||
return S.toLong(request.getParameter(param), defaultValue);
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public Integer getInteger(String param){
|
||||
protected Integer getInteger(String param){
|
||||
return S.toInt(request.getParameter(param));
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ public class BaseController {
|
|||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public int getInt(String param, Integer defaultValue){
|
||||
protected int getInt(String param, Integer defaultValue){
|
||||
return S.toInt(request.getParameter(param), defaultValue);
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public boolean getBoolean(String param){
|
||||
protected boolean getBoolean(String param){
|
||||
return S.toBoolean(request.getParameter(param));
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ public class BaseController {
|
|||
* @param defaultBoolean
|
||||
* @return
|
||||
*/
|
||||
public boolean getBoolean(String param, boolean defaultBoolean){
|
||||
protected boolean getBoolean(String param, boolean defaultBoolean){
|
||||
return S.toBoolean(request.getParameter(param), defaultBoolean);
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public Double getDouble(String param){
|
||||
protected Double getDouble(String param){
|
||||
if(V.notEmpty(request.getParameter(param))){
|
||||
return Double.parseDouble(request.getParameter(param));
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ public class BaseController {
|
|||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public Double getDouble(String param, Double defaultValue){
|
||||
protected Double getDouble(String param, Double defaultValue){
|
||||
if(V.notEmpty(request.getParameter(param))){
|
||||
return Double.parseDouble(request.getParameter(param));
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public String getString(String param){
|
||||
protected String getString(String param){
|
||||
if(V.notEmpty(request.getParameter(param))){
|
||||
return request.getParameter(param);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ public class BaseController {
|
|||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public String getString(String param, String defaultValue){
|
||||
protected String getString(String param, String defaultValue){
|
||||
if(V.notEmpty(request.getParameter(param))){
|
||||
return request.getParameter(param);
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public String[] getStringArray(String param){
|
||||
protected String[] getStringArray(String param){
|
||||
if(request.getParameterValues(param) != null){
|
||||
return request.getParameterValues(param);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public List<String> getStringList(String param){
|
||||
protected List<String> getStringList(String param){
|
||||
String[] strArray = getStringArray(param);
|
||||
if(V.isEmpty(strArray)){
|
||||
return null;
|
||||
|
@ -328,7 +328,7 @@ public class BaseController {
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public List<Long> getLongList(String param){
|
||||
protected List<Long> getLongList(String param){
|
||||
String[] strArray = getStringArray(param);
|
||||
if(V.isEmpty(strArray)){
|
||||
return null;
|
||||
|
|
|
@ -78,9 +78,21 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
warning("createEntity", "参数entity为null");
|
||||
return false;
|
||||
}
|
||||
return save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(T entity) {
|
||||
beforeCreateEntity(entity);
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于创建之前的自动填充等场景调用
|
||||
*/
|
||||
protected void beforeCreateEntity(T entity){
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public <RE, R> boolean createEntityAndRelatedEntities(T entity, List<RE> relatedEntities, ISetter<RE, R> relatedEntitySetter) {
|
||||
|
@ -130,7 +142,26 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
}
|
||||
else{
|
||||
// 批量插入
|
||||
return super.saveBatch(entityList, BaseConfig.getBatchSize());
|
||||
return saveBatch(entityList, BaseConfig.getBatchSize());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveBatch(Collection<T> entityList, int batchSize){
|
||||
// 批量插入
|
||||
beforeCreateEntities(entityList);
|
||||
return super.saveBatch(entityList, batchSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于创建之前的自动填充等场景调用
|
||||
*/
|
||||
protected void beforeCreateEntities(Collection<T> entityList){
|
||||
if(V.isEmpty(entityList)){
|
||||
return;
|
||||
}
|
||||
for(T entity : entityList){
|
||||
beforeCreateEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -649,7 +680,7 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
* @param message
|
||||
*/
|
||||
private void warning(String method, String message){
|
||||
log.warn(this.getClass().getName() + ".{} 调用错误: {}, 请检查!", method, message);
|
||||
log.warn(this.getClass().getSimpleName() + ".{} 调用错误: {}, 请检查!", method, message);
|
||||
}
|
||||
|
||||
}
|
|
@ -161,8 +161,14 @@ public class BeanUtils {
|
|||
* @return
|
||||
*/
|
||||
public static Object getProperty(Object obj, String field){
|
||||
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(obj);
|
||||
return wrapper.getPropertyValue(field);
|
||||
try {
|
||||
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(obj);
|
||||
return wrapper.getPropertyValue(field);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("获取对象属性值出错,返回null", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -17,7 +17,7 @@ compile("com.diboot:diboot-file-spring-boot-starter:{latestVersion}")
|
|||
diboot-file会自动依赖以下jar包,无需重复引入:
|
||||
* commons-fileupload: 1.4
|
||||
* easyexcel:2.x
|
||||
* okhttp:4.3.x
|
||||
* okhttp:4.7.x
|
||||
* thumbnailator: 0.4.9 (图片压缩,不需要可剔除)
|
||||
* easy-captcha: 1.6.x (验证码,不需要可剔除)
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public void addFormatters(FormatterRegistry registry) {
|
|||
* v2.1.x版本开始,extdata扩展字段将不再推荐使用,该字段设计目的用于字段冗余的json存储,可以通过数据库的json数据类型实现。
|
||||
devtools从2.1版本开始不再支持extdata的特殊处理。
|
||||
|
||||
* v2.1.x版本依赖组件升级为: Spring Boot 2.3.0,Mybatis-Plus 3.3.2,fastjson 1.2.70。根据您的依赖情况,可能会有依赖冲突需要解决。
|
||||
* v2.1.x版本依赖组件升级为: Spring Boot 2.3.x,Mybatis-Plus 3.3.x,fastjson 1.2.7x。根据您的依赖情况,可能会有依赖冲突需要解决。
|
||||
|
||||
#### 2. diboot-devtools
|
||||
* v2.1版本开始,配置参数:
|
||||
|
|
|
@ -38,13 +38,13 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>2.2.3</version>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
<!-- http -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.5.0</version>
|
||||
<version>4.7.2</version>
|
||||
</dependency>
|
||||
<!-- 图片压缩 -->
|
||||
<dependency>
|
||||
|
@ -57,7 +57,6 @@
|
|||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.5.0</version>
|
||||
<version>4.7.2</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
*/
|
||||
package com.diboot.iam.annotation.process;
|
||||
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.ContextHelper;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.iam.annotation.BindPermission;
|
||||
import com.diboot.iam.config.Cons;
|
||||
import com.diboot.iam.util.AnnotationUtils;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.diboot.iam.auth;
|
||||
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
import com.diboot.iam.entity.IamRole;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -33,7 +34,7 @@ public interface IamExtensible {
|
|||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Object getUserExtentionObj(String userType, Long userId);
|
||||
KeyValue getUserExtentionObj(String userType, Long userId);
|
||||
|
||||
/**
|
||||
* 获取可扩展的角色
|
||||
|
|
|
@ -22,12 +22,12 @@ import com.diboot.core.vo.Status;
|
|||
import com.diboot.iam.auth.AuthService;
|
||||
import com.diboot.iam.config.Cons;
|
||||
import com.diboot.iam.dto.AuthCredential;
|
||||
import com.diboot.iam.entity.BaseLoginUser;
|
||||
import com.diboot.iam.entity.IamAccount;
|
||||
import com.diboot.iam.entity.IamLoginTrace;
|
||||
import com.diboot.iam.jwt.BaseJwtAuthToken;
|
||||
import com.diboot.iam.service.IamAccountService;
|
||||
import com.diboot.iam.service.IamLoginTraceService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
@ -144,10 +144,9 @@ public class PwdAuthServiceImpl implements AuthService {
|
|||
protected void saveLoginTrace(BaseJwtAuthToken authToken, boolean isSuccess){
|
||||
IamLoginTrace loginTrace = new IamLoginTrace();
|
||||
loginTrace.setAuthType(getAuthType()).setAuthAccount(authToken.getAuthAccount()).setUserType(authToken.getUserType()).setSuccess(isSuccess);
|
||||
Object currentUser = IamSecurityUtils.getCurrentUser();
|
||||
BaseLoginUser currentUser = IamSecurityUtils.getCurrentUser();
|
||||
if(currentUser != null){
|
||||
Long userId = (Long) BeanUtils.getProperty(currentUser, Cons.FieldName.id.name());
|
||||
loginTrace.setUserId(userId);
|
||||
loginTrace.setUserId(currentUser.getId());
|
||||
}
|
||||
// 记录客户端信息
|
||||
String userAgent = request.getHeader("user-agent");
|
||||
|
|
|
@ -25,12 +25,12 @@ import com.diboot.iam.auth.AuthService;
|
|||
import com.diboot.iam.config.Cons;
|
||||
import com.diboot.iam.dto.AuthCredential;
|
||||
import com.diboot.iam.dto.SSOCredential;
|
||||
import com.diboot.iam.entity.BaseLoginUser;
|
||||
import com.diboot.iam.entity.IamAccount;
|
||||
import com.diboot.iam.entity.IamLoginTrace;
|
||||
import com.diboot.iam.jwt.BaseJwtAuthToken;
|
||||
import com.diboot.iam.service.IamAccountService;
|
||||
import com.diboot.iam.service.IamLoginTraceService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.HttpHelper;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -149,9 +149,9 @@ public class SSOAuthServiceImpl implements AuthService {
|
|||
protected void saveLoginTrace(BaseJwtAuthToken authToken, boolean isSuccess){
|
||||
IamLoginTrace loginTrace = new IamLoginTrace();
|
||||
loginTrace.setAuthType(getAuthType()).setAuthAccount(authToken.getAuthAccount()).setUserType(authToken.getUserType()).setSuccess(isSuccess);
|
||||
Object currentUser = IamSecurityUtils.getCurrentUser();
|
||||
BaseLoginUser currentUser = IamSecurityUtils.getCurrentUser();
|
||||
if(currentUser != null){
|
||||
Long userId = (Long) BeanUtils.getProperty(currentUser, Cons.FieldName.id.name());
|
||||
Long userId = currentUser.getId();
|
||||
loginTrace.setUserId(userId);
|
||||
}
|
||||
// 记录客户端信息
|
||||
|
|
|
@ -39,6 +39,10 @@ public abstract class AuthCredential implements Serializable {
|
|||
* 用户类型的Class
|
||||
*/
|
||||
private Class userTypeClass = IamUser.class;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
@NotNull(message = "认证方式不能为空")
|
||||
private String authType;
|
||||
|
@ -62,6 +66,21 @@ public abstract class AuthCredential implements Serializable {
|
|||
* @return
|
||||
*/
|
||||
public String getUserType(){
|
||||
if(userType != null){
|
||||
return userType;
|
||||
}
|
||||
return userTypeClass.getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定用户类型class
|
||||
* @param userTypeClass
|
||||
*/
|
||||
public void setUserTypeClass(Class userTypeClass){
|
||||
this.userTypeClass = userTypeClass;
|
||||
if(this.userType == null){
|
||||
this.userType = userTypeClass.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.diboot.iam.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.diboot.core.entity.BaseEntity;
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
|
||||
/**
|
||||
* 可登录用户Base类定义
|
||||
* @author mazc@dibo.ltd
|
||||
* @version v2.1.0
|
||||
* @date 2020/06/28
|
||||
*/
|
||||
public abstract class BaseLoginUser extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 获取显示名称
|
||||
* @return
|
||||
*/
|
||||
public abstract String getDisplayName();
|
||||
|
||||
/**
|
||||
* 附加对象,用于岗位等扩展
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private KeyValue extentionObj;
|
||||
|
||||
public KeyValue getExtentionObj(){
|
||||
return this.extentionObj;
|
||||
}
|
||||
public void setExtentionObj(KeyValue extentionObj){
|
||||
this.extentionObj = extentionObj;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
package com.diboot.iam.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.diboot.core.entity.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
@ -31,7 +30,7 @@ import javax.validation.constraints.NotNull;
|
|||
* @date 2019-12-17
|
||||
*/
|
||||
@Getter @Setter @Accessors(chain = true)
|
||||
public class IamUser extends BaseEntity {
|
||||
public class IamUser extends BaseLoginUser {
|
||||
private static final long serialVersionUID = -8462352695775599715L;
|
||||
|
||||
// 组织ID
|
||||
|
@ -76,8 +75,9 @@ public class IamUser extends BaseEntity {
|
|||
@TableField()
|
||||
private String avatarUrl;
|
||||
|
||||
// 附加对象,用于岗位等身份切换
|
||||
@TableField(exist = false)
|
||||
private Object extentionObj;
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return this.realname;
|
||||
}
|
||||
|
||||
}
|
|
@ -18,15 +18,16 @@ package com.diboot.iam.jwt;
|
|||
import com.diboot.core.service.BaseService;
|
||||
import com.diboot.core.util.ContextHelper;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
import com.diboot.iam.annotation.process.ApiPermissionCache;
|
||||
import com.diboot.iam.auth.AuthService;
|
||||
import com.diboot.iam.auth.AuthServiceFactory;
|
||||
import com.diboot.iam.config.Cons;
|
||||
import com.diboot.iam.entity.BaseLoginUser;
|
||||
import com.diboot.iam.entity.IamAccount;
|
||||
import com.diboot.iam.entity.IamRole;
|
||||
import com.diboot.iam.service.IamRolePermissionService;
|
||||
import com.diboot.iam.service.IamUserRoleService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
|
@ -94,31 +95,26 @@ public class BaseJwtRealm extends AuthorizingRealm {
|
|||
throw new AuthenticationException("用户账号或密码错误!");
|
||||
}
|
||||
// 获取当前user对象并缓存
|
||||
Object userObject = null;
|
||||
BaseLoginUser loginUser = null;
|
||||
BaseService userService = ContextHelper.getBaseServiceByEntity(jwtToken.getUserTypeClass());
|
||||
if(userService != null){
|
||||
userObject = userService.getEntity(account.getUserId());
|
||||
loginUser = (BaseLoginUser)userService.getEntity(account.getUserId());
|
||||
}
|
||||
else{
|
||||
throw new AuthenticationException("用户 "+jwtToken.getUserTypeClass().getName()+" 相关的Service未定义!");
|
||||
}
|
||||
if(userObject == null){
|
||||
if(loginUser == null){
|
||||
throw new AuthenticationException("用户不存在");
|
||||
}
|
||||
if(iamUserRoleService.getIamExtensible() != null){
|
||||
Object extentionObj = iamUserRoleService.getIamExtensible().getUserExtentionObj(jwtToken.getUserTypeClass().getSimpleName(), account.getUserId());
|
||||
KeyValue extentionObj = iamUserRoleService.getIamExtensible().getUserExtentionObj(jwtToken.getUserTypeClass().getSimpleName(), account.getUserId());
|
||||
if(extentionObj != null){
|
||||
try{
|
||||
BeanUtils.setProperty(userObject, "extentionObj", extentionObj);
|
||||
}
|
||||
catch (Exception e){
|
||||
log.warn("设置{}.extentionObj异常,属性不存在? {}", jwtToken.getUserTypeClass().getSimpleName(), e.getMessage());
|
||||
}
|
||||
loginUser.setExtentionObj(extentionObj);
|
||||
}
|
||||
}
|
||||
// 清空当前用户缓存
|
||||
this.clearCachedAuthorizationInfo(IamSecurityUtils.getSubject().getPrincipals());
|
||||
return new SimpleAuthenticationInfo(userObject, jwtToken.getCredentials(), this.getName());
|
||||
return new SimpleAuthenticationInfo(loginUser, jwtToken.getCredentials(), this.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,21 +126,15 @@ public class BaseJwtRealm extends AuthorizingRealm {
|
|||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||
Object currentUser = principals.getPrimaryPrincipal();
|
||||
BaseLoginUser currentUser = (BaseLoginUser) principals.getPrimaryPrincipal();
|
||||
// 根据用户类型与用户id获取roleList
|
||||
Long userId = (Long) BeanUtils.getProperty(currentUser, Cons.FieldName.id.name());
|
||||
Long extentionObjId = null;
|
||||
try{
|
||||
Object extentionObj = BeanUtils.getProperty(currentUser, "extentionObj");
|
||||
if(extentionObj != null){
|
||||
extentionObjId = (Long)BeanUtils.getProperty(extentionObj, Cons.FieldName.id.name());
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
log.warn("解析user.extentionObj异常: {}", e.getMessage());
|
||||
KeyValue extentionObj = currentUser.getExtentionObj();
|
||||
if(extentionObj != null){
|
||||
extentionObjId = (Long)extentionObj.getV();
|
||||
}
|
||||
// 获取角色列表
|
||||
List<IamRole> roleList = iamUserRoleService.getUserRoleList(currentUser.getClass().getSimpleName(), userId, extentionObjId);
|
||||
List<IamRole> roleList = iamUserRoleService.getUserRoleList(currentUser.getClass().getSimpleName(), currentUser.getId(), extentionObjId);
|
||||
// 如果没有任何角色,返回
|
||||
if (V.isEmpty(roleList)){
|
||||
return authorizationInfo;
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package com.diboot.iam.service;
|
||||
|
||||
import com.diboot.core.entity.BaseEntity;
|
||||
import com.diboot.iam.auth.IamExtensible;
|
||||
import com.diboot.iam.entity.IamRole;
|
||||
import com.diboot.iam.entity.IamUserRole;
|
||||
import com.diboot.iam.vo.IamRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -64,6 +66,13 @@ public interface IamUserRoleService extends BaseIamService<IamUserRole> {
|
|||
*/
|
||||
boolean updateUserRoleRelations(String userType, Long userId, List<Long> roleIds);
|
||||
|
||||
/***
|
||||
* 获取用户的所有角色列表(包括扩展的关联角色)
|
||||
* @param userObject
|
||||
* @return
|
||||
*/
|
||||
List<IamRoleVO> getAllRoleVOList(BaseEntity userObject);
|
||||
|
||||
/**
|
||||
* 获取Iam扩展实现
|
||||
* @return
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.diboot.iam.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.diboot.core.exception.BusinessException;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.Status;
|
||||
|
@ -26,7 +27,6 @@ import com.diboot.iam.dto.IamFrontendPermissionDTO;
|
|||
import com.diboot.iam.entity.IamFrontendPermission;
|
||||
import com.diboot.iam.mapper.IamFrontendPermissionMapper;
|
||||
import com.diboot.iam.service.IamFrontendPermissionService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.vo.IamFrontendPermissionListVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package com.diboot.iam.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.iam.entity.IamFrontendPermission;
|
||||
import com.diboot.iam.entity.IamRolePermission;
|
||||
|
@ -23,7 +24,6 @@ import com.diboot.iam.mapper.IamRolePermissionMapper;
|
|||
import com.diboot.iam.service.IamFrontendPermissionService;
|
||||
import com.diboot.iam.service.IamRolePermissionService;
|
||||
import com.diboot.iam.service.IamRoleService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import com.diboot.iam.vo.IamFrontendPermissionVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
|
@ -17,6 +17,9 @@ package com.diboot.iam.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.diboot.core.binding.Binder;
|
||||
import com.diboot.core.entity.BaseEntity;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.ContextHelper;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.iam.auth.IamExtensible;
|
||||
|
@ -28,8 +31,8 @@ import com.diboot.iam.mapper.IamUserRoleMapper;
|
|||
import com.diboot.iam.service.IamAccountService;
|
||||
import com.diboot.iam.service.IamRoleService;
|
||||
import com.diboot.iam.service.IamUserRoleService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import com.diboot.iam.vo.IamRoleVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -207,6 +210,14 @@ public class IamUserRoleServiceImpl extends BaseIamServiceImpl<IamUserRoleMapper
|
|||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IamRoleVO> getAllRoleVOList(BaseEntity userObject) {
|
||||
List<IamRole> roleList = getUserRoleList(userObject.getClass().getSimpleName(), userObject.getId());
|
||||
if (V.isEmpty(roleList)){
|
||||
return null;
|
||||
}
|
||||
return Binder.convertAndBindRelations(roleList, IamRoleVO.class);
|
||||
}
|
||||
|
||||
// 扩展接口检查标记
|
||||
private boolean iamExtensibleImplChecked = false;
|
||||
|
|
|
@ -16,20 +16,21 @@
|
|||
package com.diboot.iam.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.diboot.core.binding.Binder;
|
||||
import com.diboot.core.exception.BusinessException;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.Status;
|
||||
import com.diboot.iam.config.Cons;
|
||||
import com.diboot.iam.dto.IamUserAccountDTO;
|
||||
import com.diboot.iam.entity.*;
|
||||
import com.diboot.iam.entity.IamAccount;
|
||||
import com.diboot.iam.entity.IamFrontendPermission;
|
||||
import com.diboot.iam.entity.IamUser;
|
||||
import com.diboot.iam.entity.IamUserRole;
|
||||
import com.diboot.iam.mapper.IamUserMapper;
|
||||
import com.diboot.iam.service.IamAccountService;
|
||||
import com.diboot.iam.service.IamFrontendPermissionService;
|
||||
import com.diboot.iam.service.IamUserRoleService;
|
||||
import com.diboot.iam.service.IamUserService;
|
||||
import com.diboot.iam.util.BeanUtils;
|
||||
import com.diboot.iam.util.IamHelper;
|
||||
import com.diboot.iam.util.IamSecurityUtils;
|
||||
import com.diboot.iam.vo.IamRoleVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -37,7 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -67,34 +67,13 @@ public class IamUserServiceImpl extends BaseIamServiceImpl<IamUserMapper, IamUse
|
|||
}
|
||||
// 附加额外的一些权限给与特性的角色
|
||||
attachExtraPermissions(roleVOList);
|
||||
// 对RoleList做聚合处理,以适配前端
|
||||
List<String> nameList = new ArrayList<>();
|
||||
List<String> codeList = new ArrayList<>();
|
||||
List<IamFrontendPermission> allPermissionList = new ArrayList<>();
|
||||
roleVOList.forEach(vo -> {
|
||||
nameList.add(vo.getName());
|
||||
codeList.add(vo.getCode());
|
||||
if (V.notEmpty(vo.getPermissionList())){
|
||||
allPermissionList.addAll(vo.getPermissionList());
|
||||
}
|
||||
});
|
||||
// 对permissionList进行去重
|
||||
List permissionList = BeanUtils.distinctByKey(allPermissionList, IamFrontendPermission::getId);
|
||||
IamRoleVO roleVO = new IamRoleVO();
|
||||
roleVO.setName(S.join(nameList));
|
||||
roleVO.setCode(S.join(codeList));
|
||||
roleVO.setPermissionList(permissionList);
|
||||
|
||||
return roleVO;
|
||||
// 组合为前端格式
|
||||
return IamHelper.buildRoleVo4FrontEnd(roleVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IamRoleVO> getAllRoleVOList(IamUser iamUser) {
|
||||
List<IamRole> roleList = iamUserRoleService.getUserRoleList(IamUser.class.getSimpleName(), iamUser.getId());
|
||||
if (V.isEmpty(roleList)){
|
||||
return null;
|
||||
}
|
||||
return Binder.convertAndBindRelations(roleList, IamRoleVO.class);
|
||||
return iamUserRoleService.getAllRoleVOList(iamUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* <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 com.diboot.iam.util;
|
||||
|
||||
import com.diboot.core.util.IGetter;
|
||||
import com.diboot.core.util.V;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.PropertyAccessorFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BeanUtils extends com.diboot.core.util.BeanUtils {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BeanUtils.class);
|
||||
|
||||
/**
|
||||
* 从list对象列表中提取指定属性值到新的List
|
||||
* @param objectList 对象list
|
||||
* @param getterFn get方法
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <E,T> List collectToList(List<E> objectList, IGetter<T> getterFn){
|
||||
if(V.isEmpty(objectList)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String getterPropName = convertToFieldName(getterFn);
|
||||
return collectToList(objectList, getterPropName);
|
||||
}
|
||||
|
||||
/***
|
||||
* 从list对象列表中提取指定属性值到新的List
|
||||
* @param objectList
|
||||
* @param getterPropName
|
||||
* @param <E>
|
||||
* @return
|
||||
*/
|
||||
public static <E> List collectToList(List<E> objectList, String getterPropName){
|
||||
List fieldValueList = new ArrayList();
|
||||
try{
|
||||
for(E object : objectList){
|
||||
Object fieldValue = getProperty(object, getterPropName);
|
||||
if(fieldValue != null && !fieldValueList.contains(fieldValue)){
|
||||
fieldValueList.add(fieldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
log.warn("提取属性值异常, getterPropName="+getterPropName, e);
|
||||
}
|
||||
return fieldValueList;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取对象的属性值
|
||||
* @param obj
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
public static Object getProperty(Object obj, String field){
|
||||
try {
|
||||
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(obj);
|
||||
return wrapper.getPropertyValue(field);
|
||||
} catch (Exception e) {
|
||||
log.error("获取对象属性值出错,返回null", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.diboot.iam.util;
|
||||
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.iam.entity.IamFrontendPermission;
|
||||
import com.diboot.iam.vo.IamRoleVO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IAM相关辅助类
|
||||
*
|
||||
* @author mazc@dibo.ltd
|
||||
* @version v1.0
|
||||
* @date 2020/06/28
|
||||
*/
|
||||
public class IamHelper {
|
||||
|
||||
/**
|
||||
* 构建role-permission角色权限数据格式(合并role等),用于前端适配
|
||||
* @param roleVOList
|
||||
* @return
|
||||
*/
|
||||
public static IamRoleVO buildRoleVo4FrontEnd(List<IamRoleVO> roleVOList) {
|
||||
if (V.isEmpty(roleVOList)){
|
||||
return null;
|
||||
}
|
||||
// 对RoleList做聚合处理,以适配前端
|
||||
List<String> nameList = new ArrayList<>();
|
||||
List<String> codeList = new ArrayList<>();
|
||||
List<IamFrontendPermission> allPermissionList = new ArrayList<>();
|
||||
roleVOList.forEach(vo -> {
|
||||
nameList.add(vo.getName());
|
||||
codeList.add(vo.getCode());
|
||||
if (V.notEmpty(vo.getPermissionList())){
|
||||
allPermissionList.addAll(vo.getPermissionList());
|
||||
}
|
||||
});
|
||||
// 对permissionList进行去重
|
||||
List permissionList = BeanUtils.distinctByKey(allPermissionList, IamFrontendPermission::getId);
|
||||
IamRoleVO roleVO = new IamRoleVO();
|
||||
roleVO.setName(S.join(nameList));
|
||||
roleVO.setCode(S.join(codeList));
|
||||
roleVO.setPermissionList(permissionList);
|
||||
|
||||
return roleVO;
|
||||
}
|
||||
|
||||
}
|
8
pom.xml
8
pom.xml
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<version>2.3.1.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<springboot.version>2.3.0.RELEASE</springboot.version>
|
||||
<springboot.version>2.3.1.RELEASE</springboot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -62,7 +62,7 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- SpringBoot 2.3.0 新增依赖 -->
|
||||
<!-- SpringBoot 2.3.x 新增依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
|
@ -81,7 +81,7 @@
|
|||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.70</version>
|
||||
<version>1.2.71</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
|
Loading…
Reference in New Issue