11 changed files with 322 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@ |
|||||||
# open-JSD-8105 |
# open-JSD-8105 |
||||||
|
|
||||||
JSD-8105 开源任务材料 |
JSD-8105 开源任务材料\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
@ -0,0 +1,18 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.third.party.jsd8105</id> |
||||||
|
<name><![CDATA[获取登录token]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>0.2</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> |
||||||
|
<HttpHandlerProvider class="com.fr.plugin.third.party.jsdibaf.http.HttpHandlerProvider"/> |
||||||
|
<URLAliasProvider class="com.fr.plugin.third.party.jsdibaf.http.URLAliasProvider"/> |
||||||
|
</extra-decision> |
||||||
|
<function-recorder class="com.fr.plugin.third.party.jsdibaf.config.DataConfigInitializeMonitor"/> |
||||||
|
<lifecycle-monitor class="com.fr.plugin.third.party.jsdibaf.config.DataConfigInitializeMonitor"/> |
||||||
|
</plugin> |
@ -0,0 +1,134 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf; |
||||||
|
|
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.third.org.apache.http.HttpEntity; |
||||||
|
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.HttpGet; |
||||||
|
import com.fr.third.org.apache.http.client.methods.HttpPost; |
||||||
|
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||||
|
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
||||||
|
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.ssl.SSLContextBuilder; |
||||||
|
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||||
|
import com.fr.third.org.apache.http.util.EntityUtils; |
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier; |
||||||
|
import javax.net.ssl.SSLContext; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.cert.CertificateException; |
||||||
|
import java.security.cert.X509Certificate; |
||||||
|
|
||||||
|
public class Utils { |
||||||
|
public 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"; |
||||||
|
public static RequestConfig REQUEST_CONFIG = RequestConfig.custom() |
||||||
|
.setConnectionRequestTimeout(30000) |
||||||
|
.setSocketTimeout(30000) // 服务端相应超时
|
||||||
|
.setConnectTimeout(30000) // 建立socket链接超时时间
|
||||||
|
.build(); |
||||||
|
|
||||||
|
public static CloseableHttpClient createSSLClientDefault() { |
||||||
|
try { |
||||||
|
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||||
|
return true; |
||||||
|
} |
||||||
|
}).build(); |
||||||
|
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; |
||||||
|
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); |
||||||
|
return HttpClients.custom().setSSLSocketFactory(sslsf).build(); |
||||||
|
} catch (Exception e) { |
||||||
|
LogKit.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return HttpClients.createDefault(); |
||||||
|
} |
||||||
|
|
||||||
|
public static synchronized CloseableHttpClient createHttpClient(String url) { |
||||||
|
CloseableHttpClient httpClient = null; |
||||||
|
if (StringKit.isEmpty(url)) { |
||||||
|
httpClient = HttpClients.createDefault(); |
||||||
|
return httpClient; |
||||||
|
} |
||||||
|
|
||||||
|
if (url.startsWith("https://")) { |
||||||
|
httpClient = createSSLClientDefault(); |
||||||
|
return httpClient; |
||||||
|
} |
||||||
|
httpClient = HttpClients.createDefault(); |
||||||
|
return httpClient; |
||||||
|
} |
||||||
|
|
||||||
|
public static synchronized String createHttpGetContent(CloseableHttpClient httpClient, String url) throws IOException { |
||||||
|
if ((httpClient == null) || (StringKit.isEmpty(url))) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet(url); |
||||||
|
httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT); |
||||||
|
httpGet.setConfig(Utils.REQUEST_CONFIG); |
||||||
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
||||||
|
int statusCode = response.getStatusLine().getStatusCode(); |
||||||
|
if (statusCode != HttpStatus.SC_OK) { |
||||||
|
response.close(); |
||||||
|
LogKit.info("http请求出错,http status:" + statusCode); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
HttpEntity httpEntity = response.getEntity(); |
||||||
|
if (httpEntity == null) { |
||||||
|
response.close(); |
||||||
|
LogKit.info("http请求出错,http响应内容为空"); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
String responseContent = EntityUtils.toString(httpEntity, "UTF-8"); |
||||||
|
response.close(); |
||||||
|
if (StringKit.isEmpty(responseContent)) { |
||||||
|
LogKit.info("http请求出错,http响应内容为空1"); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
return responseContent; |
||||||
|
} |
||||||
|
|
||||||
|
public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent) throws IOException { |
||||||
|
if ((httpClient == null) || (StringKit.isEmpty(url)) || (StringKit.isEmpty(bodyContent))) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
HttpPost httpPost = new HttpPost(url); |
||||||
|
httpPost.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT); |
||||||
|
httpPost.setConfig(Utils.REQUEST_CONFIG); |
||||||
|
StringEntity bodyEntity = new StringEntity(bodyContent, "UTF-8"); |
||||||
|
httpPost.setEntity(bodyEntity); |
||||||
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
||||||
|
int statusCode = response.getStatusLine().getStatusCode(); |
||||||
|
if (statusCode != HttpStatus.SC_OK) { |
||||||
|
response.close(); |
||||||
|
LogKit.info("http请求出错,http status:" + statusCode); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
HttpEntity httpEntity = response.getEntity(); |
||||||
|
if (httpEntity == null) { |
||||||
|
response.close(); |
||||||
|
LogKit.info("http请求出错,http响应内容为空"); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
String responseContent = EntityUtils.toString(httpEntity, "UTF-8"); |
||||||
|
response.close(); |
||||||
|
if (StringKit.isEmpty(responseContent)) { |
||||||
|
LogKit.info("http请求出错,http响应内容为空1"); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
return responseContent; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf.config; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.config.*; |
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.config.holder.factory.Holders; |
||||||
|
|
||||||
|
/** |
||||||
|
* 配置数据保存 |
||||||
|
*/ |
||||||
|
@Visualization(category = "获取登录token配置") |
||||||
|
public class CustomDataConfig extends DefaultConfiguration { |
||||||
|
public String getNameSpace() { |
||||||
|
return this.getClass().getName(); |
||||||
|
} |
||||||
|
|
||||||
|
private static volatile CustomDataConfig config = null; |
||||||
|
|
||||||
|
public static CustomDataConfig getInstance() { |
||||||
|
if (config == null) { |
||||||
|
config = ConfigContext.getConfigInstance(CustomDataConfig.class); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
@Identifier(value = "loginUserName", name = "用户名称参数", description = "", status = Status.SHOW) |
||||||
|
private Conf<String> loginUserName = Holders.simple("fine_username"); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getLoginUserName() { |
||||||
|
return loginUserName.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setLoginUserName(String loginUserName) { |
||||||
|
this.loginUserName.set(loginUserName); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
CustomDataConfig cloned = (CustomDataConfig) super.clone(); |
||||||
|
cloned.loginUserName = (Conf<String>) loginUserName.clone(); |
||||||
|
//cloned.frUrl = (Conf<String>) frUrl.clone();
|
||||||
|
return cloned; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf.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.jsd8105", text = "plugin-jsd-8105", source = Original.PLUGIN) |
||||||
|
public void afterRun(PluginContext pluginContext) { |
||||||
|
CustomDataConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void beforeStop(PluginContext pluginContext) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf.http; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
|
||||||
|
public class HttpHandlerProvider extends AbstractHttpHandlerProvider { |
||||||
|
@Override |
||||||
|
public BaseHttpHandler[] registerHandlers() { |
||||||
|
return new BaseHttpHandler[] { |
||||||
|
new LoginTokenHttpHandler() |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,67 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf.http; |
||||||
|
|
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
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.plugin.third.party.jsdibaf.config.CustomDataConfig; |
||||||
|
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; |
||||||
|
|
||||||
|
public class LoginTokenHttpHandler extends BaseHttpHandler { |
||||||
|
|
||||||
|
@Override |
||||||
|
public RequestMethod getMethod() { |
||||||
|
return RequestMethod.GET; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getPath() { |
||||||
|
return "/jsd8105/get/login/token"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isPublic() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
JSONObject jsonContent = new JSONObject(); |
||||||
|
String loginUserName = WebUtils.getHTTPRequestParameter(req, CustomDataConfig.getInstance().getLoginUserName()); |
||||||
|
if (StringKit.isEmpty(loginUserName)) { |
||||||
|
jsonContent.put("status", "failure"); |
||||||
|
jsonContent.put("msg", "用户名为空"); |
||||||
|
printAsJSON(res,jsonContent); |
||||||
|
return; |
||||||
|
} |
||||||
|
User user = UserService.getInstance().getUserByUserName(loginUserName); |
||||||
|
if (StringKit.isEmpty(loginUserName)) { |
||||||
|
jsonContent.put("status", "failure"); |
||||||
|
jsonContent.put("msg", "用户名" + loginUserName + "在报表系统内不存在"); |
||||||
|
printAsJSON(res,jsonContent); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (!user.isEnable()) { |
||||||
|
jsonContent.put("status", "failure"); |
||||||
|
jsonContent.put("msg", "用户名" + loginUserName + "在报表系统被禁用"); |
||||||
|
printAsJSON(res,jsonContent); |
||||||
|
return; |
||||||
|
} |
||||||
|
String loginToken = LoginService.getInstance().login(req, res, loginUserName); |
||||||
|
jsonContent.put("status", "success "); |
||||||
|
jsonContent.put("token", loginToken); |
||||||
|
printAsJSON(res,jsonContent); |
||||||
|
} |
||||||
|
|
||||||
|
private void printAsJSON(HttpServletResponse res, JSONObject json) throws Exception { |
||||||
|
res.setContentType("application/json"); |
||||||
|
WebUtils.printAsJSON(res, json); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.plugin.third.party.jsdibaf.http; |
||||||
|
|
||||||
|
import com.fanruan.api.net.URLAliasKit; |
||||||
|
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||||
|
import com.fr.decision.webservice.url.alias.URLAlias; |
||||||
|
|
||||||
|
public class URLAliasProvider extends AbstractURLAliasProvider { |
||||||
|
@Override |
||||||
|
public URLAlias[] registerAlias() { |
||||||
|
return new URLAlias[]{ |
||||||
|
URLAliasKit.createPluginAlias("/jsd8105/get/login/token", "/jsd8105/get/login/token", true), |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
Binary file not shown.
Loading…
Reference in new issue