15 changed files with 693 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-7706 |
||||
|
||||
JSD-7706 开源任务材料 |
||||
jsd-7706 开源材料\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
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.j7706.sso.auth</id> |
||||
<name><![CDATA[jsd7706-单点登陆]]></name> |
||||
<active>yes</active> |
||||
<version>1.6.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>mqh</vendor> |
||||
<description><![CDATA[单点登陆jsd7706]]></description> |
||||
<change-notes><![CDATA[单点登陆jsd7706]]></change-notes> |
||||
<main-package>com.fr.plugin.j7706.sso</main-package> |
||||
<prefer-packages> |
||||
<prefer-package>*</prefer-package> |
||||
</prefer-packages> |
||||
<lifecycle-monitor class="com.fr.plugin.j7706.sso.LifeCycleMonitorImpl"/> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.j7706.sso.LocaleFinder"/> |
||||
</extra-core> |
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.j7706.sso.request.GlobalRequestFilterBridge"/> |
||||
<LogInOutEventProvider class="com.fr.plugin.j7706.sso.CustomLogInOutEventProvider"/> |
||||
</extra-decision> |
||||
<function-recorder class="com.fr.plugin.j7706.sso.LocaleFinder"/> |
||||
</plugin> |
@ -0,0 +1,54 @@
|
||||
/** |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: CustomLogInOutEventProvider |
||||
* Author: Louis |
||||
* Date: 2019/6/19 16:25 |
||||
* Description: CustomLogInOutEventProvider |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.j7706.sso; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import static com.fr.plugin.j7706.sso.request.GlobalRequestFilterBridge.COOKIE_TOKEN; |
||||
import static com.fr.plugin.j7706.sso.request.GlobalRequestFilterBridge.getLoginUrl; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈CustomLogInOutEventProvider〉 |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CustomLogInOutEventProvider extends AbstractLogInOutEventProvider { |
||||
|
||||
/** |
||||
* 用户登出处理 |
||||
* @param result |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
try { |
||||
clearCookie(result.getResponse()); |
||||
return getLoginUrl(result.getRequest()); |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
return StringKit.EMPTY; |
||||
} |
||||
|
||||
private void clearCookie(HttpServletResponse response) { |
||||
Cookie cookie = new Cookie(COOKIE_TOKEN, null); |
||||
cookie.setMaxAge(0); |
||||
cookie.setPath("transsion.com"); |
||||
response.addCookie(cookie); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: OneAccessLifeCycleMonitor |
||||
* Author: Louis |
||||
* Date: 2021/3/30 15:10 |
||||
*/ |
||||
package com.fr.plugin.j7706.sso; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
import com.fr.plugin.j7706.sso.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.j7706.sso; |
||||
|
||||
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.j7706.sso.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-J7706-Sso", source = Original.PLUGIN) |
||||
public String find() { |
||||
return "com/fr/plugin/j7706/sso/locale/lang"; |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: OneAccessConfig |
||||
* Author: Louis |
||||
* Date: 2021/3/30 9:38 |
||||
*/ |
||||
package com.fr.plugin.j7706.sso.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-J7706-Sso_Group") |
||||
public class SsoConfig extends DefaultConfiguration { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.j7706.sso.auth"; |
||||
|
||||
private static volatile SsoConfig config = null; |
||||
|
||||
@Focus(id = PLUGIN_ID, text = "Plugin-J7706-Sso", source = Original.PLUGIN) |
||||
public static SsoConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(SsoConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "uriBase", name = "Plugin-J7706-Sso_Config_uriBase", description = "Plugin-J7706-Sso_Config_uriBase_Description", status = Status.SHOW) |
||||
private Conf<String> uriBase = Holders.simple(StringKit.EMPTY); |
||||
@Identifier(value = "privateKey", name = "Plugin-J7706-Sso_Config_privateKey", description = "Plugin-J7706-Sso_Config_privateKey_Description", status = Status.SHOW) |
||||
private Conf<String> privateKey = Holders.simple(StringKit.EMPTY); |
||||
|
||||
public String getUriBase() { |
||||
return uriBase.get(); |
||||
} |
||||
|
||||
public void setUriBase(String uriBase) { |
||||
this.uriBase.set(uriBase); |
||||
} |
||||
|
||||
public String getPrivateKey() { |
||||
return privateKey.get(); |
||||
} |
||||
|
||||
public void setPrivateKey(String privateKey) { |
||||
this.privateKey.set(privateKey); |
||||
} |
||||
} |
@ -0,0 +1,344 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: GlobalRequestFilterBridge |
||||
* Author: Louis |
||||
* Date: 2021/3/30 22:09 |
||||
*/ |
||||
package com.fr.plugin.j7706.sso.request; |
||||
|
||||
import com.fanruan.api.decision.login.LoginKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.net.NetworkKit; |
||||
import com.fanruan.api.net.http.HttpKit; |
||||
import com.fanruan.api.util.CodeKit; |
||||
import com.fanruan.api.util.RenderKit; |
||||
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.general.ComparatorUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.j7706.sso.config.SsoConfig; |
||||
import com.fr.plugin.j7706.sso.utils.AESUtil; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.net.URLDecoder; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <GlobalRequestFilterBridge> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class GlobalRequestFilterBridge extends AbstractGlobalRequestFilterProvider { |
||||
public static final String OP_H5 = "H5"; |
||||
public static final String MOBILE_PATH = "/url/mobile"; |
||||
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 GLOBAL_EXPORT = "/v5/design/report/data/global/export"; |
||||
|
||||
public static final String HOTBACK_HEALTH = "/plugin/public/com.finebi.plugin.bi.hotback/health"; |
||||
public static final String SYSTEM_HEALTH = "/system/health"; |
||||
public static final String CODE_URL = "${uriBase}/service-pt-unified-auth/pt-unified-auth/sso?source=Fin-BI&redirect=${uriRedirect}"; |
||||
public static final String TOKEN_URL = "/service-pt-unified-auth/pt-unified-auth/auth"; |
||||
public static final String USER_URL = "/service-cp-uc-extend/cp-uc-extend/Employee/queryUserByToken"; |
||||
public static final String COOKIE_TOKEN = "token"; |
||||
|
||||
private SsoConfig config; |
||||
|
||||
/** |
||||
* 过滤器名称 |
||||
* |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String filterName() { |
||||
return "J7706Filter"; |
||||
} |
||||
|
||||
/** |
||||
* 过滤规则 |
||||
* |
||||
* @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.info("sso-GlobalRequestFilterBridge-operation-pathInfo:{}", pathInfo); |
||||
if (pathInfo.startsWith(REMOTE_DESIGN) || pathInfo.startsWith(LOGIN_OTHER) |
||||
|| StringKit.equals(LOGIN_PATH, pathInfo) |
||||
|| pathInfo.startsWith(HOTBACK_HEALTH) || pathInfo.startsWith(SYSTEM_HEALTH) || pathInfo.startsWith(GLOBAL_EXPORT) |
||||
|| 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 (LoginService.getInstance().isLogged(req)) { |
||||
return true; |
||||
} |
||||
// 请求code参数
|
||||
ParamBean paramBean; |
||||
if (validateMobile(req, pathInfo)) { |
||||
// 移动端解密参数
|
||||
paramBean = decryptQuery(req); |
||||
} else { |
||||
// PC请求decode参数
|
||||
paramBean = decodeQuery(req.getQueryString()); |
||||
if (paramBean == null) { |
||||
paramBean = paramByCookie(req); |
||||
} |
||||
} |
||||
if (paramBean == null || StringKit.isEmpty(paramBean.getToken())) { |
||||
res.sendRedirect(getLoginUrl(req)); |
||||
return false; |
||||
} |
||||
String accessToken = getAccessToken(paramBean.getToken()); |
||||
if (StringKit.isEmpty(accessToken)) { |
||||
res.sendRedirect(getLoginUrl(req)); |
||||
return false; |
||||
} |
||||
String username = getUsername(accessToken); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-operation-username:{}, employeeNo:{}", username, paramBean.getEmpNo()); |
||||
if (StringKit.isEmpty(username)) { |
||||
return true; |
||||
} |
||||
if (StringKit.isNotBlank(paramBean.getEmpNo()) && !StringKit.equals(username, paramBean.getEmpNo())) { |
||||
return true; |
||||
} |
||||
String tokenFR = LoginKit.login(req, res, username); |
||||
req.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, tokenFR); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 验证是否移动端请求 |
||||
* |
||||
* @param req |
||||
* @param pathInfo |
||||
* @return |
||||
*/ |
||||
private Boolean validateMobile(HttpServletRequest req, String pathInfo) { |
||||
String mtype = WebUtils.getHTTPRequestParameter(req, "mtype"); |
||||
return StringKit.equals(mtype, "1"); |
||||
} |
||||
|
||||
/** |
||||
* 获取access_token |
||||
* |
||||
* @param code |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private String getAccessToken(String code) throws Exception { |
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Content-Type", "application/json"); |
||||
JSONObject tokenParams = new JSONObject(); |
||||
tokenParams.put("token", code); |
||||
StringEntity stringEntity = new StringEntity(tokenParams.encode(), "UTF-8"); |
||||
String res = HttpKit.executeAndParse(com.fanruan.api.net.http.rs.HttpRequest.custom() |
||||
.url(this.config.getUriBase() + TOKEN_URL) |
||||
.post(stringEntity).headers(headers).build()); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-getAccessToken-res:{}", res); |
||||
if (StringKit.isEmpty(res)) { |
||||
return StringKit.EMPTY; |
||||
} |
||||
String resultCode = new JSONObject(res).getString("code"); |
||||
if (StringKit.equals(resultCode, "200")) { |
||||
return code; |
||||
} |
||||
return StringKit.EMPTY; |
||||
} |
||||
|
||||
/** |
||||
* 通过凭证获得username |
||||
* |
||||
* @param accessToken |
||||
* @return |
||||
*/ |
||||
private String getUsername(String accessToken) throws IOException { |
||||
Map<String, String> userInfoParams = new HashMap<>(); |
||||
userInfoParams.put("token", accessToken); |
||||
String userRes = HttpKit.get(this.config.getUriBase() + USER_URL, userInfoParams); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-getUsername-userRes:{}", userRes); |
||||
return new JSONObject(userRes).getJSONObject("data").getString("employeeNo"); |
||||
} |
||||
|
||||
/** |
||||
* 获取login_url |
||||
* |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getLoginUrl(HttpServletRequest request) throws Exception { |
||||
Map<String, Object> params = new HashMap<>(); |
||||
params.put("uriBase", SsoConfig.getInstance().getUriBase()); |
||||
params.put("uriRedirect", CodeKit.encodeURIComponent(request.getRequestURL().toString().replaceFirst("http://", "https://") |
||||
+ "?" + request.getQueryString())); |
||||
return RenderKit.renderParameter4Tpl(CODE_URL, params); |
||||
} |
||||
|
||||
/** |
||||
* cookie提取参数 |
||||
* |
||||
* @param req |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private ParamBean paramByCookie(HttpServletRequest req) throws Exception { |
||||
String token = getParameterFromCookie(req, COOKIE_TOKEN); |
||||
if (StringKit.isBlank(token)) { |
||||
return null; |
||||
} |
||||
ParamBean paramBean = new ParamBean(); |
||||
paramBean.setToken(token); |
||||
paramBean.setEmpNo(StringKit.EMPTY); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-paramByCookie-token:{}, employeeNo:{}", paramBean.getToken(), paramBean.getEmpNo()); |
||||
return paramBean; |
||||
} |
||||
|
||||
/** |
||||
* PC端解码参数 |
||||
* |
||||
* @param queryString |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static ParamBean decodeQuery(String queryString) throws Exception { |
||||
if (StringKit.isEmpty(queryString)) { |
||||
return null; |
||||
} |
||||
String url = URLDecoder.decode(queryString, "utf-8"); |
||||
if (!url.contains("token=") || !url.contains("&rtoken")) { |
||||
return null; |
||||
} |
||||
int startToken = url.indexOf("token=") + "token=".length(); |
||||
int endToken = url.indexOf("&rtoken"); |
||||
int startEmpNo = url.indexOf("employeeNo=") + "employeeNo=".length(); |
||||
int endEmpNo = url.indexOf("&lang"); |
||||
ParamBean paramBean = new ParamBean(); |
||||
paramBean.setToken(url.substring(startToken, endToken)); |
||||
paramBean.setEmpNo(url.substring(startEmpNo, endEmpNo)); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-decodeQuery-token:{}, employeeNo:{}", paramBean.getToken(), paramBean.getEmpNo()); |
||||
return paramBean; |
||||
} |
||||
|
||||
/** |
||||
* 移动端端解密参数 |
||||
* |
||||
* @param req |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private ParamBean decryptQuery(HttpServletRequest req) { |
||||
ParamBean paramBean = new ParamBean(); |
||||
String encryptToken = decodeStr(NetworkKit.getHTTPRequestParameter(req,"token")); |
||||
String encryptEmpNo = decodeStr(NetworkKit.getHTTPRequestParameter(req,"empNo")); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-decryptQuery-encryptToken:{}, encryptEmpNo:{}, privateKey:{}", encryptToken, encryptEmpNo, this.config.getPrivateKey()); |
||||
String token = AESUtil.decrypt(encryptToken, this.config.getPrivateKey()); |
||||
String empNo = AESUtil.decrypt(encryptEmpNo, this.config.getPrivateKey()); |
||||
LogKit.info("sso-GlobalRequestFilterBridge-decryptQuery-token:{}, empNo:{}", token, empNo); |
||||
paramBean.setToken(token); |
||||
paramBean.setEmpNo(empNo); |
||||
return paramBean; |
||||
} |
||||
|
||||
/** |
||||
* 处理加号和等号特殊字符 |
||||
* |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
private String decodeStr(String str) { |
||||
if (StringKit.isBlank(str)) { |
||||
return str; |
||||
} |
||||
return str.replaceAll(" ", "+"); |
||||
} |
||||
|
||||
/** |
||||
* 获取指定cookie值 |
||||
* |
||||
* @param request |
||||
* @param parameterName |
||||
* @return |
||||
*/ |
||||
private String getParameterFromCookie(HttpServletRequest request, String parameterName) { |
||||
Cookie[] cookies = request.getCookies(); |
||||
if (cookies == null) { |
||||
return null; |
||||
} |
||||
for (Cookie cookie : cookies) { |
||||
if (ComparatorUtils.equals(cookie.getName(), parameterName)) { |
||||
return cookie.getValue(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
String str1 = "pUo4gVEuLQptqgN0HH9J1A=="; |
||||
String empNo = AESUtil.decrypt(str1, "dx&kdJF*12!.KKdf"); |
||||
System.out.println(empNo); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright (C), 2018-2021 |
||||
* Project: starter |
||||
* FileName: paramBean |
||||
* Author: Louis |
||||
* Date: 2021/5/25 11:25 |
||||
*/ |
||||
package com.fr.plugin.j7706.sso.request; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <paramBean> |
||||
* |
||||
* @author Louis |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class ParamBean { |
||||
private String token; |
||||
private String empNo; |
||||
|
||||
public String getToken() { |
||||
return token; |
||||
} |
||||
|
||||
public void setToken(String token) { |
||||
this.token = token; |
||||
} |
||||
|
||||
public String getEmpNo() { |
||||
return empNo; |
||||
} |
||||
|
||||
public void setEmpNo(String empNo) { |
||||
this.empNo = empNo; |
||||
} |
||||
} |
@ -0,0 +1,89 @@
|
||||
package com.fr.plugin.j7706.sso.utils; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.third.org.apache.commons.codec.binary.Base64; |
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import javax.crypto.spec.IvParameterSpec; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
import java.security.Security; |
||||
|
||||
public class AESUtil { |
||||
/** |
||||
* 密钥算法 |
||||
*/ |
||||
private static final String KEY_ALGORITHM = "AES"; |
||||
|
||||
/** |
||||
* 加密/解密算法 / 工作模式 / 填充方式 |
||||
* Java 6支持PKCS5Padding填充方式 |
||||
* Bouncy Castle支持PKCS7Padding填充方式 |
||||
*/ |
||||
private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS7Padding"; |
||||
|
||||
/** |
||||
* 偏移量,只有CBC模式才需要 |
||||
*/ |
||||
private final static String ivParameter = "tsx&8D#23_emp~86"; |
||||
|
||||
/** |
||||
* AES要求密钥长度为128位或192位或256位,java默认限制AES密钥长度最多128位 |
||||
*/ |
||||
public static String sKey="" ; |
||||
|
||||
/** |
||||
* 编码格式 |
||||
*/ |
||||
public static final String ENCODING = "utf-8"; |
||||
|
||||
|
||||
static { |
||||
//如果是PKCS7Padding填充方式,则必须加上下面这行
|
||||
Security.addProvider(new BouncyCastleProvider()); |
||||
} |
||||
|
||||
/** |
||||
* AES加密 |
||||
* @param source 源字符串 |
||||
* @param key 密钥 |
||||
* @return 加密后的密文 |
||||
* @throws Exception |
||||
*/ |
||||
public static String encrypt(String source, String key) { |
||||
try { |
||||
byte[] sourceBytes = source.getBytes(ENCODING); |
||||
byte[] keyBytes = key.getBytes(ENCODING); |
||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM, "BC"); |
||||
IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes(ENCODING)); |
||||
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, KEY_ALGORITHM),iv); |
||||
byte[] decrypted = cipher.doFinal(sourceBytes); |
||||
return Base64.encodeBase64String(decrypted); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* AES解密 |
||||
* @param encryptStr 加密后的密文 |
||||
* @param key 密钥 |
||||
* @return 源字符串 |
||||
* @throws Exception |
||||
*/ |
||||
public static String decrypt(String encryptStr, String key) { |
||||
try { |
||||
byte[] sourceBytes = Base64.decodeBase64(encryptStr); |
||||
byte[] keyBytes = key.getBytes(ENCODING); |
||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM, "BC"); |
||||
IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes(ENCODING)); |
||||
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, KEY_ALGORITHM), iv); |
||||
byte[] decoded = cipher.doFinal(sourceBytes); |
||||
return new String(decoded, ENCODING); |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,6 @@
|
||||
Plugin-J7706-Sso=Sso Plugin |
||||
Plugin-J7706-Sso_Group=Sso Plugin |
||||
Plugin-J7706-Sso_Config_uriBase=BaseUri |
||||
Plugin-J7706-Sso_Config_uriBase_Description=BaseUri |
||||
Plugin-J7706-Sso_Config_privateKey=PrivateKey |
||||
Plugin-J7706-Sso_Config_privateKey_Description=PrivateKey |
@ -0,0 +1,6 @@
|
||||
Plugin-J7706-Sso=\u5355\u70B9\u767B\u9646\u63D2\u4EF6 |
||||
Plugin-J7706-Sso_Group=\u5355\u70B9\u767B\u9646\u63D2\u4EF6 |
||||
Plugin-J7706-Sso_Config_uriBase=\u63A5\u53E3\u5730\u5740 |
||||
Plugin-J7706-Sso_Config_uriBase_Description=\u63A5\u53E3\u5730\u5740 |
||||
Plugin-J7706-Sso_Config_privateKey=PrivateKey |
||||
Plugin-J7706-Sso_Config_privateKey_Description=PrivateKey |
Loading…
Reference in new issue