解决当数据库中菜单权限表有记录的api_set为空时,会导致非管理员账号没有其他所有已授权接口权限的问题。

This commit is contained in:
Zhaoyang 2020-03-24 21:31:38 +08:00
parent 1a088fd157
commit 2c314af03a
9 changed files with 80 additions and 9 deletions

View File

@ -1,12 +1,12 @@
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;

View File

@ -2,7 +2,6 @@ package com.diboot.iam.auth.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.diboot.core.exception.BusinessException;
import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.Encryptor;
import com.diboot.core.vo.Status;
import com.diboot.iam.auth.AuthService;
@ -13,6 +12,7 @@ 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;

View File

@ -1,7 +1,6 @@
package com.diboot.iam.jwt;
import com.diboot.core.service.BaseService;
import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.V;
import com.diboot.iam.annotation.process.ApiPermissionCache;
@ -12,6 +11,7 @@ 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;
@ -106,7 +106,7 @@ public class BaseJwtRealm extends AuthorizingRealm {
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
Object currentUser = principals.getPrimaryPrincipal();
// 根据用户类型与用户id获取roleList
Long userId = (Long)BeanUtils.getProperty(currentUser, Cons.FieldName.id.name());
Long userId = (Long) BeanUtils.getProperty(currentUser, Cons.FieldName.id.name());
List<IamRole> roleList = iamUserRoleService.getUserRoleList(currentUser.getClass().getSimpleName(), userId);
// 如果没有任何角色返回
if (V.isEmpty(roleList)){

View File

@ -3,7 +3,6 @@ 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;
@ -12,6 +11,7 @@ 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;

View File

@ -1,7 +1,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.IGetter;
import com.diboot.core.util.V;
import com.diboot.iam.entity.IamFrontendPermission;
import com.diboot.iam.entity.IamRolePermission;
@ -9,6 +9,7 @@ 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;

View File

@ -2,7 +2,6 @@ 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.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.V;
import com.diboot.iam.auth.IamExtensible;
@ -14,6 +13,7 @@ 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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -3,7 +3,6 @@ package com.diboot.iam.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.binding.RelationsBinder;
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;
@ -15,6 +14,7 @@ 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.IamSecurityUtils;
import com.diboot.iam.vo.IamRoleVO;
import lombok.extern.slf4j.Slf4j;

View File

@ -0,0 +1,71 @@
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;
}
}

View File

@ -91,5 +91,4 @@
</dependency>
</dependencies>
</project>