提交 ba70570e 编写于 作者: O o2null

更新令牌过期,通过center进行刷新

上级 4a2e9773
package com.x.organization.assemble.authentication; package com.x.organization.assemble.authentication;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.Context; import com.x.base.core.project.Context;
import com.x.base.core.project.cache.CacheManager; import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.message.MessageConnector; import com.x.base.core.project.message.MessageConnector;
import com.x.organization.assemble.authentication.jaxrs.authentication.QueueLoginRecord; import com.x.organization.assemble.authentication.jaxrs.authentication.QueueLoginRecord;
import com.x.organization.assemble.authentication.schedule.CleanupBind; import com.x.organization.assemble.authentication.schedule.CleanupBind;
...@@ -29,9 +32,12 @@ public class ThisApplication { ...@@ -29,9 +32,12 @@ public class ThisApplication {
context.startQueue(queueLoginRecord); context.startQueue(queueLoginRecord);
context.schedule(CleanupBind.class, "0 */15 * * * ?"); context.schedule(CleanupBind.class, "0 */15 * * * ?");
context.schedule(CleanupOauthCode.class, "0 */15 * * * ?"); context.schedule(CleanupOauthCode.class, "0 */15 * * * ?");
context.schedule(CleanupTokenThreshold.class, "50 50 6,12,18 * * ?");
context.scheduleLocal(UpdateTokenThresholds.class, 300, 15);
MessageConnector.start(context()); MessageConnector.start(context());
// 如果启用了安全注销需要启动定时任务进行刷新
if (BooleanUtils.isTrue(Config.person().getEnableSafeLogout())) {
context.schedule(CleanupTokenThreshold.class, "50 50 6,12,18 * * ?");
context.scheduleLocal(UpdateTokenThresholds.class, 45, 60 * 30);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -2,6 +2,7 @@ package com.x.organization.assemble.authentication.jaxrs.authentication; ...@@ -2,6 +2,7 @@ package com.x.organization.assemble.authentication.jaxrs.authentication;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
...@@ -14,7 +15,9 @@ import javax.servlet.http.HttpServletResponse; ...@@ -14,7 +15,9 @@ import javax.servlet.http.HttpServletResponse;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType; import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.config.CenterServer;
import com.x.base.core.project.config.Config; import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpToken; import com.x.base.core.project.http.HttpToken;
...@@ -33,9 +36,10 @@ class ActionSafeLogout extends BaseAction { ...@@ -33,9 +36,10 @@ class ActionSafeLogout extends BaseAction {
TokenThreshold tokenThreshold = new TokenThreshold(effectivePerson.getDistinguishedName(), new Date()); TokenThreshold tokenThreshold = new TokenThreshold(effectivePerson.getDistinguishedName(), new Date());
Config.resource_node_tokenThresholds().put(tokenThreshold.getPerson(), tokenThreshold.getThreshold()); // Config.resource_node_tokenThresholds().put(tokenThreshold.getPerson(),
// tokenThreshold.getThreshold());
update(tokenThreshold); update(tokenThreshold);
broadcast(tokenThreshold);
ActionResult<Wo> result = new ActionResult<>(); ActionResult<Wo> result = new ActionResult<>();
HttpToken httpToken = new HttpToken(); HttpToken httpToken = new HttpToken();
...@@ -70,6 +74,13 @@ class ActionSafeLogout extends BaseAction { ...@@ -70,6 +74,13 @@ class ActionSafeLogout extends BaseAction {
} }
} }
private void broadcast(TokenThreshold tokenThreshold) throws Exception {
for (Entry<String, CenterServer> entry : Config.nodes().centerServers().orderedEntry()) {
CipherConnectionAction.post(false, 4000, 8000,
Config.url_x_program_center_jaxrs(entry, "tokenthreshold", "update"), tokenThreshold);
}
}
public static class Wo extends AbstractWoAuthentication { public static class Wo extends AbstractWoAuthentication {
private static final long serialVersionUID = 4883354487268278719L; private static final long serialVersionUID = 4883354487268278719L;
......
...@@ -33,6 +33,7 @@ import com.x.program.center.jaxrs.pms.PmsAction; ...@@ -33,6 +33,7 @@ import com.x.program.center.jaxrs.pms.PmsAction;
import com.x.program.center.jaxrs.prompterrorlog.PromptErrorLogAction; import com.x.program.center.jaxrs.prompterrorlog.PromptErrorLogAction;
import com.x.program.center.jaxrs.qiyeweixin.QiyeweixinAction; import com.x.program.center.jaxrs.qiyeweixin.QiyeweixinAction;
import com.x.program.center.jaxrs.schedule.ScheduleAction; import com.x.program.center.jaxrs.schedule.ScheduleAction;
import com.x.program.center.jaxrs.tokenthreshold.TokenThresholdAction;
import com.x.program.center.jaxrs.unexpectederrorlog.UnexpectedErrorLogAction; import com.x.program.center.jaxrs.unexpectederrorlog.UnexpectedErrorLogAction;
import com.x.program.center.jaxrs.validation.ValidationAction; import com.x.program.center.jaxrs.validation.ValidationAction;
import com.x.program.center.jaxrs.warnlog.WarnLogAction; import com.x.program.center.jaxrs.warnlog.WarnLogAction;
...@@ -76,6 +77,7 @@ public class ActionApplication extends AbstractActionApplication { ...@@ -76,6 +77,7 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(DesignerAction.class); classes.add(DesignerAction.class);
classes.add(MPWeixinAction.class); classes.add(MPWeixinAction.class);
classes.add(AppPackAction.class); classes.add(AppPackAction.class);
classes.add(TokenThresholdAction.class);
return classes; return classes;
} }
} }
package com.x.program.center.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/tokenthreshold/*", asyncSupported = true)
public class TokenThresholdDispatchJaxrsFilter extends CipherManagerJaxrsFilter {
}
package com.x.program.center.jaxrs.dingding.encrypt; package com.x.program.center.jaxrs.dingding.encrypt;
import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
/** /**
* Created by fancyLou on 2020-10-26. * Created by fancyLou on 2020-10-26. Copyright © 2020 O2. All rights reserved.
* Copyright © 2020 O2. All rights reserved.
*/ */
public class Utils { public class Utils {
public Utils() {
}
public static String getRandomStr(int count) { private static final Random random = new SecureRandom();
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for(int i = 0; i < count; ++i) { private Utils() {
int number = random.nextInt(base.length()); // nothing
sb.append(base.charAt(number)); }
}
return sb.toString(); public static String getRandomStr(int count) {
} String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
public static byte[] int2Bytes(int count) { StringBuilder sb = new StringBuilder();
byte[] byteArr = new byte[]{(byte)(count >> 24 & 255), (byte)(count >> 16 & 255), (byte)(count >> 8 & 255), (byte)(count & 255)}; for (int i = 0; i < count; ++i) {
return byteArr; sb.append(base.charAt(random.nextInt(base.length())));
} }
public static int bytes2int(byte[] byteArr) { return sb.toString();
int count = 0; }
for(int i = 0; i < 4; ++i) { public static byte[] int2Bytes(int count) {
count <<= 8; return new byte[] { (byte) (count >> 24 & 255), (byte) (count >> 16 & 255), (byte) (count >> 8 & 255),
count |= byteArr[i] & 255; (byte) (count & 255) };
} }
return count; public static int bytes2int(byte[] byteArr) {
} int count = 0;
for (int i = 0; i < 4; ++i) {
count <<= 8;
count |= byteArr[i] & 255;
}
return count;
}
} }
...@@ -168,25 +168,20 @@ abstract class BaseAction extends StandardJaxrsAction { ...@@ -168,25 +168,20 @@ abstract class BaseAction extends StandardJaxrsAction {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<Class<?>> listAssemble() throws Exception { private synchronized List<Class<?>> listAssemble() throws Exception {
if (null == assembles) { if (null == assembles) {
synchronized (BaseAction.class) { try (ScanResult scanResult = new ClassGraph()
if (null == assembles) { .addClassLoader(ClassLoaderTools.urlClassLoader(true, false, false, false, false))
try (ScanResult scanResult = new ClassGraph() .enableAnnotationInfo().scan()) {
.addClassLoader(ClassLoaderTools.urlClassLoader(true, false, false, false, false)) assembles = new CopyOnWriteArrayList<Class<?>>();
.enableAnnotationInfo().scan()) { List<ClassInfo> list = new ArrayList<>();
assembles = new CopyOnWriteArrayList<Class<?>>(); list.addAll(scanResult.getClassesWithAnnotation(Module.class.getName()));
List<ClassInfo> list = new ArrayList<>(); list = list.stream().sorted(Comparator.comparing(ClassInfo::getName)).collect(Collectors.toList());
list.addAll(scanResult.getClassesWithAnnotation(Module.class.getName())); for (ClassInfo info : list) {
list = list.stream().sorted(Comparator.comparing(ClassInfo::getName)) Class<?> cls = Class.forName(info.getName());
.collect(Collectors.toList()); Module module = cls.getAnnotation(Module.class);
for (ClassInfo info : list) { if (Objects.equal(module.type(), ModuleType.ASSEMBLE)) {
Class<?> cls = Class.forName(info.getName()); assembles.add(cls);
Module module = cls.getAnnotation(Module.class);
if (Objects.equal(module.type(), ModuleType.ASSEMBLE)) {
assembles.add(cls);
}
}
} }
} }
} }
......
...@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream; ...@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileFilter;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -129,32 +128,35 @@ class ActionInstallOrUpdate extends BaseAction { ...@@ -129,32 +128,35 @@ class ActionInstallOrUpdate extends BaseAction {
FileTools.forceMkdir(dist); FileTools.forceMkdir(dist);
JarTools.unjar(zipFile, new ArrayList<>(), dist, true); JarTools.unjar(zipFile, new ArrayList<>(), dist, true);
// 过滤必要的文件 // 过滤必要的文件
File[] files = dist.listFiles(new FileFilter() { // File[] files = dist.listFiles(new FileFilter() {
public boolean accept(File pathname) { // public boolean accept(File pathname) {
return true; // return true;
} // }
}); // });
for (File file : files) { File[] files = dist.listFiles(path -> true);
if (!file.isDirectory()) { if (null != files) {
if (file.getName().toLowerCase().endsWith(".xapp")) { for (File file : files) {
String json = FileUtils.readFileToString(file, DefaultCharset.charset); if (!file.isDirectory()) {
Gson gson = new Gson(); if (file.getName().toLowerCase().endsWith(".xapp")) {
JsonElement jsonElement = gson.fromJson(json, JsonElement.class); String json = FileUtils.readFileToString(file, DefaultCharset.charset);
WrapModule module = this.convertToWrapIn(jsonElement, WrapModule.class); Gson gson = new Gson();
this.installModule(module); JsonElement jsonElement = gson.fromJson(json, JsonElement.class);
installData.setWrapModule(module); WrapModule module = this.convertToWrapIn(jsonElement, WrapModule.class);
} else if (file.getName().toLowerCase().endsWith(".app.zip")) { this.installModule(module);
logger.print("开始安装自定义应用:{}", file.getName()); installData.setWrapModule(module);
this.installCustomApp(file.getName(), FileUtils.readFileToByteArray(file)); } else if (file.getName().toLowerCase().endsWith(".app.zip")) {
installData.setCustomApp(file.getName()); logger.print("开始安装自定义应用:{}", file.getName());
logger.print("完成自定义应用安装:{}", file.getName()); this.installCustomApp(file.getName(), FileUtils.readFileToByteArray(file));
} else if (file.getName().toLowerCase().endsWith(".zip")) { installData.setCustomApp(file.getName());
logger.print("开始安装静态资源"); logger.print("完成自定义应用安装:{}", file.getName());
try { } else if (file.getName().toLowerCase().endsWith(".zip")) {
Business.dispatch(false, file.getName(), "", FileUtils.readFileToByteArray(file)); logger.print("开始安装静态资源");
installData.setStaticResource(file.getName()); try {
} catch (Exception e) { Business.dispatch(false, file.getName(), "", FileUtils.readFileToByteArray(file));
logger.print("模块安装成功但静态资源安装失败:{}", e.getMessage()); installData.setStaticResource(file.getName());
} catch (Exception e) {
logger.print("模块安装成功但静态资源安装失败:{}", e.getMessage());
}
} }
} }
} }
......
...@@ -3,10 +3,6 @@ package com.x.program.center.jaxrs.module; ...@@ -3,10 +3,6 @@ package com.x.program.center.jaxrs.module;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
...@@ -18,8 +14,10 @@ import com.x.base.core.project.x_query_assemble_designer; ...@@ -18,8 +14,10 @@ import com.x.base.core.project.x_query_assemble_designer;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache.CacheCategory; import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey; import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config; import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse; import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.connection.ConnectionAction; import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
...@@ -29,30 +27,17 @@ import com.x.base.core.project.tools.StringTools; ...@@ -29,30 +27,17 @@ import com.x.base.core.project.tools.StringTools;
import com.x.cms.core.entity.element.wrap.WrapCms; import com.x.cms.core.entity.element.wrap.WrapCms;
import com.x.portal.core.entity.wrap.WrapPortal; import com.x.portal.core.entity.wrap.WrapPortal;
import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform; import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform;
import com.x.program.center.Business;
import com.x.program.center.ThisApplication; import com.x.program.center.ThisApplication;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.x.query.core.entity.wrap.WrapQuery; import com.x.query.core.entity.wrap.WrapQuery;
class ActionCompare extends BaseAction { class ActionCompare extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception { ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>(); ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo(); Wo wo = new Wo();
// if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
// throw new ExceptionDisable();
// }
// if (!business.collectAccountNotEmpty()) {
// throw new ExceptionCollectAccountEmpty();
// }
// if (BooleanUtils.isNotTrue(business.connectCollect())) {
// throw new ExceptionConnectError();
// }
// if (BooleanUtils.isNotTrue(business.validateCollect())) {
// throw new ExceptionValidateError();
// }
Req req = new Req(); Req req = new Req();
req.setName(Config.collect().getName()); req.setName(Config.collect().getName());
req.setPassword(Config.collect().getPassword()); req.setPassword(Config.collect().getPassword());
......
...@@ -3,25 +3,23 @@ package com.x.program.center.jaxrs.module; ...@@ -3,25 +3,23 @@ package com.x.program.center.jaxrs.module;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.Applications; import com.x.base.core.project.Applications;
import com.x.base.core.project.x_cms_assemble_control; import com.x.base.core.project.x_cms_assemble_control;
import com.x.base.core.project.x_portal_assemble_designer; import com.x.base.core.project.x_portal_assemble_designer;
import com.x.base.core.project.x_processplatform_assemble_designer; import com.x.base.core.project.x_processplatform_assemble_designer;
import com.x.base.core.project.x_query_assemble_designer; import com.x.base.core.project.x_query_assemble_designer;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.ActionResponse; import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder; import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
...@@ -34,6 +32,8 @@ import com.x.portal.core.entity.wrap.WrapPortal; ...@@ -34,6 +32,8 @@ import com.x.portal.core.entity.wrap.WrapPortal;
import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform; import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform;
import com.x.program.center.ThisApplication; import com.x.program.center.ThisApplication;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.x.query.core.entity.wrap.WrapQuery; import com.x.query.core.entity.wrap.WrapQuery;
class ActionCompareUpload extends BaseAction { class ActionCompareUpload extends BaseAction {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import com.x.base.core.project.config.Config; import com.x.base.core.project.config.Config;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
...@@ -7,10 +12,6 @@ import com.x.base.core.project.jaxrs.WrapStringList; ...@@ -7,10 +12,6 @@ import com.x.base.core.project.jaxrs.WrapStringList;
import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.program.center.Business; import com.x.program.center.Business;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import java.io.File;
class ActionDispatchResource extends BaseAction { class ActionDispatchResource extends BaseAction {
......
...@@ -3,8 +3,6 @@ package com.x.program.center.jaxrs.module; ...@@ -3,8 +3,6 @@ package com.x.program.center.jaxrs.module;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
...@@ -15,31 +13,17 @@ import com.x.base.core.project.connection.ConnectionAction; ...@@ -15,31 +13,17 @@ import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.program.center.Business;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
class ActionList extends BaseAction { class ActionList extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception { ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class); Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (null == wi) { if (null == wi) {
wi = new Wi(); wi = new Wi();
} }
ActionResult<List<Wo>> result = new ActionResult<>(); ActionResult<List<Wo>> result = new ActionResult<>();
// if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
// throw new ExceptionDisable();
// }
// if (!business.collectAccountNotEmpty()) {
// throw new ExceptionCollectAccountEmpty();
// }
// if (BooleanUtils.isNotTrue(business.connectCollect())) {
// throw new ExceptionConnectError();
// }
// if (BooleanUtils.isNotTrue(business.validateCollect())) {
// throw new ExceptionValidateError();
// }
Req req = new Req(); Req req = new Req();
req.setName(Config.collect().getName()); req.setName(Config.collect().getName());
req.setPassword(Config.collect().getPassword()); req.setPassword(Config.collect().getPassword());
......
...@@ -2,8 +2,6 @@ package com.x.program.center.jaxrs.module; ...@@ -2,8 +2,6 @@ package com.x.program.center.jaxrs.module;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
...@@ -13,26 +11,12 @@ import com.x.base.core.project.connection.ConnectionAction; ...@@ -13,26 +11,12 @@ import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.program.center.Business;
class ActionListCategory extends BaseAction { class ActionListCategory extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception { ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>(); ActionResult<List<Wo>> result = new ActionResult<>();
// if (BooleanUtils.isNotTrue(Config.collect().getEnable())) {
// throw new ExceptionDisable();
// }
// if (!business.collectAccountNotEmpty()) {
// throw new ExceptionCollectAccountEmpty();
// }
// if (BooleanUtils.isNotTrue(business.connectCollect())) {
// throw new ExceptionConnectError();
// }
// if (BooleanUtils.isNotTrue(business.validateCollect())) {
// throw new ExceptionValidateError();
// }
Req req = new Req(); Req req = new Req();
req.setName(Config.collect().getName()); req.setName(Config.collect().getName());
req.setPassword(Config.collect().getPassword()); req.setPassword(Config.collect().getPassword());
......
...@@ -15,7 +15,6 @@ import com.x.base.core.project.http.EffectivePerson; ...@@ -15,7 +15,6 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.program.center.core.entity.Structure; import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.Structure_;
public class ActionListStructure extends BaseAction { public class ActionListStructure extends BaseAction {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
...@@ -18,14 +11,19 @@ import com.x.base.core.project.x_portal_assemble_designer; ...@@ -18,14 +11,19 @@ import com.x.base.core.project.x_portal_assemble_designer;
import com.x.base.core.project.x_processplatform_assemble_designer; import com.x.base.core.project.x_processplatform_assemble_designer;
import com.x.base.core.project.x_query_assemble_designer; import com.x.base.core.project.x_query_assemble_designer;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.bean.WrapCopier; import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory; import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools; import com.x.base.core.project.tools.ListTools;
import com.x.cms.core.entity.element.wrap.WrapCms; import com.x.cms.core.entity.element.wrap.WrapCms;
import com.x.portal.core.entity.wrap.WrapPortal; import com.x.portal.core.entity.wrap.WrapPortal;
...@@ -33,6 +31,7 @@ import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform; ...@@ -33,6 +31,7 @@ import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform;
import com.x.program.center.ThisApplication; import com.x.program.center.ThisApplication;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
import com.x.program.center.core.entity.Structure; import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.x.query.core.entity.wrap.WrapQuery; import com.x.query.core.entity.wrap.WrapQuery;
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import java.io.ByteArrayOutputStream;
import java.util.Optional;
import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.cache.Cache.CacheCategory; import com.x.base.core.project.cache.Cache.CacheCategory;
...@@ -14,12 +17,8 @@ import com.x.base.core.project.logger.LoggerFactory; ...@@ -14,12 +17,8 @@ import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset; import com.x.base.core.project.tools.DefaultCharset;
import com.x.program.center.ThisApplication; import com.x.program.center.ThisApplication;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
import com.x.program.center.core.entity.Structure; import com.x.program.center.core.entity.Structure;
import java.io.ByteArrayOutputStream;
import java.util.Optional;
public class ActionOutputFile extends BaseAction { public class ActionOutputFile extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionOutputFile.class); private static Logger logger = LoggerFactory.getLogger(ActionOutputFile.class);
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.*; import com.x.base.core.project.Applications;
import com.x.base.core.project.x_cms_assemble_control;
import com.x.base.core.project.x_portal_assemble_designer;
import com.x.base.core.project.x_processplatform_assemble_designer;
import com.x.base.core.project.x_query_assemble_designer;
import com.x.base.core.project.config.Config; import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.CipherConnectionAction; import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
......
...@@ -4,13 +4,6 @@ import java.util.ArrayList; ...@@ -4,13 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
...@@ -25,18 +18,25 @@ import com.x.base.core.project.annotation.FieldDescribe; ...@@ -25,18 +18,25 @@ import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache.CacheCategory; import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey; import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager; import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId; import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.jaxrs.WrapPair; import com.x.base.core.project.jaxrs.WrapPair;
import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.cms.core.entity.element.wrap.WrapCms; import com.x.cms.core.entity.element.wrap.WrapCms;
import com.x.portal.core.entity.wrap.WrapPortal; import com.x.portal.core.entity.wrap.WrapPortal;
import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform; import com.x.processplatform.core.entity.element.wrap.WrapProcessPlatform;
import com.x.program.center.ThisApplication; import com.x.program.center.ThisApplication;
import com.x.program.center.WrapModule; import com.x.program.center.WrapModule;
import com.x.program.center.core.entity.Structure;
import com.x.program.center.core.entity.wrap.WrapServiceModule;
import com.x.query.core.entity.wrap.WrapQuery; import com.x.query.core.entity.wrap.WrapQuery;
public class ActionWrite extends BaseAction { public class ActionWrite extends BaseAction {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionAllocateStorageMaaping extends LanguagePromptException { class ExceptionAllocateStorageMaaping extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionCollectAccountEmpty extends LanguagePromptException { class ExceptionCollectAccountEmpty extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionConnectError extends LanguagePromptException { class ExceptionConnectError extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionDisable extends LanguagePromptException { class ExceptionDisable extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionFlagNotExist extends LanguagePromptException { class ExceptionFlagNotExist extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionStorageNotExist extends LanguagePromptException { class ExceptionStorageNotExist extends LanguagePromptException {
......
package com.x.program.center.jaxrs.module; package com.x.program.center.jaxrs.module;
import com.x.base.core.project.exception.LanguagePromptException; import com.x.base.core.project.exception.LanguagePromptException;
import com.x.base.core.project.exception.PromptException;
class ExceptionValidateError extends LanguagePromptException { class ExceptionValidateError extends LanguagePromptException {
......
...@@ -3,7 +3,14 @@ package com.x.program.center.jaxrs.module; ...@@ -3,7 +3,14 @@ package com.x.program.center.jaxrs.module;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended; import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
package com.x.program.center.jaxrs.qiyeweixin; package com.x.program.center.jaxrs.qiyeweixin;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
...@@ -22,24 +24,28 @@ import javax.crypto.spec.IvParameterSpec; ...@@ -22,24 +24,28 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
/** /**
* 提供接收和推送给企业微信消息的加解密接口(UTF8编码的字符串). * 提供接收和推送给企业微信消息的加解密接口(UTF8编码的字符串).
* <ol> * <ol>
* <li>第三方回复加密消息给企业微信</li> * <li>第三方回复加密消息给企业微信</li>
* <li>第三方收到企业微信发送的消息,验证消息的安全性,并对消息进行解密。</li> * <li>第三方收到企业微信发送的消息,验证消息的安全性,并对消息进行解密。</li>
* </ol> * </ol>
* 说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案 * 说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案
* <ol> * <ol>
* <li>在官方网站下载JCE无限制权限策略文件(JDK7的下载地址: * <li>在官方网站下载JCE无限制权限策略文件(JDK7的下载地址:
* http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html</li> * http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html</li>
* <li>下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt</li> * <li>下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt</li>
* <li>如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件</li> * <li>如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件</li>
* <li>如果安装了JDK,将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件</li> * <li>如果安装了JDK,将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件</li>
* </ol> * </ol>
*/ */
public class WXBizMsgCrypt { public class WXBizMsgCrypt {
static Charset CHARSET = Charset.forName("utf-8");
private static final Random random = new SecureRandom();
static final Charset CHARSET = StandardCharsets.UTF_8;
Base64 base64 = new Base64(); Base64 base64 = new Base64();
byte[] aesKey; byte[] aesKey;
String token; String token;
...@@ -47,9 +53,10 @@ public class WXBizMsgCrypt { ...@@ -47,9 +53,10 @@ public class WXBizMsgCrypt {
/** /**
* 构造函数 * 构造函数
* @param token 企业微信后台,开发者设置的token *
* @param token 企业微信后台,开发者设置的token
* @param encodingAesKey 企业微信后台,开发者设置的EncodingAESKey * @param encodingAesKey 企业微信后台,开发者设置的EncodingAESKey
* @param receiveid, 不同场景含义不同,详见文档 * @param receiveid, 不同场景含义不同,详见文档
* *
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息
*/ */
...@@ -86,11 +93,9 @@ public class WXBizMsgCrypt { ...@@ -86,11 +93,9 @@ public class WXBizMsgCrypt {
// 随机生成16位字符串 // 随机生成16位字符串
String getRandomStr() { String getRandomStr() {
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random(); StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
int number = random.nextInt(base.length()); sb.append(base.charAt(random.nextInt(base.length())));
sb.append(base.charAt(number));
} }
return sb.toString(); return sb.toString();
} }
...@@ -179,8 +184,7 @@ public class WXBizMsgCrypt { ...@@ -179,8 +184,7 @@ public class WXBizMsgCrypt {
int xmlLength = recoverNetworkBytesOrder(networkOrder); int xmlLength = recoverNetworkBytesOrder(networkOrder);
xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET);
from_receiveid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), from_receiveid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET);
CHARSET);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new AesException(AesException.IllegalBuffer); throw new AesException(AesException.IllegalBuffer);
...@@ -197,14 +201,14 @@ public class WXBizMsgCrypt { ...@@ -197,14 +201,14 @@ public class WXBizMsgCrypt {
/** /**
* 将企业微信回复用户的消息加密打包. * 将企业微信回复用户的消息加密打包.
* <ol> * <ol>
* <li>对要发送的消息进行AES-CBC加密</li> * <li>对要发送的消息进行AES-CBC加密</li>
* <li>生成安全签名</li> * <li>生成安全签名</li>
* <li>将消息密文和安全签名打包成xml格式</li> * <li>将消息密文和安全签名打包成xml格式</li>
* </ol> * </ol>
* *
* @param replyMsg 企业微信待回复用户的消息,xml格式的字符串 * @param replyMsg 企业微信待回复用户的消息,xml格式的字符串
* @param timeStamp 时间戳,可以自己生成,也可以用URL参数的timestamp * @param timeStamp 时间戳,可以自己生成,也可以用URL参数的timestamp
* @param nonce 随机串,可以自己生成,也可以用URL参数的nonce * @param nonce 随机串,可以自己生成,也可以用URL参数的nonce
* *
* @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串 * @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息
...@@ -214,7 +218,7 @@ public class WXBizMsgCrypt { ...@@ -214,7 +218,7 @@ public class WXBizMsgCrypt {
String encrypt = encrypt(getRandomStr(), replyMsg); String encrypt = encrypt(getRandomStr(), replyMsg);
// 生成安全签名 // 生成安全签名
if (timeStamp == "") { if (StringUtils.isEmpty(timeStamp)) {
timeStamp = Long.toString(System.currentTimeMillis()); timeStamp = Long.toString(System.currentTimeMillis());
} }
...@@ -229,21 +233,20 @@ public class WXBizMsgCrypt { ...@@ -229,21 +233,20 @@ public class WXBizMsgCrypt {
/** /**
* 检验消息的真实性,并且获取解密后的明文. * 检验消息的真实性,并且获取解密后的明文.
* <ol> * <ol>
* <li>利用收到的密文生成安全签名,进行签名验证</li> * <li>利用收到的密文生成安全签名,进行签名验证</li>
* <li>若验证通过,则提取xml中的加密消息</li> * <li>若验证通过,则提取xml中的加密消息</li>
* <li>对消息进行解密</li> * <li>对消息进行解密</li>
* </ol> * </ol>
* *
* @param msgSignature 签名串,对应URL参数的msg_signature * @param msgSignature 签名串,对应URL参数的msg_signature
* @param timeStamp 时间戳,对应URL参数的timestamp * @param timeStamp 时间戳,对应URL参数的timestamp
* @param nonce 随机串,对应URL参数的nonce * @param nonce 随机串,对应URL参数的nonce
* @param postData 密文,对应POST请求的数据 * @param postData 密文,对应POST请求的数据
* *
* @return 解密后的原文 * @return 解密后的原文
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息
*/ */
public String DecryptMsg(String msgSignature, String timeStamp, String nonce, String postData) public String DecryptMsg(String msgSignature, String timeStamp, String nonce, String postData) throws AesException {
throws AesException {
// 密钥,公众账号的app secret // 密钥,公众账号的app secret
// 提取密文 // 提取密文
...@@ -266,16 +269,16 @@ public class WXBizMsgCrypt { ...@@ -266,16 +269,16 @@ public class WXBizMsgCrypt {
/** /**
* 验证URL * 验证URL
*
* @param msgSignature 签名串,对应URL参数的msg_signature * @param msgSignature 签名串,对应URL参数的msg_signature
* @param timeStamp 时间戳,对应URL参数的timestamp * @param timeStamp 时间戳,对应URL参数的timestamp
* @param nonce 随机串,对应URL参数的nonce * @param nonce 随机串,对应URL参数的nonce
* @param echoStr 随机串,对应URL参数的echostr * @param echoStr 随机串,对应URL参数的echostr
* *
* @return 解密之后的echostr * @return 解密之后的echostr
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息
*/ */
public String VerifyURL(String msgSignature, String timeStamp, String nonce, String echoStr) public String VerifyURL(String msgSignature, String timeStamp, String nonce, String echoStr) throws AesException {
throws AesException {
String signature = SHA1.getSHA1(token, timeStamp, nonce, echoStr); String signature = SHA1.getSHA1(token, timeStamp, nonce, echoStr);
if (!signature.equals(msgSignature)) { if (!signature.equals(msgSignature)) {
......
package com.x.program.center.jaxrs.tokenthreshold;
import com.google.gson.JsonElement;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.core.entity.log.TokenThreshold;
class ActionUpdate extends BaseAction {
private static final Logger logger = LoggerFactory.getLogger(ActionUpdate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Config.resource_node_tokenThresholds().put(wi.getPerson(), wi.getThreshold());
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
public static class Wi extends TokenThreshold {
private static final long serialVersionUID = -6020110344581428321L;
static WrapCopier<Wi, TokenThreshold> copier = WrapCopierFactory.wi(Wi.class, TokenThreshold.class, null,
ListTools.toList(TokenThreshold.person_FIELDNAME, TokenThreshold.threshold_FIELDNAME));
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = -338678364674176846L;
}
}
package com.x.program.center.jaxrs.tokenthreshold;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
\ No newline at end of file
package com.x.program.center.jaxrs.tokenthreshold;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("tokenthreshold")
@JaxrsDescribe("令牌过期")
public class TokenThresholdAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(TokenThresholdAction.class);
@JaxrsMethodDescribe(value = "接收消息,更新node节点上的过期tokenThreshold消息.", action = ActionUpdate.class)
@POST
@Path("update")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void info(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@Context HttpServletResponse response, JsonElement jsonElement) {
ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionUpdate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册