vpn 用户管理修改新增修改和删除逻辑

ip地址池增加存在可用ip地址池才在策略展示
This commit is contained in:
DuanDongmei
2018-11-30 15:48:11 +08:00
parent 64efd2b9d6
commit a2266e45d6
15 changed files with 378 additions and 208 deletions

View File

@@ -24,9 +24,9 @@ import com.nis.domain.configuration.AppPolicyCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.UserManage;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.StringUtil;
import com.nis.util.httpclient.HttpClientUtil;
import com.nis.web.dao.configuration.AppCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.configuration.UserManageDao;
@@ -77,50 +77,55 @@ public class UserManageService extends BaseService{
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveip(UserManage entity,String ips,Model model, HttpServletRequest request){
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try {
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
UserManage user=userManageDao.getUserByLoginName(entity.getUserName());
if(user==null){
entity.setServerIp(ips);
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).insert(entity);
}else{
user.setServerIp(user.getServerIp()+","+ips);
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).update(user);
}
//cgi接口添加
//循环调用接口增加
Map<String, Object> params = new HashMap<String, Object>();
params.put("server_ip", ips);
params.put("user_name", entity.getUserName());
params.put("user_pwd", entity.getUserPwd());
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_CREATE ;
String recv = HttpClientUtil.getCGI(url, params, request);
if (StringUtils.isNotBlank(recv)) {
Map<String, String> map = new HashMap<String, String>();
map = (Map<String, String>) JSON.parse(recv);
String error = map.get("error");
if (!StringUtil.isEmpty(error)) {
batchSqlSession.rollback();
} else {
batchSqlSession.commit();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (batchSqlSession != null) {
batchSqlSession.close();
}
}
public void saveip(UserManage entity,String ip)throws Exception{
userManageDao.insert(entity);
//cgi接口添加
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
params.put("server_ip", ip);
params.put("user_name", entity.getUserName());
params.put("user_pwd", entity.getUserPwd());
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = ConfigServiceUtil.getCGI(url, params);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void updatePwd(UserManage entity,String ip){
userManageDao.update(entity);
//密码修改
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd",Constants.NTC_IP_REUSE_USER_PASSWORD);
params.put("server_ip", ip);
params.put("user_name", entity.getUserName());
params.put("user_pwd", entity.getUserName());
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = ConfigServiceUtil.getCGI(url, params);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void updateip(UserManage entity,String ips,int num,Model model, HttpServletRequest request){
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
public void deleteip(UserManage entity,String ip){
userManageDao.update(entity);
//循环调用接口删除
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd",Constants.NTC_IP_REUSE_USER_DELETE);
params.put("server_ip", ip);
params.put("user_name", entity.getUserName());
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = ConfigServiceUtil.getCGI(url, params);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void updateip(UserManage entity,String ip){
userManageDao.update(entity);
//cgi接口添加
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
params.put("server_ip", ip);
params.put("user_name", entity.getUserName());
params.put("user_pwd", entity.getUserPwd());
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = ConfigServiceUtil.getCGI(url, params);
/*SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try {
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
@@ -132,9 +137,10 @@ public class UserManageService extends BaseService{
for(String ip :ipArray){
//循环调用接口删除
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd",Constants.NTC_IP_REUSE_USER_DELETE);
params.put("server_ip", ip);
params.put("user_name", olduser.getUserName());
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
Map<String,String> map=getUrl(params);
//返回处理
}
entity.setServerIp(ips);
@@ -147,11 +153,12 @@ public class UserManageService extends BaseService{
// cgi接口添加
// 循环调用接口增加
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd", Constants.NTC_IP_REUSE_USER_CREATE);
params.put("server_ip", ips);
params.put("user_name", entity.getUserName());
params.put("user_pwd", entity.getUserPwd());
String url = Constants.IP_REUSE_CALL_CGI_URL + Constants.NTC_IP_REUSE_USER_CREATE;
String recv = HttpClientUtil.getCGI(url, params, request);
String url = Constants.IP_REUSE_CALL_CGI_URL;
String recv = ConfigServiceUtil.getCGI(url, params);
if (StringUtils.isNotBlank(recv)) {
Map<String, String> map = new HashMap<String, String>();
map = (Map<String, String>) JSON.parse(recv);
@@ -162,21 +169,21 @@ public class UserManageService extends BaseService{
batchSqlSession.commit();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (MaatConvertException e) {
throw e;
} finally {
if (batchSqlSession != null) {
batchSqlSession.close();
}
}
}*/
}
public Map<String,String> getUrl(Map<String, Object> params,String urlType,HttpServletRequest request){
public Map<String,String> getUrl(Map<String, Object> params){
Map<String,String> map=new HashMap<String,String>();
try{
String url =Constants.IP_REUSE_CALL_CGI_URL+ urlType ;
String recv = HttpClientUtil.getCGI(url, params, request);
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = com.nis.util.ConfigServiceUtil.getCGI(url, params);
if (StringUtils.isNotBlank(recv)) {
map=(Map<String,String>)JSON.parse(recv);
}
@@ -187,14 +194,15 @@ public class UserManageService extends BaseService{
}
//根据vpn服务器ip获取用户vpn服务器ip信息
public Map<String,String> getUser(String serverIp,String userName,HttpServletRequest request){
public Map<String,String> getUser(String serverIp,String userName){
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd", Constants.NTC_IP_REUSE_USER_GET);
params.put("server_ip", serverIp);
params.put("user_name", userName);
Map<String,String> map=new HashMap<String,String>();
try{
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_GET ;
String recv = HttpClientUtil.getCGI(url, params, request);
String url =Constants.IP_REUSE_CALL_CGI_URL;
String recv = ConfigServiceUtil.getCGI(url, params);
if (StringUtils.isNotBlank(recv)) {
map=(Map<String,String>)JSON.parse(recv);
}
@@ -214,37 +222,22 @@ public class UserManageService extends BaseService{
* @param ids compileIds
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(Integer isValid,String ids,HttpServletRequest request){
try{
String[] idArray = ids.split(",");
List<UserManage> userList=new ArrayList<UserManage>();
for(String id :idArray){
UserManage entity = new UserManage();
entity=userManageDao.getUserById(id);
if(entity!=null){
userList.add(entity);
}
entity.setId(Long.valueOf(id));
entity.setIsValid(isValid);
entity.setEditorId(UserUtils.getUser().getId());
entity.setEditTime(new Date());
userManageDao.update(entity);
public void delete(Integer isValid,UserManage entity,String ip,boolean lastIp){
UserManage user=new UserManage();
user.setId(entity.getId());
if(!lastIp) {
user.setServerIp(user.getServerIp().replace(ip+",", ""));
}else {
user.setIsValid(-1);
}
//cgi接口删除旧数据
for (int i = 0; i < userList.size(); i++) {
String[] ipArray = userList.get(i).getServerIp().split(",");
for(String ip :ipArray){
//循环调用接口删除
Map<String, Object> params = new HashMap<String, Object>();
params.put("server_ip", ip);
params.put("user_name",userList.get(i).getUserName());
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
//返回处理
}
}
} catch (Exception e) {
logger.error("查询失败", e);
}
userManageDao.update(user);
//cgi接口删除用户vpnip
Map<String, Object> params = new HashMap<String, Object>();
params.put("cmd", Constants.NTC_IP_REUSE_USER_DELETE);
params.put("server_ip", ip);
params.put("user_name", entity.getUserName());
String url =Constants.IP_REUSE_CALL_CGI_URL ;
String recv = ConfigServiceUtil.getCGI(url, params);
}
public List<UserManage> findUsers() {