2017-12-29 16:18:40 +08:00
|
|
|
|
package com.nis.web.service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
2019-04-16 16:46:16 +08:00
|
|
|
|
import java.util.Set;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
2019-05-06 16:28:37 +08:00
|
|
|
|
import javax.ws.rs.client.Invocation.Builder;
|
|
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import org.apache.axiom.om.OMAbstractFactory;
|
|
|
|
|
|
import org.apache.axiom.om.OMElement;
|
|
|
|
|
|
import org.apache.axiom.om.OMFactory;
|
|
|
|
|
|
import org.apache.axiom.om.impl.OMNamespaceImpl;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
import org.apache.shiro.session.Session;
|
2018-12-16 11:04:25 +08:00
|
|
|
|
import org.crazycake.shiro.exception.SerializationException;
|
|
|
|
|
|
import org.crazycake.shiro.serializer.ObjectSerializer;
|
|
|
|
|
|
import org.crazycake.shiro.serializer.RedisSerializer;
|
|
|
|
|
|
import org.crazycake.shiro.serializer.StringSerializer;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.nis.domain.SrcIp;
|
|
|
|
|
|
import com.nis.domain.SysRole;
|
|
|
|
|
|
import com.nis.domain.SysUser;
|
|
|
|
|
|
import com.nis.util.Configurations;
|
2019-05-06 16:28:37 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.util.DateUtils;
|
|
|
|
|
|
import com.nis.util.IpUtil;
|
2019-04-16 16:46:16 +08:00
|
|
|
|
import com.nis.util.ServiceConfigTemplateUtil;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.util.TimeConstants;
|
2019-05-06 16:28:37 +08:00
|
|
|
|
import com.nis.util.httpclient.ClientUtil;
|
2019-05-07 10:41:17 +08:00
|
|
|
|
import com.nis.web.dao.SchedulerDao;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.web.dao.SrcIpDao;
|
|
|
|
|
|
import com.nis.web.dao.SysOfficeDao;
|
|
|
|
|
|
import com.nis.web.dao.UserDao;
|
2019-04-16 17:12:49 +08:00
|
|
|
|
import com.nis.web.dao.configuration.CommonPolicyDao;
|
2018-12-16 11:04:25 +08:00
|
|
|
|
import com.nis.web.security.CacheSessionDAO;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
import com.nis.web.security.Servlets;
|
|
|
|
|
|
import com.nis.web.security.UserUtils;
|
2019-04-16 16:46:16 +08:00
|
|
|
|
import com.nis.web.service.basics.AsnGroupInfoService;
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class SystemService extends BaseService{
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2018-12-16 11:04:25 +08:00
|
|
|
|
private CacheSessionDAO sessionDao;
|
|
|
|
|
|
/*private SessionDAO sessionDao;*/
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private UserDao userDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private SysOfficeDao sysOfficeDao;
|
|
|
|
|
|
|
2019-04-16 16:46:16 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private AsnGroupInfoService asnGroupInfoService;
|
|
|
|
|
|
|
2019-04-16 17:12:49 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private CommonPolicyDao commonPolicyDao;
|
|
|
|
|
|
|
2019-05-07 10:41:17 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private SchedulerDao schedulerDao;
|
|
|
|
|
|
|
2017-12-29 16:18:40 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private SrcIpDao srcIpDao;
|
2018-12-16 11:04:25 +08:00
|
|
|
|
private RedisSerializer keySerializer = new StringSerializer();
|
|
|
|
|
|
private RedisSerializer valueSerializer = new ObjectSerializer();
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
public Collection<Session> getActiveSessions(boolean includeLeave) {
|
|
|
|
|
|
return sessionDao.getActiveSessions(includeLeave);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Collection<Session> getActiveSessions(boolean includeLeave, Object principal, Session filterSession) {
|
|
|
|
|
|
return sessionDao.getActiveSessions(includeLeave, principal, filterSession);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteSession(Session session) {
|
|
|
|
|
|
sessionDao.delete(session);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 11:04:25 +08:00
|
|
|
|
public void deleteAuthenticationCache(String authenticationInfo) {
|
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(authenticationInfo)) {
|
|
|
|
|
|
logger.error("AuthenticationInfo is null");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
sessionDao.getRedisManager().del(keySerializer.serialize(authenticationInfo));
|
|
|
|
|
|
} catch (SerializationException e) {
|
|
|
|
|
|
logger.error("delete AuthenticationInfo error. AuthenticationInfo key=" + authenticationInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-29 16:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
public SysUser getUserByLoginName(String loginName) {
|
|
|
|
|
|
return UserUtils.getByLoginName(loginName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<SrcIp> ipLookUp(String ip) {
|
|
|
|
|
|
return srcIpDao.getIpInfo(IpUtil.getIpHostDesimal(ip));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SysUser assignUserToRole(SysRole role, SysUser user) {
|
|
|
|
|
|
if (user == null){
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
List<Long> roleIds = user.getRoleIdList();
|
|
|
|
|
|
if (roleIds.contains(role.getId())) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
user.getUserRoleList().clear();
|
|
|
|
|
|
user.getUserRoleList().add(role);
|
|
|
|
|
|
userDao.insertUserRole(user);
|
|
|
|
|
|
UserUtils.clearCache(user);
|
|
|
|
|
|
return user;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Boolean outUserInRole(SysRole role, SysUser user) {
|
|
|
|
|
|
List<SysRole> roles = user.getUserRoleList();
|
|
|
|
|
|
for (SysRole e : roles){
|
|
|
|
|
|
if (e.getId().equals(role.getId())){
|
|
|
|
|
|
roles.remove(e);
|
|
|
|
|
|
userDao.removeUserInRole(user.getId(),role.getId());
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean officeIsValid(Long officeId, Long companyId) {
|
|
|
|
|
|
return userDao.officeIsExistOfCompany(officeId, companyId) >0 ? true : false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 结果信息存入文件
|
|
|
|
|
|
* @param result
|
|
|
|
|
|
* @throws IOException
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void saveToFile(String prefixName, String result) throws IOException{
|
|
|
|
|
|
String flieName = prefixName + DateUtils.formatDate(new Date(), TimeConstants.YYYYMMDDHH24MMSS);
|
|
|
|
|
|
String filePath = Servlets.getRequest().getServletContext().getRealPath(Configurations.getStringProperty("userfiles.basedir", "")) + File.separator
|
|
|
|
|
|
+ "upload" + File.separator + flieName + ".txt";
|
|
|
|
|
|
FileUtils.writeStringToFile(new File(filePath), result, false);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 新增设置header信息,需要修改里面rid、sid对应的值、sid为服务唯一标识、 rid为请求者唯一标识
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static OMElement setHeader(String ns, String rid, String sid) {
|
|
|
|
|
|
OMFactory fac = OMAbstractFactory.getOMFactory();
|
|
|
|
|
|
// OMNamespace指定此SOAP文档名称空间。
|
|
|
|
|
|
OMNamespaceImpl omNs = (OMNamespaceImpl) fac.createOMNamespace(ns, "ns1");
|
|
|
|
|
|
// 创建header元素,并指定其在omNs指代的名称空间中,header名称固定为CyberpoliceSBReqHeader。
|
|
|
|
|
|
OMElement method = fac.createOMElement("CyberpoliceSBReqHeader", omNs);
|
|
|
|
|
|
|
|
|
|
|
|
// 指定元素的文本内容。
|
|
|
|
|
|
OMElement ridE = fac.createOMElement("rid", omNs);
|
|
|
|
|
|
// TODO将下面的值修改为请求者在系统中的唯一标识
|
|
|
|
|
|
ridE.setText(rid);
|
|
|
|
|
|
method.addChild(ridE);
|
|
|
|
|
|
|
|
|
|
|
|
OMElement sidE = fac.createOMElement("sid", omNs);
|
|
|
|
|
|
// TODO将下面的值修改要请求服务的唯一标识
|
|
|
|
|
|
sidE.setText(sid);
|
|
|
|
|
|
method.addChild(sidE);
|
|
|
|
|
|
|
|
|
|
|
|
OMElement timeoutE = fac.createOMElement("timeout", omNs);
|
|
|
|
|
|
// TODO将下面的值修改为请求的超时时间,单位秒
|
|
|
|
|
|
timeoutE.setText(Configurations.getStringProperty("webservice.request.timeout", "60"));
|
|
|
|
|
|
method.addChild(timeoutE);
|
|
|
|
|
|
|
|
|
|
|
|
OMElement secE = fac.createOMElement("sec", omNs);
|
|
|
|
|
|
// TODO将下面的值修改为请求密码,如果使用其他加密方式,则根据要求统一修改即可
|
|
|
|
|
|
secE.setText("");
|
|
|
|
|
|
method.addChild(secE);
|
|
|
|
|
|
return method;
|
|
|
|
|
|
}
|
2019-04-16 16:46:16 +08:00
|
|
|
|
|
|
|
|
|
|
public void clearPolicies() throws Exception {
|
2019-05-06 16:28:37 +08:00
|
|
|
|
// 调用服务接口 告知flushAll
|
|
|
|
|
|
String url = Constants.SERVICE_URL + Constants.DEL_ALL_CFG;
|
|
|
|
|
|
// 创建连接
|
|
|
|
|
|
WebTarget wt = ClientUtil.getWebTarger(url);
|
|
|
|
|
|
// 获取响应结果
|
|
|
|
|
|
Builder header = wt.request(MediaType.APPLICATION_JSON).header("Content-Type", MediaType.APPLICATION_JSON);
|
|
|
|
|
|
Response response = header.delete();
|
|
|
|
|
|
if(response.getStatus() == 200){
|
|
|
|
|
|
//String result= response.readEntity(String.class);
|
|
|
|
|
|
Set<String> tableNameSet = ServiceConfigTemplateUtil.getAllTableName();
|
|
|
|
|
|
tableNameSet.add("pxy_obj_spoofing_ip_pool");
|
|
|
|
|
|
for (String tableName : tableNameSet) {
|
|
|
|
|
|
commonPolicyDao.clearPolicies(tableName);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 初始化分组
|
|
|
|
|
|
asnGroupInfoService.reLoadGroupInfo();
|
2019-05-07 10:41:17 +08:00
|
|
|
|
// 失效定时任务
|
|
|
|
|
|
schedulerDao.inValidAllSchedule();
|
2019-05-06 16:28:37 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
throw new RuntimeException();
|
2019-04-16 16:46:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-12-29 16:18:40 +08:00
|
|
|
|
}
|