Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
bf4e2bf738
  1. 5
      README.md
  2. BIN
      lib/finekit-10.0.jar
  3. 21
      plugin.xml
  4. 244
      src/main/java/com/fr/plugin/third/party/jsdhcjd/config/CustomDataConfig.java
  5. 24
      src/main/java/com/fr/plugin/third/party/jsdhcjd/config/DataConfigInitializeMonitor.java
  6. 101
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/BmpFlowUtils.java
  7. 403
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpDataModel.java
  8. 18
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableData.java
  9. 50
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableDataDefine.java
  10. 76
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableDataPane.java
  11. 67
      src/main/java/com/fr/plugin/third/party/jsdhcjd/data/DatasetData.java
  12. 559
      src/main/java/com/fr/plugin/third/party/jsdhcjd/http/SessionGlobalRequestFilterProvider.java
  13. 64
      src/main/java/com/fr/plugin/third/party/jsdhcjd/test/XmlTest.java

5
README.md

@ -1,3 +1,6 @@
# open-JSD-8010
JSD-8010 开源任务材料
JSD-8010 开源任务材料\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。

BIN
lib/finekit-10.0.jar

Binary file not shown.

21
plugin.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.third.party.jsd7293</id>
<name><![CDATA[登录集成]]></name>
<active>yes</active>
<version>0.7</version>
<env-version>10.0</env-version>
<jartime>2019-01-01</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[]]></change-notes>
<extra-decision>
<GlobalRequestFilterProvider class="com.fr.plugin.third.party.jsdhcjd.http.SessionGlobalRequestFilterProvider"/>
</extra-decision>
<extra-designer>
<ServerTableDataDefineProvider class="com.fr.plugin.third.party.jsdhcjd.data.CustomHttpTableDataDefine"/>
<TableDataDefineProvider class="com.fr.plugin.third.party.jsdhcjd.data.CustomHttpTableDataDefine"/>
</extra-designer>
<function-recorder class="com.fr.plugin.third.party.jsdhcjd.config.DataConfigInitializeMonitor"/>
<lifecycle-monitor class="com.fr.plugin.third.party.jsdhcjd.config.DataConfigInitializeMonitor"/>
</plugin>

244
src/main/java/com/fr/plugin/third/party/jsdhcjd/config/CustomDataConfig.java

@ -0,0 +1,244 @@
package com.fr.plugin.third.party.jsdhcjd.config;
import com.fanruan.api.util.StringKit;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import java.util.concurrent.ConcurrentHashMap;
/**
* 配置数据保存
*/
@Visualization(category = "融创集成登录配置")
public class CustomDataConfig extends DefaultConfiguration {
public String getNameSpace() {
return this.getClass().getName();
}
private static ConcurrentHashMap<String, String> URL_MAP = new ConcurrentHashMap<String, String>();
/**
* 添加链接
* @param key
* @param url
*/
public static void addUrl(String key, String url) {
URL_MAP.put(key, url);
}
/**
* 获取链接并销毁保存
* @param key
* @return
*/
public static String getUrlAndDestroy(String key) {
String url = URL_MAP.get(key);
URL_MAP.remove(key);
return url;
}
private static volatile CustomDataConfig config = null;
public static CustomDataConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(CustomDataConfig.class);
}
return config;
}
@Identifier(value = "appValidityDuration", name = "移动端有效期时长(分钟)", description = "单位:分钟", status = Status.SHOW)
private Conf<Integer> appValidityDuration = Holders.simple(720);
@Identifier(value = "appSecurityKey", name = "移动端密钥(securityKey)", description = "", status = Status.SHOW)
private Conf<String> appSecurityKey = Holders.simple(StringKit.EMPTY);
@Identifier(value = "idmClientId", name = "IDM系统应用唯一标识(client_id)", description = "", status = Status.SHOW)
private Conf<String> idmClientId = Holders.simple("");
@Identifier(value = "idmClientSecret", name = "IDM系统应用密钥(client_secret)", description = "", status = Status.SHOW)
private Conf<String> idmClientSecret = Holders.simple("");
@Identifier(value = "frUrl", name = "报表地址(redirect_uri)", description = "", status = Status.SHOW)
private Conf<String> frUrl = Holders.simple("http://10.199.201.108/webroot/decision");
@Identifier(value = "oAuthCodeUrl", name = "获取OAuth Code地址", description = "", status = Status.SHOW)
private Conf<String> oAuthCodeUrl = Holders.simple("");
@Identifier(value = "accessTokenUrl", name = "获取Access Token地址", description = "", status = Status.SHOW)
private Conf<String> accessTokenUrl = Holders.simple("");
@Identifier(value = "userUrl", name = "获取用户信息地址", description = "", status = Status.SHOW)
private Conf<String> userUrl = Holders.simple("");
@Identifier(value = "loginTypeNameParameter", name = "登录类型参数名称", description = "", status = Status.SHOW)
private Conf<String> loginTypeNameParameter = Holders.simple("loginType");
@Identifier(value = "loginTypeValue", name = "登录类型值", description = "", status = Status.SHOW)
private Conf<String> loginTypeValue = Holders.simple("IDM_OAUTH");
@Identifier(value = "userInfoAccount", name = "获取用户信息的用户名", description = "", status = Status.SHOW)
private Conf<String> userInfoAccount = Holders.simple("idmadmin");
@Identifier(value = "userInfoPassword", name = "获取用户信息的密码", description = "", status = Status.SHOW)
private Conf<String> userInfoPassword = Holders.simple("idmpass");
@Identifier(value = "userInfoUrl", name = "获取用户信息的地址", description = "", status = Status.SHOW)
private Conf<String> userInfoUrl = Holders.simple("http://xxx:8001/WP_SUNAC/APP_PUBLIC_SERVICES/Proxy_Services/TA_IDM/PUBLIC_SUNAC_300_queryIdmUserData_PS");
@Identifier(value = "frAdminAccount", name = "报表管理员用户名", description = "", status = Status.SHOW)
private Conf<String> frAdminAccount = Holders.simple("admin");
public int getAppValidityDuration() {
return appValidityDuration.get();
}
public void setAppValidityDuration(int appValidityDuration) {
this.appValidityDuration.set(appValidityDuration);
}
public String getAppSecurityKey() {
return appSecurityKey.get();
}
public void setAppSecurityKey(String appSecurityKey) {
this.appSecurityKey.set(appSecurityKey);
}
public String getIdmClientId() {
return idmClientId.get();
}
public void setIdmClientId(String idmClientId) {
this.idmClientId.set(idmClientId);
}
public String getIdmClientSecret() {
return idmClientSecret.get();
}
public void setIdmClientSecret(String idmClientSecret) {
this.idmClientSecret.set(idmClientSecret);
}
public String getFrUrl() {
return frUrl.get();
}
public void setFrUrl(String frUrl) {
this.frUrl.set(frUrl);
}
public String getoAuthCodeUrl() {
return oAuthCodeUrl.get();
}
public void setoAuthCodeUrl(String oAuthCodeUrl) {
this.oAuthCodeUrl.set(oAuthCodeUrl);
}
public String getAccessTokenUrl() {
return accessTokenUrl.get();
}
public void setAccessTokenUrl(String accessTokenUrl) {
this.accessTokenUrl.set(accessTokenUrl);
}
public String getUserUrl() {
return userUrl.get();
}
public void setUserUrl(String userUrl) {
this.userUrl.set(userUrl);
}
public String getLoginTypeNameParameter() {
return loginTypeNameParameter.get();
}
public void setLoginTypeNameParameter(String loginTypeNameParameter) {
this.loginTypeNameParameter.set(loginTypeNameParameter);
}
public String getLoginTypeValue() {
return loginTypeValue.get();
}
public void setLoginTypeValue(String loginTypeValue) {
this.loginTypeValue.set(loginTypeValue);
}
public String getUserInfoAccount() {
return userInfoAccount.get();
}
public void setUserInfoAccount(String userInfoAccount) {
this.userInfoAccount.set(userInfoAccount);
}
public String getUserInfoPassword() {
return userInfoPassword.get();
}
public void setUserInfoPassword(String userInfoPassword) {
this.userInfoPassword.set(userInfoPassword);
}
public String getUserInfoUrl() {
return userInfoUrl.get();
}
public void setUserInfoUrl(String userInfoUrl) {
this.userInfoUrl.set(userInfoUrl);
}
public String getFrAdminAccount() {
return frAdminAccount.get();
}
public void setFrAdminAccount(String frAdminAccount) {
this.frAdminAccount.set(frAdminAccount);
}
@Override
public Object clone() throws CloneNotSupportedException {
CustomDataConfig cloned = (CustomDataConfig) super.clone();
cloned.appValidityDuration = (Conf<Integer>) appValidityDuration.clone();
cloned.appSecurityKey = (Conf<String>) appSecurityKey.clone();
cloned.idmClientId = (Conf<String>) idmClientId.clone();
cloned.idmClientSecret = (Conf<String>) idmClientSecret.clone();
cloned.frUrl = (Conf<String>) frUrl.clone();
cloned.oAuthCodeUrl = (Conf<String>) oAuthCodeUrl.clone();
cloned.accessTokenUrl = (Conf<String>) accessTokenUrl.clone();
cloned.userUrl = (Conf<String>) userUrl.clone();
cloned.loginTypeNameParameter = (Conf<String>) loginTypeNameParameter.clone();
cloned.loginTypeValue = (Conf<String>) loginTypeValue.clone();
cloned.userInfoAccount = (Conf<String>) userInfoAccount.clone();
cloned.userInfoPassword = (Conf<String>) userInfoPassword.clone();
cloned.userInfoUrl = (Conf<String>) userInfoUrl.clone();
cloned.frAdminAccount = (Conf<String>) frAdminAccount.clone();
return cloned;
}
}

24
src/main/java/com/fr/plugin/third/party/jsdhcjd/config/DataConfigInitializeMonitor.java

@ -0,0 +1,24 @@
package com.fr.plugin.third.party.jsdhcjd.config;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.record.analyzer.EnableMetrics;
/**
* 配置信息初始化
*/
@EnableMetrics
public class DataConfigInitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.third.party.jsd7293", text = "plugin-jsd-7293", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
CustomDataConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

101
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/BmpFlowUtils.java

@ -0,0 +1,101 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import com.fanruan.api.data.TableDataKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.ParameterMapNameSpace;
import com.fr.base.TableData;
import com.fr.general.data.DataModel;
import com.fr.general.data.TableDataException;
import com.fr.script.Calculator;
import com.fr.stable.Primitive;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class BmpFlowUtils {
public static String getDataModelValueAt(DataModel dataModel, int row, int col) throws TableDataException {
Object value = dataModel.getValueAt(row, col);
if (value == null) {
return "";
}
if (value instanceof Primitive) {
return "";
}
String tempValue = String.valueOf(value);
return tempValue;
}
public static String getUuid() {
String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}
public synchronized static String getSysTime() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
String nowData = format.format(date);
return nowData;
}
public synchronized static String getTimestamp() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
Date date = new Date();
String nowData = format.format(date);
return nowData;
}
public synchronized static String getRandomValue() {
int value = (int) (1 + Math.random() * (9999 - 1 + 1));
String tempValue = String.valueOf(value);
int len = tempValue.length();
String tempStr = tempValue;
if (len == 1) {
tempStr = "000" + tempValue;
} else if (len == 2) {
tempStr = "00" + tempValue;
} else if (len == 3) {
tempStr = "0" + tempValue;
}
return tempStr;
}
public static String getBizTransactionId(String qz) {
String tempValue = qz +"_" + getTimestamp() + "_" + getRandomValue();
return tempValue;
}
public static DataModel getDataDataModel(String dataId, String dataSetName) {
if (StringKit.isEmpty(dataId) || StringKit.isEmpty(dataSetName)) {
return null;
}
TableData tableData = TableDataKit.findTableData(dataSetName);
if (tableData == null) {
return null;
}
Calculator cal = Calculator.createCalculator();
Map map = new HashMap();
map.put("P_BHID", dataId);
ParameterMapNameSpace space = ParameterMapNameSpace.create(map);
cal.pushNameSpace(space);
DataModel dataModel = tableData.createDataModel(cal);
return dataModel;
}
}

403
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpDataModel.java

@ -0,0 +1,403 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.CustomConfig;
import com.fr.base.TableData;
import com.fr.data.AbstractDataModel;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.type.operation.OperationType;
import com.fr.decision.authority.data.CustomRole;
import com.fr.decision.authority.data.User;
import com.fr.decision.authority.data.personnel.DepRole;
import com.fr.decision.webservice.bean.user.UserAdditionBean;
import com.fr.decision.webservice.bean.user.UserAvailableFilter;
import com.fr.decision.webservice.impl.user.UserPageQueryBasicParam;
import com.fr.decision.webservice.utils.ControllerFactory;
import com.fr.decision.webservice.utils.DecisionStatusService;
import com.fr.decision.webservice.utils.controller.UserController;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.general.data.TableDataException;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdhcjd.config.CustomDataConfig;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.stable.query.data.DataList;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpHeaders;
import com.fr.third.org.apache.http.HttpStatus;
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.HttpPost;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.text.SimpleDateFormat;
import java.util.*;
public class CustomHttpDataModel extends AbstractDataModel {
private static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
private static String[] COLUMN_NAMES = {"user_id", "username", "password", "mobile", "mail"};
private int rowCount = TableData.RESULT_ALL;
private DatasetData datas = new DatasetData();
private List<String> updateUsers = new ArrayList<>();
public CustomHttpDataModel(int count) {
this.rowCount = count;
if (this.rowCount == 0) {
return;
}
queryData();
}
@Override
public int getColumnCount() throws TableDataException {
return COLUMN_NAMES.length;
}
@Override
public String getColumnName(int i) throws TableDataException {
return COLUMN_NAMES[i];
}
@Override
public boolean hasRow(int rowIndex) throws TableDataException {
int count = getRowCount();
return rowIndex < count;
}
@Override
public int getRowCount() throws TableDataException {
if (this.datas == null) {
return 0;
}
List<List<Object>> values = this.datas.getValues();
if (values == null) {
return 0;
}
int count = values.size();
return count;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException {
if (this.datas == null) {
return "";
}
List<List<Object>> values = this.datas.getValues();
if ((values == null) || (values.size() <= rowIndex)) {
return "";
}
List<Object> rowValues = values.get(rowIndex);
if ((rowValues == null) || (rowValues.size() <= columnIndex)) {
return "";
}
return rowValues.get(columnIndex);
}
@Override
public void release() throws Exception {
this.datas = null;
}
/**
* 查询数据
*/
private void queryData() {
try {
createDatas();
} catch (Exception e) {
LogKit.error("IDM数据集获取用户信息,请求出错," + e.getMessage(), e);
throw new NullPointerException("IDM数据集获取用户信息为空");
}
}
private void createDatas() throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(10000)
.setSocketTimeout(10000) // 服务端相应超时
.setConnectTimeout(10000) // 建立socket链接超时时间
.build();
HttpPost httpPost = new HttpPost(CustomDataConfig.getInstance().getUserInfoUrl());
httpPost.setConfig(requestConfig);
httpPost.addHeader("User-Agent", DEFAULT_USER_AGENT);
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
String auth = CustomDataConfig.getInstance().getUserInfoAccount() + ":" + CustomDataConfig.getInstance().getUserInfoPassword();
String tempAuthValue = Base64.getEncoder().encodeToString(auth.getBytes());
String authValue = "Basic " + tempAuthValue;
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authValue);
long endTimestamp = System.currentTimeMillis();
long beginTimestamp = endTimestamp - 1000 * 60 * 60 * 24 * 3;
String beginStr = getDate(beginTimestamp);
String endStr = getDate(endTimestamp);
String id = BmpFlowUtils.getUuid();
String bodyContent = "{\n" +
"\"I_REQUEST\": {\n" +
"\"REQ_BASEINFO\": {\n" +
"\"REQ_SRC_SYS\": \"BS-SHPT-P\",\n" +
"\"REQ_BSN_ID\": \"" + id + "\",\n" +
"\"REQ_REPEAT_CYCLE\": \"60\",\n" +
"\"REQ_RETRY_TIMES\": \"1\",\n" +
"\"REQ_REPEAT_FLAG\": \"1\",\n" +
"\"REQ_SEND_TIME\": \"" + BmpFlowUtils.getTimestamp() + "\",\n" +
"\"REQ_SYN_FLAG\": \"0\",\n" +
"\"COUNT\": \"1\",\n" +
"\"REQ_TAR_SYS\": \"BS-IDM-P\",\n" +
"\"REQ_SERVER_NAME\": \"PUBLIC_E888_queryIdmUserRestful\",\n" +
"\"REQ_TRACE_ID\": \"" + id + "\",\n" +
"\"BIZTRANSACTIONID\": \"" + BmpFlowUtils.getBizTransactionId("SHPT_E888") + "\"\n" +
"},\n" +
"\"MESSAGE\": {\n" +
"\"REQ_ITEM\": {\n" +
"\"BEGINDATE\": \"" + beginStr + "\",\n" +
"\"ENDDATE\": \"" + endStr + "\",\n" +
"\"PAGENO\": 1,\n" +
"\"PAGEROWNO\": 100,\n" +
"\"SYSTEMID\": \"Sunac_IDMUser\"\n" +
"} } } }";
LogKit.info("IDM数据集获取用户信息,请求体,\n" + bodyContent);
httpPost.setEntity(new StringEntity(bodyContent, "UTF-8"));
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
httpClient.close();
LogKit.info("IDM数据集获取用户信息,请求出错,http status:" + statusCode);
throw new Exception("IDM数据集获取用户信息,请求出错,http status:" + statusCode);
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
httpClient.close();
LogKit.info("IDM数据集获取用户信息,请求出错,http响应内容为空");
throw new Exception("IDM数据集获取用户信息,请求出错,http响应内容为空");
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
httpClient.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("IDM数据集获取用户信息,请求出错,http响应内容为空1");
throw new Exception("IDM数据集获取用户信息,请求出错,http响应内容为空1");
}
LogKit.info("IDM数据集获取用户信息,http响应内容\n" + responseContent);
createUpdateUsers(responseContent);
if (getRowCount() <= 0) {
LogKit.info("IDM数据集获取用户信息,用户信息为空");
throw new Exception("IDM数据集获取用户信息,用户信息为空");
}
createSysUsers();
}
private void createUpdateUsers(String content) throws DocumentException {
updateUsers.clear();
if (StringKit.isEmpty(content)) {
return;
}
JSONObject dataJson = new JSONObject(content);
JSONObject resJson = dataJson.getJSONObject("E_RESPONSE");
if (resJson == null) {
return;
}
JSONObject messageJson = resJson.getJSONObject("MESSAGE");
if (messageJson == null) {
return;
}
JSONArray usersJson = messageJson.getJSONArray("LIST");
if ((usersJson == null) || (usersJson.size() <= 0)) {
return;
}
JSONObject userJson;
String userId = "", userName = "", password = "123456", mobile = "", mail = "";
for (int i = 0, max = usersJson.size() - 1; i <= max; i++) {
userJson = usersJson.getJSONObject(i);
userId = userJson.getString("UserLogin");
userId = trimStr(userId);
if (StringKit.isEmpty(userId)) {
continue;
}
userId = userId.toLowerCase();
userName = userJson.getString("Username");
mobile = userJson.getString("Mobile");
mail = userJson.getString("Email");
addRowDatas(userId, userName, password, mobile, mail);
updateUsers.add(userId);
}
/*
String beginStr = "<web:LIST><![CDATA[";
String endStr = "]]></web:LIST>";
int index = content.indexOf(beginStr);
if (index < 0) {
return;
}
int index1 = content.indexOf(endStr, index);
if (index1 < 0) {
return;
}
String userContent = content.substring(index + beginStr.length(), index1);
if (StringKit.isEmpty(userContent)) {
return;
}
Document document = DocumentHelper.parseText(userContent);
Element rootElement = document.getRootElement();
Iterator iterator = rootElement.elementIterator();
Element tempElement;
String userId = "", userName = "", password = "123456", mobile = "", mail = "";
while (iterator.hasNext()) {
tempElement = (Element) iterator.next();
userId = getElementValue(tempElement, "UserLogin");
userId = trimStr(userId);
if (StringKit.isEmpty(userId)) {
continue;
}
userId = userId.toLowerCase();
userName = getElementValue(tempElement, "Username");
mobile = getElementValue(tempElement, "Mobile");
mail = getElementValue(tempElement, "Email");
addRowDatas(userId, userName, password, mobile, mail);
updateUsers.add(userId);
}*/
}
private String getElementValue(Element ele, String name) {
if (ele == null) {
return "";
}
if (StringKit.isEmpty(name)) {
return "";
}
Iterator iterator = ele.elementIterator();
Element tempElement;
while (iterator.hasNext()) {
tempElement = (Element) iterator.next();
if (StringKit.equals(tempElement.getName(), name)) {
return tempElement.getStringValue();
}
}
return "";
}
private String trimStr(String value) {
if (value == null) {
return "";
}
return value.trim();
}
private void createSysUsers() throws Exception {
//List<UserAdditionBean> userAdditionBeanList = getAllUsers(CustomDataConfig.getInstance().getFrAdminAccount(), 1, 1000, "", "userAlias", true, "", UserAvailableFilter.ALL);
Map<String, Object> result = UserService.getInstance().getAllUsers(CustomDataConfig.getInstance().getFrAdminAccount(), 1, 1000, "", "userAlias", true, "", UserAvailableFilter.ALL, new OperationType[0]);
List<UserAdditionBean> userAdditionBeanList = (List<UserAdditionBean>) result.get("items");
UserAdditionBean tempUserAdditionBean;
String userId = "", userName = "", password = "123456", mobile = "", mail = "";
for (int i = 0, max = userAdditionBeanList.size() - 1; i <= max; i++) {
tempUserAdditionBean = userAdditionBeanList.get(i);
userId = tempUserAdditionBean.getUsername();
if (updateUsers.contains(userId)) {
continue;
}
userName = tempUserAdditionBean.getRealName();
mobile = tempUserAdditionBean.getMobile();
mail = tempUserAdditionBean.getEmail();
addRowDatas(userId, userName, password, mobile, mail);
}
}
// {"dept_name", "job_title", "user_id", "username", "password", "mobile", "mail", "code", "fcode"};
private void addRowDatas(String userId, String userName, String password, String mobile, String mail) {
List<Object> rowDatas = new ArrayList<>();
rowDatas.add(userId);
rowDatas.add(userName);
rowDatas.add(password);
rowDatas.add(mobile);
rowDatas.add(mail);
List<List<Object>> values = this.datas.getValues();
values.add(rowDatas);
}
private synchronized String getBizTransactionId() {
//PUBLIC_SUNAC_301_20190918142548
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String id = "PUBLIC_SUNAC_301_" + sdf.format(new Date());
return id;
}
private synchronized String getDate(long timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String str = sdf.format(new Date(timestamp));
return str;
}
public List<UserAdditionBean> getAllUsers(String username, int page, int count, String keyword, String sortBy, boolean asc, String searchBy, UserAvailableFilter available) throws Exception {
String currentUserId = UserService.getInstance().getCurrentUserId(username);
QueryCondition userCondition = QueryFactory.create().addRestriction(RestrictionFactory.notIn("id", getAdminIdSet()));
if (StringUtils.isNotEmpty(sortBy) && User.COLUMNS.contains(sortBy)) {
userCondition.addSort(sortBy, !asc);
} else {
userCondition.addSort("userAlias");
}
if (!StringUtils.equals(username, "userName")) {
userCondition.addSort("id");
}
if (available.generateRestriction() != null) {
userCondition.addRestriction(available.generateRestriction());
}
searchBy = !"mobile".equals(searchBy) && !"email".equals(searchBy) ? "" : searchBy;
UserController userController = ControllerFactory.getInstance().getUserController(currentUserId);
DataList<User> userDataList = userController.findPageUsers(currentUserId, new UserPageQueryBasicParam(page, count, keyword, searchBy), userCondition);
List<UserAdditionBean> userAdditionBeanList = new ArrayList();
if (!userDataList.isEmpty()) {
Iterator var14 = userDataList.getList().iterator();
while (var14.hasNext()) {
User user = (User) var14.next();
UserAdditionBean userAdditionBean = new UserAdditionBean(user.getEmail(), user.isEnable(), user.getMobile(), user.getRealName(), user.getUserName(), user.getId());
List<DepRole> depRoles = AuthorityContext.getInstance().getDepartmentController().findDepRoleByUser(user.getId());
userAdditionBean.setDepPostNames((DepRole[]) depRoles.toArray(new DepRole[0]));
List<CustomRole> roles = AuthorityContext.getInstance().getCustomRoleController().findByUser(user.getId(), QueryFactory.create());
userAdditionBean.setRoleIdNames((CustomRole[]) roles.toArray(new CustomRole[0]));
userAdditionBeanList.add(userAdditionBean);
}
}
return userAdditionBeanList;
}
private Set<String> getAdminIdSet() throws Exception {
Set<String> adminIds = (Set) DecisionStatusService.superUserService().get("superUserIdSet");
if (adminIds == null || adminIds.isEmpty()) {
UserService.getInstance().initSuperUserCustomRoleIds();
adminIds = (Set) DecisionStatusService.superUserService().get("superUserIdSet");
}
return adminIds;
}
}

18
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableData.java

@ -0,0 +1,18 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import com.fr.base.TableData;
import com.fr.data.AbstractParameterTableData;
import com.fr.general.data.DataModel;
import com.fr.script.Calculator;
public class CustomHttpTableData extends AbstractParameterTableData {
@Override
public DataModel createDataModel(Calculator calculator) {
return createDataModel(calculator, TableData.RESULT_ALL);
}
@Override
public DataModel createDataModel(Calculator calculator, int rowCount) {
return new CustomHttpDataModel(rowCount);
}
}

50
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableDataDefine.java

@ -0,0 +1,50 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import com.fr.base.TableData;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.fun.ServerTableDataDefineProvider;
import com.fr.design.fun.impl.AbstractTableDataDefineProvider;
import com.fr.design.i18n.Toolkit;
public class CustomHttpTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider {
@Override
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public Class<? extends TableData> classForTableData() {
return CustomHttpTableData.class;
}
@Override
public Class<? extends TableData> classForInitTableData() {
return CustomHttpTableData.class;
}
@Override
public Class<? extends AbstractTableDataPane> appearanceForTableData() {
return CustomHttpTableDataPane.class;
}
@Override
public String nameForTableData() {
return Toolkit.i18nText("IDM用户数据集");
}
@Override
public String prefixForTableData() {
return "idm_users";
}
@Override
public String iconPathForTableData() {
return "";
}
}

76
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/CustomHttpTableDataPane.java

@ -0,0 +1,76 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UIButton;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.general.IOUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CustomHttpTableDataPane extends AbstractTableDataPane<CustomHttpTableData> {
public CustomHttpTableDataPane() {
super();
createContent();
}
@Override
public void populateBean(CustomHttpTableData ob) {
if (ob == null) {
return;
}
}
@Override
public CustomHttpTableData updateBean() {
CustomHttpTableData tableData = new CustomHttpTableData();
return tableData;
}
@Override
protected String title4PopupWindow() {
return DesignKit.i18nText("IDM用户数据集");
}
private void createContent() {
setLayout(new BorderLayout());
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
add(contentPane, BorderLayout.CENTER);
JPanel connectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
UIButton previewButton = createIconButton("Fine-Design_Basic_Preview", "/com/fr/design/images/m_file/preview.png");
previewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PreviewTablePane.previewTableData(updateBean());
}
});
connectionPanel.add(previewButton);
contentPane.add(connectionPanel, BorderLayout.NORTH);
}
/**
* 获取图标按钮
*
* @param toolTip 提示信息,国际化key
* @param iconPath 图标路径
* @return
*/
public static UIButton createIconButton(String toolTip, String iconPath) {
UIButton iconButton = new UIButton(IOUtils.readIcon(iconPath));
iconButton.setToolTipText(DesignKit.i18nText(toolTip));
return iconButton;
}
}

67
src/main/java/com/fr/plugin/third/party/jsdhcjd/data/DatasetData.java

@ -0,0 +1,67 @@
package com.fr.plugin.third.party.jsdhcjd.data;
import java.util.ArrayList;
import java.util.List;
/**
* 数据集数据
*/
public class DatasetData {
private String name;
private List<String> columns;
private List<List<Object>> values;
public DatasetData() {
columns = new ArrayList<String>();
values = new ArrayList<List<Object>>();
}
/**
* 获取表名
* @return 表名
*/
public String getName() {
return this.name;
}
/**
* 设置表名
* @param name 表名
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取列名
* @return 列名
*/
public List<String> getColumns() {
return this.columns;
}
/**
* 设置列名
* @param columns 列名
*/
public void setColumns(List<String> columns) {
this.columns = columns;
}
/**
* 获取表数据
* @return 表数据
*/
public List<List<Object>> getValues() {
return this.values;
}
/**
* 设置表数据
* @param values
*/
public void setValues(List<List<Object>> values) {
this.values = values;
}
}

559
src/main/java/com/fr/plugin/third/party/jsdhcjd/http/SessionGlobalRequestFilterProvider.java

@ -0,0 +1,559 @@
package com.fr.plugin.third.party.jsdhcjd.http;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.data.NetworkHelper;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.decision.mobile.terminal.TerminalHandler;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.login.TokenResource;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.general.ComparatorUtils;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.third.party.jsdhcjd.config.CustomDataConfig;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpHeaders;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.NameValuePair;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity;
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.client.methods.HttpPost;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.message.BasicNameValuePair;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.web.utils.WebUtils;
import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFilterProvider {
private static CloseableHttpClient httpClient = HttpClients.createDefault();
private static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
@Override
public String filterName() {
return "com.fr.plugin.third.party.jsd7293";
}
@Override
public String[] urlPatterns() {
return new String[]{"/decision", "/decision/*"};
}
@Override
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
try {
String fullUrl = req.getRequestURL().toString();
String queryUrl = req.getQueryString();
if ("null".equalsIgnoreCase(queryUrl)) {
queryUrl = "";
} else {
queryUrl = "?" + queryUrl;
}
String fullUrl1 = fullUrl + queryUrl;
String method = req.getMethod();
LogKit.info("融创集成登录,记录访问地址:" + method + " " + fullUrl1);
if (fullUrl.indexOf("/remote/") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (!"GET".equalsIgnoreCase(method)) {
filterChain.doFilter(req, res);
return;
}
boolean option = isLogged(req);
if (option) {
filterChain.doFilter(req, res);
return;
}
if (isAllowIdmOAuthLogin(req)) {
String state = getUuid();
String requestUrl = getRequestUrl(req);
LogKit.info("融创集成登录,访问地址," + requestUrl);
CustomDataConfig.addUrl(state, requestUrl);
String locationUrl = getOAuthCodeUrl(state);
res.sendRedirect(locationUrl);
return;
}
String loginUsername = getIdmOAuthUsername(req);
boolean pcOption = false;
if (StringKit.isNotEmpty(loginUsername)) {
pcOption = true;
LogKit.info("融创集成登录,IDM OAuth 用户名:" + loginUsername);
} else if (isAllowAppLogin(req)) {
String appUsername = WebUtils.getHTTPRequestParameter(req, "uid");
loginUsername = appUsername;
LogKit.info("融创集成登录,用户名:" + loginUsername + "移动端验证通过");
}
if (StringKit.isEmpty(loginUsername)) {
filterChain.doFilter(req, res);
return;
}
//User user = getUserByUserNameIgnoreCase(loginUsername);
loginUsername = loginUsername.toLowerCase();
User user = UserService.getInstance().getUserByUserName(loginUsername);
boolean tipsOption = false;
String tipsContent = "";
if (user == null) {
tipsOption = true;
LogKit.info("融创集成登录,用户名:" + loginUsername + "在报表平台不存在");
tipsContent = "在报表服务器上不存在";
} else if (!user.isEnable()) {
tipsOption = true;
LogKit.info("融创集成登录,用户名:" + loginUsername + "在报表平台上被禁用");
tipsContent = "在报表平台上被禁用";
}
if (tipsOption) {
String jumpContent = "<!doctype html>\n" +
"<head>\n" +
" <meta charset=\"utf-8\" />\n" +
" <title>提示</title>\n" +
"</head>\n" +
"<body>\n" +
" <script>\n" +
" var t = 20;\n" +
" var referI = setInterval(\"refer()\", 1000);\n" +
" function refer() {\n" +
" document.getElementById('show').innerHTML = \"用户:" + loginUsername + tipsContent + ",请联系管理员!<br>\" + t + \"秒后跳转到报表首页\"; \n" +
" t--;\n" +
" if (t <= 0) {\n" +
" clearInterval(referI);\n" +
" window.location = \"" + CustomDataConfig.getInstance().getFrUrl() + "\";\n" +
" }\n" +
" }\n" +
" </script>\n" +
" <div style=\"width: 100%;height:200px; line-height: 200px;font-size:30px;vertical-align:middle;text-align:center\">\n" +
" <span id=\"show\"></span>\n" +
" </div>\n" +
"</body>\n" +
"</html>";
res.setContentType("text/html;charset=UTF-8");
WebUtils.printAsString(res, jumpContent);
res.setStatus(200);
return;
}
loginUsername = user.getUserName();
LogKit.info("融创集成登录,报表平台用户名:" + loginUsername);
String loginToken = LoginService.getInstance().login(req, res, loginUsername);
req.setAttribute("fine_auth_token", loginToken);
if (pcOption) {
String state = WebUtils.getHTTPRequestParameter(req, "state");
String url = CustomDataConfig.getUrlAndDestroy(state);
LogKit.info("融创集成登录,用户名:" + loginUsername + "在报表平台,state url:" + url);
url = changeUrlScheme(url);
if (StringKit.isNotEmpty(url)) {
LogKit.info("融创集成登录,用户名:" + loginUsername + "在报表平台," + url);
res.sendRedirect(url);
return;
}
}
filterChain.doFilter(req, res);
} catch (Exception e) {
FineLoggerFactory.getLogger().error("融创集成登录出错," + e.getMessage(), e);
}
}
private String changeUrlScheme(String url) {
if (StringKit.isEmpty(url)) {
return "";
}
if ((!url.startsWith("http://")) && (!url.startsWith("https://"))) {
return url;
}
String frUrl = CustomDataConfig.getInstance().getFrUrl();
if (StringKit.isEmpty(frUrl)) {
return url;
}
if ((url.startsWith("http://")) && (frUrl.startsWith("http://"))) {
return url;
}
if ((url.startsWith("https://")) && (frUrl.startsWith("https://"))) {
return url;
}
String tempUrl = url;
if ((url.startsWith("http://")) && (frUrl.startsWith("https://"))) {
tempUrl = "https://" + url.substring(7);
}
if ((url.startsWith("https://")) && (frUrl.startsWith("http://"))) {
tempUrl = "http://" + url.substring(8);
}
return tempUrl;
}
public boolean isLogged(HttpServletRequest req) {
boolean logged = true;
try {
String token = TokenResource.COOKIE.getToken(req);
LoginService.getInstance().loginStatusValid(token, TerminalHandler.getTerminal(req, NetworkHelper.getDevice(req)));
} catch (Exception var4) {
logged = false;
}
return logged;
}
private String getOAuthCodeUrl(String state) {
String url = CustomDataConfig.getInstance().getoAuthCodeUrl() + "?client_id=" + CustomDataConfig.getInstance().getIdmClientId() + "&response_type=code&redirect_uri=" + CustomDataConfig.getInstance().getFrUrl() + "&scope=UserProfile.me&state=" + state;
return url;
}
private String getUuid() {
String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}
/**
* 判断app是否允许登录IDM OAuth
*
* @param req
* @return
*/
private boolean isAllowIdmOAuthLogin(HttpServletRequest req) {
if (req == null) {
return false;
}
String loginTypeNameParameter = CustomDataConfig.getInstance().getLoginTypeNameParameter();
String loginTypeConfigValue = CustomDataConfig.getInstance().getLoginTypeValue();
if (StringKit.isEmpty(loginTypeNameParameter) || StringKit.isEmpty(loginTypeConfigValue)) {
return false;
}
String loginTypeValue = WebUtils.getHTTPRequestParameter(req, loginTypeNameParameter);
return ComparatorUtils.equals(loginTypeConfigValue, loginTypeValue);
}
/**
* 判断app是否允许登录
*
* @param req
* @return
*/
private boolean isAllowAppLogin(HttpServletRequest req) {
if (req == null) {
return false;
}
String appUsername = WebUtils.getHTTPRequestParameter(req, "uid");
LogKit.debug("融创集成登录,移动端uid:" + appUsername);
if (StringKit.isEmpty(appUsername)) {
return false;
}
String appTimestamp = WebUtils.getHTTPRequestParameter(req, "timestamp");
LogKit.debug("融创集成登录,移动端timestamp:" + appTimestamp);
if (StringKit.isEmpty(appTimestamp)) {
return false;
}
String appToken = WebUtils.getHTTPRequestParameter(req, "token");
LogKit.debug("融创集成登录,移动端token:" + appToken);
if (StringKit.isEmpty(appToken)) {
return false;
}
return isAllowAppLogin(appUsername, appTimestamp, appToken);
}
/**
* 判断app是否允许登录
*
* @param timestamp
* @param token
* @return
*/
private boolean isAllowAppLogin(String username, String timestamp, String token) {
if (StringKit.isEmpty(timestamp) || StringKit.isEmpty(token)) {
return false;
}
if (!isNumeric(timestamp)) {
LogKit.debug("融创集成登录,移动端timestamp:不是数字");
return false;
}
long timestampValue = Long.valueOf(timestamp);
if (!isValidAppTimestamp(timestampValue)) {
LogKit.debug("融创集成登录,移动端timestamp:失效");
return false;
}
if (!isValidAppToken(username, timestamp, token)) {
LogKit.debug("融创集成登录,移动端token:无效");
return false;
}
return true;
}
private boolean isValidAppTimestamp(long timestamp) {
if (timestamp <= 0) {
return false;
}
long currentTimestamp = System.currentTimeMillis();
long endTimestamp = timestamp + CustomDataConfig.getInstance().getAppValidityDuration() * 6060 * 1000L;
if (endTimestamp >= currentTimestamp) {
return true;
}
return false;
}
private boolean isValidAppToken(String username, String timestamp, String token) {
String tempToken = createToken(username, timestamp);
boolean option = ComparatorUtils.equals(tempToken, token);
return option;
}
private String createToken(String username, String timestamp) {
//=Base64(MD5(uid+timestamp+securityKey))
if (StringKit.isEmpty(username)) {
username = "";
}
if (StringKit.isEmpty(timestamp)) {
timestamp = "";
}
String securityKey = CustomDataConfig.getInstance().getAppSecurityKey();
if (StringKit.isEmpty(securityKey)) {
securityKey = "";
}
String tempValue = username + timestamp + securityKey;
String md5Value = DigestUtils.md5Hex(tempValue);
String token = Base64.getEncoder().encodeToString(md5Value.getBytes());
return token;
}
/**
* 判断字符串是否全是数字
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
if (StringKit.isEmpty(str)) {
return false;
}
for (int i = str.length(); --i >= 0; ) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
/**
* 获取IDM OAuth 用户名
*
* @param req
* @return
*/
private String getIdmOAuthUsername(HttpServletRequest req) {
try {
if (req == null) {
return "";
}
String oAuthCode = WebUtils.getHTTPRequestParameter(req, "code");
if (StringKit.isEmpty(oAuthCode)) {
return "";
}
LogKit.info("融创集成登录,OAuth Code:" + oAuthCode);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(10000)
.setSocketTimeout(10000) // 服务端相应超时
.setConnectTimeout(10000) // 建立socket链接超时时间
.build();
//获取Access Token
String accessTokenUrl = CustomDataConfig.getInstance().getAccessTokenUrl();
HttpPost httpPost = new HttpPost(accessTokenUrl);
httpPost.addHeader("User-Agent", DEFAULT_USER_AGENT);
List<NameValuePair> params = new ArrayList<NameValuePair>();
NameValuePair redirectUriNameValuePair = new BasicNameValuePair("redirect_uri", CustomDataConfig.getInstance().getFrUrl());
NameValuePair codeNameValuePair = new BasicNameValuePair("code", oAuthCode);
NameValuePair grantTypeNameValuePair = new BasicNameValuePair("grant_type", "authorization_code");
params.add(redirectUriNameValuePair);
params.add(codeNameValuePair);
params.add(grantTypeNameValuePair);
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
String auth = CustomDataConfig.getInstance().getIdmClientId() + ":" + CustomDataConfig.getInstance().getIdmClientSecret();
String tempAuthValue = Base64.getEncoder().encodeToString(auth.getBytes());
String authValue = "Basic " + tempAuthValue;
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authValue);
httpPost.setConfig(requestConfig);
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("融创集成登录,获取Access Token请求出错,http status:" + statusCode);
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("融创集成登录,获取Access Token请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("融创集成登录,获取Access Token请求出错,http响应内容为空1");
return "";
}
LogKit.info("融创集成登录,获取Access Token请求,http响应内容\n" + responseContent);
JSONObject jsonObject = new JSONObject(responseContent);
String accessToken = jsonObject.getString("access_token");
if (StringKit.isEmpty(accessToken)) {
LogKit.info("融创集成登录,获取Access Token请求出错,access_token为空");
return "";
}
LogKit.info("融创集成登录,Access Token:" + accessToken);
String userUrl = CustomDataConfig.getInstance().getUserUrl();
HttpGet httpGet = new HttpGet(userUrl);
httpGet.setHeader(HttpHeaders.AUTHORIZATION, accessToken);
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("融创集成登录,获取用户信息请求出错,http status:" + statusCode);
return "";
}
httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("融创集成登录,获取用户信息请求出错,http响应内容为空");
return "";
}
responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("融创集成登录,获取用户信息请求出错,http响应内容为空1");
return "";
}
LogKit.info("融创集成登录,获取用户信息请求,http响应内容\n" + responseContent);
jsonObject = new JSONObject(responseContent);
String uid = jsonObject.getString("uid");
if (StringKit.isEmpty(uid)) {
LogKit.info("融创集成登录,,获取用户信息请求出错,uid为空");
return "";
}
LogKit.info("融创集成登录,uid:" + uid);
return uid;
} catch (Exception e) {
FineLoggerFactory.getLogger().error("融创集成登录获取用户名出错," + e.getMessage(), e);
}
return "";
}
private String getRequestUrl(HttpServletRequest req) {
String fullUrl = req.getRequestURL().toString();
Map<String, String[]> paraMap = req.getParameterMap();
String paraName;
String[] paraValues;
String loginTypeParaName = CustomDataConfig.getInstance().getLoginTypeNameParameter();
String queryStr = "";
for (Map.Entry<String, String[]> entry : paraMap.entrySet()) {
paraName = entry.getKey();
if (ComparatorUtils.equals(paraName, loginTypeParaName)) {
continue;
}
paraValues = entry.getValue();
queryStr = addParaToQuery(queryStr, paraName, paraValues);
}
if (StringKit.isEmpty(queryStr)) {
return fullUrl;
}
fullUrl = fullUrl + "?" + queryStr;
return fullUrl;
}
private String addParaToQuery(String query, String paraName, String[] paraValues) {
if (StringKit.isEmpty(paraName)) {
return query;
}
String fullQuery = query;
if ((paraValues == null) || (paraValues.length <= 0)) {
if (StringKit.isNotEmpty(fullQuery)) {
fullQuery = fullQuery + "&";
}
fullQuery = paraName + "=";
return fullQuery;
}
for (int i = 0, max = paraValues.length - 1; i <= max; i++) {
if (StringKit.isNotEmpty(fullQuery)) {
fullQuery = fullQuery + "&";
}
fullQuery = fullQuery + paraName + "=" + paraValues[i];
}
return fullQuery;
}
/**
* 根据用户名获取用户忽略大小写
*
* @param username
* @return
* @throws Exception
*/
public User getUserByUserNameIgnoreCase(String username) throws Exception {
if (StringUtils.isEmpty(username)) {
return null;
}
List<User> users = AuthorityContext.getInstance().getUserController().find(QueryFactory.create());
if ((users == null) || (users.size() <= 0)) {
return null;
}
User tempUser;
for (int i = 0, max = users.size() - 1; i <= max; i++) {
tempUser = users.get(i);
if (!username.equalsIgnoreCase(tempUser.getUserName())) {
continue;
}
if (UserService.getInstance().isAdmin(tempUser.getId())) {
LogKit.info("融创集成登录,用户名:" + tempUser.getUserName() + "是管理员用户,不允许登录");
return null;
}
return tempUser;
}
return null;
}
}

64
src/main/java/com/fr/plugin/third/party/jsdhcjd/test/XmlTest.java

@ -0,0 +1,64 @@
package com.fr.plugin.third.party.jsdhcjd.test;
import com.fanruan.api.util.StringKit;
import com.fr.web.controller.decision.api.user.UserResource;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.util.Iterator;
public class XmlTest {
public static void main(String[] args) throws DocumentException {
String content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
"<LIST>\n" +
" <USER>\n" +
" <UserLogin>MOXQ</UserLogin>\n" +
" <Username>毛线球</Username>\n" +
" <Email>moxq@sunac.com.cn</Email>\n" +
" <Mobile>13370138749</Mobile> \n" +
" </USER>\n" +
"\t <USER>\n" +
" <UserLogin>MOXQ1</UserLogin>\n" +
" <Username>毛线球1</Username>\n" +
" <Email>moxq@sunac.com.cn1</Email>\n" +
" <Mobile>13370138749a</Mobile> \n" +
" </USER>\n" +
"</LIST>";
Document document = DocumentHelper.parseText(content);
Element rootElement = document.getRootElement();
Iterator iterator = rootElement.elementIterator();
while (iterator.hasNext()) {
Element stu = (Element) iterator.next();
System.out.println(getElementValue(stu,"UserLogin"));
}
//UserResource
}
private static String getElementValue(Element ele, String name) {
if (ele == null) {
return "";
}
if (StringKit.isEmpty(name)) {
return "";
}
Iterator iterator = ele.elementIterator();
Element tempElement;
while (iterator.hasNext()) {
tempElement = (Element) iterator.next();
if(StringKit.equals( tempElement.getName(),name))
{
return tempElement.getStringValue();
}
}
return "";
}
}
Loading…
Cancel
Save