commit
f0ca044679
27 changed files with 1839 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.login5024</id> |
||||
<name><![CDATA[单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.5</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.login5024</main-package> |
||||
|
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.login5024.LoginRequestFilter5024"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.login5024.RecordHandler"/> |
||||
</plugin> |
@ -0,0 +1,13 @@
|
||||
package com.fr.plugin.login5024; |
||||
|
||||
public class Constants { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.login5024"; |
||||
|
||||
public Constants() { |
||||
} |
||||
|
||||
public interface GrantType { |
||||
String AUTHORIZATION_CODE = "authorization_code"; |
||||
String REFRESH_TOKEN = "refresh_token"; |
||||
} |
||||
} |
@ -0,0 +1,160 @@
|
||||
package com.fr.plugin.login5024; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.PrintWriter; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
@EnableMetrics |
||||
public class LoginRequestFilter5024 extends AbstractGlobalRequestFilterProvider { |
||||
public LoginRequestFilter5024() { |
||||
} |
||||
|
||||
public void init(FilterConfig var1) { |
||||
} |
||||
|
||||
public String filterName() { |
||||
return "LoginRequestFilter5024"; |
||||
} |
||||
|
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
String url = "http://lcoalhost:8075/webroot/decision/test"; |
||||
System.out.println(); |
||||
} |
||||
|
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||
StringBuffer url = req.getRequestURL(); |
||||
String queryStr = req.getQueryString(); |
||||
FineLoggerFactory.getLogger().info("请求: " + url); |
||||
FineLoggerFactory.getLogger().info("参数: " + queryStr); |
||||
String token = req.getParameter("accessToken"); |
||||
String configPath = ResourceIOUtils.getRealPath("config.properties"); |
||||
FineLoggerFactory.getLogger().info("--*info*--配置文件路径:" + configPath); |
||||
Utils utils = new Utils(); |
||||
Map config = utils.readFile(configPath); |
||||
String tokenUrl = (String)config.get("url"); |
||||
if (StringUtils.isEmpty(token) || isLogin(req)) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:没有token"); |
||||
release(req,res,chain); |
||||
return ; |
||||
} |
||||
|
||||
if (StringUtils.isEmpty(tokenUrl)) { |
||||
response("解析accessToken的地址未配置",res); |
||||
return; |
||||
} |
||||
|
||||
HashMap param = new HashMap(); |
||||
param.put("accessToken", token); |
||||
String result = utils.get(tokenUrl, param, (Map)null); |
||||
Map resultMap = utils.getResult(result); |
||||
Object code = resultMap.get("code"); |
||||
String username = ""; |
||||
|
||||
if (code != null && "1".equals(code.toString())) { |
||||
username = resultMap.get("username").toString(); |
||||
} |
||||
|
||||
if(!StringUtils.isNotEmpty(username)){ |
||||
response("获取用户名失败",res); |
||||
return ; |
||||
} |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:" + username); |
||||
|
||||
try { |
||||
if (utils.JudgeIsMobile(req)) { |
||||
req.setAttribute("__device__", "iPhone"); |
||||
req.setAttribute("deviceType", "iPhone"); |
||||
req.setAttribute("terminal", "H5"); |
||||
} |
||||
|
||||
if (!utils.isLogin(req, username)) { |
||||
utils.login(username, req, res); |
||||
req.getSession().setAttribute("loginUserName", username); |
||||
} |
||||
|
||||
String redirectUrl = WebUtils.getOriginalURL(req); |
||||
FineLoggerFactory.getLogger().info("FRLOG:url " + redirectUrl); |
||||
String index =(String)config.get("index"); |
||||
redirectUrl = index+redirectUrl.substring(redirectUrl.indexOf("decision")+8,redirectUrl.length()); |
||||
|
||||
res.sendRedirect(encodeCH(redirectUrl)); |
||||
} catch (Exception var24) { |
||||
response("用户名"+username+"登陆失败",res); |
||||
return ; |
||||
} |
||||
|
||||
|
||||
release(req,res,chain); |
||||
} |
||||
|
||||
private static void response(String msg,HttpServletResponse res){ |
||||
try { |
||||
PrintWriter var25 = WebUtils.createPrintWriter(res); |
||||
var25.print(msg); |
||||
var25.flush(); |
||||
var25.close(); |
||||
} catch (Exception var23) { |
||||
FineLoggerFactory.getLogger().error("返回信息失败:"+msg); |
||||
} |
||||
} |
||||
|
||||
private static void release(HttpServletRequest req,HttpServletResponse res,FilterChain chain){ |
||||
try { |
||||
chain.doFilter(req, res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error("放行失败:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否登录FR |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isLogin(HttpServletRequest req){ |
||||
return LoginService.getInstance().isLogged(req); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @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; |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.plugin.login5024; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
@FunctionRecorder |
||||
public class RecordHandler extends BaseHttpHandler { |
||||
|
||||
|
||||
public RecordHandler() { |
||||
} |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return RequestMethod.POST; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/record"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,258 @@
|
||||
package com.fr.plugin.login5024; |
||||
|
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.mobile.terminal.TerminalHandler; |
||||
import com.fr.decision.webservice.exception.user.UserNotExistException; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.TokenResource; |
||||
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.general.ComparatorUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.security.JwtUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.web.Device; |
||||
import java.io.BufferedReader; |
||||
import java.io.File; |
||||
import java.io.FileReader; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.MalformedURLException; |
||||
import java.net.URL; |
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
public class Utils { |
||||
public Utils() { |
||||
} |
||||
|
||||
public Map<String, String> readFile(String var1) { |
||||
HashMap var2 = new HashMap(16); |
||||
if (var1 == null) { |
||||
// FineLoggerFactory.getLogger().error("--*error*--readPath is null");
|
||||
return var2; |
||||
} else { |
||||
File var3 = new File(var1); |
||||
if (!var3.exists()) { |
||||
// FineLoggerFactory.getLogger().error("--*error*--the config file not exists");
|
||||
return var2; |
||||
} else { |
||||
try { |
||||
BufferedReader var4 = new BufferedReader(new FileReader(var3)); |
||||
|
||||
String var5; |
||||
while((var5 = var4.readLine()) != null) { |
||||
if (var5.contains("=")) { |
||||
int var6 = var5.indexOf("="); |
||||
if (var6 == 0) { |
||||
// FineLoggerFactory.getLogger().error("--*error*--配置文件格式有误!");
|
||||
return null; |
||||
} |
||||
|
||||
String var7 = var5.substring(0, var6); |
||||
String var8 = var5.substring(var6 + 1); |
||||
var2.put(var7, var8); |
||||
} |
||||
} |
||||
|
||||
var4.close(); |
||||
} catch (Exception var9) { |
||||
var9.printStackTrace(); |
||||
} |
||||
|
||||
return var2; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void login(String var1, HttpServletRequest var2, HttpServletResponse var3) throws Exception { |
||||
User var4 = UserService.getInstance().getUserByUserName(var1); |
||||
// FineLoggerFactory.getLogger().info("--*info*--显示返回回的user:" + var4.getUserName());
|
||||
if (var4 == null) { |
||||
throw new UserNotExistException(); |
||||
} else { |
||||
String var5 = TokenResource.COOKIE.getToken(var2); |
||||
if (var5 == null || !this.checkTokenValid(var2, var5, var1)) { |
||||
String var6 = LoginService.getInstance().login(var2, var3, var1); |
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(var2,var3,var1,true)); |
||||
|
||||
var2.setAttribute("fine_auth_token", var6); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
public boolean checkTokenValid(HttpServletRequest var1, String var2, String var3) { |
||||
try { |
||||
if (!ComparatorUtils.equals(var3, JwtUtils.parseJWT(var2).getSubject())) { |
||||
// FineLoggerFactory.getLogger().info("--*error*--username changed:" + var3);
|
||||
return false; |
||||
} else { |
||||
Device var4 = NetworkHelper.getDevice(var1); |
||||
LoginService.getInstance().loginStatusValid(var2, TerminalHandler.getTerminal(var1, var4)); |
||||
return true; |
||||
} |
||||
} catch (Exception var5) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public Map<String, Object> getResult(String var1) { |
||||
HashMap var2 = new HashMap(); |
||||
|
||||
JSONObject var3; |
||||
try { |
||||
var3 = new JSONObject(var1); |
||||
} catch (Exception var7) { |
||||
// FineLoggerFactory.getLogger().error("--*error*--响应流不是json格式:" + var1);
|
||||
return var2; |
||||
} |
||||
|
||||
int var4 = var3.getInt("code"); |
||||
var2.put("code", var4); |
||||
var2.put("msg", var3.getString("msg")); |
||||
String[] var5 = new String[]{"data", "userInfo", "username"}; |
||||
Object var6 = this.getJsonbyArray(var3, var5); |
||||
if (var6 != null) { |
||||
var2.put("username", var6.toString()); |
||||
} |
||||
|
||||
return var2; |
||||
} |
||||
|
||||
public Object getJsonbyArray(JSONObject var1, String[] var2) { |
||||
try { |
||||
Object var3 = null; |
||||
|
||||
for(int var4 = 0; var4 < var2.length; ++var4) { |
||||
if (var4 == var2.length - 1) { |
||||
var3 = var1.getString(var2[var4]); |
||||
} else { |
||||
var3 = var1 = var1.getJSONObject(var2[var4]); |
||||
} |
||||
} |
||||
|
||||
return var3; |
||||
} catch (Exception var5) { |
||||
FineLoggerFactory.getLogger().error("--*error*--解析用户名失败"); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public boolean isLogin(HttpServletRequest var1, String var2) { |
||||
Object var3 = var1.getSession().getAttribute("loginUserName"); |
||||
return var3 != null && var2.equals(var3.toString()); |
||||
} |
||||
|
||||
public String get(String var1, Map<String, Object> var2, Map<String, Object> var3) { |
||||
StringBuilder var4 = new StringBuilder(); |
||||
|
||||
try { |
||||
StringBuilder var5 = new StringBuilder(); |
||||
Iterator var6 = var2.entrySet().iterator(); |
||||
|
||||
while(var6.hasNext()) { |
||||
Map.Entry var7 = (Map.Entry)var6.next(); |
||||
var5.append((String)var7.getKey()); |
||||
var5.append("="); |
||||
var5.append(var7.getValue().toString()); |
||||
var5.append("&"); |
||||
} |
||||
|
||||
if (var5.length() > 0) { |
||||
var5.deleteCharAt(var5.lastIndexOf("&")); |
||||
} |
||||
|
||||
URL var13 = new URL(var1 + (var5.length() > 0 ? "?" + var5.toString() : "")); |
||||
HttpURLConnection var14 = (HttpURLConnection)var13.openConnection(); |
||||
var14.setRequestMethod("GET"); |
||||
var14.setRequestProperty("Accept", "application/json"); |
||||
if (var3 != null) { |
||||
Iterator var8 = var3.entrySet().iterator(); |
||||
|
||||
while(var8.hasNext()) { |
||||
Map.Entry var9 = (Map.Entry)var8.next(); |
||||
var14.setRequestProperty((String)var9.getKey(), var9.getValue().toString()); |
||||
} |
||||
} |
||||
|
||||
if (var14.getResponseCode() != 200) { |
||||
throw new RuntimeException("HTTP GET Request Failed with Error code : " + var14.getResponseCode()); |
||||
} |
||||
|
||||
InputStream var15 = var14.getInputStream(); |
||||
byte[] var16 = new byte[1024]; |
||||
boolean var10 = true; |
||||
|
||||
int var17; |
||||
while((var17 = var15.read(var16)) != -1) { |
||||
var4.append(new String(var16, 0, var17, "UTF-8")); |
||||
} |
||||
} catch (MalformedURLException var11) { |
||||
FineLoggerFactory.getLogger().error("--*error*--get请求错误1", var11); |
||||
} catch (IOException var12) { |
||||
FineLoggerFactory.getLogger().error("--*error*--get请求错误2", var12); |
||||
} |
||||
|
||||
return var4.toString(); |
||||
} |
||||
|
||||
public boolean JudgeIsMobile(HttpServletRequest var1) { |
||||
boolean var2 = false; |
||||
String[] var3 = new String[]{"iphone", "android", "ipad", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile"}; |
||||
if (var1.getHeader("User-Agent") != null) { |
||||
String var4 = var1.getHeader("User-Agent"); |
||||
String[] var5 = var3; |
||||
int var6 = var3.length; |
||||
|
||||
for(int var7 = 0; var7 < var6; ++var7) { |
||||
String var8 = var5[var7]; |
||||
if (var4.toLowerCase().indexOf(var8) >= 0 && var4.toLowerCase().indexOf("windows nt") <= 0 && var4.toLowerCase().indexOf("macintosh") <= 0) { |
||||
var2 = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return var2; |
||||
} |
||||
|
||||
public String getParams(String var1) { |
||||
StringBuffer var2 = new StringBuffer(); |
||||
if (!StringUtils.isEmpty(var1) && var1.contains("accessToken")) { |
||||
String[] var3 = var1.split("&"); |
||||
|
||||
for(int var4 = 0; var4 < var3.length; ++var4) { |
||||
String[] var5 = var3[var4].split("="); |
||||
if (var5.length <= 2 && StringUtils.isNotEmpty(var5[0]) && !"accessToken".equals(var5[0])) { |
||||
var2.append(var5[0]); |
||||
var2.append("="); |
||||
if (var5.length == 2) { |
||||
var2.append(var5[1]); |
||||
} |
||||
|
||||
var2.append("&"); |
||||
} |
||||
} |
||||
|
||||
String var6 = var2.toString(); |
||||
if (var6.contains("&")) { |
||||
int var7 = var6.lastIndexOf("&"); |
||||
var6 = var6.substring(0, var7); |
||||
} |
||||
|
||||
return var6; |
||||
} else { |
||||
FineLoggerFactory.getLogger().info("--*error*--The request parameter is null."); |
||||
return var1; |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.sln5987.login</id> |
||||
<name><![CDATA[EHR单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.5</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[EHR单点登录]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.sln5987.login</main-package> |
||||
<lifecycle-monitor class="com.fr.plugin.sln5987.login.config.PluginInitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.sln5987.login.EhrLoginRequestFilter"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.sln5987.login.config.EhrPluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login; |
||||
|
||||
public class Constants { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.sln5987.login"; |
||||
public static final String PLUGIN_CONFIG_GROUP = "EHR单点配置"; |
||||
public static final String ERRB = "POST"; |
||||
public static final String CONTENT_TYPE = "application/json"; |
||||
public static final String CANONICALIZED_QS_HEADERS = ""; |
||||
public static final String ACTION = "GetUserInfo"; |
||||
public static final String SOURCE = "fanruan"; |
||||
|
||||
public Constants() { |
||||
} |
||||
} |
@ -0,0 +1,154 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.decision.mobile.terminal.TerminalHandler; |
||||
import com.fr.decision.webservice.bean.authentication.LoginClientBean; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.TokenResource; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.sln5987.login.config.EhrPluginSimpleConfig; |
||||
import com.fr.plugin.sln5987.login.service.IdpAuthService; |
||||
import com.fr.plugin.sln5987.login.utils.FilterHelper; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
@EnableMetrics |
||||
public class EhrLoginRequestFilter extends AbstractGlobalRequestFilterProvider { |
||||
public EhrLoginRequestFilter() { |
||||
} |
||||
|
||||
public void init(FilterConfig paramFilterConfig) { |
||||
} |
||||
|
||||
public String filterName() { |
||||
return "EhrLoginRequestFilter"; |
||||
} |
||||
|
||||
public String[] urlPatterns() { |
||||
return new String[]{"/decision/*"}; |
||||
} |
||||
|
||||
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) { |
||||
String url = WebUtils.getOriginalURL(request); |
||||
FineLoggerFactory.getLogger().info("FRLOG:进入拦截器"); |
||||
|
||||
String debugHtml; |
||||
try { |
||||
HttpSession session = request.getSession(true); |
||||
debugHtml = request.getParameter("ehrToken"); |
||||
if (StringUtils.isNotEmpty(debugHtml)) { |
||||
EhrPluginSimpleConfig config = EhrPluginSimpleConfig.getInstance(); |
||||
String index = config.getIndex(); |
||||
|
||||
if (isLogin(request)) { |
||||
|
||||
String afterUrl = IdpAuthService.getLoginAfterUrl(request); |
||||
afterUrl = index+afterUrl.substring(afterUrl.indexOf("decision")+8,afterUrl.length()); |
||||
FineLoggerFactory.getLogger().info("FRLOG:login"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:afterUrl"+afterUrl); |
||||
response.sendRedirect(afterUrl); |
||||
} else { |
||||
FineLoggerFactory.getLogger().info("FRLOG:nologin"); |
||||
|
||||
IdpAuthService var10000 = FilterHelper.authService; |
||||
String urlencodeToken = IdpAuthService.getParamByName(request, "ehrToken"); |
||||
this.doOauth(request, response, filterChain, urlencodeToken,config); |
||||
} |
||||
} else { |
||||
filterChain.doFilter(request, response); |
||||
} |
||||
} catch (Exception var8) { |
||||
Exception e = var8; |
||||
|
||||
try { |
||||
FineLoggerFactory.getLogger().error("单点登录失败" + e.getMessage(), e); |
||||
debugHtml = WebServiceUtils.generateUnavailableWebPage("没有权限,无法登陆", "", ""); |
||||
WebUtils.printAsString(response, debugHtml); |
||||
} catch (Exception var7) { |
||||
FineLoggerFactory.getLogger().error(var7.getMessage(), var7); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static boolean isLogin(HttpServletRequest request) { |
||||
return LoginService.getInstance().isLogged(request); |
||||
|
||||
} |
||||
|
||||
public static String getName(HttpServletRequest request) { |
||||
String oldToken = TokenResource.COOKIE.getToken(request); |
||||
|
||||
try { |
||||
LoginClientBean loginClientBean = LoginService.getInstance().loginStatusValid(oldToken, (TerminalHandler)null); |
||||
return loginClientBean.getUsername(); |
||||
} catch (Exception var3) { |
||||
FineLoggerFactory.getLogger().error("token校验失败:" + oldToken, var3); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
private void doOauth(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain, String token,EhrPluginSimpleConfig config) throws Exception { |
||||
String index = config.getIndex(); |
||||
JSONObject userData = FilterHelper.authService.getUserInfo(token,config); |
||||
if (userData == null) { |
||||
FineLoggerFactory.getLogger().error("未获取到用户信息,返回null"); |
||||
String debugHtml = WebServiceUtils.generateUnavailableWebPage("未获取到用户信息", "", ""); |
||||
WebUtils.printAsString(response, debugHtml); |
||||
} else { |
||||
JSONObject errorObj = userData.getJSONObject("error"); |
||||
String username; |
||||
if (errorObj != null) { |
||||
username = errorObj.getString("error_msg"); |
||||
if (StringUtils.isNotEmpty(username)) { |
||||
FineLoggerFactory.getLogger().error("获取用户信息失败,返回errorMsg {},", new Object[]{username}); |
||||
String debugHtml = WebServiceUtils.generateUnavailableWebPage(username, "", ""); |
||||
WebUtils.printAsString(response, debugHtml); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
username = ""; |
||||
JSONObject returnObj = userData.getJSONObject("return"); |
||||
if (returnObj != null) { |
||||
JSONObject msgObj = returnObj.getJSONObject("msg"); |
||||
if (returnObj != null) { |
||||
username = msgObj.getString("ID"); |
||||
} |
||||
} |
||||
|
||||
String debugHtml; |
||||
if (StringUtils.isNotEmpty(username)) { |
||||
if (FilterHelper.checkUserValid(username)) { |
||||
FilterHelper.login(username, request, response); |
||||
String afterUrl =IdpAuthService.getLoginAfterUrl(request); |
||||
afterUrl = index+afterUrl.substring(afterUrl.indexOf("decision")+8,afterUrl.length()); |
||||
FineLoggerFactory.getLogger().info("FRLOG:afterUrl"+afterUrl); |
||||
|
||||
response.sendRedirect(afterUrl); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("用户不存在或者无效,username: {}", new Object[]{username}); |
||||
debugHtml = WebServiceUtils.generateUnavailableWebPage("用户不存在或者无效", "", ""); |
||||
WebUtils.printAsString(response, debugHtml); |
||||
} |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("解析用户JSON失败"); |
||||
debugHtml = WebServiceUtils.generateUnavailableWebPage("解析用户信息失败,无法登陆", "", ""); |
||||
WebUtils.printAsString(response, debugHtml); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,122 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.config; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.DefaultConfiguration; |
||||
import com.fr.config.Identifier; |
||||
import com.fr.config.Status; |
||||
import com.fr.config.Visualization; |
||||
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 = "EHR单点配置" |
||||
) |
||||
@EnableMetrics |
||||
public class EhrPluginSimpleConfig extends DefaultConfiguration { |
||||
private static volatile EhrPluginSimpleConfig config = null; |
||||
@Identifier( |
||||
value = "userInfoUrl", |
||||
name = "用户信息接口", |
||||
description = "用户信息接口", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> userInfoUrl = Holders.simple("https://xxx/UniversalApi/GetUserInfo"); |
||||
@Identifier( |
||||
value = "accessKeyId", |
||||
name = "AccessKeyId", |
||||
description = "AccessKeyId", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> accessKeyId = Holders.simple("xxx"); |
||||
@Identifier( |
||||
value = "accessKeySecret", |
||||
name = "AccessKeySecret", |
||||
description = "AccessKeySecret", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> accessKeySecret = Holders.simple("xxx"); |
||||
@Identifier( |
||||
value = "aesKey", |
||||
name = "AES密钥", |
||||
description = "AES密钥", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> aesKey = Holders.simple("xxx"); |
||||
|
||||
@Identifier( |
||||
value = "index", |
||||
name = "帆软首页", |
||||
description = "帆软首页", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> index = Holders.simple("xxx"); |
||||
|
||||
public EhrPluginSimpleConfig() { |
||||
} |
||||
|
||||
// @Focus(id="com.fr.plugin.sln5987.login", text = "EHR单点配置", source = Original.PLUGIN)
|
||||
public static EhrPluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = (EhrPluginSimpleConfig)ConfigContext.getConfigInstance(EhrPluginSimpleConfig.class); |
||||
} |
||||
|
||||
return config; |
||||
} |
||||
|
||||
public String getUserInfoUrl() { |
||||
return (String)this.userInfoUrl.get(); |
||||
} |
||||
|
||||
public void setUserInfoUrl(String userInfoUrl) { |
||||
this.userInfoUrl.set(userInfoUrl); |
||||
} |
||||
|
||||
public String getAccessKeyId() { |
||||
return (String)this.accessKeyId.get(); |
||||
} |
||||
|
||||
public void setAccessKeyId(String accessKeyId) { |
||||
this.accessKeyId.set(accessKeyId); |
||||
} |
||||
|
||||
public String getAccessKeySecret() { |
||||
return (String)this.accessKeySecret.get(); |
||||
} |
||||
|
||||
public void setAccessKeySecret(String accessKeySecret) { |
||||
this.accessKeySecret.set(accessKeySecret); |
||||
} |
||||
|
||||
public String getAesKey() { |
||||
return (String)this.aesKey.get(); |
||||
} |
||||
|
||||
public void setAesKey(String aesKey) { |
||||
this.aesKey.set(aesKey); |
||||
} |
||||
|
||||
public String getIndex() { |
||||
return (String)this.index.get(); |
||||
} |
||||
|
||||
public void setIndex(String aesKey) { |
||||
this.index.set(aesKey); |
||||
} |
||||
|
||||
public Object clone() throws CloneNotSupportedException { |
||||
EhrPluginSimpleConfig cloned = (EhrPluginSimpleConfig)super.clone(); |
||||
cloned.userInfoUrl = (Conf)this.userInfoUrl.clone(); |
||||
cloned.accessKeyId = (Conf)this.accessKeyId.clone(); |
||||
cloned.accessKeySecret = (Conf)this.accessKeySecret.clone(); |
||||
cloned.aesKey = (Conf)this.aesKey.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.config; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; |
||||
import java.io.IOException; |
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
public class PluginInitializeFilterBridge extends AbstractEmbedRequestFilterProvider { |
||||
public PluginInitializeFilterBridge() { |
||||
} |
||||
|
||||
public void init(FilterConfig filterConfig) { |
||||
EhrPluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
public class PluginInitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
public PluginInitializeMonitor() { |
||||
} |
||||
|
||||
public void afterRun(PluginContext pluginContext) { |
||||
EhrPluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
public void beforeStop(PluginContext pluginContext) { |
||||
} |
||||
} |
@ -0,0 +1,128 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.service; |
||||
|
||||
import com.fr.base.Base64; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.sln5987.login.config.EhrPluginSimpleConfig; |
||||
import com.fr.plugin.sln5987.login.utils.AESEncryptUtil; |
||||
import com.fr.plugin.sln5987.login.utils.HttpClientUtils; |
||||
import com.fr.plugin.sln5987.login.utils.MD5Util; |
||||
import com.fr.plugin.sln5987.login.utils.Sha1Util; |
||||
import com.fr.stable.StringUtils; |
||||
import java.text.DateFormat; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
import java.util.TimeZone; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
public class IdpAuthService { |
||||
public IdpAuthService() { |
||||
} |
||||
|
||||
public JSONObject getUserInfo(String accessToken,EhrPluginSimpleConfig cfg) { |
||||
try { |
||||
String userInfoUrl = cfg.getUserInfoUrl(); |
||||
String accessKeyId = cfg.getAccessKeyId(); |
||||
String accessKeySecret = cfg.getAccessKeySecret(); |
||||
String aesKey = cfg.getAesKey(); |
||||
String errb = "POST"; |
||||
String contentType = "application/json"; |
||||
String canonicalizedQSHeaders = ""; |
||||
if (!StringUtils.isEmpty(userInfoUrl) && !StringUtils.isEmpty(accessKeyId) && !StringUtils.isEmpty(accessKeySecret)) { |
||||
JSONObject params = new JSONObject(); |
||||
JSONObject data = new JSONObject(); |
||||
data.put("action", "GetUserInfo"); |
||||
data.put("source", "fanruan"); |
||||
params.put("data", data); |
||||
Date date = new Date(); |
||||
DateFormat fmt = new SimpleDateFormat("EEE d MMM yyyy HH:mm:ss 'GMT'", Locale.US); |
||||
fmt.setTimeZone(TimeZone.getTimeZone("GMT+8")); |
||||
String nowdate = fmt.format(date); |
||||
String contentMD5 = Base64.encode(MD5Util.encryptByMD5(params.toString())); |
||||
String encryptKey = errb + "\n" + contentMD5 + "\n" + contentType + "\n" + nowdate + canonicalizedQSHeaders; |
||||
byte[] sha1 = Sha1Util.HmacSHA1Encrypt(encryptKey, accessKeySecret); |
||||
String Signature = Base64.encode(sha1); |
||||
String authorization = "QuickSwanEHR" + accessKeyId + ":" + Signature; |
||||
Map<String, String> headers = new HashMap(); |
||||
headers.put("Authorization", authorization); |
||||
headers.put("Access-Token", accessToken); |
||||
headers.put("Date", nowdate); |
||||
headers.put("Content-Type", contentType); |
||||
String response = HttpClientUtils.doPostJson(userInfoUrl, params.toString(), headers); |
||||
if (StringUtils.isEmpty(response)) { |
||||
return null; |
||||
} else { |
||||
String decodeStr = AESEncryptUtil.decode(aesKey, response); |
||||
return StringUtils.isEmpty(decodeStr) ? null : new JSONObject(decodeStr); |
||||
} |
||||
} else { |
||||
return null; |
||||
} |
||||
} catch (Exception var23) { |
||||
FineLoggerFactory.getLogger().error(var23.getMessage(), var23); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
public static String getLoginAfterUrl(HttpServletRequest request) { |
||||
String requestURL = request.getRequestURL().toString(); |
||||
String queryString = request.getQueryString(); |
||||
new HashMap(); |
||||
if (StringUtils.isEmpty(queryString)) { |
||||
return requestURL; |
||||
} else { |
||||
String param = ""; |
||||
String[] split = queryString.split("&"); |
||||
StringBuffer paramSb = new StringBuffer(); |
||||
|
||||
for(int i = 0; i < split.length; ++i) { |
||||
param = split[i]; |
||||
if (!StringUtils.isEmpty(param) && !param.contains("ehrToken=")) { |
||||
paramSb.append("&").append(param); |
||||
} |
||||
} |
||||
|
||||
param = paramSb.toString(); |
||||
if (param.length() > 1) { |
||||
requestURL = requestURL + "?" + param.substring(1); |
||||
} |
||||
|
||||
return requestURL; |
||||
} |
||||
} |
||||
|
||||
public static String getParamByName(HttpServletRequest request, String paramName) { |
||||
String queryString = request.getQueryString(); |
||||
String paramVal = ""; |
||||
String[] split = queryString.split("&"); |
||||
new StringBuffer(); |
||||
String param = ""; |
||||
|
||||
for(int i = 0; i < split.length; ++i) { |
||||
param = split[i]; |
||||
if (StringUtils.isNotEmpty(param) && param.contains(paramName)) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (StringUtils.isNotEmpty(param)) { |
||||
String[] params = param.split("="); |
||||
if (params.length > 1) { |
||||
paramVal = params[1]; |
||||
} |
||||
} |
||||
|
||||
System.out.println(paramVal); |
||||
return paramVal; |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.org.apache.commons.codec.binary.Hex; |
||||
import java.security.Key; |
||||
import javax.crypto.Cipher; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
|
||||
public class AESEncryptUtil { |
||||
private static final String CipherMode = "AES"; |
||||
|
||||
public AESEncryptUtil() { |
||||
} |
||||
|
||||
public static String encode(String thisKey, String data) { |
||||
try { |
||||
Key key = new SecretKeySpec(Hex.decodeHex(thisKey), "AES"); |
||||
Cipher cipher = Cipher.getInstance("AES"); |
||||
cipher.init(2, key); |
||||
byte[] result = cipher.doFinal(Hex.decodeHex(data)); |
||||
return new String(result); |
||||
} catch (Exception var5) { |
||||
FineLoggerFactory.getLogger().error("AES加密失败", var5); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static String decode(String thisKey, String data) { |
||||
try { |
||||
Key key = new SecretKeySpec(Hex.decodeHex(thisKey), "AES"); |
||||
Cipher cipher = Cipher.getInstance("AES"); |
||||
cipher.init(2, key); |
||||
byte[] result = cipher.doFinal(Hex.decodeHex(data)); |
||||
return new String(result); |
||||
} catch (Exception var5) { |
||||
FineLoggerFactory.getLogger().error("AES解密失败", var5); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.utils; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.mobile.terminal.TerminalHandler; |
||||
import com.fr.decision.webservice.bean.authentication.LoginClientBean; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.TokenResource; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.sln5987.login.service.IdpAuthService; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class FilterHelper { |
||||
public static final IdpAuthService authService = new IdpAuthService(); |
||||
private static final String[] IGNORE_PATH = new String[]{"decision/file?path", "decision/resources?path", "decision/view/form?op=emb", "decision/view/form?op=resource", "decision/view/report?op=interface", "decision/remote/design", "/weixin", "/plugin/public/com.fr.plugin.mobile.web/", "/image", "/login/cross/domain"}; |
||||
|
||||
public FilterHelper() { |
||||
} |
||||
|
||||
public static boolean isIgnoreUrl(HttpServletRequest req) { |
||||
String url = WebUtils.getOriginalURL(req); |
||||
String[] var2 = IGNORE_PATH; |
||||
int var3 = var2.length; |
||||
|
||||
for(int var4 = 0; var4 < var3; ++var4) { |
||||
String path = var2[var4]; |
||||
if (url.contains(path)) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static boolean isLogout(HttpServletRequest req) { |
||||
HttpSession session = req.getSession(true); |
||||
String url = WebUtils.getOriginalURL(req); |
||||
return url.contains("/logout") || session.getAttribute("_cas_logout_") != null; |
||||
} |
||||
|
||||
public static boolean checkTokenValid(HttpServletRequest req, String token, String currentUserName) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(currentUserName) && StringUtils.isNotEmpty(token)) { |
||||
LoginClientBean clientBean = LoginService.getInstance().loginStatusValid(token, (TerminalHandler)null); |
||||
if (clientBean != null) { |
||||
return currentUserName.equals(clientBean.getUsername()); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} catch (Exception var4) { |
||||
FineLoggerFactory.getLogger().error("req = " + req.getRequestURL()); |
||||
FineLoggerFactory.getLogger().error("2校验token失败:", var4); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static boolean checkUserValid(String username) { |
||||
if (StringUtils.isEmpty(username)) { |
||||
return false; |
||||
} else { |
||||
try { |
||||
User user = UserService.getInstance().getUserByUserName(username); |
||||
return user != null && user.isEnable(); |
||||
} catch (Exception var2) { |
||||
FineLoggerFactory.getLogger().error(var2.getMessage(), var2); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void login(String username, HttpServletRequest req, HttpServletResponse res) throws Exception { |
||||
String oldToken = TokenResource.COOKIE.getToken(req); |
||||
if (oldToken != null && checkTokenValid(req, oldToken, username)) { |
||||
// FineLoggerFactory.getLogger().info("no need login----");
|
||||
} else { |
||||
try { |
||||
LoginService.getInstance().crossDomainLogout(req, res, ""); |
||||
} catch (Exception var5) { |
||||
FineLoggerFactory.getLogger().info("没登录"); |
||||
} |
||||
|
||||
if (JudgeIsMobile(req)) { |
||||
// FineLoggerFactory.getLogger().info("移动端请求");
|
||||
req.getSession().setAttribute("__device__", "iPhone"); |
||||
req.getSession().setAttribute("deviceType", "iPhone"); |
||||
req.getSession().setAttribute("terminal", "H5"); |
||||
} |
||||
|
||||
String token = LoginService.getInstance().login(req, res, username); |
||||
// FineLoggerFactory.getLogger().info("username = " + username);
|
||||
req.setAttribute("fine_auth_token", token); |
||||
req.getSession().setAttribute("fine_auth_token", token); |
||||
// FineLoggerFactory.getLogger().info("登录成功---");
|
||||
} |
||||
|
||||
} |
||||
|
||||
public static boolean isLogin(HttpServletRequest request) { |
||||
try { |
||||
String oldToken = TokenResource.COOKIE.getToken(request); |
||||
LoginClientBean loginClientBean = LoginService.getInstance().loginStatusValid(oldToken, (TerminalHandler)null); |
||||
if (loginClientBean != null) { |
||||
return true; |
||||
} |
||||
} catch (Exception var3) { |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private static boolean JudgeIsMobile(HttpServletRequest request) { |
||||
boolean isMobile = false; |
||||
String[] mobileAgents = new String[]{"iphone", "android", "ipad", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile"}; |
||||
if (request.getHeader("User-Agent") != null) { |
||||
String agent = request.getHeader("User-Agent"); |
||||
String[] var4 = mobileAgents; |
||||
int var5 = mobileAgents.length; |
||||
|
||||
for(int var6 = 0; var6 < var5; ++var6) { |
||||
String mobileAgent = var4[var6]; |
||||
if (agent.toLowerCase().indexOf(mobileAgent) >= 0 && agent.toLowerCase().indexOf("windows nt") <= 0 && agent.toLowerCase().indexOf("macintosh") <= 0) { |
||||
isMobile = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return isMobile; |
||||
} |
||||
} |
@ -0,0 +1,353 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.collections4.MapUtils; |
||||
import com.fr.third.org.apache.http.Consts; |
||||
import com.fr.third.org.apache.http.HeaderIterator; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.ParseException; |
||||
import com.fr.third.org.apache.http.client.config.RequestConfig; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; |
||||
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.config.Registry; |
||||
import com.fr.third.org.apache.http.config.RegistryBuilder; |
||||
import com.fr.third.org.apache.http.conn.socket.ConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.conn.socket.PlainConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
||||
import com.fr.third.org.apache.http.conn.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.entity.ContentType; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
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.conn.PoolingHttpClientConnectionManager; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContextBuilder; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
import java.io.IOException; |
||||
import java.security.KeyStore; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
public class HttpClientUtils { |
||||
private static final Integer CONNECTION_TIMEOUT = 200000; |
||||
private static final Integer SO_TIMEOUT = 1200000; |
||||
private static final Integer CONN_MANAGER_TIMEOUT = 500; |
||||
private static final String http = "http"; |
||||
private static final String https = "https"; |
||||
private static SSLConnectionSocketFactory sslsf = null; |
||||
private static PoolingHttpClientConnectionManager cm = null; |
||||
private static SSLContextBuilder builder = null; |
||||
|
||||
public HttpClientUtils() { |
||||
} |
||||
|
||||
public static String post(String url, JSONObject params, Map<String, String> header, HttpEntity entity) { |
||||
String result = ""; |
||||
CloseableHttpClient httpClient = null; |
||||
HttpResponse httpResponse = null; |
||||
HttpEntity resEntity = null; |
||||
|
||||
try { |
||||
httpClient = getHttpClient(); |
||||
HttpPost httpPost = new HttpPost(url); |
||||
if (MapUtils.isNotEmpty(header)) { |
||||
Iterator var9 = header.entrySet().iterator(); |
||||
|
||||
while(var9.hasNext()) { |
||||
Entry<String, String> entry = (Entry)var9.next(); |
||||
httpPost.addHeader((String)entry.getKey(), (String)entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
if (params != null) { |
||||
entity = new StringEntity(params.toString(), "utf-8"); |
||||
} |
||||
|
||||
if (entity != null) { |
||||
httpPost.setEntity((HttpEntity)entity); |
||||
} |
||||
|
||||
httpResponse = httpClient.execute(httpPost); |
||||
int statusCode = httpResponse.getStatusLine().getStatusCode(); |
||||
if (statusCode == 200) { |
||||
resEntity = httpResponse.getEntity(); |
||||
result = EntityUtils.toString(resEntity); |
||||
} else { |
||||
readHttpResponse(httpResponse); |
||||
} |
||||
} catch (Exception var14) { |
||||
FineLoggerFactory.getLogger().error("请求发送失败:", var14); |
||||
throw new RuntimeException("请求发送失败,URL:" + url + ",params:" + params); |
||||
} finally { |
||||
closeConnection(httpClient, httpResponse, resEntity); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
public static String get(String url, Map<String, String> params, Map<String, String> header) { |
||||
String result = ""; |
||||
CloseableHttpClient httpClient = null; |
||||
HttpResponse httpResponse = null; |
||||
HttpEntity resEntity = null; |
||||
|
||||
try { |
||||
HttpGet httpGet = null; |
||||
List<NameValuePair> formParams = new ArrayList(); |
||||
Iterator var9; |
||||
Entry entry; |
||||
if (MapUtils.isNotEmpty(params)) { |
||||
var9 = params.entrySet().iterator(); |
||||
|
||||
while(var9.hasNext()) { |
||||
entry = (Entry)var9.next(); |
||||
formParams.add(new BasicNameValuePair((String)entry.getKey(), (String)entry.getValue())); |
||||
} |
||||
|
||||
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formParams, Consts.UTF_8); |
||||
url = url + "?" + EntityUtils.toString(urlEncodedFormEntity); |
||||
} |
||||
|
||||
httpGet = new HttpGet(url); |
||||
if (MapUtils.isNotEmpty(header)) { |
||||
var9 = header.entrySet().iterator(); |
||||
|
||||
while(var9.hasNext()) { |
||||
entry = (Entry)var9.next(); |
||||
httpGet.addHeader((String)entry.getKey(), (String)entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
httpClient = getHttpClient(); |
||||
httpResponse = httpClient.execute(httpGet); |
||||
int statusCode = httpResponse.getStatusLine().getStatusCode(); |
||||
if (statusCode == 200) { |
||||
resEntity = httpResponse.getEntity(); |
||||
result = EntityUtils.toString(resEntity); |
||||
} else { |
||||
readHttpResponse(httpResponse); |
||||
} |
||||
} catch (Exception var14) { |
||||
FineLoggerFactory.getLogger().error("请求发送失败:", var14); |
||||
throw new RuntimeException("请求发送失败,URL:" + url + ",params:" + params); |
||||
} finally { |
||||
closeConnection(httpClient, httpResponse, resEntity); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
public static String getString(String url, Map<String, String> params, Map<String, String> header) { |
||||
String result = ""; |
||||
CloseableHttpClient httpClient = null; |
||||
HttpResponse httpResponse = null; |
||||
HttpEntity resEntity = null; |
||||
|
||||
try { |
||||
HttpGet httpGet = new HttpGet(url); |
||||
if (MapUtils.isNotEmpty(header)) { |
||||
Iterator var8 = header.entrySet().iterator(); |
||||
|
||||
while(var8.hasNext()) { |
||||
Entry<String, String> entry = (Entry)var8.next(); |
||||
httpGet.addHeader((String)entry.getKey(), (String)entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
httpClient = getHttpClient(); |
||||
httpResponse = httpClient.execute(httpGet); |
||||
int statusCode = httpResponse.getStatusLine().getStatusCode(); |
||||
if (statusCode == 200) { |
||||
resEntity = httpResponse.getEntity(); |
||||
result = EntityUtils.toString(resEntity); |
||||
} else { |
||||
readHttpResponse(httpResponse); |
||||
} |
||||
} catch (Exception var13) { |
||||
FineLoggerFactory.getLogger().error("请求发送失败:", var13); |
||||
throw new RuntimeException("请求发送失败,URL:" + url + ",params:" + params); |
||||
} finally { |
||||
closeConnection(httpClient, httpResponse, resEntity); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
public static CloseableHttpClient getHttpClient() { |
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).setConnectionManager(cm).setConnectionManagerShared(true).setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT).setConnectionRequestTimeout(CONN_MANAGER_TIMEOUT).setSocketTimeout(SO_TIMEOUT).build()).build(); |
||||
} |
||||
|
||||
public static String readHttpResponse(HttpResponse httpResponse) throws ParseException, IOException { |
||||
StringBuilder builder = new StringBuilder(); |
||||
HttpEntity entity = httpResponse.getEntity(); |
||||
builder.append("status:" + httpResponse.getStatusLine()); |
||||
builder.append("headers:"); |
||||
HeaderIterator iterator = httpResponse.headerIterator(); |
||||
|
||||
while(iterator.hasNext()) { |
||||
builder.append("\t" + iterator.next()); |
||||
} |
||||
|
||||
if (entity != null) { |
||||
String responseString = EntityUtils.toString(entity); |
||||
builder.append("response length:" + responseString.length()); |
||||
builder.append("response content:" + responseString.replace("\r\n", "")); |
||||
} |
||||
|
||||
return builder.toString(); |
||||
} |
||||
|
||||
public static void closeConnection(CloseableHttpClient httpClient, HttpResponse httpResponse, HttpEntity httpEntity) { |
||||
if (httpEntity != null) { |
||||
try { |
||||
EntityUtils.consume(httpEntity); |
||||
} catch (IOException var6) { |
||||
FineLoggerFactory.getLogger().error("关闭HttpEntity出错:{}", new Object[]{var6.getMessage()}); |
||||
} |
||||
} |
||||
|
||||
if (httpResponse != null) { |
||||
try { |
||||
((CloseableHttpResponse)httpResponse).close(); |
||||
} catch (IOException var5) { |
||||
FineLoggerFactory.getLogger().error("关闭HttpResponse出错:{}", new Object[]{var5.getMessage()}); |
||||
} |
||||
} |
||||
|
||||
if (httpClient != null) { |
||||
try { |
||||
httpClient.close(); |
||||
} catch (IOException var4) { |
||||
FineLoggerFactory.getLogger().error("关闭HttpClient出错:{}", new Object[]{var4.getMessage()}); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
public static String postMsg(String url, Map<String, String> params) { |
||||
CloseableHttpClient httpClient = null; |
||||
CloseableHttpResponse response = null; |
||||
String resultString = ""; |
||||
|
||||
try { |
||||
httpClient = getHttpClient(); |
||||
HttpPost post = new HttpPost(url); |
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(10000).setSocketTimeout(10000).build(); |
||||
post.setConfig(requestConfig); |
||||
post.setHeader("Content-Type", "application/json; charset=UTF-8"); |
||||
List<NameValuePair> formParams = new ArrayList(); |
||||
if (MapUtils.isNotEmpty(params)) { |
||||
Iterator var8 = params.entrySet().iterator(); |
||||
|
||||
while(var8.hasNext()) { |
||||
Entry<String, String> entry = (Entry)var8.next(); |
||||
formParams.add(new BasicNameValuePair((String)entry.getKey(), (String)entry.getValue())); |
||||
} |
||||
|
||||
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formParams, Consts.UTF_8); |
||||
post.setEntity(urlEncodedFormEntity); |
||||
} |
||||
|
||||
response = httpClient.execute(post); |
||||
if (response.getStatusLine().getStatusCode() == 200) { |
||||
resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||
} |
||||
} catch (IOException var18) { |
||||
FineLoggerFactory.getLogger().error(var18.getMessage(), var18); |
||||
} finally { |
||||
try { |
||||
if (response != null) { |
||||
response.close(); |
||||
} |
||||
} catch (IOException var17) { |
||||
var17.printStackTrace(); |
||||
} |
||||
|
||||
} |
||||
|
||||
return resultString; |
||||
} |
||||
|
||||
public static String doPostJson(String url, String json, Map<String, String> headers) throws Exception { |
||||
CloseableHttpClient httpClient = null; |
||||
CloseableHttpResponse response = null; |
||||
String resultString = ""; |
||||
HttpEntity resEntity = null; |
||||
|
||||
Iterator var8; |
||||
try { |
||||
httpClient = getHttpClient(); |
||||
HttpPost httpPost = new HttpPost(url); |
||||
if (MapUtils.isNotEmpty(headers)) { |
||||
var8 = headers.entrySet().iterator(); |
||||
|
||||
while(var8.hasNext()) { |
||||
Entry<String, String> entry = (Entry)var8.next(); |
||||
httpPost.addHeader((String)entry.getKey(), (String)entry.getValue()); |
||||
} |
||||
} |
||||
|
||||
if (StringUtils.isNotEmpty(json)) { |
||||
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); |
||||
httpPost.setEntity(entity); |
||||
} |
||||
|
||||
response = httpClient.execute(httpPost); |
||||
int statusCode = response.getStatusLine().getStatusCode(); |
||||
resEntity = response.getEntity(); |
||||
if (statusCode == 200) { |
||||
resultString = EntityUtils.toString(resEntity); |
||||
} else { |
||||
resultString = EntityUtils.toString(resEntity); |
||||
FineLoggerFactory.getLogger().error("HTTP请求返回值不是200, 是 {}", new Object[]{statusCode}); |
||||
} |
||||
|
||||
String var17 = resultString; |
||||
return var17; |
||||
} catch (Exception var13) { |
||||
FineLoggerFactory.getLogger().error("请求发送失败:", var13); |
||||
var8 = null; |
||||
} finally { |
||||
closeConnection(httpClient, response, (HttpEntity)null); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
static { |
||||
try { |
||||
builder = new SSLContextBuilder(); |
||||
builder.loadTrustMaterial((KeyStore)null, new TrustStrategy() { |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}); |
||||
sslsf = new SSLConnectionSocketFactory(builder.build(), new String[]{"TLSv1"}, (String[])null, NoopHostnameVerifier.INSTANCE); |
||||
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create(); |
||||
Registry<ConnectionSocketFactory> registry = registryBuilder.register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build(); |
||||
cm = new PoolingHttpClientConnectionManager(registry); |
||||
cm.setMaxTotal(200); |
||||
cm.setDefaultMaxPerRoute(20); |
||||
} catch (Exception var1) { |
||||
FineLoggerFactory.getLogger().error("HttpClientUtils 初始化失败", var1); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.utils; |
||||
|
||||
import java.nio.charset.Charset; |
||||
import java.security.MessageDigest; |
||||
|
||||
public class MD5Util { |
||||
public MD5Util() { |
||||
} |
||||
|
||||
public static byte[] encryptByMD5(String plainText) throws Exception { |
||||
if (plainText != null && !"".equals(plainText)) { |
||||
byte[] plainTextBytes = plainText.getBytes(); |
||||
MessageDigest md = MessageDigest.getInstance("MD5"); |
||||
md.update(plainTextBytes); |
||||
byte[] digest = md.digest(); |
||||
return digest; |
||||
} else { |
||||
throw new NullPointerException("参数不能为空"); |
||||
} |
||||
} |
||||
|
||||
public static String encryptByMD5Hex(String plainText) throws Exception { |
||||
if (plainText != null && !"".equals(plainText)) { |
||||
byte[] plainTextBytes = plainText.getBytes(Charset.defaultCharset()); |
||||
MessageDigest sha = MessageDigest.getInstance("MD5"); |
||||
sha.update(plainTextBytes); |
||||
byte[] digest = sha.digest(); |
||||
String encrypt = byteToHex(digest); |
||||
return encrypt; |
||||
} else { |
||||
throw new NullPointerException("参数不能为空"); |
||||
} |
||||
} |
||||
|
||||
public static String byteToHex(byte[] b) { |
||||
if (b == null) { |
||||
throw new IllegalArgumentException("Argument b ( byte array ) is null! "); |
||||
} else { |
||||
String hs = ""; |
||||
String stmp = ""; |
||||
|
||||
for(int n = 0; n < b.length; ++n) { |
||||
stmp = Integer.toHexString(b[n] & 255); |
||||
if (stmp.length() == 1) { |
||||
hs = hs + "0" + stmp; |
||||
} else { |
||||
hs = hs + stmp; |
||||
} |
||||
} |
||||
|
||||
return hs.toUpperCase(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,27 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln5987.login.utils; |
||||
|
||||
import javax.crypto.Mac; |
||||
import javax.crypto.SecretKey; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
|
||||
public class Sha1Util { |
||||
private static final String MAC_NAME = "HmacSHA1"; |
||||
private static final String ENCODING = "UTF-8"; |
||||
|
||||
public Sha1Util() { |
||||
} |
||||
|
||||
public static byte[] HmacSHA1Encrypt(String encryptText, String encryptKey) throws Exception { |
||||
byte[] data = encryptKey.getBytes("UTF-8"); |
||||
SecretKey secretKey = new SecretKeySpec(data, "HmacSHA1"); |
||||
Mac mac = Mac.getInstance("HmacSHA1"); |
||||
mac.init(secretKey); |
||||
byte[] text = encryptText.getBytes("UTF-8"); |
||||
return mac.doFinal(text); |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.sln6735.rsa</id> |
||||
<name><![CDATA[rsa加密单点登录]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.2</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[rsa加密单点登录]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.sln6735.rsa</main-package> |
||||
|
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.fr.plugin.sln6735.rsa.RsaFilter"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.fr.plugin.sln6735.rsa.RsaConfig"/> |
||||
</plugin> |
@ -0,0 +1,69 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln6735.rsa; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.DefaultConfiguration; |
||||
import com.fr.config.Identifier; |
||||
import com.fr.config.Status; |
||||
import com.fr.config.Visualization; |
||||
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 = "Rsa配置" |
||||
) |
||||
@EnableMetrics |
||||
public class RsaConfig extends DefaultConfiguration { |
||||
private static volatile RsaConfig config = null; |
||||
@Identifier( |
||||
value = "privateKey", |
||||
name = "私钥", |
||||
description = "用于解密", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> privateKey = Holders.simple(""); |
||||
|
||||
@Identifier( |
||||
value = "index", |
||||
name = "帆软首页", |
||||
description = "帆软首页", |
||||
status = Status.SHOW |
||||
) |
||||
private Conf<String> index = Holders.simple(""); |
||||
|
||||
public RsaConfig() { |
||||
} |
||||
|
||||
@Focus(id="com.fr.plugin.sln6735.rsa", text = "Rsa配置", source = Original.PLUGIN) |
||||
public static RsaConfig getInstance() { |
||||
if (config == null) { |
||||
config = (RsaConfig)ConfigContext.getConfigInstance(RsaConfig.class); |
||||
} |
||||
|
||||
return config; |
||||
} |
||||
|
||||
public String getPrivateKey() { |
||||
return (String)this.privateKey.get(); |
||||
} |
||||
|
||||
public void setPrivateKey(String text) { |
||||
this.privateKey.set(text); |
||||
} |
||||
|
||||
public String getIndex() { |
||||
return (String)this.index.get(); |
||||
} |
||||
|
||||
public void setIndex(String text) { |
||||
this.index.set(text); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,135 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.plugin.sln6735.rsa; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.swift.util.Strings; |
||||
import com.fr.web.utils.WebUtils; |
||||
import javax.crypto.Cipher; |
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.FilterConfig; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLEncoder; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.KeyFactory; |
||||
import java.security.interfaces.RSAPrivateKey; |
||||
import java.security.spec.PKCS8EncodedKeySpec; |
||||
import java.util.Base64; |
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
|
||||
@EnableMetrics |
||||
public class RsaFilter extends AbstractGlobalRequestFilterProvider { |
||||
public RsaFilter() { |
||||
} |
||||
|
||||
public String filterName() { |
||||
return "RsaFilter"; |
||||
} |
||||
|
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
public void init(FilterConfig filterConfig) { |
||||
RsaConfig.getInstance(); |
||||
} |
||||
|
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) { |
||||
String rsaToken = WebUtils.getHTTPRequestParameter(req, "rsaToken"); |
||||
if (Strings.isNotEmpty(rsaToken)) { |
||||
RsaConfig config = RsaConfig.getInstance(); |
||||
// FineLoggerFactory.getLogger().info("rsaToken = " + rsaToken);
|
||||
String username = this.decrypt(rsaToken, config.getPrivateKey()); |
||||
// FineLoggerFactory.getLogger().info("username = " + username);
|
||||
|
||||
try { |
||||
User user = UserService.getInstance().getUserByUserName(username); |
||||
if (user != null) { |
||||
String token = LoginService.getInstance().login(req, res, username); |
||||
req.setAttribute("fine_auth_token", token); |
||||
// FineLoggerFactory.getLogger().info("登录成功");
|
||||
String afterUrl =this.getUri(req); |
||||
afterUrl = config.getIndex()+afterUrl.substring(afterUrl.indexOf("decision")+8,afterUrl.length()); |
||||
FineLoggerFactory.getLogger().info("FRLOG:afterUrl"+afterUrl); |
||||
res.sendRedirect(afterUrl); |
||||
return; |
||||
} |
||||
} catch (Exception var9) { |
||||
FineLoggerFactory.getLogger().error("登录失败:", var9); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
filterChain.doFilter(req, res); |
||||
} catch (ServletException | IOException var8) { |
||||
var8.printStackTrace(); |
||||
} |
||||
|
||||
} |
||||
|
||||
private String getUri(HttpServletRequest req) throws UnsupportedEncodingException { |
||||
String uri = req.getRequestURI(); |
||||
Map<String, String[]> map = req.getParameterMap(); |
||||
StringBuilder paramStr = new StringBuilder(); |
||||
Iterator var5 = map.keySet().iterator(); |
||||
|
||||
while(var5.hasNext()) { |
||||
String key = (String)var5.next(); |
||||
if (!"rsaToken".equals(key)) { |
||||
paramStr.append(key).append("=").append(URLEncoder.encode(((String[])map.get(key))[0], "UTF-8")).append("&"); |
||||
} |
||||
} |
||||
|
||||
if (Strings.isNotEmpty(paramStr.toString())) { |
||||
uri = uri + "?" + paramStr.toString().substring(0, paramStr.toString().length() - 1); |
||||
} |
||||
|
||||
FineLoggerFactory.getLogger().error(uri); |
||||
return uri; |
||||
} |
||||
|
||||
private String decrypt(String str, String privateKey) { |
||||
byte[] decoded; |
||||
try { |
||||
decoded = Base64.getDecoder().decode(privateKey.replace(" ", "").replace("\n", "")); |
||||
} catch (Exception var10) { |
||||
FineLoggerFactory.getLogger().error("私钥base64解密错误", var10); |
||||
return ""; |
||||
} |
||||
|
||||
byte[] inputByte; |
||||
try { |
||||
String t = str.replaceAll("-", "+").replaceAll("\\*", "/"); |
||||
inputByte = Base64.getDecoder().decode(t.getBytes(StandardCharsets.UTF_8)); |
||||
} catch (Exception var9) { |
||||
FineLoggerFactory.getLogger().error("文本base64解密出错", var9); |
||||
return ""; |
||||
} |
||||
|
||||
try { |
||||
RSAPrivateKey priKey = (RSAPrivateKey)KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); |
||||
Cipher cipher = Cipher.getInstance("RSA"); |
||||
cipher.init(2, priKey); |
||||
String outString = new String(cipher.doFinal(inputByte)); |
||||
return outString; |
||||
} catch (Exception var8) { |
||||
FineLoggerFactory.getLogger().error("rsa解码失败", var8); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
|
||||
# open-JSD-9851 |
||||
|
||||
JSD-9851 单点+访问mac记录等\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
Loading…
Reference in new issue