Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
f3e81a6312
  1. BIN
      JSD-8173-需求确认书V1.docx
  2. 5
      README.md
  3. 33
      plugin.xml
  4. 24
      src/main/java/com/fr/plugin/login/config/simple/DemoInitializeMonitor.java
  5. 79
      src/main/java/com/fr/plugin/login/config/simple/account/PluginSimpleConfig.java
  6. 58
      src/main/java/com/fr/plugin/login/handler/AdminLogin.java
  7. 13
      src/main/java/com/fr/plugin/login/handler/ExtendAttrHandlerProvider.java
  8. 50
      src/main/java/com/fr/plugin/login/handler/GetConfig.java
  9. 51
      src/main/java/com/fr/plugin/login/handler/GetIp.java
  10. 39
      src/main/java/com/fr/plugin/login/handler/ITHandler.java
  11. 73
      src/main/java/com/fr/plugin/login/handler/ToQrcode.java
  12. 18
      src/main/java/com/fr/plugin/login/handler/URLAliasProvide.java
  13. 91
      src/main/java/com/fr/plugin/login/handler/WxAuth.java
  14. 53
      src/main/java/com/fr/plugin/login/interception/IpInterceptionDBAccessProvider.java
  15. 10
      src/main/java/com/fr/plugin/login/interception/IpInterceptionLocalFinder.java
  16. 15
      src/main/java/com/fr/plugin/login/interception/config/IpInterceptionConfig.java
  17. 16
      src/main/java/com/fr/plugin/login/interception/dao/IpInterceptionDao.java
  18. 16
      src/main/java/com/fr/plugin/login/interception/dao/UserReleaseDao.java
  19. 67
      src/main/java/com/fr/plugin/login/interception/entity/IpInterceptionEntity.java
  20. 41
      src/main/java/com/fr/plugin/login/interception/entity/UserReleaseEntity.java
  21. 188
      src/main/java/com/fr/plugin/login/interception/filter/IpInterceptionFilter.java
  22. 74
      src/main/java/com/fr/plugin/login/interception/function/CheckIpValid.java
  23. 29
      src/main/java/com/fr/plugin/login/interception/function/MobileAgents.java
  24. 158
      src/main/java/com/fr/plugin/login/utils/FRUtils.java
  25. 96
      src/main/java/com/fr/plugin/login/utils/ResponseUtils.java
  26. 94
      src/main/java/com/fr/plugin/login/utils/Utils.java
  27. 37
      src/main/java/com/fr/plugin/login/webresource/WebResourceProvider.java
  28. 59
      src/main/resources/com/fr/plugin/login/html/qrcode.html
  29. 4
      src/main/resources/com/fr/plugin/login/interception/demo.properties
  30. 4
      src/main/resources/com/fr/plugin/login/interception/demo_en_US.properties
  31. 4
      src/main/resources/com/fr/plugin/login/interception/demo_zh_CN.properties
  32. 117
      src/main/resources/com/fr/plugin/login/interception/web/ipConfig.js
  33. 109
      src/main/resources/com/fr/plugin/login/interception/web/table.js
  34. 107
      src/main/resources/com/fr/plugin/login/interception/web/tokenConfig.js
  35. 73
      src/main/resources/com/fr/plugin/login/interception/web/userIpAdd.js
  36. 4
      src/main/resources/com/fr/plugin/login/js/jquery-2.1.3.min.js
  37. 363
      src/main/resources/com/fr/plugin/login/js/login.js
  38. BIN
      使用手册.docx

BIN
JSD-8173-需求确认书V1.docx

Binary file not shown.

5
README.md

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

33
plugin.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.login</id>
<name><![CDATA[登录认证]]></name>
<active>yes</active>
<version>1.0.9</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[登录认证]]></description>
<main-package>com.fr.plugin.login</main-package>
<change-notes>
<![CDATA[
[2021-05-12]10.4.982:
修复bug<br/>
]]>
</change-notes>
<function-recorder class="com.fr.plugin.login.config.simple.account.PluginSimpleConfig"/>
<lifecycle-monitor class="com.fr.plugin.login.config.simple.DemoInitializeMonitor"/>
<extra-decision>
<GlobalRequestFilterProvider class="com.fr.plugin.login.interception.filter.IpInterceptionFilter"/>
<DecisionDBAccessProvider class="com.fr.plugin.login.interception.IpInterceptionDBAccessProvider"/>
<HttpHandlerProvider class="com.fr.plugin.login.handler.ExtendAttrHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.login.handler.URLAliasProvide"/>
<WebResourceProvider class="com.fr.plugin.login.webresource.WebResourceProvider"/>
</extra-decision>
<extra-core>
<LocaleFinder class="com.fr.plugin.login.interception.IpInterceptionLocalFinder"/>
</extra-core>
<dependence>
<Item key="com.fr.plugin.weixin" type="plugin"/>
</dependence>
</plugin>

24
src/main/java/com/fr/plugin/login/config/simple/DemoInitializeMonitor.java

@ -0,0 +1,24 @@
package com.fr.plugin.login.config.simple;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.login.config.simple.account.PluginSimpleConfig;
import com.fr.plugin.login.interception.config.IpInterceptionConfig;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
/**
* @author richie
* @version 10.0
* Created by richie on 2018-12-04
*/
public class DemoInitializeMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
PluginSimpleConfig.getInstance();
IpInterceptionConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

79
src/main/java/com/fr/plugin/login/config/simple/account/PluginSimpleConfig.java

@ -0,0 +1,79 @@
package com.fr.plugin.login.config.simple.account;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
@Visualization(category = "微信鉴权配置")
@EnableMetrics
public class PluginSimpleConfig extends DefaultConfiguration {
private static volatile PluginSimpleConfig config = null;
@Focus(id="com.fr.plugin.login.config.simple", text = "微信鉴权配置", source = Original.PLUGIN)
public static PluginSimpleConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
}
return config;
}
@Identifier(value = "appId", name = "appId", description = "appId", status = Status.SHOW)
private Conf<String> appId = Holders.simple("");
@Identifier(value = "agentId", name = "agentId", description = "agentId", status = Status.SHOW)
private Conf<String> agentId = Holders.simple("");
@Identifier(value = "secret", name = "secret", description = "secret", status = Status.SHOW)
private Conf<String> secret = Holders.simple("");
@Identifier(value = "index", name = "帆软首页地址", description = "帆软首页地址", status = Status.SHOW)
private Conf<String> index = Holders.simple("http/localhost:8075/webroot/decision");
public String getAppId() {
return appId.get();
}
public void setAppId(String url) {
this.appId.set(url);
}
public String getAgentId() {
return agentId.get();
}
public void setAgentId(String url) {
this.agentId.set(url);
}
public String getSecret() {
return secret.get();
}
public void setSecret(String url) {
this.secret.set(url);
}
public String getIndex() {
return index.get();
}
public void setIndex(String url) {
this.index.set(url);
}
@Override
public Object clone() throws CloneNotSupportedException {
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
// cloned.text = (Conf<String>) text.clone();
// cloned.count = (Conf<Integer>) count.clone();
// cloned.price = (Conf<Double>) price.clone();
// cloned.time = (Conf<Long>) time.clone();
// cloned.student = (Conf<Boolean>) student.clone();
return cloned;
}
}

58
src/main/java/com/fr/plugin/login/handler/AdminLogin.java

@ -0,0 +1,58 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.json.JSONObject;
import com.fr.locale.InterProviderFactory;
import com.fr.plugin.login.config.simple.account.PluginSimpleConfig;
import com.fr.plugin.login.utils.FRUtils;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.plugin.weixin.server.bean.WeiXinAgent;
import com.fr.plugin.weixin.server.config.WeiXinConfig;
import com.fr.plugin.weixin.server.constant.WeiXinConstants;
import com.fr.plugin.weixin.server.log.WeiXinLogErrorCode;
import com.fr.plugin.weixin.server.log.WeiXinLoggerFactory;
import com.fr.plugin.weixin.server.util.*;
import com.fr.stable.StringUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import org.slf4j.MDC;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@FunctionRecorder
public class AdminLogin extends BaseHttpHandler {
public AdminLogin() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/login";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
//登录页面登陆的用户名
String username = req.getParameter("username");
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
String index = psc.getIndex();
FRUtils.login(req,res,username,index);
}
}

13
src/main/java/com/fr/plugin/login/handler/ExtendAttrHandlerProvider.java

@ -0,0 +1,13 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
public class ExtendAttrHandlerProvider extends AbstractHttpHandlerProvider {
@Override
public HttpHandler[] registerHandlers() {
return new HttpHandler[]{
new ToQrcode(),new WxAuth(),new AdminLogin(),new GetIp(),new GetConfig()
};
}
}

50
src/main/java/com/fr/plugin/login/handler/GetConfig.java

@ -0,0 +1,50 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.login.config.simple.account.PluginSimpleConfig;
import com.fr.plugin.login.utils.ResponseUtils;
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 GetConfig extends BaseHttpHandler {
public GetConfig() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/getConfig";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String servletPath = req.getServletPath();
String contextPath = req.getContextPath();
String path =contextPath+servletPath;
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
String index = psc.getIndex();
JSONObject json = new JSONObject();
json.put("path",path);
json.put("index",index);
ResponseUtils.response(res,json);
}
}

51
src/main/java/com/fr/plugin/login/handler/GetIp.java

@ -0,0 +1,51 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.plugin.login.interception.filter.IpInterceptionFilter;
import com.fr.plugin.login.utils.ResponseUtils;
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 GetIp extends BaseHttpHandler {
public GetIp() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/getIp";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String ip = IpInterceptionFilter.getIp(req);
String username = req.getParameter("username");
int type = 1;
boolean inWhite = IpInterceptionFilter.checkUserInAllowList(username);
boolean canLogin = IpInterceptionFilter.checkUserCanLoginOnIp(username,ip);
if(inWhite && !canLogin){
type = 0;
}
ResponseUtils.successResponse(res,String.valueOf(type));
}
}

39
src/main/java/com/fr/plugin/login/handler/ITHandler.java

@ -0,0 +1,39 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
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 ITHandler extends BaseHttpHandler {
public ITHandler() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/operateUser";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res){
}
}

73
src/main/java/com/fr/plugin/login/handler/ToQrcode.java

@ -0,0 +1,73 @@
package com.fr.plugin.login.handler;
import com.fr.base.TemplateUtils;
import com.fr.decision.config.AppearanceConfig;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.http.HttpToolbox;
import com.fr.plugin.login.config.simple.account.PluginSimpleConfig;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.controller.decision.api.auth.LoginResource;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
@FunctionRecorder
public class ToQrcode extends BaseHttpHandler {
public ToQrcode() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/toQrcode";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
String origin = req.getParameter("origin");
String url = AppearanceConfig.getInstance().getLoginUrl();
String username = req.getParameter("username");
PluginSimpleConfig pluginSimpleConfig = PluginSimpleConfig.getInstance();
String appId = pluginSimpleConfig.getAppId();
String agentId = pluginSimpleConfig.getAgentId();
String index = pluginSimpleConfig.getIndex();
String servletPath = req.getServletPath();
String contextPath = req.getContextPath();
String path2 =contextPath+servletPath;
if(origin != null ){
url = HttpToolbox.appendQuery(url,"origin",origin);
}
Map<String, String> parameterMap = new HashMap<String, String>();
String path = "/com/fr/plugin/login/html/qrcode.html";
parameterMap.put("remoteServletURL", WebUtils.getOriginalURL(req));
parameterMap.put("username", username);
parameterMap.put("appId", appId);
parameterMap.put("agentId", agentId);
parameterMap.put("index", index);
parameterMap.put("path", path2);
String macPage = TemplateUtils.renderTemplate(path, parameterMap);
WebUtils.printAsString(res, macPage);
}
}

18
src/main/java/com/fr/plugin/login/handler/URLAliasProvide.java

@ -0,0 +1,18 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class URLAliasProvide extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/toQrcode","/toQrcode",true),
URLAliasFactory.createPluginAlias("/wxAuth","/wxAuth",true),
URLAliasFactory.createPluginAlias("/login","/login",true),
URLAliasFactory.createPluginAlias("/getIp","/getIp",true),
URLAliasFactory.createPluginAlias("/getConfig","/getConfig",true)
};
}
}

91
src/main/java/com/fr/plugin/login/handler/WxAuth.java

@ -0,0 +1,91 @@
package com.fr.plugin.login.handler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.login.config.simple.account.PluginSimpleConfig;
import com.fr.plugin.login.utils.FRUtils;
import com.fr.plugin.login.utils.ResponseUtils;
import com.fr.plugin.login.utils.Utils;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.plugin.weixin.server.log.WeiXinLogErrorCode;
import com.fr.plugin.weixin.server.log.WeiXinLoggerFactory;
import com.fr.plugin.weixin.server.util.WeiXinRequest;
import com.fr.plugin.weixin.server.util.WeiXinUserUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@FunctionRecorder
public class WxAuth extends BaseHttpHandler {
public WxAuth() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/wxAuth";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
//登录页面登陆的用户名
String username = req.getParameter("username");
String code = req.getParameter("code");
String secret = psc.getSecret();
String realUsername =weixinAuth(code,secret);
if(Utils.isNullStr(realUsername)){
ResponseUtils.failedResponse(res,"微信鉴权失败,请联系管理员!");
return;
}
if(!username.equals(realUsername)){
ResponseUtils.failedResponse(res,"微信关联账户与登录账户不一致,请重新登录!");
return;
}
String index = psc.getIndex();
FRUtils.login(req,res,username,index);
}
private static String weixinAuth(String code,String secret) throws Exception{
JSONObject userInfo = WeiXinRequest.getUserInfoByCode(code, secret);
FRUtils.FRLogInfo("userInfo:"+userInfo.toString());
String decUserName = "";
if (userInfo != null && userInfo.has("UserId")) {
String userId = userInfo.optString("UserId");
JSONObject detailUserInfo = WeiXinRequest.getDetailUserInfoByUserId(secret, userId);
if (WeiXinRequest.isOk(detailUserInfo)) {
FRUtils.FRLogInfo(String.format("userid为%s的用户详细信息为:", userId) + detailUserInfo.toString());
if (WeiXinUserUtils.isWeiXinUserEnable(detailUserInfo)) {
WeiXinLoggerFactory.getLogger().debug("开始匹配平台用户。。。");
decUserName = WeiXinUserUtils.weiXinUserToDecUser(detailUserInfo);
FRUtils.FRLogInfo("decUserName");
} else {
FRUtils.FRLogInfo("微信用户被禁用,请于微信管理后台设置!" + WeiXinLogErrorCode.WEIXIN_USER_DISABLE);
}
} else {
FRUtils.FRLogInfo(String.format("获取userId为%s的用户详细信息失败!", userId) + WeiXinLogErrorCode.GET_USER_DETAIL_FAIL);
}
} else {
FRUtils.FRLogInfo("code换取userId失败,请检查网络设置!" + WeiXinLogErrorCode.GET_USERID_FAIL);
}
return decUserName;
}
}

53
src/main/java/com/fr/plugin/login/interception/IpInterceptionDBAccessProvider.java

@ -0,0 +1,53 @@
package com.fr.plugin.login.interception;
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider;
import com.fr.plugin.login.interception.dao.IpInterceptionDao;
import com.fr.plugin.login.interception.dao.UserReleaseDao;
import com.fr.plugin.login.interception.entity.IpInterceptionEntity;
import com.fr.plugin.login.interception.entity.UserReleaseEntity;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
@FunctionRecorder
public class IpInterceptionDBAccessProvider extends AbstractDecisionDBAccessProvider {
@Override
@ExecuteFunctionRecord
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
new DAOProvider() {
@Override
public Class getEntityClass() {
return IpInterceptionEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return IpInterceptionDao.class;
}
},
new DAOProvider() {
@Override
public Class getEntityClass() {
return UserReleaseEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return UserReleaseDao.class;
}
}
};
}
private static DBAccessor dbAccessor = null;
public static DBAccessor getDbAccessor(){
return dbAccessor;
}
@Override
public void onDBAvailable(DBAccessor dbAccessor) {
IpInterceptionDBAccessProvider.dbAccessor = dbAccessor;
}
}

10
src/main/java/com/fr/plugin/login/interception/IpInterceptionLocalFinder.java

@ -0,0 +1,10 @@
package com.fr.plugin.login.interception;
import com.fr.stable.fun.impl.AbstractLocaleFinder;
public class IpInterceptionLocalFinder extends AbstractLocaleFinder {
@Override
public String find() {
return "com/fr/plugin/demo";
}
}

15
src/main/java/com/fr/plugin/login/interception/config/IpInterceptionConfig.java

@ -0,0 +1,15 @@
package com.fr.plugin.login.interception.config;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
public class IpInterceptionConfig extends DefaultConfiguration {
private static IpInterceptionConfig config = null;
public static IpInterceptionConfig getInstance(){
if (config == null){
config = ConfigContext.getConfigInstance(IpInterceptionConfig.class);
}
return config;
}
}

16
src/main/java/com/fr/plugin/login/interception/dao/IpInterceptionDao.java

@ -0,0 +1,16 @@
package com.fr.plugin.login.interception.dao;
import com.fr.plugin.login.interception.entity.IpInterceptionEntity;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
public class IpInterceptionDao extends BaseDAO<IpInterceptionEntity> {
public IpInterceptionDao(DAOSession daoSession) {
super(daoSession);
}
@Override
protected Class<IpInterceptionEntity> getEntityClass() {
return IpInterceptionEntity.class;
}
}

16
src/main/java/com/fr/plugin/login/interception/dao/UserReleaseDao.java

@ -0,0 +1,16 @@
package com.fr.plugin.login.interception.dao;
import com.fr.plugin.login.interception.entity.UserReleaseEntity;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
public class UserReleaseDao extends BaseDAO<UserReleaseEntity> {
public UserReleaseDao(DAOSession daoSession) {
super(daoSession);
}
@Override
protected Class<UserReleaseEntity> getEntityClass() {
return UserReleaseEntity.class;
}
}

67
src/main/java/com/fr/plugin/login/interception/entity/IpInterceptionEntity.java

@ -0,0 +1,67 @@
package com.fr.plugin.login.interception.entity;
import com.fr.stable.db.entity.BaseEntity;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
import java.util.Date;
@Entity
@Table(
name = "fine_2a4457_ip_interception"
)
public class IpInterceptionEntity extends BaseEntity {
@Column(
name = "createTime"
)
private Date createTime;
@Column(
name = "endIp"
)
private String endIp;
@Column(
name = "startIp"
)
private String startIp;
@Column(
name = "userName"
)
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getStartIp() {
return startIp;
}
public void setStartIp(String startIp) {
this.startIp = startIp;
}
public String getEndIp() {
return endIp;
}
public void setEndIp(String endIp) {
this.endIp = endIp;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

41
src/main/java/com/fr/plugin/login/interception/entity/UserReleaseEntity.java

@ -0,0 +1,41 @@
package com.fr.plugin.login.interception.entity;
import com.fr.stable.db.entity.BaseEntity;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
import java.util.Date;
@Entity
@Table(
name = "fine_2a4457_user_release"
)
public class UserReleaseEntity extends BaseEntity {
@Column(
name = "createTime"
)
private Date createTime;
@Column(
name = "userName"
)
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

188
src/main/java/com/fr/plugin/login/interception/filter/IpInterceptionFilter.java

@ -0,0 +1,188 @@
package com.fr.plugin.login.interception.filter;
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.plugin.login.interception.IpInterceptionDBAccessProvider;
import com.fr.plugin.login.interception.dao.IpInterceptionDao;
import com.fr.plugin.login.interception.dao.UserReleaseDao;
import com.fr.plugin.login.interception.entity.IpInterceptionEntity;
import com.fr.plugin.login.interception.entity.UserReleaseEntity;
import com.fr.plugin.login.interception.function.CheckIpValid;
import com.fr.plugin.login.interception.function.MobileAgents;
import com.fr.plugin.login.utils.FRUtils;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
public class IpInterceptionFilter extends AbstractGlobalRequestFilterProvider {
@Override
public String filterName() {
return "IpInterception";
}
@Override
public String[] urlPatterns() {
return new String[]{
"/decision/*"
};
}
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain){
try {
String allUrl = FRUtils.getAllUrl(req);
if (isLogin(req)) {
String currentUserName = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req);
String currentUserId = UserService.getInstance().getCurrentUserId(currentUserName);
String userAgent = req.getHeader("User-Agent");
// System.out.println(userAgent+"*******");
FineLoggerFactory.getLogger().info("Login device : " + userAgent);
//是不是移动端(移动端全部放xing)
if (!MobileAgents.checkAgentIsMobile(req)) {
//是不是admin
if (!UserService.getInstance().isAdmin(currentUserId)) {
String ip = getIp(req);
FineLoggerFactory.getLogger().info("Is not admin at :" + ip);
FineLoggerFactory.getLogger().info("inAllowList :" + !checkUserInAllowList(currentUserName));
FineLoggerFactory.getLogger().info("checkUserCanLoginOnIp :" + !checkUserCanLoginOnIp(currentUserName, ip));
//是不是白名单
if (!checkUserInAllowList(currentUserName)) {
//是否可以在指定IP登陆
if (!checkUserCanLoginOnIp(currentUserName, ip)) {
// String warning = InterProviderFactory.getProvider().getLocText("Plugin-Dec_Filter_Warning_1")
// + "\t" + ip + "\t"
// + InterProviderFactory.getProvider().getLocText("Plugin-Dec_Filter_Warning_2");
// System.out.println(warning);
// req.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, "");
// WebUtils.printAsString(res, "You are not allow to login at " + ip + "5");
// Thread.sleep(1*1000);
// WebUtils.printAsString(res, "You are not allow to login at " + ip + "4");
// Thread.sleep(1*1000);
// WebUtils.printAsString(res, "You are not allow to login at " + ip + "3");
// Thread.sleep(1*1000);
// WebUtils.printAsString(res, "You are not allow to login at " + ip + "2");
// Thread.sleep(1*1000);
// WebUtils.printAsString(res, "You are not allow to login at " + ip + "1");
// Thread.sleep(1*1000);
// LoginService.getInstance().logout(req, res);
// new LogInOutResultInfo(req, res, currentUserName, false);
// WebUtils.printAsString(res, "You are not allow to login at " + ip);
// System.out.println(""+ isLogin(req));
// req.getRequestedSessionId();
// HttpSession httpSession = req.getSession();
// httpSession.invalidate();
// req.getAttributeNames();
// req.removeAttribute("");
// new LogInOutResultInfo(req, res, currentUserName, false);
// filterChain.doFilter(req, res);
// Logo;
LoginService.getInstance().logout(req, res);
// LoginService.getInstance().cleanLoginDetailInfo(5000);
// FineLoggerFactory.getLogger().info("\n-------------------" + isLogin(req));
// return ;
}
}
}else {
FineLoggerFactory.getLogger().info("Is admin");
}
}else {
// FineLoggerFactory.getLogger().info("Login on Mobile");
}
}
filterChain.doFilter(req, res);
// LoginService.getInstance().logout(req, res);
}catch (IOException | ServletException ignored){
}catch (Exception e){
e.printStackTrace();
}
}
public static boolean checkUserCanLoginOnIp(String userName, String ip) throws Exception {
DBAccessor dbAccessor = IpInterceptionDBAccessProvider.getDbAccessor();
List<IpInterceptionEntity> entities = null;
entities = dbAccessor.runQueryAction(daoContext ->
daoContext.getDAO(IpInterceptionDao.class).find(
QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))
)
);
/**
* TODO: 1.登出 2.若填报页面内用户wei*则适用于所有的用户
*/
List<IpInterceptionEntity> allUser = dbAccessor.runQueryAction(daoContext ->
daoContext.getDAO(IpInterceptionDao.class).find(
QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", "*"))
)
);
// entities.add(allUser.get());
entities.addAll(allUser);
boolean status = false;
if (!entities.isEmpty()){
String list = "";
//只要循环里出现了1个true,就跳出循环
for(int i = 0; i < entities.size() && status == false; i++){
IpInterceptionEntity ipInterceptionEntity = entities.get(i);
// if (ip.equals(ipInterceptionEntity.getStartIp())){
// status = true;
// }
// System.out.println("----------------"+ipInterceptionEntity.getEndIp());
if (ipInterceptionEntity.getEndIp() == null || ipInterceptionEntity.getEndIp().isEmpty()){
status = CheckIpValid.ipIsValid(ipInterceptionEntity.getStartIp(), ipInterceptionEntity.getStartIp(), ip);
list = list.concat(ipInterceptionEntity.getStartIp() + "\n");
}else{
status = CheckIpValid.ipIsValid(ipInterceptionEntity.getStartIp(), ipInterceptionEntity.getEndIp(), ip);
list = list.concat(ipInterceptionEntity.getStartIp() + " - " + ipInterceptionEntity.getEndIp() + "\n");
}
// if (status){
// i = entities.size() + 1; //只要查出来一个true,就跳出循环
// }
}
FineLoggerFactory.getLogger().info("\nAllow ip : " + list);
}else {
FineLoggerFactory.getLogger().info("Not found user in ip list!");
}
// return !entities.isEmpty();
return status;
}
public static boolean checkUserInAllowList(String userName) throws Exception{
DBAccessor dbAccessor = IpInterceptionDBAccessProvider.getDbAccessor();
List<UserReleaseEntity> list = null;
list = dbAccessor.runQueryAction(daoContext ->
daoContext.getDAO(UserReleaseDao.class).find(
QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))
)
);
FineLoggerFactory.getLogger().info("User in allow list : " + !list.isEmpty());
return !list.isEmpty();
}
public static String getIp(HttpServletRequest req){
/**
* req.getRemoteAddr() : 默认的获取IP的方法但是如果是多级代理则无法判断是否为真实IP
* WebServiceUtils.getIpInfoFromRequest(req) : 帆软提供的获取IP的方法不知道能不能在多级代理中获取真实IP
*/
// return req.getRemoteAddr();
// return WebServiceUtils.getIpInfoFromRequest(req);
return CheckIpValid.getIp(req);
}
private boolean isLogin(HttpServletRequest req) {
return LoginService.getInstance().isLogged(req);
}
}

74
src/main/java/com/fr/plugin/login/interception/function/CheckIpValid.java

@ -0,0 +1,74 @@
package com.fr.plugin.login.interception.function;
import com.fr.stable.StringUtils;
import javax.servlet.http.HttpServletRequest;
public class CheckIpValid {
/**
* 获取真实的IP
* @param request
* @return
*/
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) {
//多次反向代理后会有多个ip值,第一个ip才是真实ip
int index = ip.indexOf(",");
if (index != -1) {
return ip.substring(0,index);
} else {
return ip;
}
}
ip = request.getHeader("X-Real-IP");
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) {
return ip;
}
return request.getRemoteAddr();
}
/**
* 判断IP是否在指定范围内
* @param ipStart
* @param ipEnd
* @param ip
* @return
*/
public static boolean ipIsValid(String ipStart,String ipEnd, String ip) {
if (StringUtils.isEmpty(ipStart)) {
throw new NullPointerException("起始IP不能为空!");
}
if (StringUtils.isEmpty(ipEnd)) {
throw new NullPointerException("结束IP不能为空!");
}
if (StringUtils.isEmpty(ip)) {
throw new NullPointerException("IP不能为空!");
}
ipStart = ipStart.trim();
ipEnd = ipEnd.trim();
ip = ip.trim();
final String REGX_IP = "((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)";
final String REGX_IPB = REGX_IP + "\\-" + REGX_IP;
if (!ipStart.matches(REGX_IP) || !ip.matches(REGX_IP) || !ipEnd.matches(REGX_IP)) {
return false;
}
String[] sips = ipStart.split("\\.");
String[] sipe = ipEnd.split("\\.");
String[] sipt = ip.split("\\.");
long ips = 0L, ipe = 0L, ipt = 0L;
for (int i = 0; i < 4; ++i) {
ips = ips << 8 | Integer.parseInt(sips[i]);
ipe = ipe << 8 | Integer.parseInt(sipe[i]);
ipt = ipt << 8 | Integer.parseInt(sipt[i]);
}
if (ips > ipe) {
long t = ips;
ips = ipe;
ipe = t;
}
return ips <= ipt && ipt <= ipe;
}
}

29
src/main/java/com/fr/plugin/login/interception/function/MobileAgents.java

@ -0,0 +1,29 @@
package com.fr.plugin.login.interception.function;
import com.fr.log.FineLoggerFactory;
import javax.servlet.http.HttpServletRequest;
public class MobileAgents {
//定义移动端的请求
private final static String[] AGENTS_MOBILE = {"Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser"};
public static boolean checkAgentIsMobile(HttpServletRequest request){
String ua = request.getHeader("User-Agent");
boolean flag = false;
if(!ua.contains("Windows NT") || (ua.contains("Windows NT") && ua.contains("compatible; MSIE 9.0;"))){
//排除苹果桌面系统
if (!ua.contains("Windows NT") && !ua.contains("Macintosh")){
for (String item : AGENTS_MOBILE){
if (ua.contains(item)){
FineLoggerFactory.getLogger().info("Device : " + item);
flag = true;
break;
}
}
}
}
return flag;
}
}

158
src/main/java/com/fr/plugin/login/utils/FRUtils.java

@ -0,0 +1,158 @@
package com.fr.plugin.login.utils;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.decision.webservice.login.LogInOutResultInfo;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.login.event.LogInOutEvent;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.event.EventDispatcher;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
public class FRUtils {
/**
* 判断用户是否存在
* @param userName
* @return
*/
public static boolean isUserExist(String userName){
if (StringUtils.isEmpty(userName)) {
return false;
} else {
try {
List var1 = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName)));
return var1 != null && !var1.isEmpty();
} catch (Exception var2) {
FineLoggerFactory.getLogger().error(var2.getMessage());
return false;
}
}
}
/**
* 判断是否登录FR
* @param req
* @return
*/
public static boolean isLogin(HttpServletRequest req){
return LoginService.getInstance().isLogged(req);
}
/**
* 帆软登录
* @param httpServletRequest
* @param httpServletResponse
* @param userName
* @param url
*/
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName);
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url);
//判断用户名是否为空
if(!Utils.isNullStr(userName)){
if(isUserExist(userName)){
String FRToken = "";
try {
HttpSession session = httpServletRequest.getSession(true);
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName);
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken);
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken);
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true));
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!");
if(!Utils.isNullStr(url)){
httpServletResponse.sendRedirect(url);
}
} catch (Exception e) {
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!");
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!");
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage());
}
}else{
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!");
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!");
}
}else{
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!");
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!");
}
}
/**
*
* @param httpServletRequest
* @param httpServletResponse
*/
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse)
{
if(!isLogin(httpServletRequest)){
return ;
}
try {
LoginService.getInstance().logout(httpServletRequest,httpServletResponse);
} catch (Exception e) {
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!");
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!");
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage());
}
}
/**
* 打印FR日志
* @param message
*/
public static void FRLogInfo(String message){
FineLoggerFactory.getLogger().info("FRLOG:"+message);
}
/**
* 根据用户名获取用户信息
* @param userName
* @return
*/
public static User getFRUserByUserName(String userName){
try {
return UserService.getInstance().getUserByUserName(userName);
} catch (Exception e) {
FRLogInfo("获取用户信息异常:"+e.getMessage());
}
return null;
}
/**
* 解密FR密码
* @param password
* @return
*/
// public static String decryptFRPsd(String password){
// FRLogInfo("解密密码:"+password);
// return TransmissionTool.decrypt(password);
// }
/**
* 获取带参数的访问链接
* @return
*/
public static String getAllUrl(HttpServletRequest httpServletRequest){
return WebUtils.getOriginalURL(httpServletRequest);
}
}

96
src/main/java/com/fr/plugin/login/utils/ResponseUtils.java

@ -0,0 +1,96 @@
package com.fr.plugin.login.utils;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
public class ResponseUtils {
private static final int SUCCESS = 200;
private static final int FAILED = -1;
public static void successResponse(HttpServletResponse res, String body) {
response(res, body, SUCCESS);
}
public static void failedResponse(HttpServletResponse res, String body) {
response(res, body, FAILED);
}
private static void response(HttpServletResponse res, String body, int code) {
FRUtils.FRLogInfo("body:"+body+";code:"+code);
JSONObject object = new JSONObject();
PrintWriter pw;
try {
object.put("code", code);
object.put("data", body);
pw = WebUtils.createPrintWriter(res);
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
return;
}
res.setContentType("application/json;charset=utf-8");
String result = object.toString();
pw.println(result);
pw.flush();
pw.close();
}
public static void response(HttpServletResponse res,JSONObject json){
PrintWriter pw;
try {
pw = WebUtils.createPrintWriter(res);
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
return;
}
res.setContentType("application/json;charset=utf-8");
String result = json.toString();
pw.println(result);
pw.flush();
pw.close();
}
public static void responseXml(HttpServletResponse res,String xml){
PrintWriter pw;
try {
pw = WebUtils.createPrintWriter(res);
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
return;
}
res.setContentType("text/xml;charset=utf-8");
pw.println(xml);
pw.flush();
pw.close();
}
public static void setCSRFHeader(HttpServletResponse httpServletResponse){
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH");
httpServletResponse.setHeader("Access-Control-Max-Age", "36000");
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization");
}
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){
PrintWriter pw;
try {
pw = WebUtils.createPrintWriter(res);
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
return;
}
res.setContentType("text/javascript;charset=utf-8;charset=utf-8");
String result = json.toString();
String jsonp=req.getParameter("callback");
pw.println(jsonp+"("+result+")");
pw.flush();
pw.close();
}
}

94
src/main/java/com/fr/plugin/login/utils/Utils.java

@ -0,0 +1,94 @@
package com.fr.plugin.login.utils;
import com.fr.json.JSONObject;
import com.fr.stable.CodeUtils;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.util.UUID;
public class Utils {
/**
* 判断字符串是否为空
* @param str
* @return true 空字符串 false 非空字符串
*/
public static boolean isNullStr(String str){
return !(str != null && !str.isEmpty() && !"null".equals(str));
}
/**
* 判断字符串是否非空
* @param str
* @return
*/
public static boolean isNotNullStr(String str){
return !isNullStr(str);
}
/**
* MD5加密
* @param str
* @return
*/
public static String getMd5Str(String str)
{
return DigestUtils.md5Hex(str);
}
/**
* 获取完整的访问路径
*/
public static String getAllUrl(HttpServletRequest req, String queryStr){
String url = req.getRequestURL().toString();
if(isNullStr(queryStr)){
return url;
}
return url+"?"+queryStr;
}
/**
* 帆软shaEncode加密
*/
public static String shaEncode(String str){
return CodeUtils.sha256Encode(str);
}
/**
* 获取uuid
*/
public static String uuid(){
return UUID.randomUUID().toString();
}
public static String replaceNullStr(String str,String replace){
if(isNullStr(str)){
return replace;
}
return str;
}
public static JSONObject getRequestBody(HttpServletRequest req){
StringBuffer sb = new StringBuffer();
String line = null;
try {
BufferedReader reader = req.getReader();
while ((line = reader.readLine()) != null)
sb.append(line);
} catch (Exception e) {
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage());
}
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n","");
JSONObject json = new JSONObject(jsonString);
return json;
}
}

37
src/main/java/com/fr/plugin/login/webresource/WebResourceProvider.java

@ -0,0 +1,37 @@
package com.fr.plugin.login.webresource;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.LoginComponent;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.web.struct.Atom;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
/**
* Created by zhouping on 2019/1/16.
*/
@FunctionRecorder
public class WebResourceProvider extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return LoginComponent.KEY;
}
@Override
public Atom client() {
return new Component() {
@Override
public ScriptPath script(RequestClient requestClient) {
return ScriptPath.build("/com/fr/plugin/login/js/login.js");
}
@Override
public StylePath style(RequestClient requestClient) {
return StylePath.EMPTY;
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
}
};
}
}

59
src/main/resources/com/fr/plugin/login/html/qrcode.html

@ -0,0 +1,59 @@
<html>
<head>
<title>扫描二维码</title>
</head>
<script type="text/javascript" src="${path}/file?path=/com/fr/plugin/login/js/jquery-2.1.3.min.js" ></script>
<script>
const defaultWechatConfig = {
// 企业微信配置
agentId: '1000003',//企业微信内自行获取
appId: "wwbeb7d78360b086c2",//企业微信内自行获取
callbackUrl: "http://a396979t49.qicp.vip/webroot/decision/url/wxAuth",//企业微信内自行配置获取
state: "1"//企业微信内自行配置获取
};
function loadScript(callback) {
let s = document.createElement("script");
s.setAttribute(
"src",
"http://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js"
);
document.head.appendChild(s);
s.onload = function() {
callback();
};
}
loadScript(function() {
var username =$("#username").val();
var w = defaultWechatConfig;
var appId =$("#appId").val();
var agentId =$("#agentId").val();
var index =$("#index").val();
window.WwLogin({
id: "js-layout-login-login-wechat-qrcode",
appid: appId,
agentid: agentId,
redirect_uri: index+"/url/wxAuth?username="+username,
state: w.state
});
// window.WwLogin({
// id: "js-layout-login-login-wechat-qrcode",
// appid: 'wwbeb7d78360b086c2',
// agentid: '1000002',
// redirect_uri: "http://a396979t49.qicp.vip/webroot/decison/url/wxAuth?username="+username+";RkfOBpF5YRkJokGDjZCWFemCbGdSxK_PnNTk3NlAnQI",
// state: w.state
// });
});
</script>
<body>
<input id="username" type="hidden" value="${username}" />
<input id="appId" type="hidden" value="${appId}" />
<input id="agentId" type="hidden" value="${agentId}" />
<input id="index" type="hidden" value="${index}" />
<div id="js-layout-login-login-wechat-qrcode" class="layout_qrcode" />
</body>
</html>

4
src/main/resources/com/fr/plugin/login/interception/demo.properties

@ -0,0 +1,4 @@
Plugin-Test_Function_Abs=
Plugin-Config_Demo=
Plugin-Dec_Filter_Warning_1=
Plugin-Dec_Filter_Warning_2=

4
src/main/resources/com/fr/plugin/login/interception/demo_en_US.properties

@ -0,0 +1,4 @@
Plugin-Test_Function_Abs=Test ABS
Plugin-Config_Demo= test 18n
Plugin-Dec_Filter_Warning_1= Sorry, you can't login at
Plugin-Dec_Filter_Warning_2=!

4
src/main/resources/com/fr/plugin/login/interception/demo_zh_CN.properties

@ -0,0 +1,4 @@
Plugin-Test_Function_Abs=\u6D4B\u8BD5ABS\u51FD\u6570
Plugin-Config_Demo=\u56FD\u9645\u5316\u6D4B\u8BD5
Plugin-Dec_Filter_Warning_1=\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u4E0D\u80FD\u5728
Plugin-Dec_Filter_Warning_2=\u767B\u9646!

117
src/main/resources/com/fr/plugin/login/interception/web/ipConfig.js

@ -0,0 +1,117 @@
!(function(){
BI.config("dec.constant.system.tabs", function (items) {
items.push({
value: "ipToken",
text: BI.i18nText("IP配置"), // 文字
cardType: "dec.management.ipConfig"
});
return items;
});
BI.config("dec.constant.menu.items", function (items) {
items.push({
value: "baidu",
text: BI.i18nText("百度一下"),
cardType:{
src:"http://baidu.com"
},
cls: "analysis-menu-font"
});
return items;
});
function resolvePath(path, isPublic){
if(!path || path[0] !== '/'){
path = '/' + path;
}
return isPublic === true
? '/plugin/public/com.fr.plugin.dw.dw.7.project' + path
: '/plugin/private/com.fr.plugin.dw.dw.7.project' + path;
}
var ipConfig = BI.inherit(BI.Widget, {
props: {
baseCls: "ipConfig"
},
render: function(){
var self = this;
return {
type: "bi.absolute",
items: [
{
el:{
type: "bi.button",
text: "添加",
handler: function() {
var id = "addUserPane"
var that = this;
BI.Popovers.create(id, {
type: "bi.bar_popover",
// String或者是json都行
header: "添加IP限制",
size: "small",
body: {
type: "bi.add.userTokenOrIp",
cType: "ip",
ref: function(e){
that.userIpPane = e;
}
},
listeners:[{
eventName: "EVENT_CANCEL",
action: function(){
BI.Msg.toast("点击了取消")
}
},{
eventName: "EVENT_CONFIRM",
action: function(){
var params = that.userIpPane.getValue();
console.info(params)
Dec.reqPost(resolvePath("/addIp", false), {
userName: params.userName,
ip: params.params2
}, function(){
BI.Msg.toast("保存成功")
self.tableRef.reload();
})
}
}]
}).open(id);
}
},
top: 0,
left: 0,
},
{
el:{
type: "bi.button",
text: "刷新",
handler: function(){
self.tableRef.reload();
}
},
top: 0,
left: 100,
},
{
el:{
type: "dec.management.iptoken.table",
tableType: "ipTable",
ref:function(e){
self.tableRef = e;
}
},
top: 40,
left: 0,
right: 0,
bottom: 0
}
]
};
}
});
BI.shortcut("dec.management.ipConfig", ipConfig);
}());

109
src/main/resources/com/fr/plugin/login/interception/web/table.js

@ -0,0 +1,109 @@
;(function(){
//debugger
var IpHeader = [[{
text:"id",
},{
text:"用户名",
},{
text:"IP",
},{
text:"操作"
}]];
var TokenHeader = [[{
text:"id",
},{
text:"用户名",
},{
text:"Token",
},{
text:"操作"
}]];
function resolvePath(path, isPublic){
if(!path || path[0] !== '/'){
path = '/' + path;
}
return isPublic === true
? '/plugin/public/com.fr.plugin.dw.dw.7.project' + path
: '/plugin/private/com.fr.plugin.dw.dw.7.project' + path;
}
var IPAndTokenTable = BI.inherit(BI.Widget, {
props:{
baseCls: "iptoken-table",
tableType:"ipTable"
},
beforeInit: function(render){
var that = this;
this.getData(function(data){
that.allData = data;
render();
})
},
getData: function(callBack){
var that = this;
var url="/listToken";
if(this.options.tableType === "ipTable"){
url = "/listIp"
}
Dec.reqGet(
resolvePath(url, false)
,{}
,function(data){
var tempData = BI.map(data, function(i, v){
return BI.map(v, function(ii, vv){
return {
text:vv,
whiteSpace:"normal"
}
})
});
BI.each(tempData, function(i, v){
v.push({
type: "bi.button",
text: "删除",
handler: function(){
var id = v[0].text;
var url = "/delToken";
if(that.options.tableType === "ipTable"){
url = "/delIp"
}
Dec.reqDelete(resolvePath(url, false), {
id: id
}, function(){
that.reload();
})
}
})
});
callBack(tempData);
});
},
reload: function(){
var that = this;
this.getData(function(data){
that.tableIns.populate(data)
})
},
render: function(){
var that = this;
var header = TokenHeader;
if(this.options.tableType === "ipTable"){
header = IpHeader;
}
return {
type: "bi.table_view",
width: 600,
height: 400,
ref: function(e){
that.tableIns = e;
},
minColumnSize: [100, 100, 100],
columnSize: [100, 100, 100],
regionColumnSize: [300, "fill"],
items: this.allData,
header: header,
}
}
});
BI.shortcut("dec.management.iptoken.table", IPAndTokenTable);
})();

107
src/main/resources/com/fr/plugin/login/interception/web/tokenConfig.js

@ -0,0 +1,107 @@
;(function(){
BI.config("dec.constant.management.navigation", function(items){
items.push({
value: "iptoken",
id:"ipToken-1",
text: BI.i18nText("Token配置"), // 文字
cardType: "dec.management.tokenConfig",
cls: "management-directory-font"
});
return items;
})
function resolvePath(path, isPublic){
if(!path || path[0] !== '/'){
path = '/' + path;
}
return isPublic === true
? '/plugin/public/com.fr.plugin.dw.dw.7.project' + path
: '/plugin/private/com.fr.plugin.dw.dw.7.project' + path;
}
var tokenConfig = BI.inherit(BI.Widget, {
props: {
baseCls: "tokenConfig"
},
render: function(){
var self = this;
return {
type: "bi.absolute",
items: [
{
el:{
type: "bi.button",
text: "添加",
handler: function() {
var id = "addUserPane"
var that = this;
BI.Popovers.create(id, {
type: "bi.bar_popover",
// String或者是json都行
header: "添加Token限制",
size: "small",
body: {
type: "bi.add.userTokenOrIp",
cType: "token",
ref: function(e){
that.userIpPane = e;
}
},
listeners:[{
eventName: "EVENT_CANCEL",
action: function(){
BI.Msg.toast("点击了取消")
}
},{
eventName: "EVENT_CONFIRM",
action: function(){
var params = that.userIpPane.getValue();
console.info(params)
Dec.reqPost(resolvePath("/addToken", false), {
userName: params.userName,
token:params.params2
}, function(){
BI.Msg.toast("保存成功")
self.tableRef.reload();
})
}
}]
}).open(id);
}
},
top: 0,
left: 0,
},
{
el:{
type: "bi.button",
text: "刷新",
handler: function(){
self.tableRef.reload();
}
},
top: 0,
left: 100,
},
{
el:{
type: "dec.management.iptoken.table",
tableType: "tokenTable",
ref:function(e){
self.tableRef = e;
}
},
top: 40,
left: 0,
right: 0,
bottom: 0
}
]
};
}
});
BI.shortcut("dec.management.tokenConfig", tokenConfig);
})();

73
src/main/resources/com/fr/plugin/login/interception/web/userIpAdd.js

@ -0,0 +1,73 @@
;(function(){
function resolvePath(path, isPublic){
if(!path || path[0] !== '/'){
path = '/' + path;
}
return isPublic === true
? '/plugin/public/com.fr.plugin.dw.dw.7.project' + path
: '/plugin/private/com.fr.plugin.dw.dw.7.project' + path;
}
var IPTokenEditorPane = BI.inherit(BI.Widget, {
props:{
baseCls:"iptoken-table",
cType:"token",
},
getValue:function(){
return {
userName:this.inputUserName.getValue(),
params2:this.inputIPOrToken.getValue()
}
},
render: function(){
var that = this;
var inputIPOrTokenText = "请输入IP"
if(this.options.cType === "token"){
inputIPOrTokenText = "请输入Token"
}
return {
type: "bi.vtape",
vgap: 10,
height: 200,
items:[
{
height: 20,
type: "bi.horizontal_adapt",
columnSize:[140, "fill"],
items: [{
type: "bi.label",
text: "输入用户名:",
}, {
type: "bi.text_editor",
watermark: "不能为空",
allowBlank: false,
ref: function(e){
that.inputUserName=e;
},
errorText: "非空!"
}]
},
{
height: 20,
type: "bi.horizontal_adapt",
columnSize:[140, "fill"],
items: [{
type: "bi.label",
text: inputIPOrTokenText,
}, {
type: "bi.text_editor",
watermark: "不能为空",
allowBlank: false,
ref: function(e){
that.inputIPOrToken=e;
},
errorText: "非空!"
}]
}
]
}
}
});
BI.shortcut("bi.add.userTokenOrIp", IPTokenEditorPane);
})();

4
src/main/resources/com/fr/plugin/login/js/jquery-2.1.3.min.js vendored

File diff suppressed because one or more lines are too long

363
src/main/resources/com/fr/plugin/login/js/login.js

@ -0,0 +1,363 @@
var t = "default_fail",
e = BI.inherit(BI.OB, {
init: function () {
this.failMap = {},
this._initErrorHandler()
},
addHandler: function (e, t) {
this.failMap[e] = t
},
getHandler: function (e) {
return BI.isFunction(this.failMap[e]) ? this.failMap[e] : this.failMap[t]
},
_initErrorHandler: function () {
this.failMap[DecCst.ErrorCode.USER_LOGGED] = function (e) {
this.store.setPropsInfo({
token: e.errorMsg,
isChangePwd: !0,
from: DecCst.Login.AuthenticationModule.SINGLE
}),
this.store.setNeedSlider(!1),
this.loginErrorRow.visible()
},
this.failMap[DecCst.ErrorCode.USER_LOGGED_CAN_NOT_CHANGE_PASSWORD] = function () {
this.store.setNeedSlider(!1),
this.loginNormalErrorRow.visible()
},
this.failMap[DecCst.ErrorCode.USERNAME_UNAVAILABLE] = function () {
this.usernameRow.showError(BI.i18nText("Dec-Error_Login_Username_Unable"))
},
this.failMap[DecCst.ErrorCode.USERNAME_NOT_EXIST_PASSWORD_ERROR] = function () {
this.passwordRow.showError(BI.i18nText("Dec-Error_Incorrect_Password_Username"))
},
this.failMap[90000] = function () {
this.passwordRow.showError("您的电脑未授权,请联系管理员。")
},
this.failMap[DecCst.ErrorCode.SMS_CAPTCHA_UNCHECK] = function (e) {
this.store.setPropsInfo({
token: e.errorMsg,
isChangePwd: !1,
from: DecCst.Login.AuthenticationModule.LOGIN
}),
this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING)
},
this.failMap[DecCst.ErrorCode.PASSWORD_NEED_SPLIDER] = function () {
this.store.setNeedSlider(!0),
this.sliderBar.resetAll()
},
this.failMap[DecCst.ErrorCode.PASSWORD_LOCKED] = function (e) {
this.store.setPropsInfo({
errorMsg: e.errorMsg
}),
this.store.setSelectedTab(DecCst.Login.Tabs.LOCKED)
},
this.failMap[DecCst.ErrorCode.PASSWORD_NEED_UPDATE] = function (e) {
this.store.setPropsInfo({
token: e.errorMsg,
isChangePwd: !0,
from: DecCst.Login.AuthenticationModule.PWD_UPDATE
}),
this.model.isNeedVerify ? this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : this.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
},
this.failMap[DecCst.ErrorCode.PASSWORD_STRENGTH] = function (e) {
this.store.setPropsInfo({
token: e.errorMsg,
isChangePwd: !0,
from: DecCst.Login.AuthenticationModule.PWD_STRENGTH
}),
this.model.isNeedVerify ? this.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : this.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
},
this.failMap[DecCst.ErrorCode.CAPTCHA_TIMEOUT] = function () {
this.sliderError.setText(BI.i18nText("Dec-Basic_Captcha_Timeout")),
this.sliderBar.resetAll()
},
this.addHandler(t, function () {
this.passwordRow.showError(BI.i18nText("Dec-Login_Fail"))
})
}
});
BI.service("dec.service.login.login", e)
var e = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-login-login"
},
_store: function () {
return BI.Models.getModel("dec.model.login.login")
},
watch: {
supportForgetPwd: function (e) {
this.forgetPasswordRow.setVisible(e)
},
needSlider: function (e) {
this.sliderMasker.setVisible(e)
}
},
render: function () {
var t = this;
this.options;
return {
type: "bi.absolute",
items: [{
el: {
type: "bi.vertical",
items: [{
type: "dec.login.login.item",
$testId: "dec-login-username",
iconCls: "login-username-font",
tgap: 50,
watermark: BI.i18nText("Dec-User_Name"),
ref: function (e) {
t.usernameRow = e
}
}, {
type: "dec.login.login.item",
$testId: "dec-login-password",
iconCls: "login-password-font",
watermark: BI.i18nText("Dec-Password"),
inputType: "password",
ref: function (e) {
t.passwordRow = e
}
}, {
type: "bi.left_right_vertical_adapt",
bgap: 30,
items: {
left: [{
type: "bi.multi_select_item",
$testId: "dec-login-remember",
textLgap: 5,
iconWrapperWidth: 16,
height: 16,
text: BI.i18nText("Dec-Login_Remember"),
logic: {
dynamic: !0
},
ref: function (e) {
t.rememberRow = e
}
}
],
right: [{
type: "bi.button",
$testId: "dec-login-forget-password",
clear: !0,
height: 16,
invisible: !this.model.supportForgetPwd,
text: BI.i18nText("Dec-Basic_Forget_Password"),
ref: function (e) {
t.forgetPasswordRow = e
},
handler: function () {
t.store.setSelectedTab(DecCst.Login.Tabs.FORGET_PASSWORD)
}
}
].concat(this._createItems())
}
}, {
type: "bi.horizontal_auto",
items: [{
type: "bi.button",
cls: "login-button",
text: BI.i18nText("Dec-Basic_Login"),
width: 190,
height: 40,
handler: function () {
t._start()
}
}
]
}, {
el: {
type: "bi.vertical",
$testId: "dec-login-logged-chang-text",
cls: "login-error",
invisible: !0,
scrolly: !1,
items: [{
type: "bi.text",
tagName: "span",
whiteSpace: "normal",
text: BI.i18nText("Dec-Login_Other_Logged_Tip")
}, {
type: "bi.text",
$testId: "dec-login-logged-chang-password",
tagName: "span",
cls: "password-btn",
text: BI.i18nText("Dec-Login_Change_Password"),
handler: function () {
t.model.isNeedVerify ? t.store.setSelectedTab(DecCst.Login.Tabs.VERIFY_BING) : t.store.setSelectedTab(DecCst.Login.Tabs.PASSWORD_OLD)
}
}
],
ref: function (e) {
t.loginErrorRow = e
}
},
tgap: 20
}, {
el: {
type: "bi.text",
$testId: "dec-login-logged-text",
cls: "login-error",
invisible: !0,
whiteSpace: "normal",
text: BI.i18nText("Dec-Login_Normal_Other_Logged_Tip"),
ref: function (e) {
t.loginNormalErrorRow = e
}
},
tgap: 20
}
]
},
top: 0,
right: 40,
bottom: 0,
left: 40
}, {
el: {
type: "bi.center_adapt",
cls: "slider-masker",
invisible: !0,
items: [{
type: "dec.login.slider",
listeners: [{
eventName: "EVENT_SUCCESS",
action: function () {
t._start()
}
}, {
eventName: "EVENT_CLOSE",
action: function () {
t.store.resetSlider()
}
}
],
ref: function (e) {
t.sliderBar = e
}
}
],
ref: function (e) {
t.sliderMasker = e
}
},
top: 0,
right: 40,
bottom: 0,
left: 40
}
]
}
},
mounted: function () {
var t = this;
this.store.initData(),
this.element.keyup(function (e) {
13 === e.keyCode && t._start()
})
},
_createItems: function () {
return BI.map(BI.Constants.getConstant("dec.constant.login.way.extend"), function (e, t) {
return {
type: t.cardType
}
})
},
_start: function () {
var t = this,
e = this.usernameRow.getValue(),
i = this.passwordRow.getValue(),
n = this.rememberRow.isSelected() ? -2 : -1;
t.loginErrorRow.invisible(),
t.loginNormalErrorRow.invisible(),
"" !== e ? "" !== i ? (this.store.setLoginInfo({
username: e,
validity: n,
phone: "",
captcha: ""
}), this.store.login({
username: e,
password: this.passwordRow.getCipher(),
validity: n,
sliderToken: this.model.sliderToken,
origin: Dec.Utils.getUrlQuery("origin"),
encrypted: !0
}, function (e) {
t.store.resetSlider();
//账户密码验证成功
if(e.data && e.data.accessToken){
var username = e.data.username;
//是否需要鉴权
var needAuth2 = needAuth(username);
var config = getConfig();
console.info(config);
//需要鉴权跳转微信二维码扫描页面
if(needAuth2){
window.location.href=config.index+"/url/toQrcode?username="+username;
return;
}
t.fireEvent("EVENT_LOGIN", e.data)
}else{
BI.bind(BI.Services.getService("dec.service.login.login").getHandler(e.errorCode), t)(e)
}
}
)) : this.passwordRow.showError(BI.i18nText("Dec-Error_Password_Not_Null")) : this.usernameRow.showError(BI.i18nText("Dec-Error_Username_Not_Null"))
}
});
BI.shortcut("dec.login.login", e)
//
// Dec.Utils.login = function(v,callback){
// var mac = getMac();
// console.info(mac);
// console.info(Dec.fineServletURL);
// $.ajax({
// type: 'POST',
// url: Dec.fineServletURL+"/login",
// contentType: "application/json",
// headers: {
// 'mac':mac,
// 'username':v.username
// },
// data: JSON.stringify(v),
// dataType:'json',
// success: callback
// });
//
// // Dec.reqPost("/login",v,callback);
// }
//是否需要鉴权
function needAuth(username){
//0 需要鉴权 1不需要鉴权
var needAuth = 0;
$.ajax({
type:"get",
async:false,
url:"/WebReport/decision/url/getIp?username="+username,
success:function(data){
needAuth = data.data;
}
})
return needAuth == 0 || needAuth == "0";
// return true;
}
function getConfig(){
var data2 = {};
$.ajax({
type:"get",
async:false,
// url:"/WebReport/decision/url/getConfig",
url:"/WebReport/decision/url/getConfig",
success:function(data){
data2 = data;
}
})
return data2;
}

BIN
使用手册.docx

Binary file not shown.
Loading…
Cancel
Save