commit
94e715a3b6
20 changed files with 1819 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||||
|
# open-JSD-7566 |
||||||
|
|
||||||
|
JSD-7566 单点登录 用户同步\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,26 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||||
|
<id>com.fr.plugin.ztsso</id> |
||||||
|
<name><![CDATA[单点登录和用户同步]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.0.4</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>fr.open</vendor> |
||||||
|
<description><![CDATA[单点登录和用户同步]]></description> |
||||||
|
<change-notes><![CDATA[ |
||||||
|
]]></change-notes> |
||||||
|
<main-package>com.fr.plugin.ztsso</main-package> |
||||||
|
<lifecycle-monitor class="com.fr.plugin.ztsso.config.simple.DemoInitializeMonitor"/> |
||||||
|
|
||||||
|
<extra-core> |
||||||
|
<LocaleFinder class="com.fr.plugin.ztsso.config.simple.PluginLocaleFinderBridge"/> |
||||||
|
</extra-core> |
||||||
|
<extra-decision> |
||||||
|
<HttpHandlerProvider class="com.fr.plugin.ztsso.handler.ExtendAttrHandlerProvider"/> |
||||||
|
<URLAliasProvider class="com.fr.plugin.ztsso.handler.URLAliasProvide"/> |
||||||
|
<LogInOutEventProvider class="com.fr.plugin.ztsso.logout.Logout"/> |
||||||
|
<EmbedRequestFilterProvider class="com.fr.plugin.ztsso.filter.SSOFilter"/> |
||||||
|
</extra-decision> |
||||||
|
|
||||||
|
<function-recorder class="com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig"/> |
||||||
|
</plugin> |
@ -0,0 +1,22 @@ |
|||||||
|
package com.fr.plugin.ztsso.config.simple; |
||||||
|
|
||||||
|
import com.fr.plugin.context.PluginContext; |
||||||
|
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||||
|
import com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2018-12-04 |
||||||
|
*/ |
||||||
|
public class DemoInitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||||
|
@Override |
||||||
|
public void afterRun(PluginContext pluginContext) { |
||||||
|
PluginSimpleConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void beforeStop(PluginContext pluginContext) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.fr.plugin.ztsso.config.simple; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||||
|
import com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig; |
||||||
|
|
||||||
|
import javax.servlet.FilterConfig; |
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
public class PluginInitializeFilterBridge extends AbstractEmbedRequestFilterProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void init(FilterConfig filterConfig) { |
||||||
|
PluginSimpleConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
package com.fr.plugin.ztsso.config.simple; |
||||||
|
|
||||||
|
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||||
|
|
||||||
|
public class PluginLocaleFinderBridge extends AbstractLocaleFinder { |
||||||
|
@Override |
||||||
|
public String find() { |
||||||
|
return "conf"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,169 @@ |
|||||||
|
package com.fr.plugin.ztsso.config.simple.account; |
||||||
|
|
||||||
|
import com.fr.config.*; |
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.config.holder.factory.Holders; |
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
|
||||||
|
@Visualization(category = "单点登录和用户同步配置") |
||||||
|
@EnableMetrics |
||||||
|
public class PluginSimpleConfig extends DefaultConfiguration { |
||||||
|
|
||||||
|
private static volatile PluginSimpleConfig config = null; |
||||||
|
|
||||||
|
@Focus(id="com.fr.plugin.ztsso.config.simple", text = "单点登录配置", source = Original.PLUGIN) |
||||||
|
public static PluginSimpleConfig getInstance() { |
||||||
|
if (config == null) { |
||||||
|
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
@Identifier(value = "frDomain", name = "帆软系统域名", description = "帆软系统域名", status = Status.SHOW) |
||||||
|
private Conf<String> frDomain = Holders.simple("http://localhost:8075"); |
||||||
|
|
||||||
|
@Identifier(value = "clientId", name = "clientId", description = "clientId", status = Status.SHOW) |
||||||
|
private Conf<String> appId = Holders.simple("XXXX"); |
||||||
|
|
||||||
|
@Identifier(value = "secret", name = "clientsecret", description = "clientsecret", status = Status.SHOW) |
||||||
|
private Conf<String> host = Holders.simple("xxxx"); |
||||||
|
|
||||||
|
@Identifier(value = "codeUrl", name = "获取授权码接口地址", description = "获取授权码接口地址", status = Status.SHOW) |
||||||
|
private Conf<String> codeUrl = Holders.simple("https://xxxx/idp/oauth2/authorize"); |
||||||
|
|
||||||
|
@Identifier(value = "tokenUrl", name = "获取token接口地址", description = "获取token接口地址", status = Status.SHOW) |
||||||
|
private Conf<String> tokenUrl = Holders.simple("https://xxxx/idp/oauth2/getToken"); |
||||||
|
|
||||||
|
@Identifier(value = "userInfoUrl", name = "获取用户信息接口地址", description = "获取用户信息接口地址", status = Status.SHOW) |
||||||
|
private Conf<String> userInfoUrl = Holders.simple("https://xxxx/idp/oauth2/getUserInfo"); |
||||||
|
|
||||||
|
@Identifier(value = "logoutUrl", name = "登出接口地址", description = "登出接口地址", status = Status.SHOW) |
||||||
|
private Conf<String> logoutUrl = Holders.simple("https://xxxx/idp/oauth2//Redirect/GLO"); |
||||||
|
|
||||||
|
public String getFrDomain() { |
||||||
|
return frDomain.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setFrDomain(String url) { |
||||||
|
this.frDomain.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getAppId() { |
||||||
|
return appId.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setAppId(String url) { |
||||||
|
this.appId.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getHost() { |
||||||
|
return host.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setHost(String url) { |
||||||
|
this.host.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getCodeUrl() { |
||||||
|
return codeUrl.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setCodeUrl(String codeUrl) { |
||||||
|
this.codeUrl.set(codeUrl); |
||||||
|
} |
||||||
|
|
||||||
|
public String getTokenUrl() { |
||||||
|
return tokenUrl.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTokenUrl(String tokenUrl) { |
||||||
|
this.tokenUrl.set(tokenUrl); |
||||||
|
} |
||||||
|
|
||||||
|
public String getUserInfoUrl() { |
||||||
|
return userInfoUrl.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setUserInfoUrl(String userInfoUrl) { |
||||||
|
this.userInfoUrl.set(userInfoUrl); |
||||||
|
} |
||||||
|
|
||||||
|
public String getLogoutUrl() { |
||||||
|
return logoutUrl.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setLogoutUrl(String userInfoUrl) { |
||||||
|
this.logoutUrl.set(userInfoUrl); |
||||||
|
} |
||||||
|
|
||||||
|
@Identifier(value = "consumerCode", name = "接口方调用标识", description = "接口方调用标识", status = Status.SHOW) |
||||||
|
private Conf<String> consumerCode = Holders.simple("cn.crec.group.test"); |
||||||
|
|
||||||
|
@Identifier(value = "operationCode", name = "服务接口标识", description = "服务接口标识", status = Status.SHOW) |
||||||
|
private Conf<String> operationCode = Holders.simple("cn.crec.group.sso.integration.api.jsonV2"); |
||||||
|
|
||||||
|
@Identifier(value = "integrationKey", name = "集成秘钥", description = "集成秘钥", status = Status.SHOW) |
||||||
|
private Conf<String> integrationKey = Holders.simple(""); |
||||||
|
|
||||||
|
@Identifier(value = "systemCode", name = "系统代码", description = "系统代码", status = Status.SHOW) |
||||||
|
private Conf<String> systemCode = Holders.simple("cn.crec.group.sso.integration.api.jsonV2"); |
||||||
|
|
||||||
|
@Identifier(value = "tysf", name = "统一身份接口", description = "统一身份接口", status = Status.SHOW) |
||||||
|
private Conf<String> tysf = Holders.simple("cn.crec.group.sso.integration.api.jsonV2"); |
||||||
|
|
||||||
|
|
||||||
|
public String getConsumerCode() { |
||||||
|
return consumerCode.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setConsumerCode(String url) { |
||||||
|
this.consumerCode.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getIntegrationKey() { |
||||||
|
return integrationKey.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setIntegrationKey(String url) { |
||||||
|
this.integrationKey.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getSystemCode() { |
||||||
|
return systemCode.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSystemCode(String url) { |
||||||
|
this.systemCode.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
public String getOperationCode() { |
||||||
|
return operationCode.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setOperationCode(String url) { |
||||||
|
this.operationCode.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public String getTysf() { |
||||||
|
return tysf.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTysf(String url) { |
||||||
|
this.tysf.set(url); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||||
|
// cloned.text = (Conf<String>) text.clone();
|
||||||
|
// cloned.count = (Conf<Integer>) count.clone();
|
||||||
|
// cloned.price = (Conf<Double>) price.clone();
|
||||||
|
// cloned.time = (Conf<Long>) time.clone();
|
||||||
|
// cloned.student = (Conf<Boolean>) student.clone();
|
||||||
|
return cloned; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,145 @@ |
|||||||
|
package com.fr.plugin.ztsso.filter; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig; |
||||||
|
import com.fr.plugin.ztsso.utils.FRUtils; |
||||||
|
import com.fr.plugin.ztsso.utils.HttpUtils; |
||||||
|
import com.fr.plugin.ztsso.utils.ResponseUtils; |
||||||
|
import com.fr.plugin.ztsso.utils.Utils; |
||||||
|
|
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.net.URLEncoder; |
||||||
|
|
||||||
|
|
||||||
|
public class SSOFilter extends AbstractEmbedRequestFilterProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { |
||||||
|
boolean isLogin = FRUtils.isLogin(httpServletRequest); |
||||||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||||
|
|
||||||
|
String url = FRUtils.getAllUrl(httpServletRequest,psc.getFrDomain()); |
||||||
|
|
||||||
|
String clientId = psc.getAppId(); |
||||||
|
String clientSecret= psc.getHost(); |
||||||
|
|
||||||
|
FRUtils.FRLogInfo("进入了拦截器"); |
||||||
|
|
||||||
|
//如果已经登录则放行
|
||||||
|
if(isLogin){ |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
//如果是自带登录页资源则放行
|
||||||
|
if(url.contains("login")||url.contains("decision/file")||url.contains("decision/resource")||url.contains("decision/system")||url.contains("query/ip")){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//如果是远程设计则放行
|
||||||
|
if(url.contains("remote")){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//获取code
|
||||||
|
String code = httpServletRequest.getParameter("code"); |
||||||
|
String msg = httpServletRequest.getParameter("msg"); |
||||||
|
|
||||||
|
FRUtils.FRLogInfo("进入了拦截器"); |
||||||
|
|
||||||
|
|
||||||
|
if(Utils.isNullStr(code) && Utils.isNullStr(msg)){ |
||||||
|
FRUtils.FRLogInfo("code:"+code+";msg:"+msg); |
||||||
|
|
||||||
|
String authUrl = psc.getCodeUrl(); |
||||||
|
String redirectURL = ""; |
||||||
|
try { |
||||||
|
redirectURL= URLEncoder.encode(url,"utf-8"); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FRUtils.FRLogInfo("url编码异常:"+e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
authUrl+= "?redirect_uri="+redirectURL+"&state=123&client_id="+clientId+"&response_type=code"; |
||||||
|
try { |
||||||
|
httpServletResponse.sendRedirect(authUrl); |
||||||
|
} catch (IOException e) { |
||||||
|
FRUtils.FRLogInfo("跳转异常:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
//获取code错误
|
||||||
|
if(Utils.isNotNullStr(msg)){ |
||||||
|
FRUtils.FRLogInfo("获取授权码异常:"+msg); |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"获取授权码异常:"+msg); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//获取token
|
||||||
|
String tokenUrl = psc.getTokenUrl()+"?client_id="+clientId+"&client_secret="+clientSecret+"&code="+code+"&grant_type=authorization_code"; |
||||||
|
JSONObject tokenParam = new JSONObject(); |
||||||
|
tokenParam.put("client_id",clientId); |
||||||
|
tokenParam.put("client_secret",clientSecret); |
||||||
|
tokenParam.put("code",code); |
||||||
|
tokenParam.put("grant_type","authorization_code"); |
||||||
|
|
||||||
|
String tokenParamStr = tokenParam.toString(); |
||||||
|
|
||||||
|
String tokenResult = HttpUtils.HttpPostJson(tokenUrl,tokenParamStr,null); |
||||||
|
|
||||||
|
if(Utils.isNullStr(tokenResult)){ |
||||||
|
FRUtils.FRLogInfo("获取token异常"); |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"获取token异常"); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject tokenResultJson = new JSONObject(tokenResult); |
||||||
|
String token = tokenResultJson.getString("access_token"); |
||||||
|
|
||||||
|
if(Utils.isNullStr(token)){ |
||||||
|
String tokenMsg =tokenResultJson.getString("msg"); |
||||||
|
|
||||||
|
FRUtils.FRLogInfo("获取token异常:"+tokenMsg); |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"获取token异常"+tokenMsg); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//获取用户信息
|
||||||
|
String uid = tokenResultJson.getString("uid"); |
||||||
|
|
||||||
|
String userInfoUrl = psc.getUserInfoUrl(); |
||||||
|
userInfoUrl+="?access_token="+token+"&client_id="+clientId+"&uid="+uid; |
||||||
|
|
||||||
|
String userInfoResult = HttpUtils.get(userInfoUrl,null,null); |
||||||
|
|
||||||
|
if(Utils.isNullStr(userInfoResult)){ |
||||||
|
FRUtils.FRLogInfo("获取用户信息异常"); |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"获取用户信息异常"); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject userJsonObject = new JSONObject(userInfoResult); |
||||||
|
|
||||||
|
String loginName = userJsonObject.getString("loginName"); |
||||||
|
|
||||||
|
if(Utils.isNullStr(loginName)){ |
||||||
|
String userMsg = userJsonObject.getString("msg"); |
||||||
|
FRUtils.FRLogInfo("获取用户信息异常:"+userMsg); |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"获取用户信息异常:"+userMsg); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
FRUtils.login(httpServletRequest,httpServletResponse,loginName,""); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,274 @@ |
|||||||
|
package com.fr.plugin.ztsso.handler; |
||||||
|
|
||||||
|
import com.fr.decision.authority.data.User; |
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
import com.fr.decision.webservice.bean.user.UserBean; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig; |
||||||
|
import com.fr.plugin.ztsso.utils.*; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.net.URLEncoder; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class AcountHandler extends BaseHttpHandler { |
||||||
|
|
||||||
|
|
||||||
|
public AcountHandler() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public RequestMethod getMethod() { |
||||||
|
return RequestMethod.GET; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getPath() { |
||||||
|
return "/account"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isPublic() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
//获取配置参数
|
||||||
|
PluginSimpleConfig pluginSimpleConfig = PluginSimpleConfig.getInstance(); |
||||||
|
String cosCode = pluginSimpleConfig.getConsumerCode(); |
||||||
|
String operaCode = pluginSimpleConfig.getOperationCode(); |
||||||
|
Map<String,String> header = new HashMap<String,String>(); |
||||||
|
header.put("consumerCode",cosCode); |
||||||
|
header.put("operationCode",operaCode); |
||||||
|
String sysCode = pluginSimpleConfig.getSystemCode(); |
||||||
|
String key = pluginSimpleConfig.getIntegrationKey(); |
||||||
|
//获取token
|
||||||
|
String url = pluginSimpleConfig.getTysf(); |
||||||
|
|
||||||
|
JSONObject param = new JSONObject(); |
||||||
|
param.put("method","login"); |
||||||
|
JSONObject tokenRequest = new JSONObject(); |
||||||
|
tokenRequest.put("systemCode",sysCode); |
||||||
|
tokenRequest.put("integrationKey",key); |
||||||
|
tokenRequest.put("force",true); |
||||||
|
tokenRequest.put("timestamp",System.currentTimeMillis()); |
||||||
|
param.put("request",tokenRequest); |
||||||
|
String tokenUrl = url+"?method=login&request="+URLEncoder.encode(tokenRequest.toString()); |
||||||
|
// tokenUrl = URLEncoder.encode(tokenUrl,"utf-8");
|
||||||
|
|
||||||
|
String result = HttpUtils.HttpPostJson(tokenUrl,param.toString(),header); |
||||||
|
|
||||||
|
if(Utils.isNullStr(result)){ |
||||||
|
ResponseUtils.failedResponse(res,"获取token失败"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject tokenResult = new JSONObject(result); |
||||||
|
|
||||||
|
int code = tokenResult.getInt("code"); |
||||||
|
boolean success = tokenResult.getBoolean("success"); |
||||||
|
if(!success){ |
||||||
|
String message = tokenResult.getString("message"); |
||||||
|
ResponseUtils.failedResponse(res,"获取token失败:"+message); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//获取下拉数据
|
||||||
|
String tokenId = tokenResult.getString("tokenId"); |
||||||
|
|
||||||
|
JSONObject pullTaskParam = new JSONObject(); |
||||||
|
pullTaskParam.put("method","pullTask"); |
||||||
|
JSONObject pullTaskRequest = new JSONObject(); |
||||||
|
pullTaskRequest.put("tokenId",tokenId); |
||||||
|
pullTaskRequest.put("timestamp",System.currentTimeMillis()); |
||||||
|
pullTaskParam.put("request",pullTaskRequest); |
||||||
|
|
||||||
|
String pullUrl = url+"?method=pullTask&request="+URLEncoder.encode(pullTaskRequest.toString()); |
||||||
|
// pullUrl = URLEncoder.encode(pullUrl,"utf-8");
|
||||||
|
|
||||||
|
String pullTaskResultStr = HttpUtils.HttpPostJson(pullUrl,pullTaskParam.toString(),header); |
||||||
|
|
||||||
|
if(Utils.isNullStr(pullTaskResultStr)){ |
||||||
|
ResponseUtils.failedResponse(res,"获取数据失败"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject pullTaskResult = new JSONObject(pullTaskResultStr); |
||||||
|
|
||||||
|
code = pullTaskResult.getInt("code"); |
||||||
|
success = pullTaskResult.getBoolean("success"); |
||||||
|
if(!success){ |
||||||
|
String message = pullTaskResult.getString("message"); |
||||||
|
ResponseUtils.failedResponse(res,"获取数据失败:"+message); |
||||||
|
return; |
||||||
|
} |
||||||
|
//根据不同类型进行账户或者组织机构的操作
|
||||||
|
String objectType = pullTaskResult.getString("objectType"); |
||||||
|
String taskId = pullTaskResult.getString("taskId"); |
||||||
|
String guid = pullTaskResult.getString("id"); |
||||||
|
if("TARGET_ACCOUNT".equals(objectType)){ |
||||||
|
operateAccout(pullTaskResult,res); |
||||||
|
}else if("TARGET_ORGANIZATION".equals(objectType)){ |
||||||
|
operateOrg(pullTaskResult,res); |
||||||
|
} |
||||||
|
|
||||||
|
//返回下拉完成状态
|
||||||
|
JSONObject finishTaskParam = new JSONObject(); |
||||||
|
finishTaskParam.put("method","pullFinish"); |
||||||
|
JSONObject finishTaskRequest = new JSONObject(); |
||||||
|
finishTaskRequest.put("tokenId",tokenId); |
||||||
|
finishTaskRequest.put("timestamp",System.currentTimeMillis()); |
||||||
|
finishTaskRequest.put("taskId",taskId); |
||||||
|
finishTaskRequest.put("success",true); |
||||||
|
finishTaskRequest.put("guid",guid); |
||||||
|
finishTaskParam.put("request",finishTaskRequest); |
||||||
|
|
||||||
|
String finishUrl = url+"?method=pullFinish&request="+URLEncoder.encode(finishTaskRequest.toString()); |
||||||
|
|
||||||
|
String finishResultStr = HttpUtils.HttpPostJson(finishUrl,pullTaskParam.toString(),header); |
||||||
|
|
||||||
|
if(Utils.isNullStr(finishResultStr)){ |
||||||
|
ResponseUtils.failedResponse(res,"下拉完成失败"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONObject finishResult = new JSONObject(finishResultStr); |
||||||
|
|
||||||
|
success = finishResult.getBoolean("success"); |
||||||
|
|
||||||
|
if(!success){ |
||||||
|
String message = finishResult.getString("message"); |
||||||
|
ResponseUtils.failedResponse(res,"下拉完成失败:"+message); |
||||||
|
return; |
||||||
|
} |
||||||
|
//注销登录
|
||||||
|
JSONObject loggoutParam = new JSONObject(); |
||||||
|
loggoutParam.put("method","logout"); |
||||||
|
JSONObject logoutRequest = new JSONObject(); |
||||||
|
logoutRequest.put("tokenId",tokenId); |
||||||
|
logoutRequest.put("timestamp",System.currentTimeMillis()); |
||||||
|
loggoutParam.put("request",logoutRequest); |
||||||
|
|
||||||
|
String logoutUrl = url+"?method=logout&request="+URLEncoder.encode(logoutRequest.toString()); |
||||||
|
|
||||||
|
String logoutResultStr = HttpUtils.HttpPostJson(logoutUrl,loggoutParam.toString(),header); |
||||||
|
} |
||||||
|
|
||||||
|
private void operateAccout(JSONObject pullTaskData,HttpServletResponse res) { |
||||||
|
FRUtils.FRLogInfo("account"); |
||||||
|
String effectOn = pullTaskData.getString("effectOn"); |
||||||
|
JSONObject data = pullTaskData.getJSONObject("data"); |
||||||
|
String username = data.getString("username"); |
||||||
|
String password = data.getString("password"); |
||||||
|
String fullname = data.getString("fullname"); |
||||||
|
boolean isDisabled = data.getBoolean("isDisabled"); |
||||||
|
String email = data.getString("email"); |
||||||
|
String mobile = data.getString("mobile"); |
||||||
|
|
||||||
|
UserBean userBean = new UserBean(); |
||||||
|
|
||||||
|
userBean.setUsername(username); |
||||||
|
userBean.setPassword(Utils.replaceNullStr(password,"123")); |
||||||
|
userBean.setRealName(fullname); |
||||||
|
userBean.setEnable(isDisabled); |
||||||
|
userBean.setEmail(email); |
||||||
|
userBean.setMobile(mobile); |
||||||
|
|
||||||
|
if("CREATE".equals(effectOn)){ |
||||||
|
try { |
||||||
|
FRUserUtils.addUser(userBean); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"添加用户失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("DISABLED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
String userId = FRUserUtils.getUserByUserName(username).getId(); |
||||||
|
FRUserUtils.forbidUser(userId,false); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"禁用用户失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("ENABLED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
String userId = FRUserUtils.getUserByUserName(username).getId(); |
||||||
|
FRUserUtils.forbidUser(userId,true); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"启用用户失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("DELETED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
User user = FRUserUtils.getUserByUserName(username); |
||||||
|
FRUserUtils.deleteUser(user); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"删除用户失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("UPDATED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
User user = FRUserUtils.getUserByUserName(username); |
||||||
|
UserBean userBean2 = FRUserUtils.getUser(user.getId()); |
||||||
|
|
||||||
|
userBean2.setRealName(fullname); |
||||||
|
userBean2.setEmail(email); |
||||||
|
userBean2.setMobile(mobile); |
||||||
|
FRUserUtils.updateUser(userBean2); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"修改用户失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void operateOrg(JSONObject pullTaskData,HttpServletResponse res) { |
||||||
|
FRUtils.FRLogInfo("account"); |
||||||
|
String effectOn = pullTaskData.getString("effectOn"); |
||||||
|
JSONObject data = pullTaskData.getJSONObject("data"); |
||||||
|
String name = data.getString("name"); |
||||||
|
String id = data.getString("_organization"); |
||||||
|
String parentId = data.getString("_parent"); |
||||||
|
|
||||||
|
parentId = Utils.replaceNullStr(parentId,"decision-dep-root"); |
||||||
|
|
||||||
|
FRUtils.FRLogInfo("effectOn:"+effectOn); |
||||||
|
|
||||||
|
if("CREATED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
FRDepartmentUtils.addDP(id,parentId,name); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"添加机构失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("DELETED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
FRDepartmentUtils.deleteDepartment(id); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"删除机构失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
}else if("UPDATED".equals(effectOn)){ |
||||||
|
try { |
||||||
|
FRDepartmentUtils.updateDP(id,name); |
||||||
|
} catch (Exception e) { |
||||||
|
String message = Utils.replaceNullStr(e.getMessage(),"修改机构失败"); |
||||||
|
ResponseUtils.failedResponse(res,message); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,55 @@ |
|||||||
|
package com.fr.plugin.ztsso.handler; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugin.transform.FunctionRecorder; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
@FunctionRecorder |
||||||
|
public class BlankHandler extends BaseHttpHandler { |
||||||
|
|
||||||
|
|
||||||
|
public BlankHandler() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public RequestMethod getMethod() { |
||||||
|
return RequestMethod.GET; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getPath() { |
||||||
|
return "/blank"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isPublic() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
|
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("text/html;charset=utf-8"); |
||||||
|
pw.println("<html></html>"); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,13 @@ |
|||||||
|
package com.fr.plugin.ztsso.handler; |
||||||
|
|
||||||
|
import com.fr.decision.fun.HttpHandler; |
||||||
|
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||||
|
|
||||||
|
public class ExtendAttrHandlerProvider extends AbstractHttpHandlerProvider { |
||||||
|
@Override |
||||||
|
public HttpHandler[] registerHandlers() { |
||||||
|
return new HttpHandler[]{ |
||||||
|
new AcountHandler() |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.plugin.ztsso.handler; |
||||||
|
|
||||||
|
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 URLAliasProvide extends AbstractURLAliasProvider { |
||||||
|
@Override |
||||||
|
public URLAlias[] registerAlias() { |
||||||
|
return new URLAlias[]{ |
||||||
|
URLAliasFactory.createPluginAlias("/account","/account",true), |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package com.fr.plugin.ztsso.logout; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||||
|
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||||
|
import com.fr.decision.webservice.v10.login.LoginService; |
||||||
|
import com.fr.plugin.ztsso.config.simple.account.PluginSimpleConfig; |
||||||
|
import javax.servlet.http.HttpSession; |
||||||
|
|
||||||
|
public class Logout extends AbstractLogInOutEventProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public String logoutAction(LogInOutResultInfo result) { |
||||||
|
HttpSession session = result.getRequest().getSession(true); |
||||||
|
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||||
|
session.invalidate(); |
||||||
|
|
||||||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||||
|
|
||||||
|
String authUrl = psc.getCodeUrl(); |
||||||
|
String redirectURL = psc.getFrDomain()+"/webroot/decision"; |
||||||
|
String clientId = psc.getAppId(); |
||||||
|
String logoutUrl = psc.getLogoutUrl(); |
||||||
|
|
||||||
|
logoutUrl+="?redirctToUrl="+redirectURL+"&redirectToLogin=true&entityId="+clientId; |
||||||
|
return logoutUrl; |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,227 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class DateUtilSelf { |
||||||
|
|
||||||
|
/** |
||||||
|
* 日期转换为日期字符串 |
||||||
|
* @param date |
||||||
|
* @param formatStr |
||||||
|
* @return String |
||||||
|
*/ |
||||||
|
public static String DateToString(Date date,String formatStr) { |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(formatStr); |
||||||
|
String dateStr = sdf.format(date).toString(); |
||||||
|
|
||||||
|
return dateStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 日期字符串转换日期 |
||||||
|
* @param dateStr |
||||||
|
* @param formatStr |
||||||
|
* @return Date |
||||||
|
*/ |
||||||
|
public static Date strToDate(String dateStr,String formatStr){ |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(formatStr); |
||||||
|
Date date = null; |
||||||
|
|
||||||
|
try { |
||||||
|
date = sdf.parse(dateStr); |
||||||
|
} |
||||||
|
catch(Exception e) { |
||||||
|
} |
||||||
|
|
||||||
|
return date; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Date转Timestamp |
||||||
|
* @param date |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Timestamp dateToTimestamp(Date date) { |
||||||
|
Date transDate = DateUtilSelf.strToDate(DateUtilSelf.DateToString(date, "yyyy-MM-dd hh:mm:ss"),"yyyy-MM-dd hh:mm:ss"); |
||||||
|
|
||||||
|
Timestamp timestamp = new Timestamp(transDate.getTime()); |
||||||
|
return timestamp; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Date字符串转Timestamp |
||||||
|
* @param dateStr |
||||||
|
* @param format |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Timestamp strToTimestamp(String dateStr,String format) { |
||||||
|
Date date = strToDate(dateStr,format); |
||||||
|
Timestamp timestamp = new Timestamp(date.getTime()); |
||||||
|
return timestamp; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取两个日期字符串之间的天数 |
||||||
|
* @param startDateStr |
||||||
|
* @param endDateStr |
||||||
|
* @param formatStr |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static int getDays(String startDateStr,String endDateStr,String formatStr) { |
||||||
|
|
||||||
|
Date startDate = strToDate(startDateStr,formatStr); |
||||||
|
Date endDate = strToDate(endDateStr,formatStr); |
||||||
|
|
||||||
|
long startTime = startDate.getTime(); |
||||||
|
long endTime = endDate.getTime(); |
||||||
|
|
||||||
|
int days = (int) ((endTime - startTime)/(60*60*24*1000)); |
||||||
|
|
||||||
|
return days; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取给定时间之前之后的时间 |
||||||
|
* @param type |
||||||
|
* @param dateStr |
||||||
|
* @param count |
||||||
|
* @param formatStr |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getAfterDateStr(int type,String dateStr,int count,String formatStr) { |
||||||
|
Date startDate = strToDate(dateStr,formatStr); |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(startDate); |
||||||
|
|
||||||
|
calendar.add(type, count); |
||||||
|
|
||||||
|
String endDateStr = DateToString(calendar.getTime(),formatStr); |
||||||
|
|
||||||
|
return endDateStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取给定时间之前之后的时间 |
||||||
|
* @param type |
||||||
|
* @param date |
||||||
|
* @param count |
||||||
|
* @param formatStr |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getAfterDateStr(int type,Date date,int count,String formatStr) { |
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
calendar.setTime(date); |
||||||
|
|
||||||
|
calendar.add(type, count); |
||||||
|
|
||||||
|
String endDateStr = DateToString(calendar.getTime(),formatStr); |
||||||
|
|
||||||
|
return endDateStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取给定时间之前之后的时间 |
||||||
|
* @param type |
||||||
|
* @param date |
||||||
|
* @param count |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Date getAfterDateStr(int type,Date date,int count) { |
||||||
|
Calendar dateResult = Calendar.getInstance(); |
||||||
|
dateResult.setTime(date); |
||||||
|
dateResult.add(type, count); |
||||||
|
return dateResult.getTime(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 时间戳转日期 |
||||||
|
* @param timestamp |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Date timestampToDate(Timestamp timestamp) { |
||||||
|
Date date = new Date(timestamp.getTime()); |
||||||
|
|
||||||
|
return date; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 时间戳转时间字符串 |
||||||
|
* @param timestamp |
||||||
|
* @param format 日期格式 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String timestampToStr(Timestamp timestamp,String format) { |
||||||
|
Date date = timestampToDate(timestamp); |
||||||
|
|
||||||
|
String timeStr = DateToString(date, format); |
||||||
|
|
||||||
|
return timeStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取所给日期length天内每一天的日期 |
||||||
|
* @param date 所给日期(yyyy-MM-dd) |
||||||
|
* @param length 长度 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static List<String> getDateList(String date,int length){ |
||||||
|
List<String> dateList = new ArrayList<String>(); |
||||||
|
String format = "yyyy-MM-dd"; |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
||||||
|
//获取length天后的日期
|
||||||
|
|
||||||
|
String targetDate = getAfterDateStr(Calendar.DATE,date,length,format); |
||||||
|
|
||||||
|
Date start = null; |
||||||
|
Date end = null; |
||||||
|
|
||||||
|
if(length >= 0) { |
||||||
|
start = strToDate(date,format); |
||||||
|
end = strToDate(targetDate,format); |
||||||
|
}else { |
||||||
|
start = strToDate(targetDate,format); |
||||||
|
end = strToDate(date,format); |
||||||
|
} |
||||||
|
|
||||||
|
Calendar calBegin = Calendar.getInstance(); |
||||||
|
calBegin.setTime(start); |
||||||
|
Calendar calEnd = Calendar.getInstance(); |
||||||
|
calEnd.setTime(end); |
||||||
|
|
||||||
|
while (end.after(calBegin.getTime())) { |
||||||
|
calBegin.add(Calendar.DATE, 1); |
||||||
|
String dayStr = sdf.format(calBegin.getTime()); |
||||||
|
dateList.add(dayStr); |
||||||
|
} |
||||||
|
|
||||||
|
return dateList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 比较startDate是否在endDate之前 |
||||||
|
* @param startDate |
||||||
|
* @param endDate |
||||||
|
* @param format |
||||||
|
* @return 0 两个日期相等 <0 开始日期在结束日期之前 >0 开始日期在结束日期之后 |
||||||
|
*/ |
||||||
|
public static int comparisonDate(String startDate,String endDate,String format) { |
||||||
|
Date start = strToDate(startDate,format); |
||||||
|
Date end = strToDate(endDate,format); |
||||||
|
|
||||||
|
return start.compareTo(end); |
||||||
|
} |
||||||
|
|
||||||
|
//获取当前日期年、月、日、时、分、秒
|
||||||
|
public static int getCount(int type){ |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
|
||||||
|
return calendar.get(type); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,106 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.decision.authority.AuthorityContext; |
||||||
|
import com.fr.decision.authority.base.constant.SoftRoleType; |
||||||
|
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||||
|
import com.fr.decision.authority.data.BaseUserDataRecord; |
||||||
|
import com.fr.decision.authority.data.Department; |
||||||
|
import com.fr.decision.record.OperateMessage; |
||||||
|
import com.fr.decision.webservice.bean.user.DepartmentPostBean; |
||||||
|
import com.fr.decision.webservice.exception.general.DuplicatedNameException; |
||||||
|
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||||
|
import com.fr.decision.webservice.v10.user.DepartmentService; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.intelli.record.MetricRegistry; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.query.QueryFactory; |
||||||
|
import com.fr.stable.query.condition.QueryCondition; |
||||||
|
import com.fr.stable.query.restriction.Restriction; |
||||||
|
import com.fr.stable.query.restriction.RestrictionFactory; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
|
||||||
|
public class FRDepartmentUtils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取用户Service |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static DepartmentService getDepartmentService(){ |
||||||
|
return DepartmentService.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加部门 |
||||||
|
* @param pId 父节点id |
||||||
|
* @param dpName 部门名称 |
||||||
|
*/ |
||||||
|
public static DepartmentPostBean addDP(String pId, String dpName) throws Exception { |
||||||
|
return getDepartmentService().addDepartment(pId,dpName); |
||||||
|
} |
||||||
|
|
||||||
|
public static DepartmentPostBean addDP(String id,String pId, String orgName) throws Exception { |
||||||
|
String pId2 = pId; |
||||||
|
if (ComparatorUtils.equals(pId, "decision-dep-root") ) { |
||||||
|
pId2 = null; |
||||||
|
} |
||||||
|
checkDuplicatedDepartmentName(pId2, orgName); |
||||||
|
Department var4 = (new Department()).name(orgName).parentId(pId2).id(id).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true); |
||||||
|
if (pId2 != null) { |
||||||
|
UserSourceFactory.getInstance().checkSource(var4, (BaseUserDataRecord)AuthorityContext.getInstance().getDepartmentController().getById(pId)); |
||||||
|
} |
||||||
|
|
||||||
|
AuthorityContext.getInstance().getDepartmentController().add(var4); |
||||||
|
deleteSoftData(getDepartmentService().getDepartmentFullPath(var4.getId()).replaceAll("/", "-")); |
||||||
|
MetricRegistry.getMetric().submit(OperateMessage.build("Dec-Module-User_Manager", "Dec-Department", getDepartmentFullPath(pId, orgName, "/"), "Dec-Log_Add")); |
||||||
|
return new DepartmentPostBean(var4.getId(), false, false, var4.getParentId(), "", var4.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
private static void checkDuplicatedDepartmentName(String var1, String var2) throws Exception { |
||||||
|
QueryCondition var3 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("name", var2), RestrictionFactory.eq("parentId", var1)})); |
||||||
|
Department var4 = (Department)AuthorityContext.getInstance().getDepartmentController().findOne(var3); |
||||||
|
if (var4 != null) { |
||||||
|
throw new DuplicatedNameException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void deleteSoftData(String var1) throws Exception { |
||||||
|
QueryCondition var2 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", var1), RestrictionFactory.eq("type", SoftRoleType.DEP)})); |
||||||
|
AuthorityContext.getInstance().getSoftDataController().remove(var2); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getDepartmentFullPath(String var1, String var2, String var3) throws Exception { |
||||||
|
ArrayList var4 = new ArrayList(); |
||||||
|
var4.add(var2); |
||||||
|
|
||||||
|
while(!ComparatorUtils.equals(var1, "decision-dep-root") && var1 != null) { |
||||||
|
Department var5 = (Department)AuthorityContext.getInstance().getDepartmentController().getById(var1); |
||||||
|
var4.add(var5.getName()); |
||||||
|
var1 = var5.getParentId(); |
||||||
|
} |
||||||
|
|
||||||
|
Collections.reverse(var4); |
||||||
|
return StableUtils.join(var4.toArray(new String[0]), var3); |
||||||
|
} |
||||||
|
/** |
||||||
|
* 修改组织 |
||||||
|
* @param id |
||||||
|
* @param dpName |
||||||
|
*/ |
||||||
|
public static void updateDP(String id,String dpName) throws Exception { |
||||||
|
getDepartmentService().editDepartment(id,dpName); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除机构 |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static void deleteDepartment(String id) throws Exception { |
||||||
|
getDepartmentService().deleteDepartment(id); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,111 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.decision.authority.data.User; |
||||||
|
import com.fr.decision.privilege.TransmissionTool; |
||||||
|
import com.fr.decision.webservice.bean.user.UserBean; |
||||||
|
import com.fr.decision.webservice.bean.user.UserUpdateBean; |
||||||
|
import com.fr.decision.webservice.v10.user.UserService; |
||||||
|
|
||||||
|
public class FRUserUtils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取用户Service |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static UserService getUserService(){ |
||||||
|
return UserService.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加用户 |
||||||
|
* @param userBean |
||||||
|
*/ |
||||||
|
public static void addUser(UserBean userBean) throws Exception { |
||||||
|
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||||
|
getUserService().addUser(userBean); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除用户 |
||||||
|
* @param userBean |
||||||
|
*/ |
||||||
|
public static void updateUser(UserBean userBean) throws Exception { |
||||||
|
getUserService().editUser(userBean); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除用户 |
||||||
|
* @param user |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static int deleteUser(User user) throws Exception { |
||||||
|
String userId = user.getId(); |
||||||
|
|
||||||
|
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||||
|
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||||
|
|
||||||
|
return getUserService().deleteUsers(userUpdateBean); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据用户名获取用户实体 |
||||||
|
* @param userName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static User getUserByUserName(String userName) throws Exception { |
||||||
|
return getUserService().getUserByUserName(userName); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据id获取用户 |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static UserBean getUser(String id) throws Exception { |
||||||
|
return getUserService().getUser(id); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否是管理员 |
||||||
|
* @param userId |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isAdmin(String userId){ |
||||||
|
return getUserService().isAdmin(userId); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 禁用启用用户 |
||||||
|
* @param userId |
||||||
|
* @param state false 禁用 true 启用 |
||||||
|
* @throws Exception 异常说明失败 |
||||||
|
*/ |
||||||
|
public static void forbidUser(String userId,boolean state) throws Exception { |
||||||
|
getUserService().forbidUser(userId,state); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改用户部门 |
||||||
|
* @param departmentId |
||||||
|
* @param postId |
||||||
|
* @param ud |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception { |
||||||
|
getUserService().updateDepartmentPostUsers(departmentId,postId,ud); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 验证密码是否正确
|
||||||
|
// * @param psd 明文密码
|
||||||
|
// * @param user 根据用户名获取得用户对象
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public static boolean checkPsd(String psd,User user){
|
||||||
|
// String shaPsd = CipherUtils.jdksha256(psd);
|
||||||
|
//
|
||||||
|
// return shaPsd.equals(user.getPassword());
|
||||||
|
// }
|
||||||
|
} |
@ -0,0 +1,165 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.decision.authority.AuthorityContext; |
||||||
|
import com.fr.decision.authority.data.User; |
||||||
|
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||||
|
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||||
|
import com.fr.decision.webservice.v10.login.LoginService; |
||||||
|
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||||
|
import com.fr.decision.webservice.v10.user.UserService; |
||||||
|
import com.fr.event.EventDispatcher; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.query.QueryFactory; |
||||||
|
import com.fr.stable.query.restriction.RestrictionFactory; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import javax.servlet.http.HttpSession; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class FRUtils { |
||||||
|
/** |
||||||
|
* 判断用户是否存在 |
||||||
|
* @param userName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isUserExist(String userName){ |
||||||
|
if (StringUtils.isEmpty(userName)) { |
||||||
|
return false; |
||||||
|
} else { |
||||||
|
try { |
||||||
|
List var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||||
|
return var1 != null && !var1.isEmpty(); |
||||||
|
} catch (Exception var2) { |
||||||
|
FineLoggerFactory.getLogger().error(var2.getMessage()); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否登录FR |
||||||
|
* @param req |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isLogin(HttpServletRequest req){ |
||||||
|
return LoginService.getInstance().isLogged(req); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帆软登录 |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
* @param userName |
||||||
|
* @param url |
||||||
|
*/ |
||||||
|
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||||
|
|
||||||
|
|
||||||
|
//判断用户名是否为空
|
||||||
|
if(!Utils.isNullStr(userName)){ |
||||||
|
if(isUserExist(userName)){ |
||||||
|
String FRToken = ""; |
||||||
|
|
||||||
|
try { |
||||||
|
HttpSession session = httpServletRequest.getSession(true); |
||||||
|
|
||||||
|
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||||
|
|
||||||
|
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken); |
||||||
|
|
||||||
|
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken); |
||||||
|
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||||
|
|
||||||
|
if(!Utils.isNullStr(url)){ |
||||||
|
httpServletResponse.sendRedirect(url); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param httpServletRequest |
||||||
|
* @param httpServletResponse |
||||||
|
*/ |
||||||
|
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||||
|
{ |
||||||
|
if(!isLogin(httpServletRequest)){ |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||||
|
} catch (Exception e) { |
||||||
|
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||||
|
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 打印FR日志 |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void FRLogInfo(String message){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据用户名获取用户信息 |
||||||
|
* @param userName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static User getFRUserByUserName(String userName){ |
||||||
|
try { |
||||||
|
return UserService.getInstance().getUserByUserName(userName); |
||||||
|
} catch (Exception e) { |
||||||
|
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 解密FR密码 |
||||||
|
* @param password |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
// public static String decryptFRPsd(String password){
|
||||||
|
// FRLogInfo("解密密码:"+password);
|
||||||
|
// return TransmissionTool.decrypt(password);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取带参数的访问链接 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getAllUrl(HttpServletRequest httpServletRequest,String domain){ |
||||||
|
String url = WebUtils.getOriginalURL(httpServletRequest); |
||||||
|
|
||||||
|
if(Utils.isNullStr(domain)){ |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
return domain + url.substring(url.indexOf("/webroot/decision"),url.length()); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,239 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.third.org.apache.http.HttpEntity; |
||||||
|
import com.fr.third.org.apache.http.HttpResponse; |
||||||
|
import com.fr.third.org.apache.http.HttpStatus; |
||||||
|
import com.fr.third.org.apache.http.NameValuePair; |
||||||
|
import com.fr.third.org.apache.http.client.CookieStore; |
||||||
|
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||||
|
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.entity.StringEntity; |
||||||
|
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||||
|
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.impl.cookie.BasicClientCookie; |
||||||
|
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||||
|
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||||
|
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||||
|
import com.fr.third.org.apache.http.util.EntityUtils; |
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext; |
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.security.KeyManagementException; |
||||||
|
import java.security.KeyStoreException; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.security.cert.CertificateException; |
||||||
|
import java.security.cert.X509Certificate; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
public class HttpUtils { |
||||||
|
/** |
||||||
|
* httpGet请求 |
||||||
|
* @param url |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String get(String url,Cookie[] cookies,Map<String,String> header){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||||
|
|
||||||
|
//创建httpClient
|
||||||
|
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||||
|
|
||||||
|
HttpGet getMethod = new HttpGet(url); |
||||||
|
|
||||||
|
if(header != null && header.size() > 0){ |
||||||
|
Set<String> keySet = header.keySet(); |
||||||
|
|
||||||
|
for(String key : keySet){ |
||||||
|
getMethod.setHeader(key,header.get(key)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
HttpResponse response = httpclient.execute(getMethod); |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+response.getStatusLine().getStatusCode()); |
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
||||||
|
HttpEntity entity = response.getEntity(); |
||||||
|
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||||
|
|
||||||
|
return returnResult; |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* HttpPost请求 |
||||||
|
* @param postMethod |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private static String HttpPost(HttpPost postMethod){ |
||||||
|
CloseableHttpClient httpclient = createHttpClient(null); |
||||||
|
|
||||||
|
try { |
||||||
|
HttpResponse response = httpclient.execute(postMethod); |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+response.getStatusLine().getStatusCode()); |
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
||||||
|
HttpEntity entity = response.getEntity(); |
||||||
|
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||||
|
|
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||||
|
|
||||||
|
return returnResult; |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
public static String HttpPostXML(String url, String xmlParam){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||||
|
|
||||||
|
HttpPost postMethod = new HttpPost(url); |
||||||
|
|
||||||
|
postMethod.setHeader("Content-type", "text/html"); |
||||||
|
HttpEntity entity2 = null; |
||||||
|
try { |
||||||
|
entity2 = new StringEntity(xmlParam); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
postMethod.setEntity(entity2); |
||||||
|
|
||||||
|
return HttpPost(postMethod); |
||||||
|
} |
||||||
|
|
||||||
|
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||||
|
FRUtils.FRLogInfo("param:"+param); |
||||||
|
|
||||||
|
HttpPost postMethod = new HttpPost(url); |
||||||
|
|
||||||
|
postMethod.setHeader("Content-Type","application/json"); |
||||||
|
|
||||||
|
if(header != null && header.size() > 0){ |
||||||
|
FRUtils.FRLogInfo("header:"+header.toString()); |
||||||
|
Set<String> keySet = header.keySet(); |
||||||
|
|
||||||
|
for(String key : keySet){ |
||||||
|
postMethod.setHeader(key,header.get(key)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if(!Utils.isNullStr(param)){ |
||||||
|
HttpEntity entity2 = null; |
||||||
|
try { |
||||||
|
entity2 = new StringEntity(param); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
postMethod.setEntity(entity2); |
||||||
|
} |
||||||
|
|
||||||
|
return HttpPost(postMethod); |
||||||
|
} |
||||||
|
|
||||||
|
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); |
||||||
|
|
||||||
|
HttpPost postMethod = new HttpPost(url); |
||||||
|
|
||||||
|
if(header != null && header.size() > 0){ |
||||||
|
Set<String> keySet = header.keySet(); |
||||||
|
|
||||||
|
for(String key : keySet){ |
||||||
|
postMethod.setHeader(key,header.get(key)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if(param != null && param.size() > 0){ |
||||||
|
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||||
|
|
||||||
|
for(Map.Entry<String,String> map : param.entrySet()){ |
||||||
|
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return HttpPost(postMethod); |
||||||
|
} |
||||||
|
|
||||||
|
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||||
|
|
||||||
|
SSLContext sslContext = null; |
||||||
|
try { |
||||||
|
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||||
|
@Override |
||||||
|
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||||
|
return true; |
||||||
|
} |
||||||
|
}).build(); |
||||||
|
} catch (NoSuchAlgorithmException e) { |
||||||
|
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||||
|
} catch (KeyManagementException e) { |
||||||
|
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||||
|
} catch (KeyStoreException e) { |
||||||
|
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
CloseableHttpClient httpclient = null; |
||||||
|
|
||||||
|
if(cookies != null && cookies.length > 0){ |
||||||
|
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||||
|
|
||||||
|
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||||
|
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||||
|
} |
||||||
|
else{ |
||||||
|
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||||
|
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||||
|
} |
||||||
|
|
||||||
|
return httpclient; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* cookies转cookieStore |
||||||
|
* @param cookies |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||||
|
CookieStore cookieStore = new BasicCookieStore(); |
||||||
|
|
||||||
|
if(cookies != null && cookies.length>0){ |
||||||
|
for(Cookie cookie : cookies){ |
||||||
|
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||||
|
cookieStore.addCookie(cookie1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return cookieStore; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
public class ResponseUtils { |
||||||
|
private static final int SUCCESS = 200; |
||||||
|
private static final int FAILED = -1; |
||||||
|
|
||||||
|
public static void successResponse(HttpServletResponse res, String body) { |
||||||
|
response(res, body, SUCCESS); |
||||||
|
} |
||||||
|
|
||||||
|
public static void failedResponse(HttpServletResponse res, String body) { |
||||||
|
response(res, body, FAILED); |
||||||
|
} |
||||||
|
|
||||||
|
private static void response(HttpServletResponse res, String body, int code) { |
||||||
|
JSONObject object = new JSONObject(); |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
object.put("code", code); |
||||||
|
object.put("data", body); |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("application/json;charset=utf-8"); |
||||||
|
String result = object.toString(); |
||||||
|
pw.println(result); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void response(HttpServletResponse res,JSONObject json){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("application/json;charset=utf-8"); |
||||||
|
String result = json.toString(); |
||||||
|
pw.println(result); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||||
|
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||||
|
} |
||||||
|
|
||||||
|
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||||
|
PrintWriter pw; |
||||||
|
try { |
||||||
|
pw = WebUtils.createPrintWriter(res); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
return; |
||||||
|
} |
||||||
|
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||||
|
String result = json.toString(); |
||||||
|
|
||||||
|
String jsonp=req.getParameter("callback"); |
||||||
|
|
||||||
|
pw.println(jsonp+"("+result+")"); |
||||||
|
pw.flush(); |
||||||
|
pw.close(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.json.JSONObject; |
||||||
|
|
||||||
|
public class Test { |
||||||
|
public static void main(String[] args) { |
||||||
|
String url = "localhost:8075/webroot/decision/view"; |
||||||
|
|
||||||
|
System.out.println(url.substring(url.indexOf("/webroot/decision"),url.length())); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,95 @@ |
|||||||
|
package com.fr.plugin.ztsso.utils; |
||||||
|
|
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.stable.CodeUtils; |
||||||
|
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
public class Utils { |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断字符串是否为空 |
||||||
|
* @param str |
||||||
|
* @return true 空字符串 false 非空字符串 |
||||||
|
*/ |
||||||
|
public static boolean isNullStr(String str){ |
||||||
|
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断字符串是否非空 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isNotNullStr(String str){ |
||||||
|
return !isNullStr(str); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* MD5加密 |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getMd5Str(String str) |
||||||
|
{ |
||||||
|
return DigestUtils.md5Hex(str); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取完整的访问路径 |
||||||
|
*/ |
||||||
|
public static String getAllUrl(HttpServletRequest req, String queryStr){ |
||||||
|
String url = req.getRequestURL().toString(); |
||||||
|
|
||||||
|
if(isNullStr(queryStr)){ |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
return url+"?"+queryStr; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帆软shaEncode加密 |
||||||
|
*/ |
||||||
|
|
||||||
|
public static String shaEncode(String str){ |
||||||
|
return CodeUtils.sha256Encode(str); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取uuid |
||||||
|
*/ |
||||||
|
public static String uuid(){ |
||||||
|
return UUID.randomUUID().toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public static String replaceNullStr(String str,String replace){ |
||||||
|
if(isNullStr(str)){ |
||||||
|
return replace; |
||||||
|
} |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
String line = null; |
||||||
|
try { |
||||||
|
BufferedReader reader = req.getReader(); |
||||||
|
while ((line = reader.readLine()) != null) |
||||||
|
sb.append(line); |
||||||
|
} catch (Exception e) { |
||||||
|
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||||
|
} |
||||||
|
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||||
|
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||||
|
|
||||||
|
JSONObject json = new JSONObject(jsonString); |
||||||
|
|
||||||
|
return json; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue