Browse Source

open

master
pioneer 2 years ago
commit
a2e95938c0
  1. 6
      README.md
  2. BIN
      lib/finekit-10.0-20220427.jar
  3. 23
      plugin.xml
  4. 12
      src/main/java/com/fr/plugin/FunctionRecoder.java
  5. 60
      src/main/java/com/fr/plugin/NEWLANConfig.java
  6. 18
      src/main/java/com/fr/plugin/NEWLANLifeCycleMonitor.java
  7. 16
      src/main/java/com/fr/plugin/http/NEWLANHttpHandler.java
  8. 14
      src/main/java/com/fr/plugin/http/NEWLANUrlAliasProvider.java
  9. 133
      src/main/java/com/fr/plugin/http/handler/ALLLan_login1Handler.java

6
README.md

@ -0,0 +1,6 @@
# open-JSD-10110
JSD-10110 单点集成\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

BIN
lib/finekit-10.0-20220427.jar

Binary file not shown.

23
plugin.xml

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.eco.plugin.xx.newlan</id>
<name><![CDATA[新蓝信单点]]></name>
<active>yes</active>
<version>1.0.4</version>
<env-version>10.0</env-version>
<jartime>2021-02-10</jartime>
<vendor>fr.open</vendor>
<main-package>com.fr.plugin</main-package>
<!--用来记录这个任务的创建时间-->
<description><![CDATA[
]]></description>
<!--任务ID: 10110-->
<create-day>2022-5-21 21:46:43</create-day>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.http.NEWLANHttpHandler"/>
<URLAliasProvider class="com.fr.plugin.http.NEWLANUrlAliasProvider"/>
</extra-decision>
<lifecycle-monitor class="com.fr.plugin.NEWLANLifeCycleMonitor"/>
<function-recorder class="com.fr.plugin.FunctionRecoder"/>
</plugin>

12
src/main/java/com/fr/plugin/FunctionRecoder.java

@ -0,0 +1,12 @@
package com.fr.plugin;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
@FunctionRecorder
public class FunctionRecoder {
@ExecuteFunctionRecord
public void exe(){
System.out.println("插件功能埋点,虽然不会执行,除非上架应用");
}
}

60
src/main/java/com/fr/plugin/NEWLANConfig.java

@ -0,0 +1,60 @@
package com.fr.plugin;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
@Visualization(category = "新xx单点配置")
public class NEWLANConfig extends DefaultConfiguration {
private static volatile NEWLANConfig config = null;
public static NEWLANConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(NEWLANConfig.class);
}
return config;
}
@Identifier(value = "apiUrl", name = "xx接口地址", description = "xx接口地址", status = Status.SHOW)
private Conf<String> apiUrl = Holders.simple("");
@Identifier(value = "clientId", name = "clientId", description = "clientId", status = Status.SHOW)
private Conf<String> clientId = Holders.simple("");
@Identifier(value = "clientSecret", name = "clientSecret", description = "描述", status = Status.SHOW)
private Conf<String> clientSecret = Holders.simple("");
@Identifier(value = "authUrl", name = "xx认证域名", description = "xx接口地址", status = Status.SHOW)
private Conf<String> authUrl = Holders.simple("");
public String getApiUrl() {
return apiUrl.get();
}
public void setApiUrl(String apiUrl) {
this.apiUrl.set(apiUrl);
}
public String getClientId() {
return clientId.get();
}
public void setClientId(String clientId) {
this.clientId.set(clientId);
}
public String getClientSecret() {
return clientSecret.get();
}
public void setClientSecret(String configName) {
this.clientSecret.set(configName);
}
public String getAuthUrl() {
return authUrl.get();
}
public void setAuthUrl(String authUrl) {
this.authUrl.set(authUrl);
}
@Override
public Object clone() throws CloneNotSupportedException {
NEWLANConfig cloned = (NEWLANConfig) super.clone();
cloned.apiUrl = (Conf<String>) this.apiUrl.clone();
cloned.clientId = (Conf<String>) this.clientId.clone();
cloned.clientSecret = (Conf<String>) this.clientSecret.clone();
cloned.authUrl = (Conf<String>) this.authUrl.clone();
return cloned;
}
}

18
src/main/java/com/fr/plugin/NEWLANLifeCycleMonitor.java

@ -0,0 +1,18 @@
package com.fr.plugin;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.stable.fun.Authorize;
@Authorize
public class NEWLANLifeCycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
NEWLANConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

16
src/main/java/com/fr/plugin/http/NEWLANHttpHandler.java

@ -0,0 +1,16 @@
package com.fr.plugin.http;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.plugin.http.handler.*;
public class NEWLANHttpHandler extends AbstractHttpHandlerProvider {
HttpHandler[] actions = new HttpHandler[]{
new ALLLan_login1Handler(),
};
@Override
public HttpHandler[] registerHandlers() {
return actions;
}
}

14
src/main/java/com/fr/plugin/http/NEWLANUrlAliasProvider.java

@ -0,0 +1,14 @@
package com.fr.plugin.http;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class NEWLANUrlAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/lan_login", "/lan_login", true),
};
}
}

133
src/main/java/com/fr/plugin/http/handler/ALLLan_login1Handler.java

@ -0,0 +1,133 @@
package com.fr.plugin.http.handler;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.net.http.HttpKit;
import com.fr.base.TemplateUtils;
import com.fr.data.NetworkHelper;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.NEWLANConfig;
import com.fr.stable.StringUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;
public class ALLLan_login1Handler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return null;
}
@Override
public String getPath() {
return "/lan_login";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String code = req.getParameter("code");
NEWLANConfig config = NEWLANConfig.getInstance();
if (StringUtils.isBlank(code)) {
String state= UUID.randomUUID().toString();
String originalURL = WebUtils.getOriginalURL(req);
String url =String.format("%s/oauth2/authorize?appid=%s&response_type=code&scope=basic_userinfor&state=%s&redirect_uri=%s",config.getAuthUrl(),config.getClientId(),state,originalURL);
sendRedirect(res, url);
return;
}
String appToken = getAppToken();
String userToken = getUserToken(appToken, code, WebUtils.getOriginalURL(req));
String userInfo = getUserInfo(appToken, userToken);
UserService userService = UserService.getInstance();
User user = userService.getUserByUserName(userInfo);
if (user == null) {
WebUtils.printAsString(res,"user:"+userInfo+" not found" );
return;
}
login(req, res, userInfo);
String defaultUrl = getDefaultUrl(req);
if(isMobile(req)){
LogKit.info("login to mobile {}",defaultUrl+"/url/mobile");
sendRedirect(res, defaultUrl+"/url/mobile");
return;
}
sendRedirect(res, defaultUrl);
}
public static String getDefaultUrl(HttpServletRequest req) {
StringBuilder url = new StringBuilder();
try {
url.append(req.getScheme());
url.append("://");
url.append(req.getServerName());
if (req.getServerPort() != 80) {
url.append(":");
url.append(req.getServerPort());
}
url.append(TemplateUtils.render("${fineServletURL}"));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return url.toString();
}
public static boolean isMobile(HttpServletRequest req) {
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"};
String userAgent = req.getHeader("user-agent");
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) {
for (String mobile : mobileArray) {
if (userAgent.toUpperCase().contains(mobile.toUpperCase())) {
return true;
}
}
}
return NetworkHelper.getDevice(req).isMobile();
}
private void login(HttpServletRequest req, HttpServletResponse res, String username) {
String token = null;
try {
token = LoginService.getInstance().login(req, res, username);
req.setAttribute("fine_auth_token", token);
} catch (Exception e) {
}
}
private String getUserInfo(String appToken,String userToken ) throws IOException {
NEWLANConfig config = NEWLANConfig.getInstance();
String url=String.format("%s/v1/users/fetch?app_token=%s&user_token=%s",config.getApiUrl(),appToken,userToken);
String resp = HttpKit.get(url);
LogKit.info("url:{} getUserInfo resp:{}",url,resp);
JSONObject entries = new JSONObject(resp);
return entries.getJSONObject("data").getString("externalId");
}
private String getAppToken( ) throws IOException {
NEWLANConfig config = NEWLANConfig.getInstance();
String url=String.format("%s/v1/apptoken/create?grant_type=client_credential&appid=%s&secret=%s",config.getApiUrl(),config.getClientId(),config.getClientSecret());
String resp = HttpKit.get(url);
LogKit.info("url:{} getAppToken resp:{} ",url,resp);
JSONObject entries = new JSONObject(resp);
return entries.getJSONObject("data").getString("app_token");
}
private String getUserToken(String appToken,String code ,String re) throws IOException {
NEWLANConfig config = NEWLANConfig.getInstance();
String url=String.format("%s/v1/usertoken/create?app_token=%s&grant_type=authorization_code&code=%s&redirect_uri=%s",config.getApiUrl(),appToken,code,re);
String resp = HttpKit.get(url);
LogKit.info("url:{} getUserToken resp:{}",url,resp);
JSONObject entries = new JSONObject(resp);
return entries.getJSONObject("data").getString("user_token");
}
private void sendRedirect(HttpServletResponse res, String url) {
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
}
Loading…
Cancel
Save