pioneer
2 years ago
commit
23eb3bf98c
20 changed files with 1711 additions and 0 deletions
@ -0,0 +1,7 @@
|
||||
|
||||
# open-JSD-9477 |
||||
|
||||
JSD-9477 一句话简介该插件的功能和场景\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.third.party.jsdidig</id> |
||||
<name><![CDATA[集成登录]]></name> |
||||
<active>yes</active> |
||||
<version>0.15</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.jsdidig.http.CustomHttpHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.third.party.jsdidig.http.CustomURLAliasProvider"/> |
||||
<WebResourceProvider class="com.fr.plugin.third.party.jsdidig.web.MainWebResourceProvider"/> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.third.party.jsdidig.http.SessionGlobalRequestFilterProvider"/> |
||||
</extra-decision> |
||||
<extra-designer> |
||||
<ServerTableDataDefineProvider class="com.fr.plugin.third.party.jsdidig.data.CustomHttpTableDataDefine"/> |
||||
<TableDataDefineProvider class="com.fr.plugin.third.party.jsdidig.data.CustomHttpTableDataDefine"/> |
||||
</extra-designer> |
||||
<function-recorder class="com.fr.plugin.third.party.jsdidig.config.DataConfigInitializeMonitor"/> |
||||
<lifecycle-monitor class="com.fr.plugin.third.party.jsdidig.config.DataConfigInitializeMonitor"/> |
||||
</plugin> |
@ -0,0 +1,212 @@
|
||||
package com.fr.plugin.third.party.jsdidig; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.plugin.third.party.jsdidig.config.CustomDataConfig; |
||||
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 com.fr.third.springframework.web.util.UriUtils; |
||||
|
||||
import javax.net.ssl.HostnameVerifier; |
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.UUID; |
||||
|
||||
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, String basicAuth) throws IOException { |
||||
if ((httpClient == null) || (StringKit.isEmpty(url))) { |
||||
return ""; |
||||
} |
||||
|
||||
HttpGet httpGet = new HttpGet(url); |
||||
httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT); |
||||
if (StringKit.isNotEmpty(basicAuth)) { |
||||
httpGet.addHeader("Authorization", basicAuth); |
||||
} |
||||
|
||||
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; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取完整请求链接 |
||||
* |
||||
* @param req 请求 |
||||
* @return |
||||
*/ |
||||
public static String getFullRequestUrl(HttpServletRequest req) { |
||||
if (req == null) { |
||||
return ""; |
||||
} |
||||
String url = req.getRequestURL().toString(); |
||||
String queryUrl = req.getQueryString(); |
||||
if ((queryUrl == null) || "null".equalsIgnoreCase(queryUrl)) { |
||||
queryUrl = ""; |
||||
} else { |
||||
queryUrl = "?" + queryUrl; |
||||
} |
||||
String fullUrl = url + queryUrl; |
||||
return fullUrl; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 重定向 |
||||
* |
||||
* @param res |
||||
* @param url |
||||
*/ |
||||
public static void sendRedirect(HttpServletResponse res, String url) { |
||||
if ((res == null) || (StringKit.isEmpty(url))) { |
||||
return; |
||||
} |
||||
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); |
||||
res.setHeader("Location", url); |
||||
} |
||||
|
||||
|
||||
public static synchronized String getUuid() { |
||||
String uuid = UUID.randomUUID().toString().replace("-", ""); |
||||
return uuid; |
||||
} |
||||
|
||||
public static String getOAuthCodeUrl(String url) throws UnsupportedEncodingException { |
||||
//http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/authorize?client_id=oauthdemo&redirect_uri=http://application.com:9700/oauthdemo&response_type=code
|
||||
//String mappingUrl = CustomDataConfig.getInstance().getFrUrl() + "?url_id=" + state;
|
||||
String tempUrl = UriUtils.encodeQueryParam(url, "UTF-8"); |
||||
LogKit.info("龙光IDM集成登录,授权报表地址:" + url); |
||||
//if (tempUrl.indexOf("?") >= 0) {
|
||||
// tempUrl = UriUtils.encodeQueryParam(tempUrl, "UTF-8");
|
||||
//}
|
||||
String authUrl = CustomDataConfig.getInstance().getoAuthCodeUrl() + "?client_id=" + CustomDataConfig.getInstance().getIdmClientId() + "&redirect_uri=" + tempUrl + "&response_type=code"; |
||||
LogKit.info("龙光IDM集成登录,获取临时授权码地址:" + authUrl); |
||||
return authUrl; |
||||
} |
||||
|
||||
|
||||
public static String getOAuthCodeUrlWithFr() throws UnsupportedEncodingException { |
||||
String url = CustomDataConfig.getInstance().getFrUrl(); |
||||
return getOAuthCodeUrl(url); |
||||
} |
||||
|
||||
|
||||
public static String getLogoutUrl() throws UnsupportedEncodingException { |
||||
String url = CustomDataConfig.getInstance().getFrUrl(); |
||||
String tempUrl = UriUtils.encodeQueryParam(url, "UTF-8"); |
||||
String logoutUrl = CustomDataConfig.getInstance().getLogoutUrl() + "?service=" + tempUrl + "&client_id=" + CustomDataConfig.getInstance().getIdmClientId(); |
||||
return logoutUrl; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,205 @@
|
||||
package com.fr.plugin.third.party.jsdidig.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
|
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
/** |
||||
* 配置数据保存 |
||||
*/ |
||||
@Visualization(category = "龙光IDM集成登录配置") |
||||
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; |
||||
} |
||||
private static ConcurrentHashMap<String, String> URL_MAP = new ConcurrentHashMap<String, String>(); |
||||
|
||||
/** |
||||
* 添加链接 |
||||
* @param key |
||||
* @param url |
||||
*/ |
||||
public static synchronized void addUrl(String key, String url) { |
||||
URL_MAP.put(key, url); |
||||
} |
||||
|
||||
/** |
||||
* 获取链接并销毁保存 |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
public static synchronized String getUrlAndDestroy(String key) { |
||||
String url = URL_MAP.get(key); |
||||
URL_MAP.remove(key); |
||||
return url; |
||||
} |
||||
|
||||
@Identifier(value = "idmClientId", name = "客户端id(client_id)", description = "", status = Status.SHOW) |
||||
private Conf<String> idmClientId = Holders.simple(""); |
||||
|
||||
|
||||
@Identifier(value = "idmClientSecret", name = "客户端密钥(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(""); |
||||
|
||||
|
||||
@Identifier(value = "oAuthCodeUrl", name = "获取临时令牌接口地址", description = "", status = Status.SHOW) |
||||
private Conf<String> oAuthCodeUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/authorize"); |
||||
|
||||
|
||||
@Identifier(value = "accessTokenUrl", name = "获取Access Token地址(json)", description = "", status = Status.SHOW) |
||||
private Conf<String> accessTokenUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/accessTokenByJson"); |
||||
|
||||
|
||||
@Identifier(value = "userUrl", name = "获取用户信息地址(json)", description = "", status = Status.SHOW) |
||||
private Conf<String> userUrl = Holders.simple("http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/profileByJson"); |
||||
|
||||
|
||||
@Identifier(value = "userSyncUrl", name = "用户同步的地址", description = "", status = Status.SHOW) |
||||
private Conf<String> userSyncUrl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "userSyncUsername", name = "用户同步的用户名", description = "", status = Status.SHOW) |
||||
private Conf<String> userSyncUsername = Holders.simple(""); |
||||
|
||||
@Identifier(value = "userSyncPassword", name = "用户同步的密码", description = "", status = Status.SHOW) |
||||
private Conf<String> userSyncPassword = Holders.simple(""); |
||||
|
||||
@Identifier(value = "logoutUrl", name = "退出登录地址", description = "", status = Status.SHOW) |
||||
private Conf<String> logoutUrl = Holders.simple("http://siam.logan.com.cn/siam/logout"); |
||||
|
||||
|
||||
@Identifier(value = "loginTypeNameParameter", name = "登录类型参数名称", description = "", status = Status.HIDE) |
||||
private Conf<String> loginTypeNameParameter = Holders.simple("loginType"); |
||||
|
||||
|
||||
@Identifier(value = "loginTypeValue", name = "登录类型值", description = "", status = Status.HIDE) |
||||
private Conf<String> loginTypeValue = Holders.simple("OAUTH"); |
||||
|
||||
public String getLogoutUrl() { |
||||
return logoutUrl.get(); |
||||
} |
||||
|
||||
public void setLogoutUrl(String logoutUrl) { |
||||
this.logoutUrl.set(logoutUrl); |
||||
} |
||||
|
||||
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 getUserSyncUrl() { |
||||
return userSyncUrl.get(); |
||||
} |
||||
|
||||
public void setUserSyncUrl(String userSyncUrl) { |
||||
this.userSyncUrl.set(userSyncUrl); |
||||
} |
||||
|
||||
public String getUserSyncUsername() { |
||||
return userSyncUsername.get(); |
||||
} |
||||
|
||||
public void setUserSyncUsername(String userSyncUsername) { |
||||
this.userSyncUsername.set(userSyncUsername); |
||||
} |
||||
|
||||
public String getUserSyncPassword() { |
||||
return userSyncPassword.get(); |
||||
} |
||||
|
||||
public void setUserSyncPassword(String userSyncPassword) { |
||||
this.userSyncPassword.set(userSyncPassword); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
CustomDataConfig cloned = (CustomDataConfig) super.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.logoutUrl = (Conf<String>) logoutUrl.clone(); |
||||
cloned.loginTypeNameParameter = (Conf<String>) loginTypeNameParameter.clone(); |
||||
cloned.loginTypeValue = (Conf<String>) loginTypeValue.clone(); |
||||
cloned.userSyncUrl = (Conf<String>) userSyncUrl.clone(); |
||||
cloned.userSyncUsername = (Conf<String>) userSyncUsername.clone(); |
||||
cloned.userSyncPassword = (Conf<String>) userSyncPassword.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
/** |
||||
* 配置信息初始化 |
||||
*/ |
||||
@EnableMetrics |
||||
@Authorize(callSignKey = "com.fr.plugin.third.party.jsdidig") |
||||
public class DataConfigInitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
@Focus(id = "com.fr.plugin.third.party.jsdidig", text = "plugin-jsdidig", source = Original.PLUGIN) |
||||
public void afterRun(PluginContext pluginContext) { |
||||
CustomDataConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,248 @@
|
||||
package com.fr.plugin.third.party.jsdidig.data; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractDataModel; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.third.party.jsdidig.Utils; |
||||
import com.fr.plugin.third.party.jsdidig.config.CustomDataConfig; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.utils.Base64; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class CustomHttpDataModel extends AbstractDataModel { |
||||
private static String[] COLUMN_NAMES = {"user_id", "username", "password", "mail", "mobile"}; |
||||
private int rowCount = TableData.RESULT_ALL; |
||||
private DatasetData datas = new DatasetData(); |
||||
|
||||
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(); |
||||
//if (getRowCount() <= 0) {
|
||||
// throw new NullPointerException("ESB用户数据集获取用户信息为空");
|
||||
//}
|
||||
} catch (Exception e) { |
||||
LogKit.error("ESB用户数据集获取用户信息,请求出错," + e.getMessage() + "," + e.getCause(), e); |
||||
throw new NullPointerException("ESB用户数据集获取用户信息,请求出错," + e.getMessage() + "," + e.getCause()); |
||||
} |
||||
} |
||||
|
||||
private void createDatas() throws Exception { |
||||
String userSyncUrl = CustomDataConfig.getInstance().getUserSyncUrl(); |
||||
String userSyncUsername = CustomDataConfig.getInstance().getUserSyncUsername(); |
||||
String userSyncPassword = CustomDataConfig.getInstance().getUserSyncPassword(); |
||||
if (StringKit.isEmpty(userSyncUrl) || StringKit.isEmpty(userSyncUsername) || StringKit.isEmpty(userSyncPassword)) { |
||||
return; |
||||
} |
||||
|
||||
CloseableHttpClient httpClient = Utils.createHttpClient(userSyncUrl); |
||||
String authValue = userSyncUsername + ":" + userSyncPassword; |
||||
String auth = "Basic " + Base64.getEncoder().encodeToString(authValue.getBytes("utf-8")); |
||||
String content = "", cookie = "", syncUrl = ""; |
||||
int syncCount = 0; |
||||
do { |
||||
syncUrl = userSyncUrl; |
||||
if (StringKit.isNotEmpty(cookie)) { |
||||
syncUrl = userSyncUrl + "&cookie=" + cookie; |
||||
} |
||||
content = Utils.createHttpGetContent(httpClient, syncUrl, auth); |
||||
if (StringKit.isEmpty(content)) { |
||||
httpClient.close(); |
||||
return; |
||||
} |
||||
syncCount++; |
||||
LogKit.info("ESB用户数据集,json内容" + syncCount + ":\n" + content); |
||||
addUsers(content); |
||||
cookie = getCookieValue(content); |
||||
LogKit.info("ESB用户数据集,cookie内容" + syncCount + ":" + cookie); |
||||
} while (StringKit.isNotEmpty(cookie)); |
||||
httpClient.close(); |
||||
} |
||||
|
||||
private void addUsers(String content) throws TableDataException { |
||||
String deptName = "", jobTitle = "", userId = "", userName = "", password = "", mobile = "", mail = "", userDesc = ""; |
||||
if (StringKit.isEmpty(content)) { |
||||
return; |
||||
} |
||||
JSONObject resJson = new JSONObject(content); |
||||
JSONObject resultInfoJson = resJson.getJSONObject("resultInfo"); |
||||
if (resultInfoJson == null) { |
||||
return; |
||||
} |
||||
String success = resultInfoJson.getString("success", ""); |
||||
if (!"true".equalsIgnoreCase(success)) { |
||||
return; |
||||
} |
||||
|
||||
JSONObject bodyJson = resultInfoJson.getJSONObject("body"); |
||||
if (bodyJson == null) { |
||||
return; |
||||
} |
||||
|
||||
JSONArray wsUsersJson = bodyJson.getJSONArray("wsUsers"); |
||||
if ((wsUsersJson == null) || (wsUsersJson.size() <= 0)) { |
||||
return; |
||||
} |
||||
|
||||
JSONArray attributesJson; |
||||
JSONObject attributeJson; |
||||
String userStatus, name, value; |
||||
for (int i = 0, max = wsUsersJson.size() - 1; i <= max; i++) { |
||||
attributesJson = wsUsersJson.getJSONObject(i).getJSONArray("attributes"); |
||||
if (attributesJson == null) { |
||||
continue; |
||||
} |
||||
userId = ""; |
||||
userName = ""; |
||||
password = "123456"; |
||||
mail = ""; |
||||
mobile = ""; |
||||
userStatus = "1"; |
||||
for (int j = 0, jMax = attributesJson.size() - 1; j <= jMax; j++) { |
||||
attributeJson = attributesJson.getJSONObject(j); |
||||
name = attributeJson.getString("name"); |
||||
if (StringKit.equalsIgnoreCase("alias", name)) { |
||||
userId = attributeJson.getString("value"); |
||||
continue; |
||||
} |
||||
if (StringKit.equalsIgnoreCase("usercn", name)) { |
||||
userName = attributeJson.getString("value"); |
||||
continue; |
||||
} |
||||
if (StringKit.equalsIgnoreCase("mail", name)) { |
||||
mail = attributeJson.getString("value"); |
||||
continue; |
||||
} |
||||
if (StringKit.equalsIgnoreCase("mobile", name)) { |
||||
mobile = attributeJson.getString("value"); |
||||
continue; |
||||
} |
||||
if (StringKit.equalsIgnoreCase("userstatus", name)) { |
||||
userStatus = attributeJson.getString("value"); |
||||
continue; |
||||
} |
||||
} |
||||
|
||||
if (StringKit.isEmpty(userId)) { |
||||
continue; |
||||
} |
||||
|
||||
if (!StringKit.equalsIgnoreCase("1", userStatus)) { |
||||
continue; |
||||
} |
||||
|
||||
if ((this.rowCount >= 1) && (getRowCount() >= this.rowCount)) { |
||||
return; |
||||
} |
||||
userId = userId.toLowerCase(); |
||||
addRowDatas(userId, userName, password, mail, mobile); |
||||
} |
||||
} |
||||
|
||||
private String getCookieValue(String content) { |
||||
if (StringKit.isEmpty(content)) { |
||||
return ""; |
||||
} |
||||
JSONObject resJson = new JSONObject(content); |
||||
JSONObject resultInfoJson = resJson.getJSONObject("resultInfo"); |
||||
if (resultInfoJson == null) { |
||||
return ""; |
||||
} |
||||
String success = resultInfoJson.getString("success", ""); |
||||
if (!"true".equalsIgnoreCase(success)) { |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject bodyJson = resultInfoJson.getJSONObject("body"); |
||||
if (bodyJson == null) { |
||||
return ""; |
||||
} |
||||
|
||||
String cookie = bodyJson.getString("cookie", ""); |
||||
if (StringKit.isEmpty(cookie)) { |
||||
return ""; |
||||
} |
||||
if ("null".equalsIgnoreCase(cookie)) { |
||||
return ""; |
||||
} |
||||
return cookie; |
||||
} |
||||
|
||||
// {"dept_name", "job_title", "user_id", "username", "password", "mobile", "mail", "code", "fcode"};
|
||||
private void addRowDatas(String userId, String userName, String password, String mail, String mobile) { |
||||
List<Object> rowDatas = new ArrayList<>(); |
||||
rowDatas.add(userId); |
||||
rowDatas.add(userName); |
||||
rowDatas.add(password); |
||||
rowDatas.add(mail); |
||||
rowDatas.add(mobile); |
||||
List<List<Object>> values = this.datas.getValues(); |
||||
values.add(rowDatas); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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); |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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("ESB用户数据集"); |
||||
} |
||||
|
||||
@Override |
||||
public String prefixForTableData() { |
||||
return "esb_users"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForTableData() { |
||||
return ""; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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("ESB用户数据集"); |
||||
} |
||||
|
||||
|
||||
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; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fr.plugin.third.party.jsdidig.http; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.third.party.jsdidig.Utils; |
||||
import com.fr.plugin.third.party.jsdidig.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 CustomConfigHttpHandler extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/jsdidig/oauth/config"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
res.setContentType("application/json; charset=utf-8"); |
||||
String logoutUrl = Utils.getLogoutUrl(); |
||||
String oAuthLoginUrl = Utils.getOAuthCodeUrlWithFr();; |
||||
LogKit.info("龙光IDM集成登录,退出认证登录地址:" + logoutUrl); |
||||
JSONObject json = new JSONObject(); |
||||
json.put("logoutUrl",logoutUrl); |
||||
json.put("oAuthLoginUrl",oAuthLoginUrl); |
||||
WebUtils.printAsJSON(res, json); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.third.party.jsdidig.http; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
|
||||
public class CustomHttpHandlerProvider extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public BaseHttpHandler[] registerHandlers() { |
||||
return new BaseHttpHandler[]{ |
||||
new CustomConfigHttpHandler() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.third.party.jsdidig.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 CustomURLAliasProvider extends AbstractURLAliasProvider { |
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/jsdidig/oauth/config", "/jsdidig/oauth/config", true) |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.plugin.third.party.jsdidig.http; |
||||
|
||||
public class CustomUserInfo { |
||||
private boolean valid = false; |
||||
private String userId; |
||||
private String username; |
||||
private String email; |
||||
private String phone; |
||||
|
||||
public CustomUserInfo() { |
||||
setValid(false); |
||||
} |
||||
|
||||
public boolean isValid() { |
||||
return valid; |
||||
} |
||||
|
||||
public void setValid(boolean valid) { |
||||
this.valid = valid; |
||||
} |
||||
|
||||
public String getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(String userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public String getEmail() { |
||||
return email; |
||||
} |
||||
|
||||
public void setEmail(String email) { |
||||
this.email = email; |
||||
} |
||||
|
||||
public String getPhone() { |
||||
return phone; |
||||
} |
||||
|
||||
public void setPhone(String phone) { |
||||
this.phone = phone; |
||||
} |
||||
} |
@ -0,0 +1,509 @@
|
||||
package com.fr.plugin.third.party.jsdidig.http; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.data.NetworkHelper; |
||||
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.plugin.context.PluginContexts; |
||||
|
||||
import com.fr.plugin.third.party.jsdidig.Utils; |
||||
import com.fr.plugin.third.party.jsdidig.config.CustomDataConfig; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
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.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
import com.fr.third.springframework.web.util.UriUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFilterProvider { |
||||
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.jsdidig"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/decision", "/decision/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) { |
||||
try { |
||||
if (!PluginContexts.currentContext().isAvailable()) { |
||||
LogKit.info("龙光IDM集成登录,许可证过期"); |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
String reqUrl = req.getRequestURL().toString(); |
||||
String fullUrl = Utils.getFullRequestUrl(req); |
||||
String method = req.getMethod(); |
||||
LogKit.info("龙光IDM集成登录,记录访问地址:" + method + " " + fullUrl); |
||||
|
||||
if (!"GET".equalsIgnoreCase(method)) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
if (reqUrl.indexOf("/remote/") >= 0) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
if (reqUrl.indexOf("/decision/login") >= 0) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
if (fullUrl.indexOf("/weixin/") >= 0) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
|
||||
if (fullUrl.indexOf("/dingtalk/") >= 0) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
if (isAllowIdmOAuthLogin(req)) { |
||||
String requestUrl = getRequestUrl(req); |
||||
requestUrl = replaceUrl(requestUrl); |
||||
LogKit.info("龙光IDM集成登录,真实访问地址," + requestUrl); |
||||
//CustomDataConfig.addUrl(state, requestUrl);
|
||||
String locationUrl = Utils.getOAuthCodeUrl(requestUrl); |
||||
Utils.sendRedirect(res, locationUrl); |
||||
return; |
||||
} |
||||
|
||||
String loginUsername = getIdmOAuthUsername(req); |
||||
if (StringKit.isEmpty(loginUsername)) { |
||||
filterChain.doFilter(req, res); |
||||
return; |
||||
} |
||||
|
||||
LogKit.info("龙光IDM集成登录, OAuth 用户名:" + loginUsername); |
||||
User user = UserService.getInstance().getUserByUserName(loginUsername); |
||||
boolean tipsOption = false; |
||||
String tipsContent = ""; |
||||
if (user == null) { |
||||
tipsOption = true; |
||||
LogKit.info("龙光IDM集成登录,用户名:" + loginUsername + "在报表平台不存在"); |
||||
tipsContent = "在报表服务器上不存在"; |
||||
} else if (!user.isEnable()) { |
||||
tipsOption = true; |
||||
LogKit.info("龙光IDM集成登录,用户名:" + loginUsername + "在报表平台上被禁用"); |
||||
tipsContent = "在报表平台上被禁用"; |
||||
} |
||||
|
||||
if (tipsOption) { |
||||
String jumpContent = "<!doctype html>\n" + |
||||
"<head>\n" + |
||||
" <meta charset=\"utf-8\" />\n" + |
||||
" <title>提示</title>\n" + |
||||
"<script type=\"text/javascript\">\n" + |
||||
"window.onload=function(){\n" + |
||||
" alert(\"用户:" + loginUsername + tipsContent + ",请联系管理员!\");\n" + |
||||
" window.location = \"" + CustomDataConfig.getInstance().getFrUrl() + "\";\n" + |
||||
"}\n" + |
||||
"</script>\t\n" + |
||||
"</head>\n" + |
||||
"<body>\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("龙光IDM集成登录,报表平台用户名:" + loginUsername);
|
||||
|
||||
LogKit.info("龙光IDM集成登录,报表平台用户名:" + loginUsername + "生成 login token"); |
||||
String loginToken = LoginService.getInstance().login(req, res, loginUsername); |
||||
req.setAttribute("fine_auth_token", loginToken); |
||||
|
||||
//String realUrl = getRealUrl(req);
|
||||
//if (StringKit.isEmpty(realUrl)) {
|
||||
// realUrl = CustomDataConfig.getInstance().getFrUrl();
|
||||
//}
|
||||
|
||||
if (fullUrl.indexOf("code=") >= 0) { |
||||
String requestUrl = getRequestUrl(req); |
||||
requestUrl = replaceUrl(requestUrl); |
||||
LogKit.info("龙光IDM集成登录,真实跳转地址:" + requestUrl); |
||||
Utils.sendRedirect(res, requestUrl); |
||||
return; |
||||
} |
||||
filterChain.doFilter(req, res); |
||||
} catch (Exception e) { |
||||
LogKit.error("龙光IDM集成登录出错," + e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
private String getRealUrl(HttpServletRequest req) { |
||||
if (req == null) { |
||||
return ""; |
||||
} |
||||
String state = getUrlId(req); |
||||
if (StringKit.isEmpty(state)) { |
||||
return ""; |
||||
} |
||||
String url = CustomDataConfig.getInstance().getUrlAndDestroy(state); |
||||
return url; |
||||
} |
||||
|
||||
String getUrlId(HttpServletRequest req) { |
||||
String urlId = StringKit.trim(WebUtils.getHTTPRequestParameter(req, "url_id")); |
||||
return urlId; |
||||
} |
||||
|
||||
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 getMappingUrl(String id) { |
||||
String tempUrl = StringKit.trim(CustomDataConfig.getInstance().getFrUrl()); |
||||
if (!tempUrl.endsWith("/")) { |
||||
tempUrl = tempUrl + "/"; |
||||
} |
||||
|
||||
tempUrl = tempUrl + "jsdigei-url/" + id; |
||||
return tempUrl; |
||||
} |
||||
|
||||
|
||||
private String replaceUrl(String url) { |
||||
if (StringKit.isEmpty(url)) { |
||||
return CustomDataConfig.getInstance().getFrUrl(); |
||||
} |
||||
|
||||
if (url.indexOf("/decision/login") >= 0) { |
||||
return CustomDataConfig.getInstance().getFrUrl(); |
||||
} |
||||
|
||||
String tempUrl = CustomDataConfig.getInstance().getFrUrl(); |
||||
int index = tempUrl.indexOf("/decision"); |
||||
if (index < 0) { |
||||
return url; |
||||
} |
||||
|
||||
String pUrl = tempUrl.substring(0, index); |
||||
|
||||
index = url.indexOf("/decision"); |
||||
if (index < 0) { |
||||
return url; |
||||
} |
||||
String fullUrl = pUrl + url.substring(index); |
||||
return fullUrl; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 判断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); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 判断字符串是否全是数字 |
||||
* |
||||
* @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("龙光IDM集成登录,code:" + oAuthCode); |
||||
RequestConfig requestConfig = RequestConfig.custom() |
||||
.setConnectionRequestTimeout(10000) |
||||
.setSocketTimeout(10000) // 服务端相应超时
|
||||
.setConnectTimeout(10000) // 建立socket链接超时时间
|
||||
.build(); |
||||
|
||||
//获取Access Token
|
||||
//环境地址/getTokens
|
||||
//http://ssotestnew.logan.com.cn:28080/siam/oauth2.0/accessTokenByJson
|
||||
//"client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=GRANTTYPE&code=CODE&redirect_uri=REDIRECTURL";
|
||||
String accessTokenUrl = CustomDataConfig.getInstance().getAccessTokenUrl(); |
||||
LogKit.info("龙光IDM集成登录,获取access_toke url:" + accessTokenUrl); |
||||
|
||||
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"); |
||||
NameValuePair clientIdValuePair = new BasicNameValuePair("client_id", CustomDataConfig.getInstance().getIdmClientId()); |
||||
NameValuePair clientSecretValuePair = new BasicNameValuePair("client_secret", CustomDataConfig.getInstance().getIdmClientSecret()); |
||||
params.add(redirectUriNameValuePair); |
||||
params.add(codeNameValuePair); |
||||
params.add(grantTypeNameValuePair); |
||||
params.add(clientIdValuePair); |
||||
params.add(clientSecretValuePair); |
||||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); |
||||
|
||||
httpPost.setConfig(requestConfig); |
||||
CloseableHttpClient httpClient = Utils.createHttpClient(accessTokenUrl); |
||||
CloseableHttpResponse response = httpClient.execute(httpPost); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != HttpStatus.SC_OK) { |
||||
response.close(); |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http status:" + statusCode); |
||||
return ""; |
||||
} |
||||
|
||||
HttpEntity httpEntity = response.getEntity(); |
||||
if (httpEntity == null) { |
||||
response.close(); |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http响应内容为空"); |
||||
return ""; |
||||
} |
||||
String responseContent = EntityUtils.toString(httpEntity, "UTF-8"); |
||||
response.close(); |
||||
if (StringKit.isEmpty(responseContent)) { |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,http响应内容为空1"); |
||||
return ""; |
||||
} |
||||
LogKit.info("龙光IDM集成登录,获取Access Token请求,http响应内容\n" + responseContent); |
||||
|
||||
String accessToken = getAccessToken(responseContent); |
||||
if (StringKit.isEmpty(accessToken)) { |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取Access Token请求出错,access_token为空"); |
||||
return ""; |
||||
} |
||||
LogKit.info("龙光IDM集成登录,Access Token:" + accessToken); |
||||
|
||||
|
||||
//http://192.168.0.115:8080/sso/oauth2.0/profile?access_token=TGT-2-QQbe3iHQJeXYx13daRnKRxMYh4HucodEmFlxwiSCpua2hMSxXB-c01
|
||||
String userUrl = CustomDataConfig.getInstance().getUserUrl(); |
||||
LogKit.info("龙光IDM集成登录,获取用户信息Url:" + userUrl); |
||||
httpPost = new HttpPost(userUrl); |
||||
httpPost.setConfig(requestConfig); |
||||
httpPost.addHeader("User-Agent", DEFAULT_USER_AGENT); |
||||
|
||||
params.clear(); |
||||
NameValuePair accessTokenValuePair = new BasicNameValuePair("access_token", accessToken); |
||||
params.add(accessTokenValuePair); |
||||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); |
||||
response = httpClient.execute(httpPost); |
||||
statusCode = response.getStatusLine().getStatusCode(); |
||||
if (statusCode != HttpStatus.SC_OK) { |
||||
response.close(); |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http status:" + statusCode); |
||||
return ""; |
||||
} |
||||
|
||||
httpEntity = response.getEntity(); |
||||
if (httpEntity == null) { |
||||
response.close(); |
||||
httpClient.close(); |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http响应内容为空"); |
||||
return ""; |
||||
} |
||||
responseContent = EntityUtils.toString(httpEntity, "UTF-8"); |
||||
response.close(); |
||||
httpClient.close(); |
||||
if (StringKit.isEmpty(responseContent)) { |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,http响应内容为空1"); |
||||
return ""; |
||||
} |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求,http响应内容\n" + responseContent); |
||||
|
||||
String uid = getUsername(responseContent); |
||||
if (StringKit.isEmpty(uid)) { |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,用户名为空"); |
||||
return ""; |
||||
} |
||||
LogKit.info("龙光IDM集成登录,用户名:" + uid); |
||||
uid = uid.toLowerCase(); |
||||
return uid; |
||||
} catch (Exception e) { |
||||
LogKit.error("龙光IDM集成登录获取用户名出错," + e.getMessage(), e); |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
private String getAccessToken(String content) { |
||||
if (StringKit.isEmpty(content)) { |
||||
return ""; |
||||
} |
||||
JSONObject jsonObject = new JSONObject(content); |
||||
String msg = jsonObject.getString("message"); |
||||
if (!StringKit.equalsIgnoreCase("SUCCESS", msg)) { |
||||
return ""; |
||||
} |
||||
String token = jsonObject.getString("access_token"); |
||||
if (StringKit.isNotEmpty(token) && token.startsWith("access_token=")) { |
||||
token = token.substring("access_token=".length()); |
||||
} |
||||
return token; |
||||
} |
||||
|
||||
private String getUsername(String content) { |
||||
if (StringKit.isEmpty(content)) { |
||||
return ""; |
||||
} |
||||
JSONObject jsonObject = new JSONObject(content); |
||||
String msg = jsonObject.getString("message"); |
||||
if (!StringKit.equalsIgnoreCase("SUCCESS", msg)) { |
||||
return ""; |
||||
} |
||||
JSONObject attributesJson = jsonObject.getJSONObject("attributes"); |
||||
if (attributesJson == null) { |
||||
return ""; |
||||
} |
||||
String username = attributesJson.getString("smart-alias"); |
||||
if (StringKit.isEmpty(username)) { |
||||
return ""; |
||||
} |
||||
username = username.toLowerCase(); |
||||
return username; |
||||
} |
||||
|
||||
|
||||
private String getRequestUrl(HttpServletRequest req) throws UnsupportedEncodingException { |
||||
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; |
||||
} |
||||
if (ComparatorUtils.equals(paraName, "code")) { |
||||
continue; |
||||
} |
||||
//if (ComparatorUtils.equals(paraName, "url_id")) {
|
||||
// continue;
|
||||
//}
|
||||
paraValues = entry.getValue(); |
||||
LogKit.info("龙光IDM集成登录,获取用户信息请求出错,login_name为空"); |
||||
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) throws UnsupportedEncodingException { |
||||
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; |
||||
} |
||||
String value; |
||||
for (int i = 0, max = paraValues.length - 1; i <= max; i++) { |
||||
if (StringKit.isNotEmpty(fullQuery)) { |
||||
fullQuery = fullQuery + "&"; |
||||
} |
||||
value = paraValues[i]; |
||||
if (StringKit.equals("viewlet", paraName) && (value.indexOf("%") < 0)) { |
||||
value = UriUtils.encodeQueryParam(value, "UTF-8"); |
||||
} |
||||
fullQuery = fullQuery + paraName + "=" + value; |
||||
} |
||||
return fullQuery; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.plugin.third.party.jsdidig.web; |
||||
|
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.Filter; |
||||
import com.fr.web.struct.browser.RequestClient; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
public class MainFilesComponent extends Component { |
||||
public static final MainFilesComponent KEY = new MainFilesComponent(); |
||||
private MainFilesComponent(){} |
||||
/** |
||||
* 返回需要引入的JS脚本路径 |
||||
* @param client 请求客户端描述 |
||||
* @return JS脚本路径 |
||||
*/ |
||||
public ScriptPath script(RequestClient client ) { |
||||
//如果不需要就直接返回 ScriptPath.EMPTY
|
||||
return ScriptPath.build("com/fr/plugin/third/party/jsdidig/web/main.js"); |
||||
} |
||||
|
||||
/** |
||||
* 返回需要引入的CSS样式路径 |
||||
* @param client 请求客户端描述 |
||||
* @return CSS样式路径 |
||||
*/ |
||||
public StylePath style(RequestClient client ) { |
||||
//如果不需要就直接返回 StylePath.EMPTY;
|
||||
//return StylePath.build("com/fr/plugin/jscssinput/demo/demo.css");
|
||||
return StylePath.EMPTY; |
||||
} |
||||
|
||||
/** |
||||
* 通过给定的资源过滤器控制是否加载这个资源 |
||||
* @return 资源过滤器 |
||||
*/ |
||||
public Filter filter() { |
||||
return new Filter(){ |
||||
@Override |
||||
public boolean accept() { |
||||
//任何情况下我们都在平台组件加载时加载我们的组件
|
||||
return true; |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.plugin.third.party.jsdidig.web; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.decision.web.MainComponent; |
||||
import com.fr.web.struct.Atom; |
||||
|
||||
public class MainWebResourceProvider extends AbstractWebResourceProvider { |
||||
@Override |
||||
public Atom attach() { |
||||
//在平台主组件加载时添加我们自己的组件
|
||||
return MainComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
public Atom client() { |
||||
//我们自己要引入的组件
|
||||
return MainFilesComponent.KEY; |
||||
} |
||||
} |
@ -0,0 +1,79 @@
|
||||
$(function () { |
||||
var url = Dec.fineServletURL + "/url/jsdidig/oauth/config"; |
||||
$.post(url, |
||||
function (data, status) { |
||||
if (status == "success") { |
||||
//debugger;
|
||||
var logoutUrl = data.logoutUrl; |
||||
var oAuthLoginUrl = data.oAuthLoginUrl; |
||||
|
||||
Dec.Logout = function () { |
||||
Dec.Utils.logout(function (e) { |
||||
Dec.Utils.clearLoginToken(); |
||||
window.location.href = oAuthLoginUrl; |
||||
}) |
||||
} |
||||
|
||||
var a = Dec.Logout; |
||||
|
||||
Dec.Logout = function () { |
||||
window.location.href = logoutUrl; |
||||
//$.get(logoutUrl);
|
||||
a(); |
||||
} |
||||
|
||||
var globalService = BI.Services.getService("dec.service.global"); |
||||
globalService.loginKick = function (e, t) { |
||||
var loginTimeoutFlag = false; |
||||
if (e == "21300014") { |
||||
loginTimeoutFlag = true; |
||||
} |
||||
var i = "login.timeout" |
||||
, n = t || "Dec-Login_Info_Not_Available"; |
||||
switch (e) { |
||||
case DecCst.ErrorCode.USERNAME_UNAVAILABLE: |
||||
case DecCst.ErrorCode.USERNAME_NOT_EXITS: |
||||
case DecCst.ErrorCode.PLATFORM_USER_REMOVE: |
||||
n = "Dec-Login_Account_Not_Available"; |
||||
break; |
||||
case DecCst.ErrorCode.SINGLE_LOGIN_KICK: |
||||
n = "Dec-Login_Single_Logged_Tip"; |
||||
break; |
||||
case DecCst.ErrorCode.USERNAME_PASSWORD_ERROR: |
||||
n = "Dec-Login_Password_Changed" |
||||
} |
||||
BI.isNotNull(Dec.socket) && Dec.socket.disconnect(), |
||||
BI.Popovers.create(i, { |
||||
header: BI.i18nText("BI-Basic_Prompt"), |
||||
size: "small", |
||||
closable: !1, |
||||
body: { |
||||
type: "bi.label", |
||||
whiteSpace: "normal", |
||||
text: BI.i18nText(n) |
||||
}, |
||||
footer: { |
||||
type: "bi.right_vertical_adapt", |
||||
items: [{ |
||||
type: "bi.button", |
||||
$testId: "dec-login-kick-btn", |
||||
text: BI.i18nText("BI-Basic_OK"), |
||||
height: 24, |
||||
handler: function () { |
||||
BI.Popovers.remove(i); |
||||
if (loginTimeoutFlag) { |
||||
window.location.href = oAuthLoginUrl; |
||||
return; |
||||
} |
||||
window.location.reload(!0); |
||||
} |
||||
}] |
||||
} |
||||
}, this).open(i) |
||||
}; |
||||
|
||||
} |
||||
}, "json"); |
||||
|
||||
|
||||
}); |
Loading…
Reference in new issue