|
@@ -93,6 +93,7 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
* @param sysUser
|
|
* @param sysUser
|
|
* @param roleId
|
|
* @param roleId
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
@Override
|
|
@Override
|
|
public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
|
|
public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
|
|
List<SysRolePrivilege> sysRolePrivilegeList = cacheService.rolePrivilegeCache(roleId);
|
|
List<SysRolePrivilege> sysRolePrivilegeList = cacheService.rolePrivilegeCache(roleId);
|
|
@@ -103,6 +104,22 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
sysUserRoleService.saveBatch(sysUserRoleList);
|
|
sysUserRoleService.saveBatch(sysUserRoleList);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * 新增用户权限
|
|
|
|
+ *
|
|
|
|
+ * @param sysUser
|
|
|
|
+ * @param roleIds
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void addUserRolePrivilege(SysUser sysUser, Long[] roleIds) {
|
|
|
|
+ List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < roleIds.length; i++) {
|
|
|
|
+ sysUserRoleList.add(new SysUserRole(sysUser.getId(), roleIds[i]));
|
|
|
|
+ }
|
|
|
|
+ sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
* 获取用户角色权限
|
|
* 获取用户角色权限
|
|
*
|
|
*
|
|
@@ -148,12 +165,12 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
|
|
|
List<SysUserRole> sysUserRoleList = cacheService.userRolePrivilegeCache(user.getId());
|
|
List<SysUserRole> sysUserRoleList = cacheService.userRolePrivilegeCache(user.getId());
|
|
if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
|
|
if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
|
|
- Set<Long> roleIds = new HashSet<>();
|
|
+ Set<Long> roleIds = sysUserRoleList.stream().map(s -> s.getRoleId()).collect(Collectors.toSet());
|
|
- Set<Long> privilegeIds = new HashSet<>();
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
- sysUserRoleList.forEach(s -> {
|
|
+ for (Long l : roleIds) {
|
|
- roleIds.add(s.getRoleId());
|
|
+ sysRolePrivilegeList.addAll(cacheService.rolePrivilegeCache(l));
|
|
- privilegeIds.add(s.getPrivilegeId());
|
|
+ }
|
|
- });
|
|
+ Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
sysRoleQueryWrapper.lambda().in(SysRole::getId, roleIds)
|
|
sysRoleQueryWrapper.lambda().in(SysRole::getId, roleIds)
|
|
.eq(SysRole::getEnable, true);
|
|
.eq(SysRole::getEnable, true);
|
|
@@ -161,7 +178,9 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.ADMIN).count() : 0;
|
|
int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.ADMIN).count() : 0;
|
|
QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
- sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
+ Long schoolId = (Long) ServletUtil.getRequestSchoolByNotVaild();
|
|
|
|
+ sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getSchoolId, schoolId)
|
|
|
|
+ .eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()));
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()));
|
|
@@ -169,6 +188,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
BasicSchool tbSchool = Objects.nonNull(user.getSchoolId()) ? cacheService.schoolCache(user.getSchoolId()) : null;
|
|
BasicSchool tbSchool = Objects.nonNull(user.getSchoolId()) ? cacheService.schoolCache(user.getSchoolId()) : null;
|
|
SysOrg org = Objects.nonNull(user.getOrgId()) ? cacheService.orgCache(user.getOrgId()) : null;
|
|
SysOrg org = Objects.nonNull(user.getOrgId()) ? cacheService.orgCache(user.getOrgId()) : null;
|
|
sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
|
|
+ .eq(SysPrivilege::getSchoolId, user.getSchoolId())
|
|
|
|
+ .eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
|
|
@@ -636,19 +657,19 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
String token = SystemConstant.getUuid();
|
|
String token = SystemConstant.getUuid();
|
|
cacheService.userCache(sysUser.getId());
|
|
cacheService.userCache(sysUser.getId());
|
|
|
|
|
|
- Set<RoleTypeEnum> roleType = authBean.getRoleList().stream().map(s -> s.getType()).collect(Collectors.toSet());
|
|
+ Set<String> roleName = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
|
|
- String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleType.toString().hashCode()), platform.name());
|
|
+ String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleName.toString().hashCode()), platform.name());
|
|
|
|
|
|
-
|
|
+ String test = SignatureEntityTest.build(SignatureType.TOKEN, sessionId, token);
|
|
ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
|
|
ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
|
|
- TBSession tbSession = new TBSession(sessionId, String.valueOf(sysUser.getId()), roleType.toString(),
|
|
+ TBSession tbSession = new TBSession(sysUser.getSchoolId(), sessionId, String.valueOf(sysUser.getId()), roleName.toString(),
|
|
platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
|
|
platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
|
|
expireTime.getDate().getTime(), appSource);
|
|
expireTime.getDate().getTime(), appSource);
|
|
tbSessionService.saveOrUpdate(tbSession);
|
|
tbSessionService.saveOrUpdate(tbSession);
|
|
redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
|
|
redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
|
|
|
|
|
|
-
|
|
+ LoginResult loginResult = new LoginResult(sysUser, sessionId, test, roleName, appSource);
|
|
- LoginResult loginResult = new LoginResult(sysUser, sessionId, token, roleType, appSource);
|
|
+
|
|
loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? loginResult.new SchoolNativeBean(authBean.getSchool()) : null);
|
|
loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? loginResult.new SchoolNativeBean(authBean.getSchool()) : null);
|
|
loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|
|
loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|
|
loginResult.setTime(System.currentTimeMillis());
|
|
loginResult.setTime(System.currentTimeMillis());
|