新增角色组绑定功能,新增后台拦截,新增cas框架配置文件

This commit is contained in:
lhc
2021-04-13 11:24:04 +08:00
parent 630e712bf3
commit 6015c64500
7 changed files with 80 additions and 17 deletions

View File

@@ -20,18 +20,7 @@
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>1.4.0-GA</version>
<exclusions>
<exclusion>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>${java.cas.client.version}</version>
<version>2.2.0-GA</version>
</dependency>
<dependency>
<groupId>com.hcframe</groupId>

View File

@@ -72,8 +72,9 @@ public class ShiroRealmConfig implements SystemRealm {
map.put("/swagger/**",ShiroType.ANON);
// druid 资源路径
map.put("/druid/**",ShiroType.ANON);
map.put("/cas/valid",ShiroType.ANON);
// 其余路径均拦截
map.put("/**", ShiroType.ANON);
map.put("/**", ShiroType.AUTH);
return map;
}

View File

@@ -5,6 +5,8 @@ import com.hcframe.base.common.ResultVO;
import com.hcframe.base.common.WebPageInfo;
import com.hcframe.user.module.auth.service.RoleGroupServie;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@@ -52,4 +54,23 @@ public class RoleGroupController {
return roleGroupServie.getList(data, webPageInfo);
}
@PostMapping("bind")
@ApiOperation(value = "绑定角色组")
@ApiImplicitParams({
@ApiImplicitParam(name = "roleGroupId", value = "角色组ID",required = true),
@ApiImplicitParam(name = "roleIds", value = "角色ID数组",required = true)
})
public ResultVO<Object> bind(Integer roleGroupId, String roleIds) {
return roleGroupServie.bind(roleGroupId, roleIds);
}
@GetMapping("getRoles")
@ApiOperation(value = "绑定角色组")
@ApiImplicitParams({
@ApiImplicitParam(name = "roleGroupId", value = "角色组ID",required = true),
})
public ResultVO<Object> getRoles(Integer roleGroupId) {
return roleGroupServie.getRoles(roleGroupId);
}
}

View File

@@ -23,4 +23,8 @@ public interface RoleGroupServie {
ResultVO<Integer> delete(String ids);
ResultVO<PageInfo<Map<String, Object>>> getList(String data, WebPageInfo webPageInfo);
ResultVO<Object> bind(Integer roleGroupId, String roleIds);
ResultVO<Object> getRoles(Integer roleGroupId);
}

View File

@@ -3,14 +3,20 @@ package com.hcframe.user.module.auth.service.impl;
import com.github.pagehelper.PageInfo;
import com.hcframe.base.common.ResultVO;
import com.hcframe.base.common.WebPageInfo;
import com.hcframe.base.common.utils.JudgeException;
import com.hcframe.base.module.data.module.BaseMapper;
import com.hcframe.base.module.data.module.BaseMapperImpl;
import com.hcframe.base.module.data.module.Condition;
import com.hcframe.base.module.data.module.DataMap;
import com.hcframe.base.module.data.service.TableService;
import com.hcframe.base.module.tableconfig.entity.OsSysTable;
import com.hcframe.user.module.auth.service.RoleGroupServie;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -25,6 +31,11 @@ public class RoleGroupServiceImpl implements RoleGroupServie {
private static final String PK_ID = "GROUP_ID";
private static final String TABLE_NAME = "OS_SYS_ROLE_GROUP";
private static final String OS_SYS_ROLE = "OS_SYS_ROLE";
private static final String ROLE_ID = "ROLE_ID";
private static final String OS_REL_GROUP_ROLE = "OS_REL_GROUP_ROLE";
private static final String ROLE_GROUP_ID = "ROLE_GROUP_ID";
private static final String COMMA = ",";
private static final OsSysTable TABLE_INFO = OsSysTable.builder().tableName(TABLE_NAME).tablePk(PK_ID).build();
final BaseMapper baseMapper;
@@ -49,13 +60,47 @@ public class RoleGroupServiceImpl implements RoleGroupServie {
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultVO<Integer> delete(String ids) {
// TODO 补全删除的关联信息
return tableService.delete(TABLE_INFO, ids);
tableService.delete(TABLE_INFO, ids);
baseMapper.deleteInPk(DataMap
.builder()
.tableName(OS_SYS_ROLE)
.pkName(ROLE_ID)
.ids(ids)
.build());
return ResultVO.getSuccess();
}
@Override
public ResultVO<PageInfo<Map<String, Object>>> getList(String data, WebPageInfo webPageInfo) {
return ResultVO.getSuccess(tableService.searchSingleTables(data, TABLE_INFO, webPageInfo));
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultVO<Object> bind(Integer roleGroupId, String roleIds) {
baseMapper.deleteByCondition(OS_REL_GROUP_ROLE, Condition.creatCriteria().andEqual(PK_ID,roleGroupId).build());
for (String str : roleIds.split(COMMA)) {
Integer roleId = Integer.parseInt(str);
DataMap<Object> dataMap = DataMap
.builder()
.pkName(ROLE_GROUP_ID)
.tableName(OS_REL_GROUP_ROLE)
.add(ROLE_ID,roleId)
.add(PK_ID,roleGroupId)
.build();
baseMapper.save(dataMap);
}
return ResultVO.getSuccess();
}
@Override
public ResultVO<Object> getRoles(Integer roleGroupId) {
JudgeException.isNull(roleGroupId,"roleGroupId 不能为空!");
Map<String, Object> map = new HashMap<>(1);
map.put(ROLE_GROUP_ID, roleGroupId);
List<Map<String, Object>> list = baseMapper.selectByEqual(OS_REL_GROUP_ROLE,map);
return ResultVO.getSuccess(list);
}
}

View File

@@ -3,6 +3,7 @@ package com.hcframe.user.module.manage.controller;
import com.hcframe.base.common.ResultVO;
import com.hcframe.redis.RedisUtil;
import net.unicon.cas.client.configuration.CasClientConfigurationProperties;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
@@ -55,7 +56,8 @@ public class CasController {
@GetMapping("userinfo")
@ResponseBody
public ResultVO<Object> getUserInfo(String token) {
return ResultVO.getSuccess(redisUtil.hget("session", token));
// return ResultVO.getSuccess(redisUtil.hget("session", token));
return ResultVO.getSuccess(SecurityUtils.getSubject().getPrincipal());
}
@GetMapping("/logout")

View File

@@ -52,7 +52,7 @@ spring:
druid:
# 配置sqlite文件路径需要填写绝对路径推荐将sqlite文件放入到服务器上而非程序jar包或war包中
driver-class-name: dm.jdbc.driver.DmDriver
url: jdbc:dm://192.168.100.98:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
url: jdbc:dm://192.168.1.131:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
username: GBCAS
password: 123456789
#使用Druid数据源
@@ -93,6 +93,7 @@ hcframe:
# 是否开启controller日志监控
showControllerLog: true
multi-data-source: false
cas: true
# swagger配置
swagger:
# 配置controller包路径