Browse Source

open

master
pioneer 2 years ago
commit
1e825434f2
  1. BIN
      doc/4A用户同步和单点登录插件使用文档.docx
  2. BIN
      doc/JSD-9179-需求确认书V2.docx
  3. BIN
      lib/banboocloud_Codec-0.0.1.jar
  4. BIN
      lib/dom4j-1.6.1.jar
  5. BIN
      lib/fastjson-1.2.47.jar
  6. BIN
      lib/finekit-10.0-20200828.jar
  7. BIN
      lib/xml-apis-1.0.b2.jar
  8. 21
      plugin.xml
  9. 6
      readme.md
  10. 12
      src/main/java/com/fr/plugin/FunctionRecoder.java
  11. 81
      src/main/java/com/fr/plugin/SYNCConfig.java
  12. 18
      src/main/java/com/fr/plugin/SYNCLifeCycleMonitor.java
  13. 40
      src/main/java/com/fr/plugin/http/AttributeEntity.java
  14. 20
      src/main/java/com/fr/plugin/http/SYNCHttpHandler.java
  15. 18
      src/main/java/com/fr/plugin/http/SYNCUrlAliasProvider.java
  16. 103
      src/main/java/com/fr/plugin/http/handler/ALLAuthcallbak1Handler.java
  17. 100
      src/main/java/com/fr/plugin/http/handler/ALLSchemaServiceHandler.java
  18. 86
      src/main/java/com/fr/plugin/http/handler/ALLUserDeleteHandler.java
  19. 85
      src/main/java/com/fr/plugin/http/handler/ALLUserSync2Handler.java
  20. 101
      src/main/java/com/fr/plugin/http/handler/ALLUserUpdateHandler.java
  21. 72
      src/main/java/com/fr/plugin/utils/BamboocloudUtils.java
  22. 195
      src/main/java/com/fr/plugin/utils/HttpApi.java

BIN
doc/4A用户同步和单点登录插件使用文档.docx

Binary file not shown.

BIN
doc/JSD-9179-需求确认书V2.docx

Binary file not shown.

BIN
lib/banboocloud_Codec-0.0.1.jar

Binary file not shown.

BIN
lib/dom4j-1.6.1.jar

Binary file not shown.

BIN
lib/fastjson-1.2.47.jar

Binary file not shown.

BIN
lib/finekit-10.0-20200828.jar

Binary file not shown.

BIN
lib/xml-apis-1.0.b2.jar

Binary file not shown.

21
plugin.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.eco.plugin.zzl.4a.sync</id>
<name><![CDATA[4A集成和用户同步]]></name>
<active>yes</active>
<version>1.0.4</version>
<env-version>10.0</env-version>
<jartime>2021-02-10</jartime>
<vendor>fr.open</vendor>
<main-package>com.fr.plugin</main-package>
<description><![CDATA[
]]></description>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.http.SYNCHttpHandler"/>
<URLAliasProvider class="com.fr.plugin.http.SYNCUrlAliasProvider"/>
</extra-decision>
<lifecycle-monitor class="com.fr.plugin.SYNCLifeCycleMonitor"/>
<function-recorder class="com.fr.plugin.FunctionRecoder"/>
</plugin>

6
readme.md

@ -0,0 +1,6 @@
# open-JSD-9179
JSD-xxxx 一句话简介该插件的功能和场景\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

12
src/main/java/com/fr/plugin/FunctionRecoder.java

@ -0,0 +1,12 @@
package com.fr.plugin;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
@FunctionRecorder
public class FunctionRecoder {
@ExecuteFunctionRecord
public void exe(){
System.out.println("插件功能埋点,虽然不会执行,除非上架应用");
}
}

81
src/main/java/com/fr/plugin/SYNCConfig.java

@ -0,0 +1,81 @@
package com.fr.plugin;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
@Visualization(category = "4A集成和用户同步配置")
public class SYNCConfig extends DefaultConfiguration {
private static volatile SYNCConfig config = null;
public static SYNCConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(SYNCConfig.class);
}
return config;
}
@Identifier(value = "apiUrl", name = "单点登录接口路径", description = "描述", status = Status.SHOW)
private Conf<String> apiUrl = Holders.simple("http://IP地址:端口");
@Identifier(value = "clientId", name = "单点登录client_id", description = "单点登录client_id", status = Status.SHOW)
private Conf<String> clientId = Holders.simple("");
@Identifier(value = "frUrl", name = "单点登录帆软URL", description = "单点登录帆软URL", status = Status.SHOW)
private Conf<String> frUrl = Holders.simple("http://localhost:8075/webroot/decision");
@Identifier(value = "clientSecret", name = "单点登录clientSecret", description = "描述", status = Status.SHOW)
private Conf<String> clientSecret = Holders.simple("");
@Identifier(value = "syncSecret", name = "用户同步秘钥", description = "描述", status = Status.SHOW)
private Conf<String> syncSecret = Holders.simple("");
public String getSyncSecret() {
return syncSecret.get();
}
public void setSyncSecret(String syncSecret) {
this.syncSecret.set(syncSecret);
}
public String getApiUrl() {
return apiUrl.get();
}
public void setApiUrl(String apiUrl) {
this.apiUrl.set(apiUrl);
}
public String getClientId() {
return clientId.get();
}
public void setClientId(String clientId) {
this.clientId.set(clientId);
}
public String getFrUrl() {
return frUrl.get();
}
public void setFrUrl(String frUrl) {
this.frUrl.set(frUrl);
}
public String getClientSecret() {
return clientSecret.get();
}
public void setClientSecret(String clientSecret) {
this.clientSecret.set(clientSecret);
}
@Override
public Object clone() throws CloneNotSupportedException {
SYNCConfig cloned = (SYNCConfig) super.clone();
cloned.apiUrl = (Conf<String>) this.apiUrl.clone();
cloned.clientId = (Conf<String>) this.clientId.clone();
cloned.frUrl = (Conf<String>) this.frUrl.clone();
cloned.syncSecret = (Conf<String>) this.syncSecret.clone();
cloned.clientSecret = (Conf<String>) this.clientSecret.clone();
return cloned;
}
}

18
src/main/java/com/fr/plugin/SYNCLifeCycleMonitor.java

@ -0,0 +1,18 @@
package com.fr.plugin;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.stable.fun.Authorize;
@Authorize
public class SYNCLifeCycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
SYNCConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

40
src/main/java/com/fr/plugin/http/AttributeEntity.java

@ -0,0 +1,40 @@
package com.fr.plugin.http;
public class AttributeEntity {
private String name;
private String type;
private boolean isRequired;
private boolean isMultivalued;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
public boolean isRequired() {
return this.isRequired;
}
public void setRequired(boolean isRequired) {
this.isRequired = isRequired;
}
public boolean isMultivalued() {
return this.isMultivalued;
}
public void setMultivalued(boolean isMultivalued) {
this.isMultivalued = isMultivalued;
}
}

20
src/main/java/com/fr/plugin/http/SYNCHttpHandler.java

@ -0,0 +1,20 @@
package com.fr.plugin.http;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.plugin.http.handler.*;
public class SYNCHttpHandler extends AbstractHttpHandlerProvider {
HttpHandler[] actions = new HttpHandler[]{
new ALLAuthcallbak1Handler(),
new ALLUserDeleteHandler(),
new ALLSchemaServiceHandler(),
new ALLUserUpdateHandler(),
new ALLUserSync2Handler(),
};
@Override
public HttpHandler[] registerHandlers() {
return actions;
}
}

18
src/main/java/com/fr/plugin/http/SYNCUrlAliasProvider.java

@ -0,0 +1,18 @@
package com.fr.plugin.http;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class SYNCUrlAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/authcallbak", "/authcallbak", true),
URLAliasFactory.createPluginAlias("/UserCreateService", "/userCreate", true),
URLAliasFactory.createPluginAlias("/UserDeleteService", "/userDelete", true),
URLAliasFactory.createPluginAlias("/UserUpdateService", "/userUpdate", true),
URLAliasFactory.createPluginAlias("/SchemaService", "/schemaService", true),
};
}
}

103
src/main/java/com/fr/plugin/http/handler/ALLAuthcallbak1Handler.java

@ -0,0 +1,103 @@
package com.fr.plugin.http.handler;
import com.alibaba.fastjson.JSON;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.net.http.HttpKit;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.SYNCConfig;
import com.fr.plugin.utils.BamboocloudUtils;
import com.fr.plugin.utils.HttpApi;
import com.fr.stable.StringUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ALLAuthcallbak1Handler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/authcallbak";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String code = req.getParameter("code");
SYNCConfig syncConfig = SYNCConfig.getInstance();
if (StringUtils.isBlank(code)) {
String goAuth = String.format("%s/idp/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=123",syncConfig.getApiUrl(),syncConfig.getClientId(),syncConfig.getFrUrl()+"/url/authcallbak");
sendRedirect(res,goAuth);
return;
}
String accessToken = getTokenByCode(code);
String loginName = getUserInfoByAccessToken(accessToken);
User userByUserName = UserService.getInstance().getUserByUserName(loginName);
if (userByUserName == null) {
WebUtils.printAsString(res, loginName + "用户不存在,请联系管理员");
return;
}
login(req, res, loginName);
sendRedirect(res, syncConfig.getFrUrl());
LogKit.info("登录成功:{}",loginName);
}
private void sendRedirect(HttpServletResponse res, String url) {
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
private void login(HttpServletRequest req, HttpServletResponse res, String username) {
String token = null;
try {
token = LoginService.getInstance().login(req, res, username);
req.setAttribute("fine_auth_token", token);
} catch (Exception e) {
}
}
private String getUserInfoByAccessToken(String code) throws IOException {
SYNCConfig syncConfig = SYNCConfig.getInstance();
String url = String.format("%s/idp/oauth2/getUserInfo?client_id=%s&access_token=%s", syncConfig.getApiUrl(), syncConfig.getClientId(), code);
// Map<String, String> entries = new HashMap<>();
// entries.put("client_id", syncConfig.getClientId());
// entries.put("access_token", code);
String respJson = HttpApi.httpsGet(url);
FineLoggerFactory.getLogger().info("getUserInfoByAccessToken:{}", respJson);
JSONObject resp = new JSONObject(respJson);
return resp.getString("loginName");
}
private String getTokenByCode(String code) {
SYNCConfig syncConfig = SYNCConfig.getInstance();
String url = String.format("%s/idp/oauth2/getToken?client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s", syncConfig.getApiUrl(), syncConfig.getClientId(), syncConfig.getClientSecret(), code);
JSONObject entries = new JSONObject();
entries.put("client_id", syncConfig.getClientId());
entries.put("client_secret", syncConfig.getClientSecret());
entries.put("grant_type", "authorization_code");
entries.put("code", code);
String respJson = HttpApi.sendJsonPost(url, entries, "UTF-8");
FineLoggerFactory.getLogger().info("url:{} getTokenByCode respJson:{}",url, respJson);
JSONObject resp = new JSONObject(respJson);
return resp.getString("access_token");
}
}

100
src/main/java/com/fr/plugin/http/handler/ALLSchemaServiceHandler.java

@ -0,0 +1,100 @@
package com.fr.plugin.http.handler;
import com.alibaba.fastjson.JSON;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fanruan.api.log.LogKit;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.controller.UserController;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.plugin.SYNCConfig;
import com.fr.plugin.http.AttributeEntity;
import com.fr.plugin.utils.BamboocloudUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ALLSchemaServiceHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/schemaService";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String bodyparam = BamboocloudUtils.getRequestBody(req);
SYNCConfig syncConfig = SYNCConfig.getInstance();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
LogKit.info("json--param-->" + bodyparam);
Map<String,Object> reqmap = (Map<String,Object>) JSON.parse(bodyparam);
// if (BamboocloudUtils.verify(reqmap, "MD5").booleanValue()) {
String username = (String) reqmap.get("bimRemoteUser");
String password = (String) reqmap.get("bimRemotePwd");
BamboocloudUtils.checkUsernamePassword(username, password);
Map<String, Object> schema = new HashMap<String, Object>();
List<AttributeEntity> accountAttrList = new ArrayList<AttributeEntity>();
AttributeEntity attr1 = new AttributeEntity();
attr1.setType("String");
attr1.setName("loginName");
attr1.setRequired(true);
attr1.setMultivalued(false);
accountAttrList.add(attr1);
AttributeEntity attr3 = new AttributeEntity();
attr3.setType("String");
attr3.setName("fullName");
attr3.setRequired(true);
attr3.setMultivalued(false);
accountAttrList.add(attr3);
AttributeEntity attr5 = new AttributeEntity();
attr5.setType("String");
attr5.setName("password");
attr5.setRequired(true);
attr5.setMultivalued(false);
accountAttrList.add(attr5);
schema.put("account", accountAttrList);
schema.put("bimRequestId", reqmap.get("bimRequestId"));
String mapJson = JSON.toJSONString(schema);
LogKit.info("response---json-->" + mapJson);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
return;
// }
// WebUtils.printAsString(res, BamboocloudFacade.encrypt(JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "500", "接口验证失败")), syncConfig.getSyncSecret(), "AES"));
}
private Map createJson(String bimRequestId, String code, String msg) {
Map<String, Object> schema = new HashMap<String, Object>();
schema.put("bimRequestId", bimRequestId);
schema.put("resultCode", code);
schema.put("message", msg);
return schema;
}
}

86
src/main/java/com/fr/plugin/http/handler/ALLUserDeleteHandler.java

@ -0,0 +1,86 @@
package com.fr.plugin.http.handler;
import com.alibaba.fastjson.JSON;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fanruan.api.log.LogKit;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
import com.fr.decision.authority.controller.UserController;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.privilege.encrpt.PasswordValidator;
import com.fr.decision.webservice.utils.UserSourceFactory;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.plugin.SYNCConfig;
import com.fr.plugin.utils.BamboocloudUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
public class ALLUserDeleteHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/userDelete";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String bodyparam = BamboocloudUtils.getRequestBody(req);
System.out.println("first--param-->" + bodyparam);
SYNCConfig syncConfig = SYNCConfig.getInstance();
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
LogKit.info("xml--param-->" + bodyparam);
// bodyparam = XmlUtils.xmlToJson(bodyparam);
// System.out.println("json--param-->" + bodyparam);
Map<String, Object> reqmap = (Map<String, Object>) JSON.parse(bodyparam);
// if (BamboocloudUtils.verify(reqmap, "MD5").booleanValue()) {
String username = (String) reqmap.get("bimRemoteUser");
String password = (String) reqmap.get("bimRemotePwd");
String uid = (String) reqmap.get("bimUid");
BamboocloudUtils.checkUsernamePassword(username, password);
UserController userController = AuthorityContext.getInstance().getUserController();
User user = userController.findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", uid)));
if (user == null) {
LogKit.error("删除当前用户不存在:{}", uid);
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "500", "删除当前用户不存在" + uid));
LogKit.info("response---json-->" + mapJson);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
return;
}
userController.remove(user.getId());
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "0", "success"));
LogKit.info("response---json-->" + mapJson);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
// }
}
private Map createJson(String bimRequestId, String code, String msg) {
Map<String, Object> schema = new HashMap<String, Object>();
schema.put("bimRequestId", bimRequestId);
schema.put("resultCode", code);
schema.put("message", msg);
return schema;
}
}

85
src/main/java/com/fr/plugin/http/handler/ALLUserSync2Handler.java

@ -0,0 +1,85 @@
package com.fr.plugin.http.handler;
import com.alibaba.fastjson.JSON;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fanruan.api.log.LogKit;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
import com.fr.decision.authority.controller.UserController;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.privilege.encrpt.PasswordValidator;
import com.fr.decision.webservice.utils.UserSourceFactory;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.plugin.SYNCConfig;
import com.fr.plugin.utils.BamboocloudUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ALLUserSync2Handler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/userCreate";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest request, HttpServletResponse res) throws Exception {
String bodyparam = BamboocloudUtils.getRequestBody(request);
SYNCConfig syncConfig = SYNCConfig.getInstance();
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
LogKit.info("json--param-->" + bodyparam);
Map<String, Object> reqmap = (Map<String, Object>) JSON.parse(bodyparam);
// if (BamboocloudUtils.verify(reqmap, "MD5").booleanValue()) {
String username = (String) reqmap.get("bimRemoteUser");
String password = (String) reqmap.get("bimRemotePwd");
BamboocloudUtils.checkUsernamePassword(username, password);
String uid = UUID.randomUUID().toString();
UserController userController = AuthorityContext.getInstance().getUserController();
UserService userService = UserService.getInstance();
String loginName = (String) reqmap.get("loginName");
PasswordValidator passwordValidator = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator();
User user = userService.getUserByUserName(loginName);
boolean add = false;
if (user == null) {
add = true;
user = new User();
user.setId(uid);
}
user.setUserName(loginName);
user.setRealName((String) reqmap.get("fullName"));
user.setEnable(true);
user.setPassword(passwordValidator.encode(username, password));
if (add) {
userController.add(user);
} else {
userController.update(user);
}
Map<String, Object> schema = new HashMap<String, Object>();
schema.put("uid", uid);
schema.put("bimRequestId", reqmap.get("bimRequestId"));
schema.put("resultCode", "0");
schema.put("message", "success");
String mapJson = JSON.toJSONString(schema);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
// }
}
}

101
src/main/java/com/fr/plugin/http/handler/ALLUserUpdateHandler.java

@ -0,0 +1,101 @@
package com.fr.plugin.http.handler;
import com.alibaba.fastjson.JSON;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fanruan.api.log.LogKit;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
import com.fr.decision.authority.controller.UserController;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.privilege.encrpt.PasswordValidator;
import com.fr.decision.webservice.utils.UserSourceFactory;
import com.fr.plugin.SYNCConfig;
import com.fr.plugin.utils.BamboocloudUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public class ALLUserUpdateHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/userUpdate";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String bodyparam = BamboocloudUtils.getRequestBody(req);
System.out.println("first--param-->" + bodyparam);
SYNCConfig syncConfig = SYNCConfig.getInstance();
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
LogKit.info("xml--param-->" + bodyparam);
// bodyparam = XmlUtils.xmlToJson(bodyparam);
// System.out.println("json--param-->" + bodyparam);
Map<String, Object> reqmap = (Map<String, Object>) JSON.parse(bodyparam);
// if (BamboocloudUtils.verify(reqmap, "MD5").booleanValue()) {
String username = (String) reqmap.get("bimRemoteUser");
String bimRemotePwd = (String) reqmap.get("bimRemotePwd");
String uid = (String) reqmap.get("bimUid");
BamboocloudUtils.checkUsernamePassword(username, bimRemotePwd);
String password = (String) reqmap.get("password");
UserController userController = AuthorityContext.getInstance().getUserController();
User user = userController.findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", uid)));
if (user == null) {
LogKit.error("当前用户不存在:{}", uid);
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "500", "当前用户不存在" + uid));
LogKit.info("response---json-->" + mapJson);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
return;
}
PasswordValidator passwordValidator = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator();
String fullName = (String) reqmap.get("fullName");
if (StringUtils.isNotEmpty(fullName)) {
user.setRealName(fullName);
}
Object enable = reqmap.get("__ENABLE__");
if (enable != null) {
String en = enable.toString();
user.setEnable(StringUtils.equals(en, "true"));
}
if (!StringUtils.isEmpty(password)) {
user.setPassword(passwordValidator.encode(username, password));
}
userController.update(user);
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "0", "success"));
LogKit.info("response---json-->" + mapJson);
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
WebUtils.printAsString(res, mapJson);
// }
}
private Map createJson(String bimRequestId, String code, String msg) {
Map<String, Object> schema = new HashMap<String, Object>();
schema.put("bimRequestId", bimRequestId);
schema.put("resultCode", code);
schema.put("message", msg);
return schema;
}
}

72
src/main/java/com/fr/plugin/utils/BamboocloudUtils.java

@ -0,0 +1,72 @@
package com.fr.plugin.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import com.banboocloud.Codec.BamboocloudFacade;
import com.fr.log.FineLoggerFactory;
public abstract class BamboocloudUtils {
public static void checkUsernamePassword(String username, String password) {
System.out.println("username --->" + username + " password --- >" + password + " ----ok");
}
public static String getPlaintext(String ciphertext, String key, String type) {
return BamboocloudFacade.decrypt(ciphertext, key, type);
}
public static Boolean verify(Map<String, Object> reqmap, String type) {
Map<String, Object> verifymap = new TreeMap<String, Object>();
StringBuffer sb = new StringBuffer();
Iterator<String> it = reqmap.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
verifymap.put(key, reqmap.get(key));
}
Iterator<String> ittree = verifymap.keySet().iterator();
while (ittree.hasNext()) {
String key = (String) ittree.next();
if (!"signature".equals(key)) {
sb.append(key).append("=").append(verifymap.get(key)).append("&");
}
}
sb.deleteCharAt(sb.length() - 1);
FineLoggerFactory.getLogger().info(reqmap.get("signature") + " now " + sb.toString());
return BamboocloudFacade.verify(reqmap.get("signature").toString(), sb.toString(), type);
}
public static String getRequestBody(HttpServletRequest request) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String str = "";
try {
br = request.getReader();
while ((str = br.readLine()) != null) {
sb.append(str);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
if (br != null)
try {
br.close();
} catch (IOException eo) {
eo.printStackTrace();
}
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
}

195
src/main/java/com/fr/plugin/utils/HttpApi.java

@ -0,0 +1,195 @@
package com.fr.plugin.utils;
import com.fr.base.ServerConfig;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.client.ClientProtocolException;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClientBuilder;
import com.fr.third.org.apache.http.util.EntityUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class HttpApi {
private static String getParam(Map<String, Object> var0, String enc) {
String var1 = "";
Set var2 = var0.keySet();
Iterator var3 = var2.iterator();
while (var3.hasNext()) {
String var4 = (String) var3.next();
String var5 = var0.get(var4) + "";
try {
var1 = var1 + (var1.length() == 0 ? "" : "&") + URLEncoder.encode(var4, enc) + "=" + URLEncoder.encode(var5, enc);
} catch (Exception var7) {
;
}
}
return var1;
}
public static String httpsGet(String requestUrl) throws UnsupportedEncodingException {
String data = "";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httppost = new HttpGet(requestUrl);
httppost.setHeader("Content-Type", "application/json");
httppost.setHeader("Authorization", "");
httppost.setHeader("Accept", "application/json;charset=UTF-8");
// 响应模型
CloseableHttpResponse response = null;
try {
// 配置信息
RequestConfig requestConfig = RequestConfig.custom()
// 设置连接超时时间(单位毫秒)
.setConnectTimeout(5000)
// 设置请求超时时间(单位毫秒)
.setConnectionRequestTimeout(5000)
// socket读写超时时间(单位毫秒)
.setSocketTimeout(5000)
// 设置是否允许重定向(默认为true)
.setRedirectsEnabled(true).build();
// 将上面的配置信息 运用到这个Get请求里
httppost.setConfig(requestConfig);
// 由客户端执行(发送)Post请求
response = httpClient.execute(httppost);
// 从响应模型中获取响应实体
HttpEntity responseEntity = response.getEntity();
FineLoggerFactory.getLogger().info("响应状态为:" + response.getStatusLine());
if (responseEntity != null) {
// System.out.println("响应内容为:" + EntityUtils.toString(responseEntity));
data = EntityUtils.toString(responseEntity).toString();
FineLoggerFactory.getLogger().info("响应内容长度为:{} 内容:{}", responseEntity.getContentLength(),data);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
// 释放资源
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return data;
}
public static String post(String path, Map<String, Object> param) {
String var3 = getParam(param, ServerConfig.getInstance().getServerCharset());
PrintWriter var4 = null;
BufferedReader var5 = null;
String var6 = "";
try {
URL var7 = new URL(path);
HttpURLConnection var8 = (HttpURLConnection) var7.openConnection();
var8.setRequestProperty("accept", "*/*");
var8.setRequestProperty("connection", "Keep-Alive");
var8.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// var8.setRequestProperty("Accept-Charset", "UTF-8");
var8.setRequestMethod("POST");
var8.setDoOutput(true);
var8.setDoInput(true);
var4 = new PrintWriter(var8.getOutputStream());
var4.print(var3);
var4.flush();
String var9;
for (var5 = new BufferedReader(new InputStreamReader(var8.getInputStream(), "UTF-8")); (var9 = var5.readLine()) != null; var6 = var6 + var9) {
;
}
} catch (Exception var18) {
var18.printStackTrace();
} finally {
try {
if (var4 != null) {
var4.close();
}
if (var5 != null) {
var5.close();
}
} catch (Exception var17) {
;
}
}
return var6;
}
public static String sendJsonPost(String var0, JSONObject var1, String var2) {
PrintWriter var3 = null;
BufferedReader var4 = null;
HttpURLConnection var5 = null;
String var6 = "";
try {
URL var7 = new URL(var0);
var5 = (HttpURLConnection) var7.openConnection();
var5.setRequestProperty("Content-Type", "application/json;charset=utf8");
// var5.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf8");
var5.setRequestProperty("accept", "*/*");
var5.setRequestProperty("connection", "Keep-Alive");
var5.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
var5.setRequestProperty("Accept-Charset", var2);
var5.setRequestMethod("POST");
var5.setDoOutput(true);
var5.setDoInput(true);
var3 = new PrintWriter(var5.getOutputStream());
var3.print(var1.toString());
var3.flush();
String var8;
for (var4 = new BufferedReader(new InputStreamReader(var5.getInputStream(), var2)); (var8 = var4.readLine()) != null; var6 = var6 + var8) {
;
}
} catch (Exception var17) {
var17.printStackTrace();
} finally {
try {
if (var3 != null) {
var3.close();
}
if (var4 != null) {
var4.close();
}
} catch (Exception var16) {
;
}
var5.disconnect();
}
System.out.println(var6);
return var6;
}
}
Loading…
Cancel
Save