Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
91d02bd72f
  1. 5
      README.md
  2. BIN
      lib/fastjson-1.2.73.jar
  3. BIN
      lib/fr-plugin-weixin-10.4.982.jar
  4. BIN
      lib/logback-classic-1.2.3.jar
  5. BIN
      lib/logback-core-1.2.3.jar
  6. BIN
      lib/slf4j-api-1.7.25.jar
  7. 66
      plugin.xml
  8. 43
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserController.java
  9. 305
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserDBController.java
  10. 79
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserDao.java
  11. 55
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserEntity.java
  12. 97
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserMacDAO.java
  13. 96
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserMacEntity.java
  14. 15
      src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/ControllerBridge.java
  15. 317
      src/main/java/com/fr/plugin/loginAuth/filter/SSOFilter.java
  16. 12
      src/main/java/com/fr/plugin/loginAuth/handler/ExtendAttrHandlerProvider.java
  17. 99
      src/main/java/com/fr/plugin/loginAuth/handler/ToDecisionLogin.java
  18. 14
      src/main/java/com/fr/plugin/loginAuth/handler/URLAliasProvide.java
  19. 111
      src/main/java/com/fr/plugin/loginAuth/httpAuth/Login.java
  20. 11
      src/main/java/com/fr/plugin/loginAuth/httpAuth/Test.java
  21. 262
      src/main/java/com/fr/plugin/loginAuth/utils/CipherUtils.java
  22. 158
      src/main/java/com/fr/plugin/loginAuth/utils/FRUtils.java
  23. 237
      src/main/java/com/fr/plugin/loginAuth/utils/HttpUtils.java
  24. 96
      src/main/java/com/fr/plugin/loginAuth/utils/ResponseUtils.java
  25. 96
      src/main/java/com/fr/plugin/loginAuth/utils/Utils.java
  26. 35
      src/main/java/com/fr/plugin/loginAuth/webresource/WebResourceProvider.java
  27. 29
      src/main/resources/com/fr/plugin/loginAuth/js/login.html
  28. 333
      src/main/resources/com/fr/plugin/loginAuth/js/login.js
  29. BIN
      使用手册.docx

5
README.md

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

BIN
lib/fastjson-1.2.73.jar

Binary file not shown.

BIN
lib/fr-plugin-weixin-10.4.982.jar

Binary file not shown.

BIN
lib/logback-classic-1.2.3.jar

Binary file not shown.

BIN
lib/logback-core-1.2.3.jar

Binary file not shown.

BIN
lib/slf4j-api-1.7.25.jar

Binary file not shown.

66
plugin.xml

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.loginAuth</id>
<name><![CDATA[登录认证]]></name>
<active>yes</active>
<version>1.0.19</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[登录认证]]></description>
<main-package>com.fr.plugin.loginAuth</main-package>
<change-notes>
<![CDATA[
[2021-05-12]10.4.982:
修复bug<br/>
[2021-04-28]10.4.981:
修复bug<br/>
[2021-04-14]10.4.979:
修复bug<br/>
[2021-03-16]10.4.977:
推送时定时调度运行监控页面报错优化<br/>
日志中增加错误码和解决方案页面的url<br/>
[2021-01-26]10.4.976:
解决bug<br/>
[2020-12-15]10.4.975:
微信集成下支持获取经纬度js<br/>
新增获取用户绑定关系接口<br/>
[2020-10-30]10.4.97:
链接可设置是否提前计算公式<br/>
解决bug<br/>
[2020-09-11]10.4.90:
解决bug<br/>
[2020-07-31]10.4.84:
修复微信定时调度图片持久化失败的bug<br/>
解决bug<br/>
[2020-06-30]10.4.80:
消息推送支持推送到微信群<br/>
[2020-06-03]10.4.76:
H5拍照上传支持前置摄像头和选择是否原图<br/>
生成模板链接支持选择参数<br/>
[2020-04-23]10.4.69:
支持集群<br/>
[2020-04-03]10.4.66:
增加单点登录、定时调度和同步通讯录模块的日志监控<br/>
[2020-02-28]10.4.61:
手动匹配用户时,用户名显示为姓名(用户名)格式,方便查找用户<br/>
服务器和代理服务器添加注释<br/>
]]>
</change-notes>
<function-recorder class="com.fr.plugin.loginAuth.dbAccessProvider.AuthUserDBController"/>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.loginAuth.handler.ExtendAttrHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.loginAuth.handler.URLAliasProvide"/>
<EmbedRequestFilterProvider class="com.fr.plugin.loginAuth.filter.SSOFilter"/>
<ControllerRegisterProvider class="com.fr.plugin.loginAuth.dbAccessProvider.ControllerBridge"/>
<!-- <HttpAuthorizeProvider class="com.fr.plugin.loginAuth.httpAuth.Login"/>-->
<WebResourceProvider class="com.fr.plugin.loginAuth.webresource.WebResourceProvider"/>
</extra-decision>
<extra-core>
<DBAccessProvider class="com.fr.plugin.loginAuth.dbAccessProvider.AuthUserDBController"/>
</extra-core>
<dependence>
<Item key="com.fr.plugin.weixin" type="plugin"/>
</dependence>
</plugin>

43
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserController.java

@ -0,0 +1,43 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.RequestMapping;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
@Controller("DBAccessDemoController")
@LoginStatusChecker(required = false)
@RequestMapping(value = "/db/demo")
public class AuthUserController {
// @RequestMapping( value = "/dm_entity", method = RequestMethod.POST )
// @ResponseBody
// public Response add( @RequestBody AuthUserEntity bean )throws Exception{
// AuthUserDBController.add(bean);
// return Response.ok( bean );
// }
//
// @RequestMapping( value = "/dm_entity/{entity}", method = RequestMethod.DELETE )
// @ResponseBody
// public Response delete( @PathVariable("entity") String entity )throws Exception{
// return Response.ok( AuthUserDBController.deleteOrg(entity) );
// }
//
// @RequestMapping( value = "/dm_entity", method = RequestMethod.PUT )
// @ResponseBody
// public Response update( @RequestBody AuthUserEntity bean )throws Exception{
// AuthUserDBController.update(bean);
// return Response.ok( bean );
// }
//
// @RequestMapping( value = "/dm_entity", method = RequestMethod.GET )
// @ResponseBody
// public Response like( @RequestParam(value = "key") String key )throws Exception{
// return Response.ok( AuthUserDBController.like(key) );
// }
}

305
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserDBController.java

@ -0,0 +1,305 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.db.fun.impl.AbstractDBAccessProvider;
import com.fr.plugin.loginAuth.utils.FRUtils;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.action.DBAction;
import com.fr.stable.db.dao.DAOContext;
import com.fr.stable.db.dao.DAOProvider;
import java.util.ArrayList;
import java.util.List;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
@EnableMetrics
@FunctionRecorder
public class AuthUserDBController extends AbstractDBAccessProvider {
private static DBAccessor accessor;
public static DBAccessor getAccessor() {
return accessor;
}
@Override
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
AuthUserDao.DAO,
AuthUserMacDAO.DAO
};
}
@Override
public void onDBAvailable(DBAccessor accessor) {
AuthUserDBController.accessor = accessor;
}
public static List<AuthUserEntity> getByUserName(final String username ){
try{
return accessor.runQueryAction(new DBAction<List<AuthUserEntity>>() {
@Override
public List<AuthUserEntity> run(DAOContext context) throws Exception {
List<AuthUserEntity> list = context.getDAO(AuthUserDao.class).getByUserName(username);
return list;
}
});
}catch(Throwable e){
FRUtils.FRLogInfo("getByUserName:"+e.getMessage());
}
return new ArrayList<AuthUserEntity>();
}
public static List<AuthUserMacEntity> getUserAuthMac(final String username, final String mac) throws Exception{
return accessor.runQueryAction(new DBAction<List<AuthUserMacEntity>>() {
@Override
public List<AuthUserMacEntity> run(DAOContext context) throws Exception {
List<AuthUserMacEntity> list = context.getDAO(AuthUserMacDAO.class).getAuthUserMac(username,mac);
return list;
}
});
}
public static List<AuthUserMacEntity> getUserAuthMac2(final String username, final String mac,final String deviceType) throws Exception{
return accessor.runQueryAction(new DBAction<List<AuthUserMacEntity>>() {
@Override
public List<AuthUserMacEntity> run(DAOContext context) throws Exception {
List<AuthUserMacEntity> list = context.getDAO(AuthUserMacDAO.class).getAuthUserMac2(username,mac,deviceType);
return list;
}
});
}
/**
* 业务对象
* @param bean
*/
public static void addUserAuth( final AuthUserEntity bean ) throws Exception {
accessor.runDMLAction(new DBAction<Boolean>() {
@Override
public Boolean run(DAOContext context) throws Exception {
context.getDAO(AuthUserDao.class).add(bean);
return true;
}
});
}
/**
* 业务对象
* @param bean
*/
public static void add( final AuthUserMacEntity bean ) throws Exception {
accessor.runDMLAction(new DBAction<Boolean>() {
@Override
public Boolean run(DAOContext context) throws Exception {
context.getDAO(AuthUserMacDAO.class).add(bean);
return true;
}
});
}
// /**
// * 获取org对象
// * @param orgCode
// * @return
// */
// public static AuthUserEntity getOrg(final String orgCode){
// try{
// return accessor.runQueryAction(new DBAction<AuthUserEntity>() {
// @Override
// public AuthUserEntity run(DAOContext context) throws Exception {
// List<AuthUserEntity> result = new ArrayList<AuthUserEntity>();
// List<AuthUserEntity> list = context.getDAO(AuthUserDao.class).likeByKey(orgCode);
// for( AuthUserEntity item : list ){
//// result.add( toDataBean(item,null) );
// }
// return result != null && result.size() > 0 ? result.get(0) : new AuthUserEntity();
// }
// });
// }catch(Throwable e){
//// LogKit.error(e,"Get DataBeans{} Error:{}",key,e.getMessage());
// }
// return new AuthUserEntity();
// }
//
// /**
// * 业务对象——增
// * @param bean
// */
// public static void add( final AuthUserEntity bean ){
// try{
// accessor.runDMLAction(new DBAction<Boolean>() {
// @Override
// public Boolean run(DAOContext context) throws Exception {
// context.getDAO(AuthUserDao.class).add( loadDemoEntity(bean,true) );
//// context.getDAO(LinkDao.class).add( loadLinkEntities(bean,true) );
// return true;
// }
// });
// }catch(Throwable e){
// e.printStackTrace();
//// LogKit.error(e,"Add DataBean Error:{}",e.getMessage());
// }
// }
//
// /**
// * 业务对象——删
// * @param id
// */
// public static AuthUserEntity deleteOrg( final String id ){
// try{
// return accessor.runDMLAction(new DBAction<AuthUserEntity>() {
// @Override
// public AuthUserEntity run(DAOContext context) throws Exception {
// AuthUserEntity entity = context.getDAO(AuthUserDao.class).getById(id);
// if( null == entity ){
// return null;
// }
// context.getDAO(AuthUserDao.class).remove( id );
//// List<LinkEntity> list = context.getDAO(LinkDao.class).removeByKey(entity.getDid());
// return toDataBean(entity,null);
// }
// });
// }catch(Throwable e){
//// LogKit.error(e,"Delete DataBean[{}] Error:{}",id,e.getMessage());
// }
// return null;
// }
//
// /**
// * 业务对象——改
// * @param bean
// */
// public static void update( AuthUserEntity bean ){
// final AuthUserEntity bean2 = bean;
// try{
// accessor.runDMLAction(new DBAction<Boolean>() {
// @Override
// public Boolean run(DAOContext context) throws Exception {
// context.getDAO(AuthUserDao.class).update( loadDemoEntity(bean2,false) );
// context.getDAO(AuthUserMacDAO.class).addOrUpdate( loadLinkEntities(bean2,false) );
// return true;
// }
// });
// }catch(Throwable e){
//// LogKit.error(e,"Update DataBean Error:{}",e.getMessage());
// }
// }
//
// /**
// * 业务对象——查
// * @param key
// * @return
// */
// public static List<AuthUserEntity> like(String key ){
// final String key2 = key;
// try{
// return accessor.runQueryAction(new DBAction<List<AuthUserEntity>>() {
// @Override
// public List<AuthUserEntity> run(DAOContext context) throws Exception {
// List<AuthUserEntity> result = new ArrayList<AuthUserEntity>();
// List<AuthUserEntity> list = context.getDAO(AuthUserDao.class).likeByKey(key2);
// for( AuthUserEntity item : list ){
//// List<LinkEntity> links = context.getDAO(LinkDao.class).getByKey(item.getDid());
// result.add( toDataBean(item,null) );
// }
// return result;
// }
// });
// }catch(Throwable e){
//// LogKit.error(e,"Get DataBeans{} Error:{}",key,e.getMessage());
// }
// return new ArrayList<AuthUserEntity>();
// }
//
// /**
// * 根据pId和type查询
// * @param pId
// * @param type
// * @return
// */
// public static List<AuthUserEntity> like(final String pId,final String type){
// try{
// return accessor.runQueryAction(new DBAction<List<AuthUserEntity>>() {
// @Override
// public List<AuthUserEntity> run(DAOContext context) throws Exception {
// List<AuthUserEntity> result = new ArrayList<AuthUserEntity>();
// List<AuthUserEntity> list = context.getDAO(AuthUserDao.class).like(pId,type);
// for( AuthUserEntity item : list ){
//// List<LinkEntity> links = context.getDAO(LinkDao.class).getByKey(item.getDid());
// result.add( toDataBean(item,null) );
// }
// return result;
// }
// });
// }catch(Throwable e){
//// LogKit.error(e,"Get DataBeans{} Error:{}",key,e.getMessage());
// }
// return new ArrayList<AuthUserEntity>();
// }
//
// private static AuthUserEntity loadDemoEntity(AuthUserEntity bean, boolean isAdd ){
// AuthUserEntity entity = new AuthUserEntity();
//// if(isAdd || StringUtils.isEmpty( bean.getId() ) ){
//// bean.setId(UUIDUtil.generate());
//// }
//// entity.setId( bean.getId() );
//// entity.setDid( bean.getDid());
//// entity.setCode(bean.getCode());
//// entity.setType(bean.getType());
//// entity.setPid(bean.getPid());
//// entity.setBean( bean.getBean() );
// return entity;
// }
//
// private static AuthUserEntity toDataBean(AuthUserEntity entity, List<AuthUserMacEntity> list ){
// AuthUserEntity bean = new AuthUserEntity();
//// bean.setId( entity.getId() );
//// bean.setDid( entity.getDid());
//// bean.setCode(entity.getCode());
//// bean.setType(entity.getType());
//// bean.setPid(entity.getPid());
//// bean.setBean( entity.getBean() );
//// bean.setAttr3( toAttrBeans(list) );
// return bean;
// }
//
// private static List<AuthUserEntity> toAttrBeans( List<AuthUserMacEntity> links ){
// List<AuthUserEntity> list = new ArrayList<AuthUserEntity>();
// for( AuthUserMacEntity item : links ){
// AuthUserEntity bean = new AuthUserEntity();
//// bean.setAttr1(item.getId());
//// bean.setAttr2(item.getAttr3());
// list.add( bean );
// }
// return list;
// }
//
// private static List<AuthUserMacEntity> loadLinkEntities(AuthUserEntity bean, boolean isAdd ){
// List<AuthUserMacEntity> list = new ArrayList<AuthUserMacEntity>();
//// List<DemoBean> attr3 = bean.getAttr3();
//// for( DemoBean item : attr3 ){
//// if(isAdd || StringUtils.isEmpty( item.getAttr1() ) ){
//// item.setAttr1(UUIDUtil.generate());
//// }
//// list.add( new LinkEntity()
//// .id( item.getAttr1() )
//// .key( bean.getKey() )
//// .attr3( item.getAttr2() )
//// );
//// }
// return list;
// }
}

79
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserDao.java

@ -0,0 +1,79 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
import com.fr.stable.db.session.DAOSession;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.stable.query.restriction.RestrictionFactory;
import java.util.List;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
public class AuthUserDao extends BaseDAO<AuthUserEntity> {
public AuthUserDao(DAOSession session) {
super(session);
}
@Override
protected Class<AuthUserEntity> getEntityClass() {
return AuthUserEntity.class;
}
public final static DAOProvider DAO = new DAOProvider() {
@Override
public Class getEntityClass() {
return AuthUserEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return AuthUserDao.class;
}
};
public List<AuthUserEntity> getByUserName(String username ) throws Exception{
QueryCondition condition = QueryFactory.create()
.addRestriction(RestrictionFactory.eq(AuthUserEntity.COLUMN_WORKCODE, username));
return find(condition);
// QueryCondition condition = QueryFactory.create()
// .addRestriction(RestrictionFactory.eq(AuthUserEntity.COLUMN_WORKCODE, username));
//
// return find(condition);
}
// public List<AuthUserEntity> likeByKey(String key )throws Exception{
// QueryCondition condition = QueryFactory.create()
// .addRestriction(RestrictionFactory.eq(AuthUserEntity.COLUMN_CD, key));
// return find(condition);
// }
//
// public List<AuthUserEntity> like(String pid, String type)throws Exception{
// QueryCondition condition = QueryFactory.create()
// .addRestriction(RestrictionFactory.like(AuthUserEntity.COLUMN_CD, pid)).addRestriction(RestrictionFactory.like(AuthUserEntity.COLUMN_CD,type));
// return find(condition);
// }
//
public void add(AuthUserEntity entity) throws Exception {
getSession().persist(entity);
}
//
// public void update(AuthUserEntity entity) throws Exception {
// getSession().merge(entity);
// }
//
// public AuthUserEntity getById(String id) throws Exception {
// return getSession().getById(id, AuthUserEntity.class);
// }
//
// public void remove(String id) throws Exception {
// getSession().remove(QueryFactory.create()
// .addRestriction(RestrictionFactory.eq("id", id)),
// this.getEntityClass());
// }
}

55
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserEntity.java

@ -0,0 +1,55 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
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;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
@Entity
@Table(name = "HT_Auth_User")
public class AuthUserEntity extends BaseEntity {
public static final String COLUMN_WORKCODE = "workcode";
public static final String COLUMN_WORKNAME = "workname";
public static final String COLUMN_CREATEDDATE = "createddate";
@Column(name = COLUMN_WORKCODE)
private String workcode = null;
@Column(name = COLUMN_WORKNAME)
private String workname = null;
@Column(name = COLUMN_CREATEDDATE)
private Date createddate = null;
public String getWorkcode() {
return workcode;
}
public void setWorkcode(String workcode) {
this.workcode = workcode;
}
public String getWorkname() {
return workname;
}
public void setWorkname(String workname) {
this.workname = workname;
}
public Date getCreateddate() {
return createddate;
}
public void setCreateddate(Date createddate) {
this.createddate = createddate;
}
}

97
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserMacDAO.java

@ -0,0 +1,97 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
import com.fr.stable.db.session.DAOSession;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.stable.query.restriction.RestrictionFactory;
import java.util.List;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
public class AuthUserMacDAO extends BaseDAO<AuthUserMacEntity> {
public AuthUserMacDAO(DAOSession session) {
super(session);
}
@Override
protected Class<AuthUserMacEntity> getEntityClass() {
return AuthUserMacEntity.class;
}
public final static DAOProvider DAO = new DAOProvider() {
@Override
public Class getEntityClass() {
return AuthUserMacEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return AuthUserMacDAO.class;
}
};
public List<AuthUserMacEntity> getAuthUserMac(String username, String mac ) throws Exception{
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_WC, username))
.addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_DM, mac));
return find(condition);
}
public void add( AuthUserMacEntity item) throws Exception {
getSession().persist(item);
}
public List<AuthUserMacEntity> getAuthUserMac2(String username, String mac, String deviceType) throws Exception {
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_WC, username))
.addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_DM, mac)).addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_DT,deviceType));
return find(condition);
}
//
// public void addOrUpdate( List<AuthUserMacEntity> list )throws Exception {
// for( AuthUserMacEntity item : list ){
// addOrUpdate(item);
// }
// }
//
// public List<AuthUserMacEntity> removeByKey(String key )throws Exception{
// QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_AS, key));
// List<AuthUserMacEntity> list = find(condition);
// for( AuthUserMacEntity item : list ){
// remove( item.getId() );
// }
// return list;
// }
//
// public List<AuthUserMacEntity> getByKey(String key )throws Exception{
// QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq(AuthUserMacEntity.COLUMN_AS, key));
// return find(condition);
// }
//
// public void add(AuthUserMacEntity entity) throws Exception {
// getSession().persist(entity);
// }
//
// public void update(AuthUserMacEntity entity) throws Exception {
// getSession().merge(entity);
// }
//
// public void addOrUpdate(AuthUserMacEntity entity) throws Exception {
// if (entity != null && this.getById(entity.getId()) != null) {
// update(entity);
// } else {
// add(entity);
// }
// }
//
// public AuthUserMacEntity getById(String id) throws Exception {
// return this.getSession().getById(id, AuthUserMacEntity.class);
// }
//
// public void remove(String id) throws Exception {
// this.getSession().remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("id", id)), this.getEntityClass());
// }
}

96
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/AuthUserMacEntity.java

@ -0,0 +1,96 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.stable.db.entity.BaseEntity;
import com.fr.stable.db.entity.TableAssociation;
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;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
@Entity
@Table(name = "HT_Auth_UserMac")
@TableAssociation(associated = true)
public class AuthUserMacEntity extends BaseEntity {
public static final String COLUMN_WC = "workcode";
public static final String COLUMN_DM = "devicemac";
public static final String COLUMN_DT = "devicetype";
public static final String COLUMN_AS = "authstatus";
public static final String COLUMN_CD = "createddate";
public static final String COLUMN_AD = "authdate";
@Column(name = COLUMN_WC)
private String workcode = null;
@Column(name = COLUMN_DM)
private String devicemac = null;
@Column(name = COLUMN_DT)
private String devicetype = null;
@Column(name = COLUMN_AS)
private int authstatus = 0;
@Column(name = COLUMN_CD)
private Date createddate = null;
@Column(name = COLUMN_AD)
private Date authdate = null;
public String getWorkcode() {
return workcode;
}
public void setWorkcode(String workcode) {
this.workcode = workcode;
}
public String getDevicemac() {
return devicemac;
}
public void setDevicemac(String devicemac) {
this.devicemac = devicemac;
}
public String getDevicetype() {
return devicetype;
}
public void setDevicetype(String devicetype) {
this.devicetype = devicetype;
}
public int getAuthstatus() {
return authstatus;
}
public void setAuthstatus(int authstatus) {
this.authstatus = authstatus;
}
public Date getCreateddate() {
return createddate;
}
public void setCreateddate(Date createddate) {
this.createddate = createddate;
}
public Date getAuthdate() {
return authdate;
}
public void setAuthdate(Date authdate) {
this.authdate = authdate;
}
}

15
src/main/java/com/fr/plugin/loginAuth/dbAccessProvider/ControllerBridge.java

@ -0,0 +1,15 @@
package com.fr.plugin.loginAuth.dbAccessProvider;
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-25
**/
public class ControllerBridge extends AbstractControllerRegisterProvider {
@Override
public Class<?>[] getControllers() {
return new Class[]{AuthUserController.class};
}
}

317
src/main/java/com/fr/plugin/loginAuth/filter/SSOFilter.java

@ -0,0 +1,317 @@
package com.fr.plugin.loginAuth.filter;
import com.fr.base.Base64;
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider;
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.loginAuth.dbAccessProvider.AuthUserDBController;
import com.fr.plugin.loginAuth.dbAccessProvider.AuthUserEntity;
import com.fr.plugin.loginAuth.dbAccessProvider.AuthUserMacEntity;
import com.fr.plugin.loginAuth.utils.FRUtils;
import com.fr.plugin.loginAuth.utils.ResponseUtils;
import com.fr.plugin.loginAuth.utils.Utils;
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.web.utils.WebUtils;
import org.slf4j.MDC;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class SSOFilter extends AbstractEmbedRequestFilterProvider {
@Override
public void filter(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
String url = FRUtils.getAllUrl(httpServletRequest);
FRUtils.FRLogInfo(url);
FRUtils.FRLogInfo("pc认证" + url.contains("/decision/login"));
//PC认证
if (url.contains("/decision/login")) {
String username = httpServletRequest.getHeader("username");
String mac = httpServletRequest.getHeader("mac");
FRUtils.FRLogInfo("pcParam:username=" + username + ";mac=" + mac);
if (Utils.isNotNullStr(username)) {
//没有mac直接加入黑名单
if (Utils.isNullStr(mac)) {
mac = "";
AuthUserMacEntity ame = new AuthUserMacEntity();
ame.setAuthstatus(1);
ame.setDevicemac(mac);
ame.setWorkcode(username);
ame.setId(UUID.randomUUID().toString());
ame.setCreateddate(new Date());
ame.setDevicetype("PC");
FRUtils.FRLogInfo("添加mac");
try {
List<AuthUserEntity> authUserMac = AuthUserDBController.getByUserName(username);
if (authUserMac != null && authUserMac.size() > 0) {
List<AuthUserMacEntity> authUserMacs = AuthUserDBController.getUserAuthMac2(username, mac, "PC");
if (authUserMacs != null && authUserMacs.size() <= 0) {
AuthUserDBController.add(ame);
}
}
} catch (Exception e) {
FRUtils.FRLogInfo("添加mac匹配异常:" + e.getMessage());
}
JSONObject json = new JSONObject();
json.put("errorCode", "90000");
json.put("errorMsg", "没有权限登录");
ResponseUtils.response(httpServletResponse, json);
return;
}
//查询用户是否再AuthUser表中,如果在
List<AuthUserEntity> blackList = null;
try {
blackList = AuthUserDBController.getByUserName(username);
} catch (Exception e) {
FRUtils.FRLogInfo("获取黑名单异常:" + e.getMessage());
JSONObject json = new JSONObject();
json.put("errorCode", "90000");
json.put("errorMsg", "没有权限登录");
ResponseUtils.response(httpServletResponse, json);
return;
}
if (blackList != null && blackList.size() > 0) {
FRUtils.FRLogInfo("黑名单:" + blackList.size());
FRUtils.FRLogInfo("黑名单:" + blackList.get(0).getWorkcode());
//查询AuthUserMac表
List<AuthUserMacEntity> authUserMac = null;
try {
authUserMac = AuthUserDBController.getUserAuthMac2(username, mac, "PC");
} catch (Exception e) {
FRUtils.FRLogInfo("获取mac匹配异常:" + e.getMessage());
JSONObject json = new JSONObject();
json.put("errorCode", "90000");
json.put("errorMsg", "没有权限登录");
ResponseUtils.response(httpServletResponse, json);
return;
}
//如果没有或者只有姓名,则添加一条username
if (authUserMac == null || authUserMac.size() <= 0) {
AuthUserMacEntity ame = new AuthUserMacEntity();
ame.setAuthstatus(1);
ame.setDevicemac(mac);
ame.setWorkcode(username);
ame.setId(UUID.randomUUID().toString());
ame.setCreateddate(new Date());
ame.setDevicetype("PC");
FRUtils.FRLogInfo("添加mac");
try {
AuthUserDBController.add(ame);
} catch (Exception e) {
FRUtils.FRLogInfo("添加mac匹配异常:" + e.getMessage());
}
JSONObject json = new JSONObject();
json.put("errorCode", "90000");
json.put("errorMsg", "没有权限登录");
ResponseUtils.response(httpServletResponse, json);
return;
}
//如果有并且匹配,查询状态并确定是否放行
boolean flag = false;
for (AuthUserMacEntity ame : authUserMac) {
if (ame.getAuthstatus() == 0) {
flag = true;
}
}
if (!flag) {
JSONObject json = new JSONObject();
json.put("errorCode", "90000");
json.put("errorMsg", "没有权限登录");
ResponseUtils.response(httpServletResponse, json);
return;
}
}
}
}
//微信认证
try {
boolean isWeixin = url.contains("weixin/single/login");
//企业微信单点
if (isWeixin) {
boolean available = WeiXinUtils.isLicenseAvailable();
if (available) {
MDC.put("logger", WeiXinConstants.LOGIN);
FRUtils.FRLogInfo("===开始单点登录===");
String decUserName = StringUtils.EMPTY;
String code = WebUtils.getHTTPRequestParameter(httpServletRequest, "code");
FRUtils.FRLogInfo("code: " + code);
String param = WebUtils.getHTTPRequestParameter(httpServletRequest, "sb");
FRUtils.FRLogInfo("sb: " + param);
String redirectUrl = httpServletRequest.getParameter("redirectUrl"); // 这里不能使用WebUtils的方法,会把中文模板名称的编码给解析了导致找不到模板
if (WeiXinConfig.getInstance().getUrlMap().containsKey(redirectUrl)) {
redirectUrl = WeiXinConfig.getInstance().getUrlMap().get(redirectUrl);
}
FRUtils.FRLogInfo("redirectUrl: " + redirectUrl);
FRUtils.FRLogInfo("isnotEmpty:" + StringUtils.isNotEmpty(redirectUrl));
FRUtils.FRLogInfo("2:" + WeiXinUtils.compareUrlDomain(redirectUrl, WeiXinConfig.getInstance().getUrl()));
if (StringUtils.isNotEmpty(redirectUrl) && WeiXinUtils.compareUrlDomain(redirectUrl, WeiXinConfig.getInstance().getUrl())) {
FRUtils.FRLogInfo("agent:1");
WeiXinAgent agent = WeiXinAgentUtils.getAgentByCheckMD5(param);
FRUtils.FRLogInfo("agent:2");
String secret = StringUtils.EMPTY;
if (agent != null) {
secret = agent.getSecret();
} else {
FRUtils.FRLogInfo("单点登录请求中sb参数不正确,无法找到对应微信应用!" + WeiXinLogErrorCode.LOST_SB_PARAM);
}
FRUtils.FRLogInfo("secret:" + secret);
JSONObject userInfo = WeiXinRequest.getUserInfoByCode(code, secret);
FRUtils.FRLogInfo("userInfo:" + userInfo.toString());
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);
} 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);
}
if (WeiXinDecUserUtils.isUserExist(decUserName)) {
FRUtils.FRLogInfo("decUserName:"+decUserName);
boolean isLogin = allowLogin(decUserName,userInfo);
if(!isLogin){
ResponseUtils.failedResponse(httpServletResponse,"您的电脑未授权,请联系管理员");
return ;
}
String token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, decUserName, StringUtils.EMPTY, WeiXinConstants.WEIXIN_PLUGIN_ID);
FRUtils.FRLogInfo("单点登录成功!生成token为:" + token);
} else if (StringUtils.isNotEmpty(decUserName)) {
FRUtils.FRLogInfo(String.format("平台用户中无%s用户!", decUserName) + WeiXinLogErrorCode.NO_DEC_USER);
}
String jsApiPath = Base64.encode(WeiXinConstants.WEIXIN_JSAPI_PATH.getBytes("UTF-8"));
redirectUrl = WeiXinURLUtils.putParamToUrl(redirectUrl, "js_api_path", jsApiPath);
redirectUrl = redirectUrl + "&sb=" + param;
FRUtils.FRLogInfo("开始跳转url:" + redirectUrl);
httpServletResponse.sendRedirect(redirectUrl);
FRUtils.FRLogInfo("===单点登录结束===");
MDC.clear();
} else {
FRUtils.FRLogInfo("进入了else2");
WebUtils.printAsString(httpServletResponse, WebServiceUtils.generateUnavailableWebPage(
InterProviderFactory.getProvider().getLocText("Dec-WeiXin_Not_Trusted_Domain_Error"),
"",
InterProviderFactory.getProvider().getLocText("Dec-WeiXin_Not_Trusted_Domain_Exception")
));
}
} else {
FRUtils.FRLogInfo("进入了else");
WeiXinUtils.routeToExpirePage(httpServletRequest, httpServletResponse);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static boolean allowLogin(String userName,JSONObject userInfo) {
//查询用户是否再AuthUser表中,如果在
List<AuthUserEntity> blackList = null;
try {
blackList = AuthUserDBController.getByUserName(userName);
} catch (Exception e) {
FRUtils.FRLogInfo("获取黑名单异常:" + e.getMessage());
return false;
}
if (blackList != null && blackList.size() > 0) {
FRUtils.FRLogInfo("blackListSize:" + blackList.size());
String mac = userInfo.getString("DeviceId");
//查询AuthUserMac表
List<AuthUserMacEntity> authUserMac = null;
try {
authUserMac = AuthUserDBController.getUserAuthMac2(userName, mac, "mobile");
} catch (Exception e) {
FRUtils.FRLogInfo("获取mac匹配异常:" + e.getMessage());
return false;
}
//如果没有或者只有姓名,则添加一条
if (authUserMac == null || authUserMac.size() <= 0) {
AuthUserMacEntity ame = new AuthUserMacEntity();
ame.setAuthstatus(1);
ame.setDevicemac(mac);
ame.setWorkcode(userName);
ame.setId(UUID.randomUUID().toString());
ame.setCreateddate(new Date());
ame.setDevicetype("mobile");
try {
AuthUserDBController.add(ame);
} catch (Exception e) {
FRUtils.FRLogInfo("添加mac匹配异常:" + e.getMessage());
}
return false;
}
FRUtils.FRLogInfo("authUserMac:" + authUserMac.size());
//如果有并且匹配,查询状态并确定是否放行
boolean flag = false;
for (AuthUserMacEntity ame : authUserMac) {
if (ame.getAuthstatus() == 0) {
flag = true;
}
}
return flag;
}
return true;
}
}

12
src/main/java/com/fr/plugin/loginAuth/handler/ExtendAttrHandlerProvider.java

@ -0,0 +1,12 @@
package com.fr.plugin.loginAuth.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[]{
};
}
}

99
src/main/java/com/fr/plugin/loginAuth/handler/ToDecisionLogin.java

@ -0,0 +1,99 @@
package com.fr.plugin.loginAuth.handler;
import com.fr.base.ServerConfig;
import com.fr.decision.config.AppearanceConfig;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.web.LoginComponent;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.decision.webservice.v10.config.ConfigService;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.general.CloudCenter;
import com.fr.general.CloudCenterConfig;
import com.fr.security.SecurityConfig;
import com.fr.security.encryption.SystemEncryptionManager;
import com.fr.security.encryption.transmission.impl.SM4TransmissionEncryption;
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.Browser;
import com.fr.web.struct.AtomBuilder;
import com.fr.web.struct.PathGroup;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
public class ToDecisionLogin extends BaseHttpHandler {
public ToDecisionLogin() {
}
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/toDecisionLogin";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
//特定版本
Map<String, Object> param = new HashMap();
ObjectMapper mapper = new ObjectMapper();
param.put("title", AppearanceConfig.getInstance().getPlatformTitle());
param.put("loginConfig", mapper.writeValueAsString(ConfigService.getInstance().getLoginAppearanceConfig()));
param.put("charset", ServerConfig.getInstance().getServerCharset());
PathGroup group = AtomBuilder.create().buildAssembleFilePath(Browser.resolve(req), LoginComponent.KEY);
param.put("styleTag", AtomBuilder.create().toHtmlTag(group.toStylePathGroup()));
param.put("scriptTag", AtomBuilder.create().toHtmlTag(group.toScriptPathGroup()));
Map<String, Object> system = new HashMap();
system.put("frontSeed", SecurityConfig.getInstance().getFrontSeed());
system.put("cloudEnabled", CloudCenterConfig.getInstance().isOnline());
system.put("urlIP", CloudCenter.getInstance().acquireConf("decision.queryip", ""));
if (AppearanceConfig.getInstance().isCopyrightInfoDisplay()) {
system.putAll(LoginService.getInstance().getCopyrightInfo(req));
}
param.put("system", mapper.writeValueAsString(system));
String a = WebServiceUtils.parseWebPageResourceSafe("/com/fr/plugin/loginAuth/js/login.html", param);
WebUtils.printAsString(res, a);
// HashMap var3 = new HashMap();
// ObjectMapper var4 = new ObjectMapper();
// var3.put("title", AppearanceConfig.getInstance().getPlatformTitle());
// var3.put("loginConfig", var4.writeValueAsString(ConfigService.getInstance().getLoginAppearanceConfig()));
// var3.put("charset", ServerConfig.getInstance().getServerCharset());
// PathGroup var5 = AtomBuilder.create().buildAssembleFilePath(Browser.resolve(req), LoginComponent.KEY);
// var3.put("styleTag", AtomBuilder.create().toHtmlTag(var5.toStylePathGroup()));
// var3.put("scriptTag", AtomBuilder.create().toHtmlTag(var5.toScriptPathGroup()));
// HashMap var6 = new HashMap();
// var6.put("frontSeed", SecurityConfig.getInstance().getFrontSeed());
// var6.put("transmissionEncryption", SystemEncryptionManager.getInstance().getTransmissionEncryption().getType());
// var6.put("frontSM4Key", SM4TransmissionEncryption.getInstance().getTransmissionKey());
// var6.put("cloudEnabled", CloudCenterConfig.getInstance().isOnline());
// var6.put("urlIP", CloudCenter.getInstance().acquireConf("decision.queryip", ""));
// if (AppearanceConfig.getInstance().isCopyrightInfoDisplay()) {
// var6.putAll(LoginService.getInstance().getCopyrightInfo(req));
// }
//
// var3.put("system", var4.writeValueAsString(var6));
//
// String a =WebServiceUtils.parseWebPageResourceSafe("/com/fr/web/controller/decision/entrance/resources/login.html", var3);
// WebUtils.printAsString(res, a);
}
}

14
src/main/java/com/fr/plugin/loginAuth/handler/URLAliasProvide.java

@ -0,0 +1,14 @@
package com.fr.plugin.loginAuth.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("/toDecisionLogin","/toDecisionLogin",true)
};
}
}

111
src/main/java/com/fr/plugin/loginAuth/httpAuth/Login.java

@ -0,0 +1,111 @@
package com.fr.plugin.loginAuth.httpAuth;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.AbstractHttpAuthorizeProvider;
import com.fr.json.JSONObject;
import com.fr.plugin.loginAuth.dbAccessProvider.AuthUserDBController;
import com.fr.plugin.loginAuth.dbAccessProvider.AuthUserEntity;
import com.fr.plugin.loginAuth.dbAccessProvider.AuthUserMacEntity;
import com.fr.plugin.loginAuth.utils.CipherUtils;
import com.fr.plugin.loginAuth.utils.FRUtils;
import com.fr.plugin.loginAuth.utils.HttpUtils;
import com.fr.plugin.loginAuth.utils.Utils;
import com.fr.plugin.transform.FunctionRecorder;
import java.util.List;
import java.util.UUID;
@FunctionRecorder
public class Login extends AbstractHttpAuthorizeProvider {
@Override
public Scope scope() {
return Scope.REPLACE;
}
@Override
public boolean authorize(String userName, String psd, String s2, String s3) {
//查询用户是否再AuthUser表中,如果在
List<AuthUserEntity> blackList = null;
try {
blackList = AuthUserDBController.getByUserName(userName);
} catch (Exception e) {
FRUtils.FRLogInfo("获取黑名单异常:"+e.getMessage());
return false;
}
if(blackList != null && blackList.size() > 0){
String mac = getMac();
if(Utils.isNullStr(mac)){
return false;
}
//查询AuthUserMac表
List<AuthUserMacEntity> authUserMac = null;
try {
authUserMac = AuthUserDBController.getUserAuthMac(userName,mac);
} catch (Exception e) {
FRUtils.FRLogInfo("获取mac匹配异常:"+e.getMessage());
return false;
}
//如果没有或者只有姓名,则添加一条
if(authUserMac == null || authUserMac.size() <= 0){
AuthUserMacEntity ame = new AuthUserMacEntity();
ame.setAuthstatus(1);
ame.setDevicemac(mac);
ame.setWorkcode(userName);
ame.setId(UUID.randomUUID().toString());
try {
AuthUserDBController.add(ame);
} catch (Exception e) {
FRUtils.FRLogInfo("添加mac匹配异常:"+e.getMessage());
}
return false;
}
//如果有并且匹配,查询状态并确定是否放行
boolean flag = false;
for(AuthUserMacEntity ame : authUserMac){
if(ame.getAuthstatus() == 0){
flag = true;
}
}
if(!flag){
return false;
}
}
String password = CipherUtils.jdksha256(psd);
User user = FRUtils.getFRUserByUserName(userName);
return password.equals(user.getPassword());
//
}
@Override
public boolean authorize(String s, String s1) {
return false;
}
private String getMac(){
String url = "http://localhost:9090/domain/getDomain";
String result = HttpUtils.get(url,null,null);
if(Utils.isNullStr(result)){
return "";
}
JSONObject json = new JSONObject(result);
boolean success = json.getBoolean("success");
if(!success){
return "";
}
return json.getString("domain");
}
}

11
src/main/java/com/fr/plugin/loginAuth/httpAuth/Test.java

@ -0,0 +1,11 @@
package com.fr.plugin.loginAuth.httpAuth;
import com.fr.plugin.loginAuth.utils.CipherUtils;
public class Test {
public static void main(String[] args) {
String a = "YL365XOEliTb47pFLn9fTw==";
System.out.println(CipherUtils.jdksha256("xiamaofa888"));
}
}

262
src/main/java/com/fr/plugin/loginAuth/utils/CipherUtils.java

@ -0,0 +1,262 @@
package com.fr.plugin.loginAuth.utils;
import com.fr.log.FineLoggerFactory;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.Key;
import java.security.MessageDigest;
import java.security.SecureRandom;
/**
* 加解密工具类
*/
public class CipherUtils {
/**
* 加密
*
* @param datasource
* byte[]
* @param password
* String
* @return byte[]
*/
public static byte[] desEncrypt(byte[] datasource, String password) {
try {
SecureRandom random = new SecureRandom();
DESKeySpec desKey = new DESKeySpec(password.getBytes());
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
// 现在,获取数据并加密
// 正式执行加密操作
return cipher.doFinal(datasource);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
/**
* 解密
*
* @param src
* byte[]
* @param password
* String
* @return byte[]
* @throws Exception
*/
public static byte[] desDecrypt(byte[] src, String password) throws Exception {
// DES算法要求有一个可信任的随机数源
SecureRandom random = new SecureRandom();
// 创建一个DESKeySpec对象
DESKeySpec desKey = new DESKeySpec(password.getBytes("UTF-8"));
// 创建一个密匙工厂
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
// 将DESKeySpec对象转换成SecretKey对象
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成解密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, securekey, random);
// 真正开始解密操作
return cipher.doFinal(src);
}
/**
* 自定义一个key
**/
public static byte[] getKey(String keyRule) {
Key key = null;
byte[] keyByte = keyRule.getBytes();
// 创建一个空的八位数组,默认情况下为0
byte[] byteTemp = new byte[8];
// 将用户指定的规则转换成八位数组
for (int i = 0; i < byteTemp.length && i < keyByte.length; i++) {
byteTemp[i] = keyByte[i];
}
key = new SecretKeySpec(byteTemp, "DES");
return key.getEncoded();
}
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1) return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
/***
* 解密数据
* @param decryptString
* @param decryptKey
* @return
* @throws Exception
*/
public static String decryptDES(String decryptString, String decryptKey) throws Exception {
SecretKeySpec key = new SecretKeySpec(getKey(decryptKey), "DES");
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
byte decryptedData[] = cipher.doFinal(parseHexStr2Byte(decryptString));
return new String(decryptedData,"utf-8");
}
/**
* jdksha256加密
* @param str
* @return
*/
public static String jdksha256(String str)
{
String sha256Str = "";
try {
MessageDigest sha256Deget = MessageDigest.getInstance("SHA-256");
byte[] sha256Encode = sha256Deget.digest(str.getBytes());
sha256Str = ByteToHexStr(sha256Encode);
}catch (Exception e){
FineLoggerFactory.getLogger().info("FRLOG:SHA256加密异常:"+e.getMessage());
}
return sha256Str;
}
/**
* byte数组转16进制字符串
* @param bytes
* @return
*/
private static String ByteToHexStr(byte[] bytes)
{
String hexStr = "";
for(int i =0;i<bytes.length;i++)
{
int temp = bytes[i] & 0xff;
String tempHex = Integer.toHexString(temp);
if(tempHex.length() < 2)
{
hexStr += "0"+tempHex;
}
else {
hexStr += tempHex;
}
}
return hexStr;
}
/**
* base64加密
* @param key
* @return
*/
public static String base64Encode(String key){
return (new BASE64Encoder()).encodeBuffer(key.getBytes());
}
/**
* base64解密
* @param key
* @return
*/
public static String base64Decode(String key){
String result = "";
try {
result = new String((new BASE64Decoder()).decodeBuffer(key));
} catch (IOException e) {
FineLoggerFactory.getLogger().info("FRLOG:BASE64解密异常:"+e.getMessage());
}
return result;
}
public static String getBase64DecodeStr(String str){
if(str == null || str.isEmpty()){
return "";
}
String result = base64Decode(str);
return result.contains("base64")?result:str;
}
/**
* 是否被base64加密过
* @param str
* @return
*/
public static boolean isBase64(String str) {
if (str == null || str.trim().length() == 0) {
return false;
}
else {
if (str.length() % 4 != 0) {
return false;
}
char[] strChars = str.toCharArray();
for (char c:strChars) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
|| c == '+' || c == '/' || c == '=') {
continue;
}
else {
return false;
}
}
return true;
}
}
public static void main(String[] args) throws Exception {
// String key = "z2bse2zh";
// String key = "ajshcjzj";
// String str = "男";
////
// byte[] a =desEncrypt(str.getBytes(),key);
//// System.out.println(new String(a));
// String a1 = new BASE64Encoder().encodeBuffer(a);
////
// System.out.println(a1);
////
//// byte[] b = desDecrypt(a,key);
//// System.out.println(new String(b));
//
// String key2 = "rdTK5iLsDFw=";
// byte[] b2 = desDecrypt(new BASE64Decoder().decodeBuffer(key2),"ajshcjzj");
// System.out.println(new String(b2));
// //密钥
// String key = "z2bse2zh";
// //解密数据
// String encryDate = "DF2DF0F837C38A1233A8B1255B0532E36E9D29052873B7F8707936C025E2FE368B0A8919A93C8869";
// String a = "ED33AD65CDBAEF49";
// String result = decryptDES(a, key);
//
// System.out.println("result:" + result);
// System.out.println("result2:"+new String(decrypt(result.getBytes(),key)));
}
}

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

@ -0,0 +1,158 @@
package com.fr.plugin.loginAuth.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);
}
}

237
src/main/java/com/fr/plugin/loginAuth/utils/HttpUtils.java

@ -0,0 +1,237 @@
package com.fr.plugin.loginAuth.utils;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpResponse;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.NameValuePair;
import com.fr.third.org.apache.http.client.CookieStore;
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity;
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.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.BasicCookieStore;
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.cookie.BasicClientCookie;
import com.fr.third.org.apache.http.message.BasicNameValuePair;
import com.fr.third.org.apache.http.ssl.SSLContexts;
import com.fr.third.org.apache.http.ssl.TrustStrategy;
import com.fr.third.org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.servlet.http.Cookie;
import java.io.UnsupportedEncodingException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class HttpUtils {
/**
* httpGet请求
* @param url
* @return
*/
public static String get(String url,Cookie[] cookies,Map<String,String> header){
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url);
//创建httpClient
CloseableHttpClient httpclient = createHttpClient(cookies);
HttpGet getMethod = new HttpGet(url);
if(header != null && header.size() > 0){
Set<String> keySet = header.keySet();
for(String key : keySet){
getMethod.setHeader(key,header.get(key));
}
}
try {
HttpResponse response = httpclient.execute(getMethod);
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
String returnResult = EntityUtils.toString(entity, "utf-8");
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult);
return returnResult;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage());
}
return "";
}
/**
* HttpPost请求
* @param postMethod
* @return
*/
private static String HttpPost(HttpPost postMethod){
CloseableHttpClient httpclient = createHttpClient(null);
try {
HttpResponse response = httpclient.execute(postMethod);
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
String returnResult = EntityUtils.toString(entity, "utf-8");
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult);
return returnResult;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage());
}
return "";
}
public static String HttpPostXML(String url, String xmlParam){
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url);
HttpPost postMethod = new HttpPost(url);
postMethod.setHeader("Content-type", "text/html");
HttpEntity entity2 = null;
try {
entity2 = new StringEntity(xmlParam);
} catch (UnsupportedEncodingException e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage());
return "";
}
postMethod.setEntity(entity2);
return HttpPost(postMethod);
}
public static String HttpPostJson(String url, String param,Map<String,String> header){
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url);
HttpPost postMethod = new HttpPost(url);
postMethod.setHeader("Content-Type","application/json");
if(header != null && header.size() > 0){
Set<String> keySet = header.keySet();
for(String key : keySet){
postMethod.setHeader(key,header.get(key));
}
}
if(!Utils.isNullStr(param)){
HttpEntity entity2 = null;
try {
entity2 = new StringEntity(param);
} catch (UnsupportedEncodingException e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage());
return "";
}
postMethod.setEntity(entity2);
}
return HttpPost(postMethod);
}
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url);
HttpPost postMethod = new HttpPost(url);
if(header != null && header.size() > 0){
Set<String> keySet = header.keySet();
for(String key : keySet){
postMethod.setHeader(key,header.get(key));
}
}
if(param != null && param.size() > 0){
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size());
for(Map.Entry<String,String> map : param.entrySet()){
params.add(new BasicNameValuePair(map.getKey(), map.getValue()));
}
try {
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage());
return "";
}
}
return HttpPost(postMethod);
}
private static CloseableHttpClient createHttpClient(Cookie[] cookies){
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
}).build();
} catch (NoSuchAlgorithmException e) {
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage());
} catch (KeyManagementException e) {
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage());
} catch (KeyStoreException e) {
FRUtils.FRLogInfo("createHttpClientException:"+e.getMessage());
}
CloseableHttpClient httpclient = null;
if(cookies != null && cookies.length > 0){
CookieStore cookieStore = cookieToCookieStore(cookies);
httpclient = HttpClients.custom().setSslcontext(sslContext).
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build();
}
else{
httpclient = HttpClients.custom().setSslcontext(sslContext).
setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
}
return httpclient;
}
/**
* cookies转cookieStore
* @param cookies
* @return
*/
public static CookieStore cookieToCookieStore(Cookie[] cookies){
CookieStore cookieStore = new BasicCookieStore();
if(cookies != null && cookies.length>0){
for(Cookie cookie : cookies){
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue());
cookieStore.addCookie(cookie1);
}
}
return cookieStore;
}
}

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

@ -0,0 +1,96 @@
package com.fr.plugin.loginAuth.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();
}
}

96
src/main/java/com/fr/plugin/loginAuth/utils/Utils.java

@ -0,0 +1,96 @@
package com.fr.plugin.loginAuth.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 javax.servlet.http.HttpServletRequestWrapper;
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(HttpServletRequestWrapper 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;
}
}

35
src/main/java/com/fr/plugin/loginAuth/webresource/WebResourceProvider.java

@ -0,0 +1,35 @@
package com.fr.plugin.loginAuth.webresource;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.LoginComponent;
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.
*/
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/loginAuth/js/login.js");
}
@Override
public StylePath style(RequestClient requestClient) {
return StylePath.EMPTY;
// return StylePath.build("/com/fr/plugin/jdfSSO/css/icon.css");
}
};
}
}

29
src/main/resources/com/fr/plugin/loginAuth/js/login.html

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${charset}">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>${title}</title>
<!--css文件-->
${styleTag}
</head>
<body>
<div id="wrapper"></div>
<script type="text/javascript">
window.Dec = window.Dec || {};
window.Dec.injection = window.Dec.injection || {};
</script>
<script type="text/javascript">
Dec.fineServletURL = "${fineServletURL}";
Dec.loginConfig = ${loginConfig};
Dec.system = ${system};
</script>
${scriptTag}
<script>
Dec.start();
</script>
</body>
</html>

333
src/main/resources/com/fr/plugin/loginAuth/js/login.js

@ -0,0 +1,333 @@
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) {
console.info(e);
console.info(BI.Services.getService("dec.service.login.login").getHandler(e.errorCode));
t.store.resetSlider(),
e.data && e.data.accessToken ? t.fireEvent("EVENT_LOGIN", e.data) : 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){
console.info(callback);
console.info("登录方法注入!");
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 getMac(){
var mac = "";
$.ajax({
type:"get",
async:false,
url:"http://localhost:9090/domain/getDomain",
success:function(data){
mac = data.domain;
}
})
return mac;
}

BIN
使用手册.docx

Binary file not shown.
Loading…
Cancel
Save