Merge remote-tracking branch 'origin/very_pig' into leng_dev

This commit is contained in:
pig666 committed 2020-05-24 17:28:56 +08:00
commit a504f00b64
5 files changed
+26 -9

No files matched your search

@@ -30,8 +30,8 @@ public interface DataScopeHandle {
/**
* 计算用户数据权限
*
* @param deptList
* @return
* @param deptList 部门ID,如果为空表示没有任何数据权限。
* @return 返回true表示无需进行数据过滤处理,返回false表示需要进行数据过滤
*/
Boolean calcScope(List<Integer> deptList);
}
@@ -78,8 +78,13 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
if (CollUtil.isEmpty(deptIds) && dataScopeHandle.calcScope(deptIds)) {
return invocation.proceed();
}
String join = CollectionUtil.join(deptIds, ",");
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
if(deptIds.isEmpty()){
originalSql = "select * from (" + originalSql + ") temp_data_scope where 1 = 2";
}else{
String join = CollectionUtil.join(deptIds, ",");
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
}
metaObject.setValue("delegate.boundSql.sql", originalSql);
return invocation.proceed();
}
@@ -17,6 +17,7 @@
package com.pig4cloud.pigx.common.data.datascope;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
@@ -56,10 +57,16 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
.filter(authority -> authority.startsWith(SecurityConstants.ROLE))
.map(authority -> authority.split(StrUtil.UNDERLINE)[1])
.collect(Collectors.toList());
// 当前用户的角色为空
if(CollectionUtil.isEmpty(roleIdList)){
return false;
}
SysRole role = dataScopeService.getRoleList(roleIdList).getData().stream()
.min(Comparator.comparingInt(SysRole::getDsType)).get();
.min(Comparator.comparingInt(SysRole::getDsType)).orElse(null);
// 角色有可能已经删除了
if(role == null){
return false;
}
Integer dsType = role.getDsType();
// 查询全部
if (DataScopeTypeEnum.ALL.getType() == dsType) {
@@ -100,7 +100,7 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils
.collectionToCommaDelimitedString((Collection<?>) authorities));
}
throw new IllegalArgumentException("Authorities must be either a String or a Collection");
return AuthorityUtils.NO_AUTHORITIES;
}
private void validateTenantId(Map<String, ?> map) {
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -46,7 +47,7 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
Authentication authentication = (Authentication) event.getSource();
if (CollUtil.isNotEmpty(authentication.getAuthorities()) && successHandler != null) {
if (successHandler != null && isUserAuthentication(authentication)) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)
RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
@@ -56,4 +57,8 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
}
}
private boolean isUserAuthentication(Authentication authentication){
return authentication instanceof User || CollUtil.isNotEmpty(authentication.getAuthorities());
}
}