28 changed files with 2436 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8345 |
||||
|
||||
JSD-8345 开源任务材料 |
||||
JSD-8345 开源任务材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.ztzzSSO</id> |
||||
<name><![CDATA[单点登录和组织用户同步]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.10</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>wink</vendor> |
||||
<description><![CDATA[单点登录和组织用户同步]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.ztzzSSO</main-package> |
||||
<lifecycle-monitor class="com.fr.plugin.ztzzSSO.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<LogInOutEventProvider class="com.fr.plugin.ztzzSSO.logout.Logout"/> |
||||
<EmbedRequestFilterProvider class="com.fr.plugin.ztzzSSO.filter.SSOFilter"/> |
||||
<HttpHandlerProvider class="com.fr.plugin.ztzzSSO.handler.ExtendAttrHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.ztzzSSO.handler.URLAliasProvide"/> |
||||
</extra-decision> |
||||
<extra-designer> |
||||
<ServerTableDataDefineProvider class="com.fr.plugin.ztzzSSO.serverDS.UserHttpTableDataDefine"/> |
||||
<ServerTableDataDefineProvider class="com.fr.plugin.ztzzSSO.serverDS.OrgHttpTableDataDefine"/> |
||||
</extra-designer> |
||||
|
||||
<function-recorder class="com.fr.plugin.ztzzSSO.config.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.fr.plugin.ztzzSSO.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2018-12-04 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,176 @@
|
||||
package com.fr.plugin.ztzzSSO.config; |
||||
|
||||
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 = "client_id", status = Status.SHOW) |
||||
private Conf<String> appId = Holders.simple("xxx"); |
||||
|
||||
@Identifier(value = "secret", name = "clientsecret", description = "client_secret", status = Status.SHOW) |
||||
private Conf<String> host = Holders.simple("xxx"); |
||||
|
||||
@Identifier(value = "codeUrl", name = "获取授权码接口地址", description = "authorize", status = Status.SHOW) |
||||
private Conf<String> codeUrl = Holders.simple("https://xxx/idp/oauth2/authorize"); |
||||
|
||||
@Identifier(value = "tokenUrl", name = "获取token接口地址", description = "getToken", status = Status.SHOW) |
||||
private Conf<String> tokenUrl = Holders.simple("https://xxx/idp/oauth2/getToken"); |
||||
|
||||
@Identifier(value = "userInfoUrl", name = "获取用户信息接口地址", description = "getUserInfo", status = Status.SHOW) |
||||
private Conf<String> userInfoUrl = Holders.simple("https://xxx/idp/oauth2/getUserInfo"); |
||||
|
||||
@Identifier(value = "logoutUrl", name = "登出接口地址", description = "GLO", status = Status.SHOW) |
||||
private Conf<String> logoutUrl = Holders.simple("https://xxx/idp/oauth2//Redirect/GLO"); |
||||
|
||||
@Identifier(value = "rzzxUrl", name = "认证中心登录地址", description = "认证中心登录地址", status = Status.SHOW) |
||||
private Conf<String> rzzxUrl = Holders.simple("https://xxx/idp/oauth2//Redirect/GLO"); |
||||
|
||||
|
||||
// -----------------------------------用户同步---------------------------------
|
||||
@Identifier(value = "username", name = "用户名-数据同步", description = "用户名-数据同步", status = Status.SHOW) |
||||
private Conf<String> username = Holders.simple("xxx"); |
||||
|
||||
@Identifier(value = "psd", name = "密码-数据同步", description = "密码-数据同步", status = Status.SHOW) |
||||
private Conf<String> psd = Holders.simple("xxx"); |
||||
|
||||
@Identifier(value = "tokenUrl2", name = "token接口-数据同步", description = "获取token-数据同步", status = Status.SHOW) |
||||
private Conf<String> tokenUrl2 = Holders.simple("http://xxx/api/users/login"); |
||||
|
||||
@Identifier(value = "orgUrl", name = "组织接口-数据同步", description = "组织接口-数据同步", status = Status.SHOW) |
||||
private Conf<String> orgUrl = Holders.simple("http://xxx/api/mdm/m_organization/query"); |
||||
|
||||
@Identifier(value = "userUrl", name = "用户接口-数据同步", description = "用户接口-数据同步", status = Status.SHOW) |
||||
private Conf<String> userUrl = Holders.simple("http://xxx/api/mdm/m_person_basic_info/query"); |
||||
|
||||
public String getRzzxUrl() { |
||||
return rzzxUrl.get(); |
||||
} |
||||
|
||||
public void settRzzxUrl(String userInfoUrl) { |
||||
this.rzzxUrl.set(userInfoUrl); |
||||
} |
||||
|
||||
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 getTokenUrl2() { |
||||
return tokenUrl2.get(); |
||||
} |
||||
|
||||
public void setTokenUrl2(String tokenUrl) { |
||||
this.tokenUrl2.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); |
||||
} |
||||
|
||||
public String getUsername() { |
||||
return username.get(); |
||||
} |
||||
|
||||
public void setUsername(String url) { |
||||
this.username.set(url); |
||||
} |
||||
|
||||
public String getPsd() { return psd.get(); } |
||||
|
||||
public void setPsd(String url) { |
||||
this.psd.set(url); |
||||
} |
||||
|
||||
|
||||
public String getOrgUrl() { return orgUrl.get(); } |
||||
|
||||
public void setOrgUrl(String url) { |
||||
this.orgUrl.set(url); |
||||
} |
||||
|
||||
|
||||
public String getUserUrl() { return userUrl.get(); } |
||||
|
||||
public void setUserUrl(String url) { |
||||
this.userUrl.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,175 @@
|
||||
package com.fr.plugin.ztzzSSO.filter; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.ztzzSSO.config.PluginSimpleConfig; |
||||
import com.fr.plugin.ztzzSSO.utils.FRUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.HttpUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.ResponseUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.Utils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
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) { |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
//是否登录
|
||||
boolean isLogin = FRUtils.isLogin(httpServletRequest); |
||||
|
||||
//访问路径
|
||||
String url = FRUtils.getAllUrl(httpServletRequest,psc.getFrDomain()); |
||||
//获取code
|
||||
String code = httpServletRequest.getParameter("code"); |
||||
String msg = httpServletRequest.getParameter("msg"); |
||||
|
||||
//跳转路径
|
||||
String redirectUrl = ""; |
||||
//是否从一体化进入
|
||||
String fromSSO = httpServletRequest.getParameter("fromSSO"); |
||||
|
||||
//从一体化进入每次都重新请求code
|
||||
if(Utils.isNotNullStr(fromSSO) && "1".equals(fromSSO)){ |
||||
FRUtils.FRLogInfo("一体化跳转:"+url); |
||||
redirectUrl = url.substring(0,url.indexOf("?fromSSO")); |
||||
FRUtils.FRLogInfo("一体化跳转,截取后url:"+url); |
||||
|
||||
redirect(httpServletRequest,httpServletResponse,redirectUrl); |
||||
return ; |
||||
} |
||||
|
||||
//如果已经登录而且没有code和msg则放行
|
||||
if(isLogin && Utils.isNullStr(code) && Utils.isNullStr(msg)){ |
||||
return ; |
||||
} |
||||
|
||||
//如果是自带登录页资源则放行
|
||||
if(url.contains("test")||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
|
||||
if(Utils.isNullStr(code) && Utils.isNullStr(msg)){ |
||||
redirect(httpServletRequest,httpServletResponse,url); |
||||
return ; |
||||
} |
||||
|
||||
|
||||
//获取code错误
|
||||
if(Utils.isNotNullStr(msg)){ |
||||
FRUtils.FRLogInfo("获取授权码异常:"+msg); |
||||
ResponseUtils.failedResponse(httpServletResponse,"获取授权码异常:"+msg); |
||||
return; |
||||
} |
||||
|
||||
//获取token
|
||||
JSONObject tokenResultJson = getToken(code); |
||||
String token = tokenResultJson.getString("access_token"); |
||||
|
||||
if(Utils.isNullStr(token)){ |
||||
ResponseUtils.failedResponse(httpServletResponse,"获取token异常:"); |
||||
} |
||||
|
||||
//获取用户信息
|
||||
String uid = tokenResultJson.getString("uid"); |
||||
|
||||
String loginName = getUsername(token,uid); |
||||
|
||||
if(Utils.isNullStr(loginName)){ |
||||
FRUtils.FRLogInfo("获取用户信息异常:"); |
||||
ResponseUtils.failedResponse(httpServletResponse,"获取用户信息异常:"); |
||||
|
||||
return; |
||||
} |
||||
|
||||
if(url.contains("code=")){ |
||||
url = url.contains("&code") ? url.substring(0,url.indexOf("&code")) :url.substring(0,url.indexOf("?code")); |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("登陆成功-url:"+url); |
||||
|
||||
FRUtils.login(httpServletRequest,httpServletResponse,loginName,url); |
||||
|
||||
} |
||||
|
||||
private String getUsername(String token,String uid){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientId = psc.getAppId(); |
||||
|
||||
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("获取用户信息异常"); |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject userJsonObject = new JSONObject(userInfoResult); |
||||
|
||||
String loginName = userJsonObject.getString("loginName"); |
||||
|
||||
return loginName; |
||||
} |
||||
|
||||
private void redirect(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,String redirectUrl){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientId = psc.getAppId(); |
||||
|
||||
String authUrl = psc.getCodeUrl(); |
||||
|
||||
try { |
||||
redirectUrl= URLEncoder.encode(redirectUrl,"utf-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
return; |
||||
} |
||||
|
||||
authUrl+= "?redirect_uri="+redirectUrl+"&state=123&client_id="+clientId+"&response_type=code"; |
||||
try { |
||||
httpServletResponse.sendRedirect(authUrl); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogInfo("跳转异常:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
private JSONObject getToken(String code){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String clientId = psc.getAppId(); |
||||
String clientSecret= psc.getHost(); |
||||
//获取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)){ |
||||
return new JSONObject(); |
||||
} |
||||
|
||||
JSONObject tokenResultJson = new JSONObject(tokenResult); |
||||
|
||||
return tokenResultJson; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.plugin.ztzzSSO.handler; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.io.context.info.GetConfig; |
||||
|
||||
public class ExtendAttrHandlerProvider extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new Test() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.plugin.ztzzSSO.handler; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.plugin.ztzzSSO.utils.FRUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.ResponseUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
@FunctionRecorder |
||||
public class Test extends BaseHttpHandler { |
||||
|
||||
|
||||
public Test() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/test"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String username = req.getParameter("username"); |
||||
FRUtils.login(req,res,username,"http://localhost:8075/webroot/decision"); |
||||
System.out.println(); |
||||
// HttpSession session = req.getSession(true);
|
||||
// LoginService.getInstance().crossDomainLogout(req,res,"");
|
||||
// session.invalidate();
|
||||
//
|
||||
// String username = LoginService.getInstance().getCurrentUserNameFromRequest(req);
|
||||
//
|
||||
// ResponseUtils.successResponse(res,username);
|
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,17 @@
|
||||
package com.fr.plugin.ztzzSSO.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("/test","/test",true) |
||||
|
||||
|
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fr.plugin.ztzzSSO.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.ztzzSSO.config.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,67 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
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,268 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractDataModel; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.ztzzSSO.config.PluginSimpleConfig; |
||||
import com.fr.plugin.ztzzSSO.utils.FRUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.HttpUtils; |
||||
|
||||
import java.io.*; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
import java.util.*; |
||||
|
||||
public class ORGHttpDataModel extends AbstractDataModel { |
||||
private static String[] COLUMN_NAMES = {"DISPLAY_PATH", "DISPLAY_PATH_NAME", "MDM_CODE","ORG_NAME","ORG_NAME_SHORT", |
||||
"FOUND_DATE","UPDATE_TIME","REG_ADDRESS","ORG_CODE","ORG_UID","ORG_PID"}; |
||||
private int rowCount = TableData.RESULT_ALL; |
||||
private DatasetData datas = new DatasetData(); |
||||
|
||||
public ORGHttpDataModel(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; |
||||
} |
||||
|
||||
public static String httpRequest(String requestUrl, String requestMethod, |
||||
String outputStr, String tokenid) { |
||||
StringBuffer buffer = null; |
||||
HttpURLConnection conn = null; |
||||
InputStream is = null; |
||||
InputStreamReader isr = null; |
||||
try { |
||||
URL url = new URL(requestUrl); |
||||
conn = (HttpURLConnection) url.openConnection(); |
||||
conn.setDoOutput(true); |
||||
conn.setDoInput(true); |
||||
conn.setRequestMethod(requestMethod); |
||||
conn.setRequestProperty("Content-Type", "application/json"); |
||||
conn.setRequestProperty("Authorization", tokenid); |
||||
conn.setRequestProperty("X-MDM-UNIFIED-RESPONSE", "true"); |
||||
conn.connect(); |
||||
// 往服务器端写内容 也就是发起http请求需要带的参数
|
||||
if (null != outputStr) { |
||||
OutputStream os = conn.getOutputStream(); |
||||
os.write(outputStr.getBytes("utf-8")); |
||||
os.close(); |
||||
} |
||||
|
||||
// 读取服务器端返回的内容
|
||||
is = conn.getInputStream(); |
||||
isr = new InputStreamReader(is, "utf-8"); |
||||
BufferedReader br = new BufferedReader(isr); |
||||
buffer = new StringBuffer(); |
||||
String line = null; |
||||
while ((line = br.readLine()) != null) { |
||||
buffer.append(line); |
||||
} |
||||
System.out.println(buffer); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
}finally{ |
||||
if(null != conn){ |
||||
conn.disconnect(); |
||||
} |
||||
if(null != is){ |
||||
try { |
||||
is.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
if(null != isr){ |
||||
try { |
||||
isr.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
return buffer.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 查询数据 |
||||
*/ |
||||
private void queryData() { |
||||
try { |
||||
String token = getToken(); |
||||
FRUtils.FRLogInfo("orgToken:"+token); |
||||
createDatas(0,token); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("数据集获取组织信息,请求出错:"+e.getMessage()); |
||||
throw new NullPointerException("数据集获取组织信息为空," + e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @return |
||||
*/ |
||||
private String getToken(){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String tokenUrl = psc.getTokenUrl2(); |
||||
String username = psc.getUsername(); |
||||
String psd = psc.getPsd(); |
||||
|
||||
Map<String,String> header = new HashMap<String,String>(); |
||||
header.put("Content-Type","application/json"); |
||||
header.put("X-MDM-UNIFIED-RESPONSE","true"); |
||||
|
||||
JSONObject params = new JSONObject(); |
||||
// Map<String,String> params = new HashMap<String,String>();
|
||||
params.put("username",username); |
||||
params.put("password",psd); |
||||
|
||||
String result = ""; |
||||
|
||||
try { |
||||
result = HttpUtils.HttpPostJson(tokenUrl,params.toString(),header); |
||||
} catch (Exception e) { |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject resultJson = new JSONObject(result); |
||||
|
||||
return resultJson.getString("token"); |
||||
} |
||||
|
||||
/** |
||||
* 获取组织数据 |
||||
* @param pageNum |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
private JSONObject getOrg(int pageNum,String token){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
String orgUrl = psc.getOrgUrl()+"?pageNum="+pageNum+"&pageSize=1000";; |
||||
|
||||
FRUtils.FRLogInfo("orgUrl:"+orgUrl); |
||||
|
||||
String result = httpRequest(orgUrl,"POST",null,token); |
||||
FRUtils.FRLogInfo("orgResult:"+result); |
||||
|
||||
return new JSONObject(result); |
||||
} |
||||
|
||||
private void createDatas(int pageNum,String token) { |
||||
JSONObject json = getOrg(pageNum,token); |
||||
JSONArray jsonArray = json.getJSONArray("content"); |
||||
addRowDatas(jsonArray); |
||||
|
||||
boolean last = json.getBoolean("last"); |
||||
if(last){ |
||||
return; |
||||
} |
||||
|
||||
pageNum = pageNum+1; |
||||
|
||||
createDatas(pageNum,token); |
||||
} |
||||
|
||||
/** |
||||
* 添加行数据 |
||||
* @param jsonArray |
||||
*/ |
||||
private void addRowDatas(JSONArray jsonArray) { |
||||
if(jsonArray == null || jsonArray.size() <= 0){ |
||||
return ; |
||||
} |
||||
|
||||
for(int i =0;i< jsonArray.size();i++){ |
||||
JSONObject org = jsonArray.getJSONObject(i); |
||||
|
||||
String DISPLAY_PATH = org.getString("DISPLAY_PATH"); |
||||
String DISPLAY_PATH_NAME = org.getString("DISPLAY_PATH_NAME"); |
||||
String MDM_CODE = org.getString("MDM_CODE"); |
||||
String ORG_NAME = org.getString("ORG_NAME"); |
||||
String ORG_NAME_SHORT = org.getString("ORG_NAME_SHORT"); |
||||
String FOUND_DATE = org.getString("FOUND_DATE"); |
||||
String UPDATE_TIME = org.getString("UPDATE_TIME"); |
||||
String REG_ADDRESS = org.getString("REG_ADDRESS"); |
||||
String ORG_CODE = org.getString("ORG_CODE"); |
||||
String ORG_UID = org.getString("ORG_UID"); |
||||
String ORG_PID = org.getString("ORG_PID"); |
||||
|
||||
List<Object> rowDatas = new ArrayList<Object>(); |
||||
|
||||
rowDatas.add(DISPLAY_PATH); |
||||
rowDatas.add(DISPLAY_PATH_NAME); |
||||
rowDatas.add(MDM_CODE); |
||||
rowDatas.add(ORG_NAME); |
||||
rowDatas.add(ORG_NAME_SHORT); |
||||
rowDatas.add(FOUND_DATE); |
||||
rowDatas.add(UPDATE_TIME); |
||||
rowDatas.add(REG_ADDRESS); |
||||
rowDatas.add(ORG_CODE); |
||||
rowDatas.add(ORG_UID); |
||||
rowDatas.add(ORG_PID); |
||||
|
||||
List<List<Object>> values = this.datas.getValues(); |
||||
values.add(rowDatas); |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractParameterTableData; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.script.Calculator; |
||||
|
||||
public class OrgHttpTableData extends AbstractParameterTableData { |
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator) { |
||||
return createDataModel(calculator, TableData.RESULT_ALL); |
||||
} |
||||
|
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator, int rowCount) { |
||||
return new ORGHttpDataModel(rowCount); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
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 OrgHttpTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForTableData() { |
||||
return OrgHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForInitTableData() { |
||||
return OrgHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||
return OrgHttpTableDataPane.class; |
||||
} |
||||
|
||||
@Override |
||||
public String nameForTableData() { |
||||
return Toolkit.i18nText("组织机构数据集"); |
||||
} |
||||
|
||||
@Override |
||||
public String prefixForTableData() { |
||||
return "zt_org"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForTableData() { |
||||
return ""; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,74 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.design.data.datapane.preview.PreviewTablePane; |
||||
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.general.IOUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
|
||||
public class OrgHttpTableDataPane extends AbstractTableDataPane<OrgHttpTableData> { |
||||
public OrgHttpTableDataPane() { |
||||
super(); |
||||
createContent(); |
||||
} |
||||
|
||||
|
||||
|
||||
@Override |
||||
public void populateBean(OrgHttpTableData ob) { |
||||
if (ob == null) { |
||||
return; |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public OrgHttpTableData updateBean() { |
||||
OrgHttpTableData tableData = new OrgHttpTableData(); |
||||
return tableData; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Toolkit.i18nText("组织机构数据集"); |
||||
} |
||||
|
||||
|
||||
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(Toolkit.i18nText(toolTip)); |
||||
return iconButton; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,260 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractDataModel; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.ztzzSSO.config.PluginSimpleConfig; |
||||
import com.fr.plugin.ztzzSSO.utils.FRUtils; |
||||
import com.fr.plugin.ztzzSSO.utils.HttpUtils; |
||||
|
||||
import java.io.*; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class UserHttpDataModel extends AbstractDataModel { |
||||
private static String[] COLUMN_NAMES = {"Mobile_Phone", "Email", "Gender","Name","Main_Org_Id", |
||||
"Account_Number","Main_Org_Id__ref","Gender__ref"}; |
||||
private int rowCount = TableData.RESULT_ALL; |
||||
private DatasetData datas = new DatasetData(); |
||||
|
||||
public UserHttpDataModel(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){ |
||||
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() { |
||||
this.datas = null; |
||||
} |
||||
|
||||
/** |
||||
* 查询数据 |
||||
*/ |
||||
private void queryData() { |
||||
try { |
||||
String token = getToken(); |
||||
createDatas(0,token); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("数据集获取用户信息,请求出错:"+e.getMessage()); |
||||
throw new NullPointerException("数据集获取用户信息为空," + e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @return |
||||
*/ |
||||
private String getToken(){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String tokenUrl = psc.getTokenUrl2(); |
||||
String username = psc.getUsername(); |
||||
String psd = psc.getPsd(); |
||||
|
||||
Map<String,String> header = new HashMap<String,String>(); |
||||
header.put("Content-Type","application/json"); |
||||
header.put("X-MDM-UNIFIED-RESPONSE","true"); |
||||
|
||||
JSONObject params = new JSONObject(); |
||||
// Map<String,String> params = new HashMap<String,String>();
|
||||
params.put("username",username); |
||||
params.put("password",psd); |
||||
|
||||
String result = ""; |
||||
|
||||
try { |
||||
result = HttpUtils.HttpPostJson(tokenUrl,params.toString(),header); |
||||
} catch (Exception e) { |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject resultJson = new JSONObject(result); |
||||
|
||||
return resultJson.getString("token"); |
||||
} |
||||
|
||||
/** |
||||
* 获取组织数据 |
||||
* @param pageNum |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
private JSONObject getUser(int pageNum,String token){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String orgUrl = psc.getUserUrl()+"?pageNum="+pageNum+"&pageSize=1000"; |
||||
String result = httpRequest(orgUrl,"POST",null,token); |
||||
|
||||
return new JSONObject(result); |
||||
} |
||||
|
||||
public static String httpRequest(String requestUrl, String requestMethod, |
||||
String outputStr, String tokenid) { |
||||
StringBuffer buffer = null; |
||||
HttpURLConnection conn = null; |
||||
InputStream is = null; |
||||
InputStreamReader isr = null; |
||||
try { |
||||
URL url = new URL(requestUrl); |
||||
conn = (HttpURLConnection) url.openConnection(); |
||||
conn.setDoOutput(true); |
||||
conn.setDoInput(true); |
||||
conn.setRequestMethod(requestMethod); |
||||
conn.setRequestProperty("Content-Type", "application/json"); |
||||
conn.setRequestProperty("Authorization", tokenid); |
||||
conn.setRequestProperty("X-MDM-UNIFIED-RESPONSE", "true"); |
||||
conn.connect(); |
||||
// 往服务器端写内容 也就是发起http请求需要带的参数
|
||||
if (null != outputStr) { |
||||
OutputStream os = conn.getOutputStream(); |
||||
os.write(outputStr.getBytes("utf-8")); |
||||
os.close(); |
||||
} |
||||
|
||||
// 读取服务器端返回的内容
|
||||
is = conn.getInputStream(); |
||||
isr = new InputStreamReader(is, "utf-8"); |
||||
BufferedReader br = new BufferedReader(isr); |
||||
buffer = new StringBuffer(); |
||||
String line = null; |
||||
while ((line = br.readLine()) != null) { |
||||
buffer.append(line); |
||||
} |
||||
System.out.println(buffer); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
}finally{ |
||||
if(null != conn){ |
||||
conn.disconnect(); |
||||
} |
||||
if(null != is){ |
||||
try { |
||||
is.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
if(null != isr){ |
||||
try { |
||||
isr.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
return buffer.toString(); |
||||
} |
||||
|
||||
private void createDatas(int pageNum,String token) { |
||||
JSONObject json = getUser(pageNum,token); |
||||
JSONArray jsonArray = json.getJSONArray("content"); |
||||
addRowDatas(jsonArray); |
||||
|
||||
boolean last = json.getBoolean("last"); |
||||
if(last){ |
||||
return; |
||||
} |
||||
|
||||
pageNum = pageNum+1; |
||||
|
||||
createDatas(pageNum,token); |
||||
} |
||||
|
||||
/** |
||||
* 添加行数据 |
||||
* @param jsonArray |
||||
*/ |
||||
private void addRowDatas(JSONArray jsonArray) { |
||||
if(jsonArray == null || jsonArray.size() <= 0){ |
||||
return ; |
||||
} |
||||
|
||||
for(int i =0;i< jsonArray.size();i++){ |
||||
JSONObject org = jsonArray.getJSONObject(i); |
||||
String Mobile_Phone = org.getString("Mobile_Phone"); |
||||
String Email = org.getString("Email"); |
||||
String Gender = org.getString("Gender"); |
||||
String Name = org.getString("Name"); |
||||
String Main_Org_Id = org.getString("Main_Org_Id"); |
||||
String Account_Number = org.getString("Account_Number"); |
||||
String Main_Org_Id__ref = org.getString("Main_Org_Id__ref"); |
||||
String Gender__ref = org.getString("Gender__ref"); |
||||
|
||||
List<Object> rowDatas = new ArrayList<Object>(); |
||||
|
||||
rowDatas.add(Mobile_Phone); |
||||
rowDatas.add(Email); |
||||
rowDatas.add(Gender); |
||||
rowDatas.add(Name); |
||||
rowDatas.add(Main_Org_Id); |
||||
rowDatas.add(Account_Number); |
||||
rowDatas.add(Main_Org_Id__ref); |
||||
rowDatas.add(Gender__ref); |
||||
|
||||
|
||||
List<List<Object>> values = this.datas.getValues(); |
||||
values.add(rowDatas); |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractParameterTableData; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.script.Calculator; |
||||
|
||||
public class UserHttpTableData extends AbstractParameterTableData { |
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator) { |
||||
return createDataModel(calculator, TableData.RESULT_ALL); |
||||
} |
||||
|
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator, int rowCount) { |
||||
return new UserHttpDataModel(rowCount); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
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 UserHttpTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForTableData() { |
||||
return UserHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForInitTableData() { |
||||
return UserHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||
return UserHttpTableDataPane.class; |
||||
} |
||||
|
||||
@Override |
||||
public String nameForTableData() { |
||||
return Toolkit.i18nText("用户信息数据集"); |
||||
} |
||||
|
||||
@Override |
||||
public String prefixForTableData() { |
||||
return "zt_user"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForTableData() { |
||||
return ""; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,74 @@
|
||||
package com.fr.plugin.ztzzSSO.serverDS; |
||||
|
||||
import com.fr.design.data.datapane.preview.PreviewTablePane; |
||||
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.general.IOUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
|
||||
public class UserHttpTableDataPane extends AbstractTableDataPane<UserHttpTableData> { |
||||
public UserHttpTableDataPane() { |
||||
super(); |
||||
createContent(); |
||||
} |
||||
|
||||
|
||||
|
||||
@Override |
||||
public void populateBean(UserHttpTableData ob) { |
||||
if (ob == null) { |
||||
return; |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public UserHttpTableData updateBean() { |
||||
UserHttpTableData tableData = new UserHttpTableData(); |
||||
return tableData; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Toolkit.i18nText("用户信息数据集"); |
||||
} |
||||
|
||||
|
||||
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(Toolkit.i18nText(toolTip)); |
||||
return iconButton; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,227 @@
|
||||
package com.fr.plugin.ztzzSSO.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.ztzzSSO.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.ztzzSSO.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,174 @@
|
||||
package com.fr.plugin.ztzzSSO.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); |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志-error |
||||
* @param message |
||||
*/ |
||||
public static void FRLogError(String message){ |
||||
FineLoggerFactory.getLogger().error("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.ztzzSSO.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.ztzzSSO.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,20 @@
|
||||
package com.fr.plugin.ztzzSSO.utils; |
||||
|
||||
public class Test { |
||||
public static void main(String[] args) { |
||||
// String tokenUrl = "https://tyrz.crec.cn/idp/oauth2/getToken?client_id=fanruan&client_secret=364c4775f2cf42f79e00cfa69157536c&code=0bfe69dbce3de295fa4c7402226b73a4&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);
|
||||
// System.out.println();
|
||||
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.ztzzSSO.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; |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue