use of com.albedo.java.plugins.database.mybatis.datascope.DataScope in project albedo by somowhere.
the class DeptResource method findTreeList.
/**
* 部门树列表信息
*
* @return 分页对象
*/
@GetMapping
@PreAuthorize("@pms.hasPermission('sys_dept_view')")
@LogOperate(value = "部门管理查看")
public Result<IPage<DeptVo>> findTreeList(DeptQueryCriteria deptQueryCriteria) {
DataScope dataScope = SecurityUtil.getDataScope();
if (!dataScope.isAll()) {
ArgumentAssert.notEmpty(dataScope.getDeptIds(), "login user deptIds is empty");
deptQueryCriteria.setDeptIds(dataScope.getDeptIds());
}
return Result.buildOkData(deptService.findTreeList(deptQueryCriteria));
}
use of com.albedo.java.plugins.database.mybatis.datascope.DataScope in project albedo by somowhere.
the class UserDetailsServiceImpl method getUserDetails.
/**
* 构建userdetails
*
* @param userInfo 用户信息
* @return
*/
private UserDetails getUserDetails(UserInfo userInfo) {
ArgumentAssert.notNull(userInfo, () -> new UsernameNotFoundException("用户不存在"));
Set<String> dbAuthsSet = new HashSet<>();
if (ArrayUtil.isNotEmpty(userInfo.getRoles())) {
// 获取角色
Arrays.stream(userInfo.getRoles()).forEach(role -> dbAuthsSet.add(SecurityConstants.ROLE + role));
// 获取资源
dbAuthsSet.addAll(Arrays.asList(userInfo.getPermissions()));
}
List<GrantedAuthority> authorities = AuthUtil.createAuthorityList(dbAuthsSet.toArray(new String[0]));
UserVo userVo = userInfo.getUser();
DataScope dataScope = new DataScope();
if (CollUtil.isNotEmpty(userVo.getRoleDoList())) {
for (RoleDo roleDo : userVo.getRoleDoList()) {
if (DataScopeType.ALL.eq(roleDo.getDataScope())) {
dataScope.setAll(true);
break;
} else if (DataScopeType.THIS_LEVEL_CHILDREN.eq(roleDo.getDataScope())) {
dataScope.getDeptIds().addAll(deptService.findDescendantIdList(userVo.getDeptId()));
} else if (DataScopeType.THIS_LEVEL.eq(roleDo.getDataScope())) {
dataScope.getDeptIds().add(userVo.getDeptId());
} else if (DataScopeType.SELF.eq(roleDo.getDataScope())) {
dataScope.setSelf(true);
dataScope.setUserId(userVo.getId());
} else if (DataScopeType.CUSTOMIZE.eq(roleDo.getDataScope())) {
dataScope.getDeptIds().addAll(roleService.findDeptIdsByRoleId(roleDo.getId()));
}
}
}
// 构造security用户
return new UserDetail(userVo.getId(), userVo.getDeptId(), userVo.getDeptName(), userVo.getUsername(), SecurityConstants.BCRYPT + userVo.getPassword(), userVo.isAvailable(), true, true, true, authorities, dataScope);
}
Aggregations