14 changed files with 439 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@ |
|||||||
# open-JSD-7814 |
# open-JSD-7814 |
||||||
|
|
||||||
JSD-7814 开源任务材料 |
jsd-7814 开源材料\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,25 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.j7814.sso</id> |
||||||
|
<name><![CDATA[jsd7814-单点登陆]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.1</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>mqh</vendor> |
||||||
|
<description><![CDATA[单点登陆jsd7814]]></description> |
||||||
|
<change-notes><![CDATA[单点登陆jsd7814]]></change-notes> |
||||||
|
<main-package>com.fr.plugin.j7814</main-package> |
||||||
|
<prefer-packages> |
||||||
|
<prefer-package>com.fanruan.api</prefer-package> |
||||||
|
</prefer-packages> |
||||||
|
<lifecycle-monitor class="com.fr.plugin.j7814.LifeCycleMonitorImpl"/> |
||||||
|
<extra-core> |
||||||
|
<LocaleFinder class="com.fr.plugin.j7814.LocaleFinder"/> |
||||||
|
</extra-core> |
||||||
|
<extra-decision> |
||||||
|
<GlobalRequestFilterProvider class="com.fr.plugin.j7814.request.GlobalRequestFilterBridge"/> |
||||||
|
<HttpAuthorizeProvider class="com.fr.plugin.j7814.request.HttpAuthorizeBridge"/> |
||||||
|
</extra-decision> |
||||||
|
<function-recorder class="com.fr.plugin.j7814.LocaleFinder"/> |
||||||
|
</plugin> |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: OneAccessLifeCycleMonitor |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/3/30 15:10 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.j7814; |
||||||
|
|
||||||
|
import com.fr.plugin.context.PluginContext; |
||||||
|
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||||
|
import com.fr.plugin.j7814.config.SsoConfig; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <OneAccessLifeCycleMonitor> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class LifeCycleMonitorImpl extends AbstractPluginLifecycleMonitor { |
||||||
|
public LifeCycleMonitorImpl() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterRun(PluginContext pluginContext) { |
||||||
|
SsoConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void beforeStop(PluginContext pluginContext) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2020 |
||||||
|
* Project: starter |
||||||
|
* FileName: LocaleFinder |
||||||
|
* Author: Louis |
||||||
|
* Date: 2020/8/31 22:19 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.j7814; |
||||||
|
|
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||||
|
|
||||||
|
import static com.fr.plugin.j7814.config.SsoConfig.PLUGIN_ID; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <LocaleFinder> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
public class LocaleFinder extends AbstractLocaleFinder { |
||||||
|
|
||||||
|
@Override |
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-J7814-Sso", source = Original.PLUGIN) |
||||||
|
public String find() { |
||||||
|
return "com/fr/plugin/j7814/sso/locale/lang"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,78 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: OneAccessConfig |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/3/30 9:38 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.j7814.config; |
||||||
|
|
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <SsoConfig> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@Visualization(category = "Plugin-J7814-Sso_Group") |
||||||
|
public class SsoConfig extends DefaultConfiguration { |
||||||
|
public static final String PLUGIN_ID = "com.fr.plugin.j7814"; |
||||||
|
|
||||||
|
private static volatile SsoConfig config = null; |
||||||
|
|
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-J7814-Sso", source = Original.PLUGIN) |
||||||
|
public static SsoConfig getInstance() { |
||||||
|
if (config == null) { |
||||||
|
config = ConfigContext.getConfigInstance(SsoConfig.class); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
@Identifier(value = "clientId", name = "Plugin-J7814-Sso_Config_clientId", description = "Plugin-J7814-Sso_Config_clientId_Description", status = Status.SHOW) |
||||||
|
private Conf<String> clientId = Holders.simple(StringKit.EMPTY); |
||||||
|
@Identifier(value = "clientSecret", name = "Plugin-J7814-Sso_Config_clientSecret", description = "Plugin-J7814-Sso_Config_clientSecret_Description", status = Status.SHOW) |
||||||
|
private Conf<String> clientSecret = Holders.simple(StringKit.EMPTY); |
||||||
|
@Identifier(value = "ipgUrl", name = "Plugin-J7814-Sso_Config_ipgUrl", description = "Plugin-J7814-Sso_Config_ipgUrl_Description", status = Status.SHOW) |
||||||
|
private Conf<String> ipgUrl = Holders.simple(StringKit.EMPTY); |
||||||
|
@Identifier(value = "publicKey", name = "Plugin-J7814-Sso_Config_publicKey", description = "Plugin-J7814-Sso_Config_publicKey_Description", status = Status.SHOW) |
||||||
|
private Conf<String> publicKey = Holders.simple(StringKit.EMPTY); |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
public String getIpgUrl() { |
||||||
|
return ipgUrl.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setIpgUrl(String ipgUrl) { |
||||||
|
this.ipgUrl.set(ipgUrl); |
||||||
|
} |
||||||
|
|
||||||
|
public String getPublicKey() { |
||||||
|
return publicKey.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setPublicKey(String publicKey) { |
||||||
|
this.publicKey.set(publicKey); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,151 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: GlobalRequestFilterBridge |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/3/30 22:09 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.j7814.request; |
||||||
|
|
||||||
|
import com.fanruan.api.decision.login.LoginKit; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.net.NetworkKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||||
|
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||||
|
import com.fr.decision.webservice.v10.login.LoginService; |
||||||
|
import com.fr.plugin.j7814.config.SsoConfig; |
||||||
|
import com.idsmanager.dingdang.jwt.DingdangUserRetriever; |
||||||
|
|
||||||
|
import javax.servlet.FilterChain; |
||||||
|
import javax.servlet.FilterConfig; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <GlobalRequestFilterBridge> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class GlobalRequestFilterBridge extends AbstractGlobalRequestFilterProvider { |
||||||
|
public static final String REMOTE_DESIGN = "/remote/design"; |
||||||
|
public static final String RESOURCES_PATH = "/resources"; |
||||||
|
public static final String VIEW_FORM = "/view/form"; |
||||||
|
public static final String VIEW_REPORT = "/view/report"; |
||||||
|
public static final String FILE_PATH = "/file"; |
||||||
|
public static final String SYSTEM_INFO = "/system/info"; |
||||||
|
public static final String MATERIALS_MIN_JS_MAP = "/materials.min.js.map"; |
||||||
|
public static final String LOGIN_PATH = "/login"; |
||||||
|
public static final String LOGIN_OTHER = "/login/"; |
||||||
|
public static final String LOGOUT_PATH = "/logout"; |
||||||
|
public static final String USER_LANGUAGE = "/v10/user/language"; |
||||||
|
|
||||||
|
public static final String ID_TOKEN = "id_token"; |
||||||
|
|
||||||
|
private SsoConfig config; |
||||||
|
|
||||||
|
/** |
||||||
|
* 过滤器名称 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String filterName() { |
||||||
|
return "J7814Filter"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 过滤规则 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String[] urlPatterns() { |
||||||
|
return new String[]{"/decision/*"}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 过滤器初始化 |
||||||
|
* |
||||||
|
* @param filterConfig |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void init(FilterConfig filterConfig) { |
||||||
|
this.config = SsoConfig.getInstance(); |
||||||
|
super.init(filterConfig); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 过滤器处理 |
||||||
|
* |
||||||
|
* @param request |
||||||
|
* @param response |
||||||
|
* @param filterChain |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) { |
||||||
|
try { |
||||||
|
if (operation(request, response)) { |
||||||
|
filterChain.doFilter(request, response); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
LogKit.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户验证登陆操作 |
||||||
|
* |
||||||
|
* @param req |
||||||
|
* @param res |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private boolean operation(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||||
|
String pathInfo = (req.getPathInfo() != null) ? req.getPathInfo() : StringKit.EMPTY; |
||||||
|
LogKit.error("sso-GlobalRequestFilterBridge-operation-pathInfo:{}", pathInfo); |
||||||
|
if (pathInfo.startsWith(REMOTE_DESIGN) || pathInfo.startsWith(LOGIN_OTHER) |
||||||
|
|| StringKit.equals(LOGIN_PATH, pathInfo) |
||||||
|
|| pathInfo.startsWith(RESOURCES_PATH) || pathInfo.startsWith(LOGOUT_PATH) |
||||||
|
|| pathInfo.startsWith(SYSTEM_INFO) || pathInfo.startsWith(MATERIALS_MIN_JS_MAP) |
||||||
|
|| pathInfo.startsWith(USER_LANGUAGE) || pathInfo.startsWith(FILE_PATH)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
// if (pathInfo.startsWith(VIEW_REPORT) || pathInfo.startsWith(VIEW_FORM)) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// 已登录
|
||||||
|
if (LoginService.getInstance().isLogged(req)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
String token = NetworkKit.getHTTPRequestParameter(req, ID_TOKEN); |
||||||
|
LogKit.error("sso-GlobalRequestFilterBridge-operation-token:{}", token); |
||||||
|
if (StringKit.isEmpty(token)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
String username = getUsername(token); |
||||||
|
LogKit.error("sso-GlobalRequestFilterBridge-operation-username:{}", username); |
||||||
|
if (StringKit.isEmpty(username)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
String tokenFR = LoginKit.login(req, res, username); |
||||||
|
req.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, tokenFR); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 通过凭证获得username |
||||||
|
* |
||||||
|
* @param token |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private String getUsername(String token) throws Exception { |
||||||
|
DingdangUserRetriever retriever = new DingdangUserRetriever(token, this.config.getPublicKey()); |
||||||
|
DingdangUserRetriever.User user = retriever.retrieve(); |
||||||
|
if (user == null) { |
||||||
|
return StringKit.EMPTY; |
||||||
|
} |
||||||
|
return user.getUsername(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: HttpAuthorizeBridge |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/8/9 9:24 |
||||||
|
* Description: HttpAuthorizeBridge |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.j7814.request; |
||||||
|
|
||||||
|
import com.fanruan.api.json.JSONKit; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.net.http.HttpKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.decision.fun.impl.AbstractHttpAuthorizeProvider; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.plugin.j7814.config.SsoConfig; |
||||||
|
import com.fr.third.org.apache.http.entity.StringEntity; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈HttpAuthorizeBridge http认证〉 |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class HttpAuthorizeBridge extends AbstractHttpAuthorizeProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Scope scope() { |
||||||
|
return Scope.REPLACE; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean authorize(String inputUsername, String inputPassword, String savedPassword, String hashPassword) { |
||||||
|
SsoConfig config = SsoConfig.getInstance(); |
||||||
|
String httpUrl = config.getIpgUrl(); |
||||||
|
if (StringKit.isEmpty(httpUrl)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
try { |
||||||
|
JSONObject bodyParams = JSONKit.create(); |
||||||
|
bodyParams.put("username", inputUsername); |
||||||
|
bodyParams.put("password", inputPassword); |
||||||
|
bodyParams.put("clientId", config.getClientId()); |
||||||
|
bodyParams.put("clientSecret", config.getClientSecret()); |
||||||
|
Map<String, String> headers = new HashMap<>(); |
||||||
|
headers.put("Content-Type", "application/json"); |
||||||
|
StringEntity stringEntity = new StringEntity(bodyParams.encode(), "UTF-8"); |
||||||
|
String result = HttpKit.executeAndParse(com.fanruan.api.net.http.rs.HttpRequest.custom() |
||||||
|
.url(httpUrl).post(stringEntity).headers(headers).build()); |
||||||
|
LogKit.error("sso-HttpAuthorizeBridge-authorize-result:{}", result); |
||||||
|
return validateResult(result, inputUsername); |
||||||
|
} catch (Exception e) { |
||||||
|
LogKit.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断验证结果 |
||||||
|
* |
||||||
|
* @param result |
||||||
|
* @param inputUsername |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private Boolean validateResult(String result, String inputUsername){ |
||||||
|
if (StringKit.isEmpty(result)){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
final JSONObject jsonObject = JSONKit.create(result); |
||||||
|
int errorNumber = jsonObject.getInt("errorNumber"); |
||||||
|
if (!ComparatorUtils.equals(errorNumber, 0)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
final JSONObject applicationObject = jsonObject.getJSONObject("applicationAPIDto"); |
||||||
|
JSONArray applicationUsername = applicationObject.getJSONArray("applicationUsernames"); |
||||||
|
if (applicationUsername == null || applicationUsername.isEmpty()) { |
||||||
|
LogKit.error("sso-HttpAuthorizeBridge-validateResult-applicationUsername is null."); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return applicationUsername.contains(inputUsername); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
Plugin-J7814-Sso=Sso Plugin |
||||||
|
Plugin-J7814-Sso_Group=Sso Plugin |
||||||
|
Plugin-J7814-Sso_Config_clientId=ClientId |
||||||
|
Plugin-J7814-Sso_Config_clientId_Description=ClientId |
||||||
|
Plugin-J7814-Sso_Config_clientSecret=ClientSecret |
||||||
|
Plugin-J7814-Sso_Config_clientSecret_Description=ClientSecret |
||||||
|
Plugin-J7814-Sso_Config_ipgUrl=IPG Url |
||||||
|
Plugin-J7814-Sso_Config_ipgUrl_Description=IPG Url |
||||||
|
Plugin-J7814-Sso_Config_publicKey=Public Key |
||||||
|
Plugin-J7814-Sso_Config_publicKey_Description=Public Key |
@ -0,0 +1,10 @@ |
|||||||
|
Plugin-J7814-Sso=\u5355\u70B9\u767B\u9646\u63D2\u4EF6 |
||||||
|
Plugin-J7814-Sso_Group=\u5355\u70B9\u767B\u9646\u63D2\u4EF6 |
||||||
|
Plugin-J7814-Sso_Config_clientId=ClientId |
||||||
|
Plugin-J7814-Sso_Config_clientId_Description=ClientId |
||||||
|
Plugin-J7814-Sso_Config_clientSecret=ClientSecret |
||||||
|
Plugin-J7814-Sso_Config_clientSecret_Description=ClientSecret |
||||||
|
Plugin-J7814-Sso_Config_ipgUrl=IPG Url |
||||||
|
Plugin-J7814-Sso_Config_ipgUrl_Description=IPG Url |
||||||
|
Plugin-J7814-Sso_Config_publicKey=\u516C\u94A5 |
||||||
|
Plugin-J7814-Sso_Config_publicKey_Description=\u516C\u94A5 |
Loading…
Reference in new issue