增加配置保护名单管理功能.
This commit is contained in:
57
src/main/java/com/nis/domain/basics/ProtectionListInfo.java
Normal file
57
src/main/java/com/nis/domain/basics/ProtectionListInfo.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.nis.domain.basics;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.nis.domain.configuration.BaseCfg;
|
||||
|
||||
public class ProtectionListInfo extends BaseCfg<ProtectionListInfo> implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3781310894175345207L;
|
||||
private Integer proId;
|
||||
private String keyword;
|
||||
private String targetType;
|
||||
private String description;
|
||||
|
||||
|
||||
public Integer getProId() {
|
||||
return proId;
|
||||
}
|
||||
public void setProId(Integer proId) {
|
||||
this.proId = proId;
|
||||
}
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
public String getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
public void setTargetType(String targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Date getEditTime() {
|
||||
return editTime;
|
||||
}
|
||||
public void setEditTime(Date editTime) {
|
||||
this.editTime = editTime;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -828,5 +828,10 @@ public final class Constants {
|
||||
/**
|
||||
* vpn cgi接口报错信息
|
||||
*/
|
||||
public static final String CGI_ERROR = Configurations.getStringProperty("cgiError","");;
|
||||
public static final String CGI_ERROR = Configurations.getStringProperty("cgiError","");
|
||||
|
||||
/**
|
||||
* 配置保护名单字典key
|
||||
*/
|
||||
public static final String CACHE_PROTECTION_LIST_DICT = "protetionListDict";
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ import com.nis.web.service.SystemService;
|
||||
import com.nis.web.service.UserService;
|
||||
import com.nis.web.service.basics.AsnGroupInfoService;
|
||||
import com.nis.web.service.basics.AsnIpCfgService;
|
||||
import com.nis.web.service.basics.InnerProtectionListService;
|
||||
import com.nis.web.service.basics.IpReuseIpCfgService;
|
||||
import com.nis.web.service.basics.PolicyGroupInfoService;
|
||||
import com.nis.web.service.basics.ServiceDictInfoService;
|
||||
@@ -331,6 +332,8 @@ public class BaseController {
|
||||
protected PxyObjSpoofingIpPoolService pxyObjSpoofingIpPoolService;// 欺骗IP池
|
||||
@Autowired
|
||||
protected AsnGroupInfoService asnGroupInfoService;// asn组
|
||||
@Autowired
|
||||
protected InnerProtectionListService innerProtectionListService;
|
||||
/**
|
||||
* 管理基础路径
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.nis.web.controller.basics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.basics.ProtectionListInfo;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
/**
|
||||
* 内置配置保护名单管理
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/basics/innerProtectionList")
|
||||
public class InnerProtectionListController extends BaseController{
|
||||
|
||||
@RequestMapping(value = {"/list", ""})
|
||||
public String policyGroupList(ProtectionListInfo cfg,HttpServletRequest request, HttpServletResponse response, Model model,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
if(cfg == null)cfg=new ProtectionListInfo();
|
||||
Page<ProtectionListInfo> pageCondition = new Page<ProtectionListInfo>(request, response,"r");
|
||||
Page page = innerProtectionListService.findProtectionInfoList(pageCondition,cfg);
|
||||
|
||||
model.addAttribute("cfg", cfg);
|
||||
model.addAttribute("page", page);
|
||||
return "/basics/protectionInfoList";
|
||||
}
|
||||
|
||||
@RequestMapping(value={"/form"})
|
||||
public String form(Integer groupType,String ids,Model model,String doAction,RedirectAttributes redirectAttributes) {
|
||||
ProtectionListInfo protectionListInfo = new ProtectionListInfo();
|
||||
if(!StringUtil.isEmpty(ids)){
|
||||
protectionListInfo = innerProtectionListService.getById(Integer.parseInt(ids));
|
||||
}
|
||||
model.addAttribute("_cfg", protectionListInfo);
|
||||
return "/basics/protectionInfoForm";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(ProtectionListInfo cfg,Model model,String itType,Integer groupType,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
try {
|
||||
innerProtectionListService.saveOrUpdate(cfg);
|
||||
addMessage(redirectAttributes,"success","save_success");
|
||||
} catch (Exception e) {
|
||||
logger.error("新增失败",e);
|
||||
addMessage(redirectAttributes,"error","save_failed");
|
||||
}
|
||||
return "redirect:" + adminPath + "/basics/innerProtectionList/list";
|
||||
}
|
||||
|
||||
@RequestMapping(value={"delete"})
|
||||
public String delete(RedirectAttributes redirectAttributes,String ids,int isValid) {
|
||||
try {
|
||||
innerProtectionListService.deldete(ids,isValid);
|
||||
addMessage(redirectAttributes,"success","delete_success");
|
||||
} catch (Exception e) {
|
||||
logger.error("删除失败",e);
|
||||
addMessage(redirectAttributes,"error","delete_failed");
|
||||
}
|
||||
return "redirect:" + adminPath + "/basics/innerProtectionList/list";
|
||||
}
|
||||
|
||||
@RequestMapping(value="ajaxGetAllInfo",method=RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Map<String,List<String>> ajaxGetAllInfo(HttpServletRequest request, HttpServletResponse response){
|
||||
return innerProtectionListService.ajaxGetAllInfo();
|
||||
}
|
||||
}
|
||||
21
src/main/java/com/nis/web/dao/basics/InnerProtectionDao.java
Normal file
21
src/main/java/com/nis/web/dao/basics/InnerProtectionDao.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.nis.web.dao.basics;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nis.domain.basics.ProtectionListInfo;
|
||||
import com.nis.web.dao.CrudDao;
|
||||
import com.nis.web.dao.MyBatisDao;
|
||||
|
||||
@MyBatisDao
|
||||
public interface InnerProtectionDao extends CrudDao<ProtectionListInfo> {
|
||||
|
||||
List<ProtectionListInfo> findProtectionInfoList(ProtectionListInfo protectionListInfo);
|
||||
|
||||
ProtectionListInfo getById(@Param("proId")int proId);
|
||||
|
||||
List<ProtectionListInfo> ajaxGetAllInfo();
|
||||
|
||||
|
||||
}
|
||||
128
src/main/java/com/nis/web/dao/basics/InnerProtectionDao.xml
Normal file
128
src/main/java/com/nis/web/dao/basics/InnerProtectionDao.xml
Normal file
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.nis.web.dao.basics.InnerProtectionDao" >
|
||||
|
||||
<resultMap id="ProtectionListInfoMap" type="com.nis.domain.basics.ProtectionListInfo" >
|
||||
<id column="id" property="proId" jdbcType="INTEGER" />
|
||||
<result column="keyword" property="keyword" jdbcType="VARCHAR" />
|
||||
<result column="target_type" property="targetType" jdbcType="VARCHAR" />
|
||||
<result column="description" property="description" jdbcType="VARCHAR" />
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
|
||||
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
|
||||
<result column="creator_id" property="creatorId" jdbcType="INTEGER" />
|
||||
<result column="editor_id" property="editorId" jdbcType="INTEGER" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="ProtectionListInfoColumns">
|
||||
r.id,r.keyword,r.target_type,r.description,r.create_time,r.edit_time,r.creator_id,r.editor_id
|
||||
</sql>
|
||||
|
||||
<!-- 查出所有 有效数据-->
|
||||
<select id="findProtectionInfoList" resultMap="ProtectionListInfoMap">
|
||||
SELECT
|
||||
<include refid="ProtectionListInfoColumns"/>
|
||||
<trim prefix="," prefixOverrides=",">
|
||||
,s.name as creator_name ,e.name as editor_name
|
||||
</trim>
|
||||
FROM inner_protection_list r
|
||||
left join sys_user s on r.creator_id=s.id
|
||||
left join sys_user e on r.editor_id=e.id
|
||||
<trim prefix="WHERE" prefixOverrides="AND |OR ">
|
||||
<if test="page !=null and page.where != null and page.where != ''">
|
||||
AND ${page.where}
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND r.keyword like CONCAT(CONCAT('%',#{keyword,jdbcType=VARCHAR}),'%')
|
||||
</if>
|
||||
<if test="targetType != null">
|
||||
AND r.target_type like CONCAT(CONCAT('%',#{targetType,jdbcType=VARCHAR}),'%')
|
||||
</if>
|
||||
AND r.IS_VALID = 1
|
||||
<if test="creatorName != null and creatorName != ''">
|
||||
AND r.creator_name like CONCAT(CONCAT('%',#{creatorName,jdbcType=VARCHAR}),'%')
|
||||
</if>
|
||||
<if test="editorName != null and editorName != ''">
|
||||
AND r.editor_name like CONCAT(CONCAT('%',#{editorName,jdbcType=VARCHAR}),'%')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<!-- ${sqlMap.dsf} -->
|
||||
</trim>
|
||||
<choose>
|
||||
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
|
||||
ORDER BY ${page.orderBy}
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY r.id DESC
|
||||
</otherwise>
|
||||
</choose>
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getById" resultMap="ProtectionListInfoMap">
|
||||
SELECT
|
||||
<include refid="ProtectionListInfoColumns"/>
|
||||
FROM
|
||||
inner_protection_list r
|
||||
WHERE
|
||||
r.ID = #{proId} AND r.IS_VALID = 1
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.nis.domain.basics.ProtectionListInfo" >
|
||||
INSERT INTO inner_protection_list(
|
||||
KEYWORD,
|
||||
TARGET_TYPE,
|
||||
DESCRIPTION,
|
||||
IS_VALID,
|
||||
CREATOR_ID,
|
||||
CREATE_TIME
|
||||
)VALUES (
|
||||
#{keyword,jdbcType=VARCHAR},
|
||||
#{targetType,jdbcType=VARCHAR},
|
||||
#{description,jdbcType=VARCHAR},
|
||||
#{isValid,jdbcType=INTEGER},
|
||||
#{creatorId,jdbcType=INTEGER},
|
||||
#{createTime,jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.nis.domain.basics.ProtectionListInfo" >
|
||||
update inner_protection_list
|
||||
<set >
|
||||
<trim suffixOverrides=",">
|
||||
<if test="keyword != null and keyword != ''" >
|
||||
keyword = #{keyword,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="targetType != null and targetType != ''" >
|
||||
target_type = #{targetType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="description != null and description != ''" >
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="isValid != null" >
|
||||
is_valid = #{isValid,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="editorId != null" >
|
||||
editor_id = #{editorId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="editTime != null and editTime != ''" >
|
||||
edit_time = #{editTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
</trim>
|
||||
</set>
|
||||
<where>
|
||||
<if test="proId != null" >
|
||||
AND id = #{proId,jdbcType=INTEGER}
|
||||
</if>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<select id="ajaxGetAllInfo" resultType="com.nis.domain.basics.ProtectionListInfo">
|
||||
SELECT
|
||||
<include refid="ProtectionListInfoColumns"/>
|
||||
FROM
|
||||
inner_protection_list r
|
||||
WHERE
|
||||
r.IS_VALID = 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.nis.web.service.basics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.basics.ProtectionListInfo;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.CacheUtils;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.dao.basics.InnerProtectionDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.BaseService;
|
||||
|
||||
@Service
|
||||
public class InnerProtectionListService extends BaseService{
|
||||
|
||||
@Autowired
|
||||
private InnerProtectionDao innerProtectionDao;
|
||||
|
||||
public Page<ProtectionListInfo> findProtectionInfoList(Page<ProtectionListInfo> page, ProtectionListInfo entity) {
|
||||
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
||||
entity.setPage(page);
|
||||
List<ProtectionListInfo> list = innerProtectionDao.findProtectionInfoList(entity);
|
||||
page.setList(list);
|
||||
return page;
|
||||
}
|
||||
|
||||
public ProtectionListInfo getById(int id) {
|
||||
ProtectionListInfo protectionListInfo = innerProtectionDao.getById(id);
|
||||
return protectionListInfo;
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveOrUpdate(ProtectionListInfo cfg) throws MaatConvertException{
|
||||
cfg.setIsValid(1);
|
||||
if(cfg.getProId()==null){//新增
|
||||
Date createTime=new Date();
|
||||
cfg.setCreatorId(UserUtils.getUser().getId());
|
||||
cfg.setCreateTime(createTime);
|
||||
innerProtectionDao.insert(cfg);
|
||||
|
||||
}else{//更新
|
||||
Date editTime=new Date();
|
||||
cfg.setEditorId(UserUtils.getUser().getId());
|
||||
cfg.setEditTime(editTime);
|
||||
innerProtectionDao.update(cfg);
|
||||
|
||||
}
|
||||
this.updateProtetionListDict();
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void deldete(String ids, int isValid){
|
||||
ProtectionListInfo entity=new ProtectionListInfo();
|
||||
Date editTime=new Date();
|
||||
entity.setEditorId(UserUtils.getUser().getId());
|
||||
entity.setEditTime(editTime);
|
||||
entity.setIsValid(isValid);
|
||||
if(!StringUtil.isEmpty(ids)){
|
||||
for (String id : ids.split(",")) {
|
||||
if(!StringUtil.isEmpty(id)){
|
||||
entity.setProId(Integer.parseInt(id));
|
||||
innerProtectionDao.update(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateProtetionListDict();
|
||||
}
|
||||
|
||||
public Map<String,List<String>> ajaxGetAllInfo() {
|
||||
Map<String,List<String>> dictMap = (Map<String,List<String>>)CacheUtils.get(Constants.CACHE_PROTECTION_LIST_DICT);
|
||||
if(StringUtil.isEmpty(dictMap)) {
|
||||
dictMap = this.updateProtetionListDict();
|
||||
}
|
||||
return dictMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典缓存
|
||||
* @return
|
||||
*/
|
||||
private Map<String, List<String>> updateProtetionListDict() {
|
||||
Map<String,List<String>> dictMap = new HashMap<String,List<String>>();
|
||||
List<ProtectionListInfo> list = innerProtectionDao.ajaxGetAllInfo();
|
||||
for (ProtectionListInfo info : list) {
|
||||
List<String> putList = new ArrayList<String>();
|
||||
if(dictMap.containsKey(info.getTargetType())) {
|
||||
putList = dictMap.get(info.getTargetType());
|
||||
}
|
||||
putList.add(info.getKeyword());
|
||||
dictMap.put(info.getTargetType(), putList);
|
||||
}
|
||||
CacheUtils.put(Constants.CACHE_PROTECTION_LIST_DICT, dictMap);
|
||||
return dictMap;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user