23 changed files with 1857 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8642 |
||||
|
||||
JSD-8642 开源任务材料 |
||||
JSD-8642 OA集成模板免登 开源任务材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.wcSSO</id> |
||||
<name><![CDATA[单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.8</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.wcSSO</main-package> |
||||
|
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.wcSSO.config.simple.PluginLocaleFinderBridge"/> |
||||
</extra-core> |
||||
<lifecycle-monitor class="com.fr.plugin.wcSSO.config.simple.DemoInitializeMonitor"/> |
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.wcSSO.handler.ExtendAttrHandlerProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.wcSSO.handler.URLAliasProvide"/> |
||||
<LogInOutEventProvider class="com.fr.plugin.wcSSO.logout.Logout"/> |
||||
<EmbedRequestFilterProvider class="com.fr.plugin.wcSSO.filter.SSOFilter"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.wcSSO.config.simple.account.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,22 @@
|
||||
package com.fr.plugin.wcSSO.config.simple; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
import com.fr.plugin.wcSSO.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.wcSSO.config.simple; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||
import com.fr.plugin.wcSSO.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.wcSSO.config.simple; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
public class PluginLocaleFinderBridge extends AbstractLocaleFinder { |
||||
@Override |
||||
public String find() { |
||||
return "conf"; |
||||
} |
||||
} |
@ -0,0 +1,79 @@
|
||||
package com.fr.plugin.wcSSO.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.wcSSO.config.simple", text = "单点登录配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "index", name = "报表系统域名", description = "报表系统域名", status = Status.SHOW) |
||||
private Conf<String> index = Holders.simple("https://dmpreport.microport.com.cn"); |
||||
|
||||
@Identifier(value = "domainName", name = "认证中心域名", description = "认证中心域名", status = Status.SHOW) |
||||
private Conf<String> domainName = Holders.simple("https://dmpreport.microport.com.cn"); |
||||
|
||||
@Identifier(value = "clientId", name = "认证中心clientId", description = "认证中心clientId", status = Status.SHOW) |
||||
private Conf<String> clientId = Holders.simple("13"); |
||||
|
||||
@Identifier(value = "clientSecret", name = "认证中心Secret", description = "认证中心Secret", status = Status.SHOW) |
||||
private Conf<String> clientSecret = Holders.simple("8a7d7981172640af8648b574b0d00d34"); |
||||
|
||||
public String getDomainName() { |
||||
return domainName.get(); |
||||
} |
||||
|
||||
public void setDomainName(String domainName) { |
||||
this.domainName.set(domainName); |
||||
} |
||||
|
||||
public String getIndex() { |
||||
return index.get(); |
||||
} |
||||
|
||||
public void setIndex(String index) { |
||||
this.index.set(index); |
||||
} |
||||
|
||||
public String getClientId() { |
||||
return clientId.get(); |
||||
} |
||||
|
||||
public void setClientId(String clientId) { |
||||
this.clientId.set(clientId); |
||||
} |
||||
|
||||
public String getClientSecret() { |
||||
return clientSecret.get(); |
||||
} |
||||
|
||||
public void setClientSecret(String clientSecret) { |
||||
this.clientSecret.set(clientSecret); |
||||
} |
||||
|
||||
@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,80 @@
|
||||
package com.fr.plugin.wcSSO.filter; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.wcSSO.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.wcSSO.handler.Login; |
||||
import com.fr.plugin.wcSSO.utils.FRUtils; |
||||
import com.fr.plugin.wcSSO.utils.HttpUtils; |
||||
import com.fr.plugin.wcSSO.utils.ResponseUtils; |
||||
import com.fr.plugin.wcSSO.utils.Utils; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.net.URLEncoder; |
||||
|
||||
public class SSOFilter extends AbstractEmbedRequestFilterProvider { |
||||
|
||||
@Override |
||||
public void filter(HttpServletRequest req, HttpServletResponse res) { |
||||
PluginSimpleConfig simpleConfig = PluginSimpleConfig.getInstance(); |
||||
String clientId = simpleConfig.getClientId(); |
||||
String clientSecret = simpleConfig.getClientSecret(); |
||||
String sso =req.getParameter("sso"); |
||||
String url = FRUtils.getAllUrl(req,simpleConfig.getIndex()); |
||||
|
||||
FRUtils.FRLogInfo("ssofilter url :"+url); |
||||
|
||||
|
||||
//非单点链接,跳过
|
||||
if(!"1".equals(sso)){ |
||||
return ; |
||||
} |
||||
|
||||
//授权码
|
||||
String code = req.getParameter("code"); |
||||
|
||||
//跳转链接
|
||||
if(code == null || Utils.isNullStr(code)){ |
||||
redirect(req,res); |
||||
return; |
||||
} |
||||
|
||||
//获取token
|
||||
String token = Login.getToken(clientId,clientSecret); |
||||
|
||||
if(token == null || Utils.isNullStr(token)){ |
||||
FRUtils.FRLogInfo("获取token失败!"); |
||||
ResponseUtils.failedResponse(res,"获取token失败!"); |
||||
|
||||
return; |
||||
} |
||||
url = url.substring(0,url.indexOf(url.contains("&sso") ? "&sso" : "?sso" )); |
||||
url = Utils.encodeCH(url); |
||||
//获取用户信息
|
||||
String userName = Login.getUserInfo(code,token); |
||||
|
||||
FRUtils.login(req,res,userName,url); |
||||
} |
||||
|
||||
private void redirect(HttpServletRequest req, HttpServletResponse res) { |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String url = FRUtils.getAllUrl(req,psc.getIndex()); |
||||
|
||||
FRUtils.FRLogInfo("redirect url "+url); |
||||
|
||||
PluginSimpleConfig simpleConfig = PluginSimpleConfig.getInstance(); |
||||
String tokenUrl = simpleConfig.getDomainName()+"/AuthUser/CheckUser?client_id="+simpleConfig.getClientId()+"&redirect_uri="+ URLEncoder.encode(url); |
||||
|
||||
FRUtils.FRLogInfo("redirect rzzxurl "+tokenUrl); |
||||
|
||||
|
||||
try { |
||||
res.sendRedirect(tokenUrl); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogInfo("redirect exception: "+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.wcSSO.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 Login(),new ToLogin(),new ToDecisionLogin(),new GetDomainName() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
package com.fr.plugin.wcSSO.handler; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.config.AppearanceConfig; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.plugin.wcSSO.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.wcSSO.utils.ResponseUtils; |
||||
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.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@FunctionRecorder |
||||
public class GetDomainName extends BaseHttpHandler { |
||||
|
||||
|
||||
public GetDomainName() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/getDomainName"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String url = psc.getIndex(); |
||||
String domainName = psc.getDomainName(); |
||||
String clientId = psc.getClientId(); |
||||
|
||||
ResponseUtils.successResponse(res,url+","+domainName+","+clientId); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,129 @@
|
||||
package com.fr.plugin.wcSSO.handler; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.plugin.wcSSO.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.wcSSO.utils.FRUtils; |
||||
import com.fr.plugin.wcSSO.utils.HttpUtils; |
||||
import com.fr.plugin.wcSSO.utils.ResponseUtils; |
||||
import com.fr.plugin.wcSSO.utils.Utils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
@FunctionRecorder |
||||
public class Login extends BaseHttpHandler { |
||||
public Login() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/sso"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
PluginSimpleConfig simpleConfig = PluginSimpleConfig.getInstance(); |
||||
String clientId = simpleConfig.getClientId(); |
||||
String clientSecret = simpleConfig.getClientSecret(); |
||||
String url = simpleConfig.getIndex(); |
||||
String origin = req.getParameter("origin"); |
||||
|
||||
if(Utils.isNotNullStr(origin)){ |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(origin); |
||||
String originUrl = originUrlResponseBean.getOriginUrl(); |
||||
url = url+originUrl; |
||||
}else{ |
||||
url +="/webroot/decision"; |
||||
} |
||||
|
||||
//授权码
|
||||
String code = req.getParameter("code"); |
||||
|
||||
if(code == null || Utils.isNullStr(code)){ |
||||
FRUtils.FRLogInfo("code为空!"); |
||||
ResponseUtils.failedResponse(res,"code为空!"); |
||||
|
||||
return; |
||||
} |
||||
//获取token
|
||||
String token = getToken(clientId,clientSecret); |
||||
|
||||
if(token == null || Utils.isNullStr(token)){ |
||||
FRUtils.FRLogInfo("获取token失败!"); |
||||
ResponseUtils.failedResponse(res,"获取token失败!"); |
||||
|
||||
return; |
||||
} |
||||
|
||||
//获取用户信息
|
||||
String userName = getUserInfo(code,token); |
||||
|
||||
FRUtils.login(req,res,userName,url); |
||||
} |
||||
|
||||
public static String getToken(String clientId,String clientSecret){ |
||||
PluginSimpleConfig simpleConfig = PluginSimpleConfig.getInstance(); |
||||
|
||||
String tokenUrl = simpleConfig.getDomainName()+"/api/sns/AppToken?clientId="+clientId+"&clientSecret="+clientSecret; |
||||
|
||||
String result = HttpUtils.httpGet(tokenUrl,null); |
||||
|
||||
if(result == null || Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
|
||||
String errorMessage = json.getString("ErrorMessage"); |
||||
|
||||
if(errorMessage != null && Utils.isNotNullStr(errorMessage)){ |
||||
FRUtils.FRLogInfo("获取token失败:"+errorMessage); |
||||
} |
||||
|
||||
return json.getString("AppToken"); |
||||
} |
||||
|
||||
public static String getUserInfo(String code,String token){ |
||||
PluginSimpleConfig simpleConfig = PluginSimpleConfig.getInstance(); |
||||
|
||||
String userInfoUrl = simpleConfig.getDomainName()+"/api/sns/UserInfo?appToken="+token+"&useraccesstoken="+code; |
||||
|
||||
String result = HttpUtils.httpGet(userInfoUrl,null); |
||||
|
||||
if(result == null || Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject jsonObject = new JSONObject(result); |
||||
|
||||
String name = jsonObject.getString("Name"); |
||||
|
||||
if(name != null){ |
||||
return name; |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,99 @@
|
||||
package com.fr.plugin.wcSSO.handler; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.decision.config.AppearanceConfig; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.web.LoginComponent; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.config.ConfigService; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.general.CloudCenter; |
||||
import com.fr.general.CloudCenterConfig; |
||||
import com.fr.security.SecurityConfig; |
||||
import com.fr.security.encryption.SystemEncryptionManager; |
||||
import com.fr.security.encryption.transmission.impl.SM4TransmissionEncryption; |
||||
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.Browser; |
||||
import com.fr.web.struct.AtomBuilder; |
||||
import com.fr.web.struct.PathGroup; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class ToDecisionLogin extends BaseHttpHandler { |
||||
|
||||
|
||||
public ToDecisionLogin() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/toDecisionLogin"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
|
||||
//特定版本
|
||||
Map<String, Object> param = new HashMap(); |
||||
ObjectMapper mapper = new ObjectMapper(); |
||||
param.put("title", AppearanceConfig.getInstance().getPlatformTitle()); |
||||
param.put("loginConfig", mapper.writeValueAsString(ConfigService.getInstance().getLoginAppearanceConfig())); |
||||
param.put("charset", ServerConfig.getInstance().getServerCharset()); |
||||
PathGroup group = AtomBuilder.create().buildAssembleFilePath(Browser.resolve(req), LoginComponent.KEY); |
||||
param.put("styleTag", AtomBuilder.create().toHtmlTag(group.toStylePathGroup())); |
||||
param.put("scriptTag", AtomBuilder.create().toHtmlTag(group.toScriptPathGroup())); |
||||
Map<String, Object> system = new HashMap(); |
||||
system.put("frontSeed", SecurityConfig.getInstance().getFrontSeed()); |
||||
system.put("cloudEnabled", CloudCenterConfig.getInstance().isOnline()); |
||||
system.put("urlIP", CloudCenter.getInstance().acquireConf("decision.queryip", "")); |
||||
if (AppearanceConfig.getInstance().isCopyrightInfoDisplay()) { |
||||
system.putAll(LoginService.getInstance().getCopyrightInfo(req)); |
||||
} |
||||
|
||||
param.put("system", mapper.writeValueAsString(system)); |
||||
String a = WebServiceUtils.parseWebPageResourceSafe("/com/fr/web/controller/decision/entrance/resources/login.html", param); |
||||
WebUtils.printAsString(res, a); |
||||
// HashMap var3 = new HashMap();
|
||||
// ObjectMapper var4 = new ObjectMapper();
|
||||
// var3.put("title", AppearanceConfig.getInstance().getPlatformTitle());
|
||||
// var3.put("loginConfig", var4.writeValueAsString(ConfigService.getInstance().getLoginAppearanceConfig()));
|
||||
// var3.put("charset", ServerConfig.getInstance().getServerCharset());
|
||||
// PathGroup var5 = AtomBuilder.create().buildAssembleFilePath(Browser.resolve(req), LoginComponent.KEY);
|
||||
// var3.put("styleTag", AtomBuilder.create().toHtmlTag(var5.toStylePathGroup()));
|
||||
// var3.put("scriptTag", AtomBuilder.create().toHtmlTag(var5.toScriptPathGroup()));
|
||||
// HashMap var6 = new HashMap();
|
||||
// var6.put("frontSeed", SecurityConfig.getInstance().getFrontSeed());
|
||||
// var6.put("transmissionEncryption", SystemEncryptionManager.getInstance().getTransmissionEncryption().getType());
|
||||
// var6.put("frontSM4Key", SM4TransmissionEncryption.getInstance().getTransmissionKey());
|
||||
// var6.put("cloudEnabled", CloudCenterConfig.getInstance().isOnline());
|
||||
// var6.put("urlIP", CloudCenter.getInstance().acquireConf("decision.queryip", ""));
|
||||
// if (AppearanceConfig.getInstance().isCopyrightInfoDisplay()) {
|
||||
// var6.putAll(LoginService.getInstance().getCopyrightInfo(req));
|
||||
// }
|
||||
//
|
||||
// var3.put("system", var4.writeValueAsString(var6));
|
||||
//
|
||||
// String a =WebServiceUtils.parseWebPageResourceSafe("/com/fr/web/controller/decision/entrance/resources/login.html", var3);
|
||||
// WebUtils.printAsString(res, a);
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,58 @@
|
||||
package com.fr.plugin.wcSSO.handler; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.config.AppearanceConfig; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.controller.decision.api.auth.LoginResource; |
||||
import com.fr.web.utils.WebUtils; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@FunctionRecorder |
||||
public class ToLogin extends BaseHttpHandler { |
||||
|
||||
|
||||
public ToLogin() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.GET; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/toSso"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String origin = req.getParameter("origin"); |
||||
String url = AppearanceConfig.getInstance().getLoginUrl(); |
||||
|
||||
if(origin != null ){ |
||||
url = HttpToolbox.appendQuery(url,"origin",origin); |
||||
} |
||||
|
||||
Map<String, String> parameterMap = new HashMap<String, String>(); |
||||
String path = "/com/fr/plugin/wcSSO/html/login.html"; |
||||
parameterMap.put("remoteServletURL", WebUtils.getOriginalURL(req)); |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,17 @@
|
||||
package com.fr.plugin.wcSSO.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("/sso","/sso",true), |
||||
URLAliasFactory.createPluginAlias("/toSso","/toSso",true), |
||||
URLAliasFactory.createPluginAlias("/toDecisionLogin","/toDecisionLogin",true), |
||||
URLAliasFactory.createPluginAlias("/getDomainName","/getDomainName",true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.wcSSO.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.wcSSO.config.simple.account.PluginSimpleConfig; |
||||
import com.fr.plugin.wcSSO.utils.FRUtils; |
||||
|
||||
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(); |
||||
FRUtils.FRLogInfo("logout:"); |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String reportDomain = psc.getIndex(); |
||||
return reportDomain+"/webroot/decision"; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,159 @@
|
||||
package com.fr.plugin.wcSSO.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); |
||||
return domain+url.substring(url.indexOf("/webroot"),url.length()); |
||||
} |
||||
} |
@ -0,0 +1,221 @@
|
||||
package com.fr.plugin.wcSSO.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 httpGet(String url,Cookie[] cookies){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
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){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
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,61 @@
|
||||
package com.fr.plugin.wcSSO.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
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"); |
||||
} |
||||
} |
@ -0,0 +1,197 @@
|
||||
package com.fr.plugin.wcSSO.utils; |
||||
|
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.BufferedReader; |
||||
import java.net.URLEncoder; |
||||
import java.util.UUID; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
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); |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
/** |
||||
* 替换空字符串 |
||||
* @param str |
||||
* @param replace |
||||
* @return |
||||
*/ |
||||
public static String replaceNullStr(String str,String replace){ |
||||
if(isNullStr(str)){ |
||||
return replace; |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求体 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
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; |
||||
} |
||||
|
||||
/** |
||||
* 获取ip |
||||
* @return |
||||
*/ |
||||
public static String getIp(HttpServletRequest req){ |
||||
String realIp = req.getHeader("X-Real-IP"); |
||||
String fw = req.getHeader("X-Forwarded-For"); |
||||
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||
int var3 = fw.indexOf(","); |
||||
return var3 != -1 ? fw.substring(0, var3) : fw; |
||||
} else { |
||||
fw = realIp; |
||||
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||
return realIp; |
||||
} else { |
||||
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||
fw = req.getHeader("Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getRemoteAddr(); |
||||
} |
||||
|
||||
return fw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据key获取cookie |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||
Cookie[] cookies = req.getCookies(); |
||||
String cookie = ""; |
||||
|
||||
if(cookies == null || cookies.length <=0){ |
||||
return ""; |
||||
} |
||||
|
||||
for(int i = 0; i < cookies.length; i++) { |
||||
Cookie item = cookies[i]; |
||||
if (item.getName().equalsIgnoreCase(key)) { |
||||
cookie = item.getValue(); |
||||
} |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("cookie:"+cookie); |
||||
|
||||
return cookie; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是手机端的链接 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest req) { |
||||
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||
String userAgent = req.getHeader("user-agent"); |
||||
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||
for(String mobile : mobileArray) { |
||||
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return NetworkHelper.getDevice(req).isMobile(); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String encodeCH(String url ){ |
||||
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||
|
||||
while(matcher.find()){ |
||||
String chn = matcher.group(); |
||||
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||
} |
||||
|
||||
return url; |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 71 KiB |
@ -0,0 +1,204 @@
|
||||
<!DOCTYPE html> |
||||
<!-- saved from url=(0109)http://microport.onesignon.jqk.cool:20002/AuthUser/CheckUser?client_id=1019&redirect_uri=demo.myonesignon.com --> |
||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||
<meta name="viewport" content="width=device-width"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=11,chrome=1"> |
||||
<!-- Open Graph data --> |
||||
<meta property="og:title" content="OneSignon集中登录"> |
||||
<!-- <meta property="og:image" content="http://microport.onesignon.jqk.cool:20002/Content/SSO/image/logothunil.png"> --> |
||||
<meta property="og:image" content="http://microport.onesignon.jqk.cool:20002/Content/SSO/image/logothunil.png"> |
||||
<meta property="og:description" content="OneSignon为企业提供集中的、安全的和完善的登录解决方案。"> |
||||
<title>登录</title> |
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div class="container body-content"> |
||||
|
||||
|
||||
<link href="/webroot/decision/file?path=/com/fr/plugin/wcSSO/html/microport-login.css" rel="stylesheet"> |
||||
<!--<link href="https://dmpreport.microport.com.cn/webroot/decision/file?path=/com/fr/plugin/wcSSO/html/microport-login.css" rel="stylesheet">--> |
||||
<style> |
||||
.hidediv { |
||||
display:none; |
||||
} |
||||
</style> |
||||
<div class="loading" style="display: none;"> |
||||
<img src="/webroot/decision/resources?path=/com/fr/plugin/wcSSO/html/loading.gif"> |
||||
<!-- <img src="https://dmpreport.microport.com.cn/webroot/decision/resources?path=/com/fr/plugin/wcSSO/html/loading.gif">--> |
||||
</div> |
||||
<script src="/webroot/decision/file?path=/com/fr/plugin/wcSSO/html/jquery-2.1.3.min.js"></script> |
||||
<!--<script src="https://dmpreport.microport.com.cn/webroot/decision/file?path=/com/fr/plugin/wcSSO/html/jquery-2.1.3.min.js"></script>--> |
||||
|
||||
<script type="text/javascript"> |
||||
var reportDomain = ""; |
||||
var rzzxDomain = ""; |
||||
var _client_id = ""; |
||||
var _redirect_uri = ""; |
||||
// var _registerType = encodeURIComponent(""); |
||||
// var _refSalesEID = encodeURIComponent(""); |
||||
var _app_logo = ""; |
||||
var _fr_login_url = ""; |
||||
|
||||
$(function(){ |
||||
getDomainName(); |
||||
_redirect_uri = encodeURIComponent(reportDomain+"/webroot/decision/url/sso"); |
||||
_fr_login_url = reportDomain+"/webroot/decision/url/toDecisionLogin"; |
||||
}) |
||||
|
||||
function getDomainName(){ |
||||
$.ajax({ |
||||
type:"GET", |
||||
async:false, |
||||
url:"/webroot/decision/url/getDomainName", |
||||
success:function(data){ |
||||
if(data.code == '200'){ |
||||
var domains = data.data.split(","); |
||||
reportDomain = domains[0]; |
||||
rzzxDomain = domains[1]; |
||||
_client_id =encodeURIComponent(domains[2]); |
||||
}else{ |
||||
// ("获取域名失败!"); |
||||
} |
||||
}, |
||||
error:function(data){ |
||||
// alert("获取域名失败!"); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
//获取origin参数 |
||||
function getOrigin(){ |
||||
var origin = ""; |
||||
var url = location.href; |
||||
|
||||
if(url.indexOf('?') == -1){ |
||||
return ""; |
||||
} |
||||
|
||||
var paramStrs = url.split("?")[1]; |
||||
var params = paramStrs.split("&") |
||||
|
||||
$.each(params,function(index,item){ |
||||
var param = item.split("="); |
||||
if(param[0] == "origin"){ |
||||
origin = param[1]; |
||||
} |
||||
|
||||
}) |
||||
|
||||
return origin; |
||||
} |
||||
|
||||
//外部用户登录 |
||||
function goaccount() { |
||||
var origin =getOrigin(); |
||||
|
||||
var url =_fr_login_url; |
||||
|
||||
if(origin != ""){ |
||||
url += "?origin="+origin; |
||||
} |
||||
|
||||
window.location.href = url; |
||||
return; |
||||
} |
||||
|
||||
// function gowx() { |
||||
// var appid = "wxf020452f7b476a58"; |
||||
// var palt_redirect_uri = encodeURIComponent(_basedomain + "/WxResponse/GetUser"); |
||||
// var baseurl = "https://open.weixin.qq.com/connect/oauth2/authorize"; |
||||
// var url = baseurl + "?appid=" + appid + "&redirect_uri=" + palt_redirect_uri + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect"; |
||||
// window.location.href = url; |
||||
// return; |
||||
// } |
||||
|
||||
//内部用户登录 |
||||
function gosso() { |
||||
var origin =getOrigin(); |
||||
|
||||
if(origin != ""){ |
||||
// _redirect_uri = encodeURIComponent("http://dmpqas.microport.com.cn:9000/webroot/decision/url/sso?origin="+origin); |
||||
_redirect_uri = encodeURIComponent(reportDomain+"/webroot/decision/url/sso?origin="+origin); |
||||
} |
||||
|
||||
var baseurl = rzzxDomain + "/AuthUser/CheckUser"; |
||||
var url = baseurl + "?client_id=" + _client_id + "&redirect_uri=" + _redirect_uri ; |
||||
window.location.href = url; |
||||
return; |
||||
} |
||||
</script> |
||||
|
||||
<div class="login-body"> |
||||
<div class="logo"> |
||||
<img src="/webroot/decision/resources?path=/com/fr/plugin/wcSSO/html/test.png"> |
||||
</div> |
||||
<div class="bottoms" data-logintype="account|sso"> |
||||
<div class="button-content"> |
||||
<div class="button-container" id="sso_platform"> |
||||
<a class="login-type" href="javascript:"> |
||||
<p class="text">内部员工登录</p> |
||||
<p class="text-en">Staff Login</p> |
||||
</a> |
||||
</div> |
||||
<div class="button-container" id="account_platform"> |
||||
<a class="login-type" href="javascript:"> |
||||
<p class="text">外部用户登录</p> |
||||
<p class="text-en">Account Login</p> |
||||
</a> |
||||
</div> |
||||
|
||||
</div> |
||||
</div> |
||||
<div class="footer-contact"> |
||||
<p class="f-m">联系我们</p> |
||||
<p class="f-m">1234@microport.com</p> |
||||
</div> |
||||
</div> |
||||
|
||||
<script type="text/javascript"> |
||||
$(document).ready(function () { |
||||
//账号认证 |
||||
$("#account_platform").click(function () { |
||||
goaccount(); |
||||
}); |
||||
//微信登录平台 |
||||
$("#wx_platform").click(function () { |
||||
gowx(); |
||||
}); |
||||
//AD认证 |
||||
$("#sso_platform").click(function () { |
||||
gosso(); |
||||
}); |
||||
|
||||
//处理logo |
||||
$("#applogo").attr('src', _app_logo); |
||||
|
||||
switch ($(".bottoms").data("logintype")) { |
||||
case "account": |
||||
goaccount(); |
||||
break; |
||||
case "sso": |
||||
gosso(); |
||||
break; |
||||
case "wx": |
||||
gowx(); |
||||
break; |
||||
default: |
||||
$(".hidediv").removeClass("hidediv"); |
||||
$(".loading").hide(); |
||||
break; |
||||
} |
||||
|
||||
}); |
||||
</script> |
||||
|
||||
|
||||
|
||||
<footer> |
||||
</footer> |
||||
</div> |
||||
|
||||
|
||||
|
||||
</body></html> |
@ -0,0 +1,373 @@
|
||||
@font-face { |
||||
font-family: 'Alibaba-Light'; |
||||
src: url('/Content/ali-font/Alibaba-PuHuiTi-Light.ttf') format('opentype'); |
||||
} |
||||
|
||||
@font-face { |
||||
font-family: 'Alibaba-Medium'; |
||||
src: url('/Content/ali-font/Alibaba-PuHuiTi-Medium.ttf') format('opentype'); |
||||
} |
||||
|
||||
@font-face { |
||||
font-family: 'Alibaba-Regular'; |
||||
src: url('/Content/ali-font/Alibaba-PuHuiTi-Regular.ttf') format('opentype'); |
||||
} |
||||
|
||||
@font-face { |
||||
font-family: 'Alibaba-Heavy'; |
||||
src: url('/Content/ali-font/Alibaba-PuHuiTi-Heavy.ttf') format('opentype'); |
||||
} |
||||
|
||||
@font-face { |
||||
font-family: 'Alibaba-Bold'; |
||||
src: url('/Content/ali-font/Alibaba-PuHuiTi-Bold.ttf') format('opentype'); |
||||
} |
||||
|
||||
body { |
||||
font-family: "Alibaba-Regular"; |
||||
} |
||||
|
||||
* { |
||||
padding: 0; |
||||
margin: 0; |
||||
text-decoration: none; |
||||
list-style: none; |
||||
} |
||||
|
||||
|
||||
.f-l { |
||||
font-family: "Alibaba-Light"; |
||||
} |
||||
|
||||
.f-m { |
||||
font-family: "Alibaba-Medium"; |
||||
} |
||||
|
||||
.f-h { |
||||
font-family: "Alibaba-Heavy"; |
||||
} |
||||
|
||||
.f-b { |
||||
font-family: "Alibaba-Bold"; |
||||
} |
||||
|
||||
.loading { |
||||
position: absolute; |
||||
top: 50%; |
||||
left: 50%; |
||||
transform: translateX(-50%) translateY(-50%); |
||||
z-index: 100; |
||||
} |
||||
.login-body { |
||||
width: 100vw; |
||||
min-height: 100vh; |
||||
background: url('/Content/image/bg_welcome_pc.png') no-repeat; |
||||
background-size: cover; |
||||
position: relative; |
||||
overflow-x: hidden; |
||||
} |
||||
|
||||
.login-body .logo { |
||||
text-align: center; |
||||
margin: auto; |
||||
padding-top: 20vh; |
||||
} |
||||
.login-body .logo img { |
||||
width: 391px; |
||||
} |
||||
.login-body .logo .center-left { |
||||
transform: translateX(-300px); |
||||
} |
||||
|
||||
.login-body .button-content { |
||||
margin: auto; |
||||
padding: 20vh 0; |
||||
display: flex; |
||||
width: 1000px; |
||||
} |
||||
|
||||
.login-body .button-content .button-container { |
||||
width: 100%; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type { |
||||
display: block; |
||||
text-align: center; |
||||
background-image: linear-gradient(46deg, #114697 0%, #1359AF 100%); |
||||
border-radius: 10px; |
||||
padding: 20px 0; |
||||
margin: 30px; |
||||
text-decoration: none; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type .text { |
||||
font-size: 36px; |
||||
color: #fff; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type .text-en { |
||||
color: #fff; |
||||
font-size: 26px; |
||||
} |
||||
|
||||
|
||||
|
||||
.login-body .login-star-bg { |
||||
position: absolute; |
||||
z-index: 0; |
||||
left: 50%; |
||||
top: 50%; |
||||
transform: translateX(-50%) translateY(-50%); |
||||
z-index: 1; |
||||
max-width: 30rem; |
||||
padding: 3rem; |
||||
user-select: none; |
||||
} |
||||
|
||||
.login-body .login-star-bg.bg1 img { |
||||
margin-left: 175px; |
||||
margin-bottom: 365px; |
||||
} |
||||
|
||||
.login-body .login-star-bg.bg2 img { |
||||
margin-left: -318px; |
||||
margin-top: 410px; |
||||
} |
||||
|
||||
.login-body .form-box { |
||||
box-shadow: 0 5px 19px 0 rgba(0,0,0,0.10); |
||||
border-radius: 12.48px; |
||||
width: 400px; |
||||
max-width: 80%; |
||||
margin: auto; |
||||
background: #FFFFFF; |
||||
padding: 50px; |
||||
position: absolute; |
||||
z-index: 2; |
||||
left: 50%; |
||||
top: 50%; |
||||
transform: translateX(-50%) translateY(-50%); |
||||
} |
||||
|
||||
.login-body .form-box .login-title { |
||||
font-size: 31.2px; |
||||
color: #012675; |
||||
line-height: 37.44px; |
||||
padding-bottom: 20px; |
||||
} |
||||
|
||||
.login-body .form-box .login-title .title-img { |
||||
display: block; |
||||
height: 6px; |
||||
width: 220px; |
||||
margin-top: 8px; |
||||
} |
||||
|
||||
.login-body .form-box .form-row { |
||||
margin-top: 20px; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .error-message { |
||||
color: #d89a25; |
||||
margin-top: 10px; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .form-input { |
||||
border: 1px solid #D8D8D8; |
||||
padding: 0 12px; |
||||
border-radius: 4px; |
||||
width: 100%; |
||||
line-height: 50px; |
||||
height: 50px; |
||||
font-size: 18px; |
||||
color: #000; |
||||
outline: none; |
||||
box-sizing: border-box; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .form-input:focus { |
||||
background: #ECF0FF; |
||||
border: 1px solid #496FFF; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .valid-row { |
||||
display: flex; |
||||
align-items: flex-end; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .valid-row input { |
||||
flex: 0 0 68%; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .valid-row button { |
||||
flex: 0 0 28%; |
||||
color: #ffffff; |
||||
background: #1E46A9; |
||||
border-radius: 4px; |
||||
line-height: 29px; |
||||
margin-left: auto; |
||||
border: none; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .valid-row button:disabled { |
||||
background: #ccc; |
||||
} |
||||
|
||||
.login-body .form-box .submit-button { |
||||
background-image: linear-gradient(180deg, #496FFF 0%, #022C71 100%); |
||||
border-radius: 4px; |
||||
width: 100%; |
||||
color: #fff; |
||||
font-size: 21px; |
||||
margin-top: 20px; |
||||
line-height: 50px; |
||||
border: none; |
||||
cursor: pointer; |
||||
} |
||||
|
||||
.login-body .form-box .submit-button:disabled { |
||||
background: #ccc; |
||||
} |
||||
|
||||
.login-body .form-box .validation-summary-errors li { |
||||
list-style: none; |
||||
color: #d89a25; |
||||
} |
||||
|
||||
.login-body .form-box .login-type-tab { |
||||
margin-bottom: 20px; |
||||
} |
||||
|
||||
.login-body .form-box .login-type-tab ul { |
||||
display: flex; |
||||
align-items: baseline; |
||||
border-bottom: 2px solid #D8D8D8; |
||||
} |
||||
|
||||
.login-body .form-box .login-type-tab ul li { |
||||
display: flex; |
||||
list-style: none; |
||||
cursor: pointer; |
||||
font-size: 20px; |
||||
color: #999999; |
||||
height: 40px; |
||||
position: relative; |
||||
margin-right: 30px; |
||||
} |
||||
|
||||
.login-body .form-box .login-type-tab ul li.active { |
||||
font-size: 24px; |
||||
color: #333333; |
||||
} |
||||
|
||||
.login-body .form-box .login-type-tab ul li.active:after { |
||||
content: ""; |
||||
position: absolute; |
||||
width: 100%; |
||||
height: 4px; |
||||
bottom: -7px; |
||||
left: 0; |
||||
background-image: linear-gradient(90deg, #00246C 0%, #FF2552 100%); |
||||
} |
||||
|
||||
.login-body .form-box .form-footer-link { |
||||
margin-top: 10px; |
||||
display: flex; |
||||
} |
||||
|
||||
.login-body .form-box .form-footer-link a { |
||||
color: #022a72; |
||||
} |
||||
|
||||
.login-body .form-box .form-footer-link a:nth-child(2) { |
||||
margin-left: auto; |
||||
} |
||||
|
||||
.login-body .footer-contact { |
||||
position: absolute; |
||||
bottom: 30px; |
||||
text-align: center; |
||||
font-size: 16px; |
||||
color: #999999; |
||||
width: 100%; |
||||
line-height: 24px; |
||||
} |
||||
|
||||
|
||||
@media screen and (max-width: 800px) { |
||||
|
||||
.login-body { |
||||
background-image: url('/Content/image/bg_welcome_m.png'); |
||||
} |
||||
|
||||
.login-body .logo { |
||||
padding-top: 10vh; |
||||
} |
||||
|
||||
.login-body .logo .center-left { |
||||
transform: inherit; |
||||
} |
||||
|
||||
.login-body .logo img { |
||||
max-width: 70vw; |
||||
} |
||||
|
||||
|
||||
.login-body .button-content { |
||||
display: inherit; |
||||
width: 100vw; |
||||
padding: 35vh 0 0 0; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type { |
||||
padding: 15px 0; |
||||
margin: 30px 50px; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type .text { |
||||
font-size: 18px; |
||||
} |
||||
|
||||
.login-body .button-content .button-container .login-type .text-en { |
||||
font-size: 13px; |
||||
} |
||||
|
||||
.login-body .login-star-bg { |
||||
display: none; |
||||
} |
||||
|
||||
.login-body .form-box { |
||||
padding: 30px 20px; |
||||
background-image: url('/Content/image/bg_login_m.png'); |
||||
background-repeat: no-repeat; |
||||
background-size: 100%; |
||||
width: 80%; |
||||
} |
||||
|
||||
.login-body .form-box .login-title { |
||||
font-size: 20px; |
||||
line-height: 20px; |
||||
} |
||||
|
||||
.login-body .form-box .login-title .title-img { |
||||
width: 140px; |
||||
} |
||||
|
||||
.login-body .form-box .form-row { |
||||
margin-top: 20px; |
||||
} |
||||
|
||||
.login-body .form-box .form-row .form-input { |
||||
font-size: 14px; |
||||
line-height: 40px; |
||||
} |
||||
|
||||
.login-body .form-box .submit-button { |
||||
border-radius: 30px; |
||||
line-height: 40px; |
||||
width: 80%; |
||||
margin-top: 20px; |
||||
margin-left: 10%; |
||||
font-size: 16px; |
||||
} |
||||
} |
Loading…
Reference in new issue