pioneer
2 years ago
commit
7f35a77142
28 changed files with 2498 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-9472 |
||||
|
||||
JSD-9472 对接客户4A平台做单点登录\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.xx.zgydsso</id> |
||||
<name><![CDATA[单点登录及用户同步]]></name> |
||||
<active>yes</active> |
||||
<!-- <version>1.0.3</version>--> |
||||
<version>1.0.15</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[单点登录及用户同步]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.xx.zgydsso</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.xx.zgydsso.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.eco.plugin.xx.zgydsso.filter.SSOFilter"/> |
||||
<!-- <LogInOutEventProvider class="com.eco.plugin.xx.zgydsso.logout.Logout"/>--> |
||||
<ControllerRegisterProvider class="com.eco.plugin.xx.zgydsso.controller.ControllerRegisterProvider"/> |
||||
</extra-decision> |
||||
<extra-core> |
||||
<FunctionDefineProvider class="com.eco.plugin.xx.zgydsso.function.AuthFunction" name="syncData" description="数据同步"/> |
||||
<DBAccessProvider class="com.eco.plugin.xx.zgydsso.db.controller.DBController"/> |
||||
</extra-core> |
||||
<function-recorder class="com.eco.plugin.xx.zgydsso.config.PluginSimpleConfig"/> |
||||
</plugin> |
@ -0,0 +1,21 @@
|
||||
package com.eco.plugin.xx.zgydsso.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.eco.plugin.xx.zgydsso.config; |
||||
|
||||
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.eco.plugin.xx.zgydsso.config", text = "认证集成配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "configurl", name = "properties配置文件路径", description = "配置文件路径", status = Status.SHOW) |
||||
private Conf<String> configurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "configurlxml", name = "xml配置文件路径", description = "xml配置文件路径", status = Status.SHOW) |
||||
private Conf<String> configurlxml = Holders.simple(""); |
||||
|
||||
@Identifier(value = "dataurl", name = "同步文件路径", description = "同步文件路径", status = Status.SHOW) |
||||
private Conf<String> dataurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "usernamefile", name = "工号文件前缀", description = "工号文件前缀", status = Status.SHOW) |
||||
private Conf<String> usernamefile = Holders.simple(""); |
||||
|
||||
@Identifier(value = "rolelinkfile", name = "工号角色关系文件前缀", description = "工号角色关系文件前缀", status = Status.SHOW) |
||||
private Conf<String> rolelinkfile = Holders.simple(""); |
||||
|
||||
@Identifier(value = "needToken", name = "是否需要拼接token", description = "是否需要拼接token", status = Status.SHOW) |
||||
private Conf<Boolean> needToken = Holders.simple(false); |
||||
|
||||
public String getConfigurl() { |
||||
return configurl.get(); |
||||
} |
||||
|
||||
public void setConfigurl(String url) { |
||||
this.configurl.set(url); |
||||
} |
||||
|
||||
public String getConfigurlxml() { |
||||
return configurlxml.get(); |
||||
} |
||||
|
||||
public void setConfigurlxml(String url) { |
||||
this.configurlxml.set(url); |
||||
} |
||||
|
||||
public String getDataurl() { |
||||
return dataurl.get(); |
||||
} |
||||
|
||||
public void setDataurl(String url) { |
||||
this.dataurl.set(url); |
||||
} |
||||
|
||||
public String getUsernamefile() { |
||||
return usernamefile.get(); |
||||
} |
||||
|
||||
public void setUsernamefile(String url) { |
||||
this.usernamefile.set(url); |
||||
} |
||||
|
||||
public String getRolelinkfile() { |
||||
return rolelinkfile.get(); |
||||
} |
||||
|
||||
public void setRolelinkfile(String url) { |
||||
this.rolelinkfile.set(url); |
||||
} |
||||
|
||||
public Boolean getNeedToken() { |
||||
return needToken.get(); |
||||
} |
||||
|
||||
public void setNeedToken(Boolean url) { |
||||
this.needToken.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; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.eco.plugin.xx.zgydsso.controller; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
|
||||
@FunctionRecorder |
||||
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
return new Class[]{ |
||||
ControllerSelf.class |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,176 @@
|
||||
package com.eco.plugin.xx.zgydsso.controller; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.UserEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.controller.DBController; |
||||
import com.eco.plugin.xx.zgydsso.utils.*; |
||||
import com.fr.decision.authority.data.Authority; |
||||
import com.fr.decision.authority.data.CustomRole; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.GetMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
public class ControllerSelf { |
||||
|
||||
@GetMapping(value = "/toOther") |
||||
@ResponseBody |
||||
public void toOther(HttpServletRequest request,HttpServletResponse response) throws IOException { |
||||
String redirect = request.getParameter("redirect"); |
||||
FRUtils.FRLogInfo("toOther"); |
||||
UserBean user = null; |
||||
try { |
||||
user = FRUserUtils.getCurrentUserBean(request); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(response,"获取当前用户失败!"); |
||||
} |
||||
String username = user.getUsername(); |
||||
UserEntity userEntity = DBController.getByUsername(username); |
||||
|
||||
String role = Utils.arrayToStr(user.getRoleIds(),","); |
||||
String city = userEntity.getCity(); |
||||
|
||||
redirect += redirect.contains("?") ? "&operid="+username :"?operid="+username; |
||||
|
||||
redirect+="&role="+role+"&city="+city; |
||||
|
||||
if(PluginSimpleConfig.getInstance().getNeedToken()){ |
||||
String token = Utils.getCookieByKey(request,"fine_auth_token"); |
||||
redirect += "&token="+token; |
||||
} |
||||
FRUtils.FRLogInfo("toOther"); |
||||
|
||||
response.sendRedirect(redirect); |
||||
} |
||||
|
||||
@PostMapping(value = "/validateToken") |
||||
@ResponseBody |
||||
public Map<String,Object> validateToken(HttpServletRequest request,HttpServletResponse response) throws IOException { |
||||
JSONObject param = Utils.getRequestBody(request); |
||||
String token = param.getString("token"); |
||||
String username = FRUserUtils.getUsernameFromToken(token); |
||||
JSONObject userinfo = null; |
||||
try { |
||||
userinfo = getInfoByUsername(username); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(response,"获取用户信息失败"); |
||||
} |
||||
String role = userinfo.getString("role"); |
||||
String city = userinfo.getString("city"); |
||||
String authrity = userinfo.getString("authrity"); |
||||
|
||||
Map<String,Object> json = new HashMap<>(); |
||||
|
||||
Map<String,String> result = new HashMap<>(); |
||||
result.put("username",username); |
||||
result.put("role",role); |
||||
result.put("city",city); |
||||
result.put("catalogue",authrity); |
||||
|
||||
json.put("code",200); |
||||
json.put("data",result); |
||||
|
||||
return json; |
||||
} |
||||
|
||||
@PostMapping(value = "/getUserInfo") |
||||
@ResponseBody |
||||
public Map<String,Object> getUserInfo(HttpServletRequest request,HttpServletResponse response) throws IOException { |
||||
JSONObject param = Utils.getRequestBody(request); |
||||
String username = param.getString("username"); |
||||
JSONObject userinfo = null; |
||||
try { |
||||
userinfo = getInfoByUsername(username); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(response,"获取用户信息失败"); |
||||
} |
||||
String role = userinfo.getString("role"); |
||||
String city = userinfo.getString("city"); |
||||
String authrity = userinfo.getString("authrity"); |
||||
|
||||
Map<String,Object> json = new HashMap<>(); |
||||
|
||||
Map<String,String> result = new HashMap<>(); |
||||
result.put("username",username); |
||||
result.put("role",role); |
||||
result.put("city",city); |
||||
result.put("catalogue",authrity); |
||||
|
||||
json.put("code",200); |
||||
json.put("data",result); |
||||
|
||||
return json; |
||||
} |
||||
|
||||
private static JSONObject getInfoByUsername(String username) throws Exception { |
||||
JSONObject result = new JSONObject(); |
||||
|
||||
UserBean user = FRUserUtils.getUserBeanByUserName(username); |
||||
|
||||
List<CustomRole> roleList = FRRoleUtils.getRoleByUser(user.getId()); |
||||
|
||||
String role = ""; |
||||
String authrity = ""; |
||||
|
||||
if(roleList != null){ |
||||
for(CustomRole cr : roleList){ |
||||
role += ","+cr.getId(); |
||||
List<Authority> authorityList = AuthorityUtils.getAuthorityByRole(cr.getId()); |
||||
authrity+=getAuthorityStr(authorityList); |
||||
} |
||||
|
||||
if(Utils.isNotNullStr(role)){ |
||||
role = role.substring(1); |
||||
} |
||||
|
||||
if(Utils.isNotNullStr(authrity)){ |
||||
authrity = authrity.substring(1); |
||||
} |
||||
} |
||||
|
||||
result.put("authrity",authrity); |
||||
|
||||
|
||||
|
||||
result.put("role",role); |
||||
|
||||
UserEntity userEntity = DBController.getByUsername(username); |
||||
String city = userEntity.getCity(); |
||||
|
||||
if(Utils.isNullStr(city)){ |
||||
city = ""; |
||||
} |
||||
|
||||
result.put("city",city); |
||||
|
||||
|
||||
|
||||
return result; |
||||
} |
||||
|
||||
private static String getAuthorityStr(List<Authority> authorityList){ |
||||
if(authorityList == null || authorityList.size() <= 0){ |
||||
return ""; |
||||
} |
||||
|
||||
String result = ""; |
||||
|
||||
for(Authority authority : authorityList){ |
||||
result+= ","+authority.getDisplayName(); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.bean; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_xx_entity_roleuserlink") |
||||
@TableAssociation(associated = true) |
||||
public class RoleUserLinkEntity extends BaseEntity { |
||||
|
||||
//用户名
|
||||
@Column(name = "username") |
||||
private String username = null; |
||||
|
||||
//角色编码
|
||||
@Column(name = "roleid") |
||||
private String roleid = null; |
||||
|
||||
//名称
|
||||
@Column(name = "system") |
||||
private String system = null; |
||||
|
||||
//状态
|
||||
@Column(name = "status") |
||||
private String status = null; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public String getRoleid() { |
||||
return roleid; |
||||
} |
||||
|
||||
public void setRoleid(String roleid) { |
||||
this.roleid = roleid; |
||||
} |
||||
|
||||
public String getSystem() { |
||||
return system; |
||||
} |
||||
|
||||
public void setSystem(String system) { |
||||
this.system = system; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.bean; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_xx_entity_time") |
||||
@TableAssociation(associated = true) |
||||
public class TimeEntity extends BaseEntity { |
||||
|
||||
//用户名
|
||||
@Column(name = "filename") |
||||
private String filename = null; |
||||
|
||||
//类型 user 工号 link 角色工号关联
|
||||
@Column(name = "type") |
||||
private String type = null; |
||||
|
||||
public String getFilename() { |
||||
return filename; |
||||
} |
||||
|
||||
public void setFilename(String filename) { |
||||
this.filename = filename; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(String type) { |
||||
this.type = type; |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.bean; |
||||
|
||||
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; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@Entity |
||||
@Table(name = "plugin_xx_entity_user") |
||||
@TableAssociation(associated = true) |
||||
public class UserEntity extends BaseEntity { |
||||
|
||||
//用户名
|
||||
@Column(name = "username") |
||||
private String username = null; |
||||
|
||||
//密码
|
||||
@Column(name = "password") |
||||
private String password = null; |
||||
|
||||
//名称
|
||||
@Column(name = "realname") |
||||
private String realname = null; |
||||
|
||||
//状态
|
||||
@Column(name = "status") |
||||
private String status = null; |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public String getRealname() { |
||||
return realname; |
||||
} |
||||
|
||||
public void setRealname(String realname) { |
||||
this.realname = realname; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getCity() { |
||||
return city; |
||||
} |
||||
|
||||
public void setCity(String city) { |
||||
this.city = city; |
||||
} |
||||
|
||||
//地市
|
||||
@Column(name = "city") |
||||
private String city = null; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String userid) { |
||||
this.username = userid; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,206 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.controller; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.db.bean.RoleUserLinkEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.TimeEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.UserEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.dao.FilenameDao; |
||||
import com.eco.plugin.xx.zgydsso.db.dao.RoleUserLinkDao; |
||||
import com.eco.plugin.xx.zgydsso.db.dao.UserDao; |
||||
import com.eco.plugin.xx.zgydsso.utils.FRUtils; |
||||
import com.fr.db.fun.impl.AbstractDBAccessProvider; |
||||
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 xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-07-29 |
||||
**/ |
||||
@EnableMetrics |
||||
@FunctionRecorder |
||||
public class DBController extends AbstractDBAccessProvider { |
||||
|
||||
private static DBAccessor accessor; |
||||
|
||||
public static DBAccessor getAccessor() { |
||||
return accessor; |
||||
} |
||||
|
||||
@Override |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
UserDao.DAO, RoleUserLinkDao.DAO,FilenameDao.DAO |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor accessor) { |
||||
DBController.accessor = accessor; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 批量操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batchUser(List<UserEntity> addOrUpdate, List<UserEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final UserEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
UserEntity ae =context.getDAO(UserDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(UserDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(UserDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdate exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final UserEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(UserDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据username获取信息 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static UserEntity getByUsername(final String username){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<UserEntity>() { |
||||
@Override |
||||
public UserEntity run(DAOContext context) throws Exception { |
||||
UserEntity result = context.getDAO(UserDao.class).getByUsername(username); |
||||
|
||||
return result == null ? new UserEntity() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getByUsername:"+e.getMessage()); |
||||
} |
||||
|
||||
return new UserEntity(); |
||||
} |
||||
|
||||
/** |
||||
* 批量操作 |
||||
* @param addOrUpdate |
||||
* @param delete |
||||
* @return |
||||
*/ |
||||
public static boolean batchLink(List<RoleUserLinkEntity> addOrUpdate, List<RoleUserLinkEntity> delete){ |
||||
//新增或者删除
|
||||
if(addOrUpdate != null && addOrUpdate.size() > 0){ |
||||
for(final RoleUserLinkEntity dbe : addOrUpdate){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
RoleUserLinkEntity ae =context.getDAO(RoleUserLinkDao.class).getById(dbe.getId()); |
||||
if(ae != null ){ |
||||
context.getDAO(RoleUserLinkDao.class).update(dbe); |
||||
}else{ |
||||
context.getDAO(RoleUserLinkDao.class).add(dbe); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch addOrUpdateLink exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(delete != null && delete.size() > 0){ |
||||
for(final RoleUserLinkEntity dbe : delete){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(RoleUserLinkDao.class).remove(dbe.getId()); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("batch delete exception ->"+e.getMessage() + dbe.toString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
public static boolean addTime(TimeEntity time){ |
||||
|
||||
try{ |
||||
accessor.runDMLAction(new DBAction<Boolean>() { |
||||
@Override |
||||
public Boolean run(DAOContext context) throws Exception { |
||||
context.getDAO(FilenameDao.class).add(time); |
||||
return true; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("addTime exception ->"+e.getMessage()+time.toString()); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public static List<TimeEntity> getAllTime(final String type){ |
||||
try{ |
||||
return accessor.runQueryAction(new DBAction<List<TimeEntity>>() { |
||||
@Override |
||||
public List<TimeEntity> run(DAOContext context) throws Exception { |
||||
List<TimeEntity> result = context.getDAO(FilenameDao.class).getAllTime(type); |
||||
|
||||
return result == null ? new ArrayList<TimeEntity>() : result; |
||||
} |
||||
}); |
||||
}catch(Throwable e){ |
||||
FRUtils.FRLogError("exception getAllTime:"+e.getMessage()); |
||||
} |
||||
|
||||
return new ArrayList<TimeEntity>(); |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.dao; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.db.bean.TimeEntity; |
||||
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 xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
**/ |
||||
public class FilenameDao extends BaseDAO<TimeEntity> { |
||||
|
||||
public FilenameDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<TimeEntity> getEntityClass() { |
||||
return TimeEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return TimeEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return FilenameDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(TimeEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(TimeEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public List<TimeEntity> getAllTime(String type) throws Exception { |
||||
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.eq("type",type)).addSort("filename",true); |
||||
|
||||
|
||||
return find(condition); |
||||
} |
||||
|
||||
|
||||
public List<TimeEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(TimeEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,68 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.dao; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.db.bean.RoleUserLinkEntity; |
||||
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 xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
**/ |
||||
public class RoleUserLinkDao extends BaseDAO<RoleUserLinkEntity> { |
||||
|
||||
public RoleUserLinkDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<RoleUserLinkEntity> getEntityClass() { |
||||
return RoleUserLinkEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return RoleUserLinkEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return RoleUserLinkDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(RoleUserLinkEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(RoleUserLinkEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public RoleUserLinkEntity getByUsername(String username) throws Exception { |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("username", username)); |
||||
|
||||
return findOne(condition); |
||||
} |
||||
|
||||
|
||||
public List<RoleUserLinkEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(RoleUserLinkEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.eco.plugin.xx.zgydsso.db.dao; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.db.bean.UserEntity; |
||||
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 xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
**/ |
||||
public class UserDao extends BaseDAO<UserEntity> { |
||||
|
||||
public UserDao(DAOSession session) { |
||||
super(session); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<UserEntity> getEntityClass() { |
||||
return UserEntity.class; |
||||
} |
||||
|
||||
public final static DAOProvider DAO = new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return UserEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return UserDao.class; |
||||
} |
||||
}; |
||||
|
||||
public void add(UserEntity entity) throws Exception { |
||||
getSession().persist(entity); |
||||
} |
||||
|
||||
public void remove(String id) throws Exception { |
||||
getSession().remove(QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("id", id)), |
||||
this.getEntityClass()); |
||||
} |
||||
|
||||
public void update(UserEntity entity) throws Exception { |
||||
getSession().merge(entity); |
||||
} |
||||
|
||||
|
||||
public UserEntity getByUsername(String username) throws Exception { |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.eq("username", username)); |
||||
|
||||
return findOne(condition); |
||||
} |
||||
|
||||
|
||||
public List<UserEntity> like(String pid, String type)throws Exception{ |
||||
QueryCondition condition = QueryFactory.create() |
||||
.addRestriction(RestrictionFactory.like("", pid)).addRestriction(RestrictionFactory.like(UserEntity.COLUMN_ID,type)); |
||||
return find(condition); |
||||
} |
||||
} |
@ -0,0 +1,109 @@
|
||||
package com.eco.plugin.xx.zgydsso.filter; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xx.zgydsso.utils.FRUtils; |
||||
import com.eco.plugin.xx.zgydsso.utils.Utils; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.ultrapower.casp.client.LoginUtil; |
||||
import com.ultrapower.casp.client.config.CaspClientConfig; |
||||
import com.ultrapower.casp.common.datatran.data.ticket.TransferTicket; |
||||
import com.ultrapower.casp.common.datatran.data.user.UserInfo; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = "com.eco.plugin.xx.zgydsso") |
||||
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
||||
@Override |
||||
public String filterName() { |
||||
return "zgydssoFilter"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
||||
|
||||
if(PluginContexts.currentContext().isAvailable()){ |
||||
//code
|
||||
|
||||
//是否放行
|
||||
boolean release = isRelease(req); |
||||
|
||||
if(release){ |
||||
release(req,res,chain); |
||||
return; |
||||
} |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
LoginUtil loginUtil = LoginUtil.getInstance(); |
||||
loginUtil.initCustom(psc.getConfigurl(),psc.getConfigurlxml()); |
||||
// loginUtil.init(PluginSimpleConfig.getInstance().getConfigurl());
|
||||
CaspClientConfig caspClientConfig = CaspClientConfig.getInstance(); |
||||
FRUtils.FRLogInfo("appcode:"+caspClientConfig.getAppCode()+";appkey:"+caspClientConfig.getAppKey()); |
||||
boolean hasTicket = loginUtil.checkTicket(req); |
||||
FRUtils.FRLogInfo("url:"+FRUtils.getAllUrl(req)+";hasTicket"+hasTicket); |
||||
|
||||
if(!hasTicket){ |
||||
loginUtil.redirectToServer(req,res); |
||||
return ; |
||||
} |
||||
|
||||
String ticket = loginUtil.getTicket(req); |
||||
FRUtils.FRLogInfo("ticket:"+ticket); |
||||
|
||||
TransferTicket transferTicket = loginUtil.analysTicket(ticket); |
||||
FRUtils.FRLogInfo("transferTicket is null :"+(transferTicket == null)); |
||||
|
||||
FRUtils.FRLogInfo("transferTicket:"+transferTicket.toString()); |
||||
UserInfo user = loginUtil.qryUserByTicket(transferTicket); |
||||
FRUtils.FRLogInfo("user:"+user.toString()); |
||||
|
||||
String username = user.getAccountID(); |
||||
FRUtils.FRLogInfo("username:"+username); |
||||
|
||||
String url = Utils.getRedirectUrl(req,"iamcaspticket"); |
||||
|
||||
//登出用
|
||||
HttpSession session = req.getSession(true); |
||||
session.setAttribute("ticket",ticket); |
||||
//登录
|
||||
FRUtils.login(req,res,username,url); |
||||
} |
||||
|
||||
release(req,res,chain); |
||||
} |
||||
|
||||
private boolean isRelease(HttpServletRequest req) { |
||||
String url = FRUtils.getAllUrl(req); |
||||
String reft = req.getParameter("ref_t"); |
||||
|
||||
boolean isLogin = FRUtils.isLogin(req); |
||||
boolean isRemote = url.contains("remote"); |
||||
boolean isLoginPage = url.contains("login")||url.contains("decision/file")||url.contains("decision/resource")||url.contains("decision/system")||url.contains("query/ip"); |
||||
boolean isViewlt = url.contains("viewlet") || "design".equals(reft) || url.contains("view/report") || url.contains("view/form"); |
||||
boolean isValidate = url.contains("validateToken") || url.contains("getUserInfo") ||url.contains("/toOther"); |
||||
return isLogin || isLoginPage || isRemote || isValidate; |
||||
// return isLogin || isRemote || isLoginPage || isViewlt;
|
||||
} |
||||
|
||||
//放行拦截器
|
||||
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||
try{ |
||||
chain.doFilter(req,res); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogInfo("拦截失败"); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,221 @@
|
||||
package com.eco.plugin.xx.zgydsso.function; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.RoleUserLinkEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.TimeEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.bean.UserEntity; |
||||
import com.eco.plugin.xx.zgydsso.db.controller.DBController; |
||||
import com.eco.plugin.xx.zgydsso.utils.FRUtils; |
||||
import com.eco.plugin.xx.zgydsso.utils.FileUtils; |
||||
import com.eco.plugin.xx.zgydsso.utils.Utils; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
import java.io.*; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Authorize(callSignKey = "com.eco.plugin.xx.zgydsso") |
||||
public class AuthFunction extends AbstractFunction { |
||||
|
||||
@Override |
||||
public Object run(Object[] objects) { |
||||
if(!PluginContexts.currentContext().isAvailable()) { |
||||
return "fail"; |
||||
} |
||||
|
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
//获取上一次同步的工号文件名
|
||||
List<TimeEntity> userTimes = DBController.getAllTime("user"); |
||||
String userTime = "0"; |
||||
if(userTimes != null && userTimes.size() > 0){ |
||||
FRUtils.FRLogInfo("userFileCount:"+userTimes.size()); |
||||
userTime = userTimes.get(0).getFilename(); |
||||
} |
||||
|
||||
final String userTimeFinal = userTime; |
||||
//增量文件文件夹及工号、工号角色文件前缀
|
||||
String folderPath = psc.getDataurl(); |
||||
String userPre = psc.getUsernamefile(); |
||||
String linkPre = psc.getRolelinkfile(); |
||||
|
||||
//工号文件过滤器,规则为以工号文件开头且文件名大于上次同步文件的文件名,按文件名的hash值排序(默认排序即是hash值,所以这里不显示指定)
|
||||
FileFilter userFilter = new FileFilter() { |
||||
@Override |
||||
public boolean accept(File pathname) { |
||||
String filename = pathname.getName(); |
||||
return filename.startsWith(userPre) && filename.compareTo(userTimeFinal) > 0 ; |
||||
} |
||||
}; |
||||
File[] userFiles = FileUtils.getFileInFolderAndSort(folderPath,userFilter,null); |
||||
|
||||
//遍历文件并操作用户,结束后将本次最后的文件名插入数据库中
|
||||
if(userFiles != null && userFiles.length > 0){ |
||||
for(int i=0;i<userFiles.length;i++){ |
||||
File userFile = userFiles[i]; |
||||
operUser(userFile); |
||||
} |
||||
|
||||
String userFilename = userFiles[userFiles.length -1].getName(); |
||||
TimeEntity te = new TimeEntity(); |
||||
te.setId(UUID.randomUUID().toString()); |
||||
te.setFilename(userFilename); |
||||
te.setType("user"); |
||||
DBController.addTime(te); |
||||
} |
||||
|
||||
//获取上一次同步的关联文件名
|
||||
List<TimeEntity> linkTimes = DBController.getAllTime("link"); |
||||
String linkTime = "0"; |
||||
if(linkTimes != null && linkTimes.size() > 0){ |
||||
FRUtils.FRLogInfo("linkFileCount:"+linkTimes.size()); |
||||
linkTime = linkTimes.get(0).getFilename(); |
||||
|
||||
} |
||||
|
||||
final String linkTimeFinal = linkTime; |
||||
//关联文件过滤器,规则为以关联文件开头且文件名大于上次同步文件的文件名,按文件名的hash值排序(默认排序即是hash值,所以这里不显示指定)
|
||||
FileFilter linkFilter = new FileFilter() { |
||||
@Override |
||||
public boolean accept(File pathname) { |
||||
String filename = pathname.getName(); |
||||
return filename.startsWith(linkPre) && filename.compareTo(linkTimeFinal) > 0; |
||||
} |
||||
}; |
||||
File[] linkFiles = FileUtils.getFileInFolderAndSort(folderPath,linkFilter,null); |
||||
|
||||
//遍历文件并操作关联关系,结束后将本次最后的文件名插入数据库中
|
||||
if(linkFiles != null && linkFiles.length > 0){ |
||||
for(int i=0;i<linkFiles.length;i++){ |
||||
File linkFile = linkFiles[i]; |
||||
operRoleUserLink(linkFile); |
||||
} |
||||
|
||||
String userFilename = linkFiles[linkFiles.length -1].getName(); |
||||
TimeEntity te = new TimeEntity(); |
||||
te.setId(UUID.randomUUID().toString()); |
||||
te.setFilename(userFilename); |
||||
te.setType("link"); |
||||
DBController.addTime(te); |
||||
} |
||||
|
||||
return "success"; |
||||
} |
||||
|
||||
/** |
||||
* 处理用户同步 |
||||
*/ |
||||
private static void operUser(File file){ |
||||
if(file == null || !file.isFile() || !file.exists()){ |
||||
return; |
||||
} |
||||
|
||||
List<UserEntity> addorupdate = new ArrayList<UserEntity>(); |
||||
List<UserEntity> delete = new ArrayList<UserEntity>(); |
||||
|
||||
BufferedReader br = null; |
||||
try{ |
||||
FileInputStream fis = new FileInputStream(file); |
||||
InputStreamReader reader = new InputStreamReader(fis,"GBK"); |
||||
br = new BufferedReader(reader); |
||||
String line = ""; |
||||
while((line = br.readLine()) != null){ |
||||
String[] userBean = line.split("&&"); |
||||
String username = userBean[0]; |
||||
String password = userBean[15]; |
||||
|
||||
//如果密码为空则设置为123456
|
||||
if(Utils.isNullStr(password)){ |
||||
password = "123456"; |
||||
} |
||||
|
||||
String city = userBean[7]; |
||||
String status = userBean[2]; |
||||
String realname = userBean[1]; |
||||
UserEntity user = new UserEntity(); |
||||
user.setId(username); |
||||
user.setUsername(username); |
||||
user.setPassword(password); |
||||
user.setCity(city); |
||||
user.setStatus(status); |
||||
user.setRealname(realname); |
||||
|
||||
addorupdate.add(user); |
||||
} |
||||
|
||||
br.close(); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogError("读取txt文件异常!"); |
||||
}finally { |
||||
if(br != null){ |
||||
try { |
||||
br.close(); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogError("BufferedReader关闭异常"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
DBController.batchUser(addorupdate,delete); |
||||
} |
||||
|
||||
private static void operRoleUserLink(File file){ |
||||
if(file == null || !file.isFile() || !file.exists()){ |
||||
return; |
||||
} |
||||
|
||||
List<RoleUserLinkEntity> addorupdate = new ArrayList<RoleUserLinkEntity>(); |
||||
List<RoleUserLinkEntity> delete = new ArrayList<RoleUserLinkEntity>(); |
||||
|
||||
BufferedReader br = null; |
||||
try{ |
||||
FileInputStream fis = new FileInputStream(file); |
||||
InputStreamReader reader = new InputStreamReader(fis,"GBK"); |
||||
br = new BufferedReader(reader); |
||||
String line = ""; |
||||
while((line = br.readLine()) != null){ |
||||
String[] array = line.split("&&"); |
||||
String username = array[0]; |
||||
String roleid = array[1]; |
||||
String system = array[2]; |
||||
String status = array[4]; |
||||
String oprtype = array[8]; |
||||
|
||||
if(!"RPT".equals(system)){ |
||||
continue; |
||||
} |
||||
|
||||
RoleUserLinkEntity user = new RoleUserLinkEntity(); |
||||
user.setId(username); |
||||
user.setUsername(username); |
||||
user.setRoleid(roleid); |
||||
user.setSystem(system); |
||||
user.setStatus(status); |
||||
|
||||
if("DEL".equals(oprtype)){ |
||||
delete.add(user); |
||||
} |
||||
else{ |
||||
addorupdate.add(user); |
||||
} |
||||
} |
||||
|
||||
br.close(); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogError("读取txt文件异常!"); |
||||
}finally { |
||||
if(br != null){ |
||||
try { |
||||
br.close(); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogError("BufferedReader关闭异常"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
DBController.batchLink(addorupdate,delete); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.eco.plugin.xx.zgydsso.logout; |
||||
|
||||
import com.eco.plugin.xx.zgydsso.config.PluginSimpleConfig; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.ultrapower.casp.client.LoginUtil; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class Logout extends AbstractLogInOutEventProvider { |
||||
|
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
HttpSession session = result.getRequest().getSession(true); |
||||
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||
session.invalidate(); |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
|
||||
LoginUtil loginUtil = LoginUtil.getInstance(); |
||||
loginUtil.initCustom(psc.getConfigurl(),psc.getConfigurlxml()); |
||||
loginUtil.logout(String.valueOf(session.getAttribute("ticket"))); |
||||
return getUrl(result.getRequest()); |
||||
} |
||||
|
||||
private static String getUrl(HttpServletRequest req){ |
||||
String scheme = req.getScheme(); |
||||
String serverName = req.getServerName(); |
||||
|
||||
return scheme+"://"+serverName+"/webroot/decision"; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,34 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import com.fr.decision.authority.base.constant.type.authority.AuthorityType; |
||||
import com.fr.decision.authority.data.Authority; |
||||
import com.fr.decision.webservice.impl.privilege.PrivilegeType; |
||||
import com.fr.decision.webservice.impl.privilege.RoleTypePrivilegeProcessFactory; |
||||
import com.fr.stable.query.QueryFactory; |
||||
|
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 权限工具类 |
||||
*/ |
||||
public class AuthorityUtils { |
||||
|
||||
/** |
||||
* 根据角色id获取目录权限 |
||||
* @param roleid |
||||
* @return |
||||
*/ |
||||
public static List<Authority> getAuthorityByRole(String roleid) throws Exception { |
||||
PrivilegeType var5 = RoleTypePrivilegeProcessFactory.getPrivilegeType("entry"); |
||||
Set<Integer> privilegeTypes = new HashSet<Integer>(); |
||||
privilegeTypes.add(1); |
||||
privilegeTypes.add(3); |
||||
Set<AuthorityType> authorityType = AuthorityType.fromInteger(privilegeTypes); |
||||
|
||||
List<Authority> authorityList= var5.findByCustomRole(roleid, true, QueryFactory.create(), (AuthorityType[])authorityType.toArray(new AuthorityType[0])); |
||||
|
||||
return authorityList; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import com.fr.decision.authority.data.CustomRole; |
||||
import com.fr.decision.webservice.v10.user.CustomRoleService; |
||||
import com.fr.decision.webservice.v10.user.controller.SuperCustomRoleController; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class FRRoleUtils { |
||||
|
||||
/** |
||||
* 获取角色service |
||||
* @return |
||||
*/ |
||||
private static CustomRoleService getRoleService(){ |
||||
return CustomRoleService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全部角色 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static CustomRole[] getAllRole() throws Exception { |
||||
// List<RoleBean> roleBean = UserMiddleRoleService.getInstance().getAllCustomRoles();
|
||||
CustomRole[] roles = SuperCustomRoleController.KEY.getAllCustomRoles((String)null, ""); |
||||
return roles; |
||||
} |
||||
|
||||
/** |
||||
* 根据角色id获取角色列表 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<CustomRole> getRoleByUser(String userid) throws Exception { |
||||
|
||||
return getRoleService().getCustomRolesByUser(userid); |
||||
} |
||||
} |
@ -0,0 +1,220 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.user.*; |
||||
import com.fr.decision.webservice.v10.login.ExtendTokenProcessor; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class FRUserUtils { |
||||
|
||||
/** |
||||
* 获取用户Service |
||||
* @return |
||||
*/ |
||||
public static UserService getUserService(){ |
||||
return UserService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全量用户 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<UserAdditionBean> getAllUsers() throws Exception { |
||||
// List<UserBean> userbean = UserMiddleRoleService.getInstance().getAllUsers(false);
|
||||
List<UserAdditionBean> users = new ArrayList<UserAdditionBean>(); |
||||
getAllUser(getAdminUser().getUsername(),0,1000,users); |
||||
return users; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param adminUsername 管理员用户名 |
||||
* @param page 页数 |
||||
* @param num 每页的数据 |
||||
* @param users 保存用户的列表 |
||||
*/ |
||||
private static void getAllUser(String adminUsername,int page,int num,List<UserAdditionBean> users) throws Exception { |
||||
Map<String,Object> result = getUserService().getAllUsers(adminUsername,page,num,"","",true); |
||||
Long total = (Long)result.get("total"); |
||||
List<UserAdditionBean> item = (List<UserAdditionBean>)result.get("items"); |
||||
users.addAll(item); |
||||
|
||||
page = page+1; |
||||
|
||||
if(page * num >= total){ |
||||
return ; |
||||
} |
||||
|
||||
getAllUser(adminUsername,page,num,users); |
||||
} |
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void addUser(UserBean userBean) throws Exception { |
||||
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||
getUserService().addUser(userBean); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void updateUser(UserBean userBean) throws Exception { |
||||
getUserService().editUser(userBean,getAdminUser().getId()); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static int deleteUser(User user) throws Exception { |
||||
String userId = user.getId(); |
||||
|
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||
|
||||
return getUserService().deleteUsers(userUpdateBean); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getUserByUserName(String userName) throws Exception { |
||||
return getUserService().getUserByUserName(userName); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static UserBean getUserBeanByUserName(String userName ) throws Exception { |
||||
String id = getUserService().getUserByUserName(userName).getId(); |
||||
return getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取用户 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static UserBean getUser(String id) throws Exception { |
||||
return getUserService().getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return getUserService().isAdmin(getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 禁用启用用户 |
||||
* @param userId |
||||
* @param state false 禁用 true 启用 |
||||
* @throws Exception 异常说明失败 |
||||
*/ |
||||
public static void forbidUser(String userId,boolean state) throws Exception { |
||||
getUserService().forbidUser(userId,state); |
||||
} |
||||
|
||||
/** |
||||
* 修改用户部门 |
||||
* @param departmentId |
||||
* @param postId |
||||
* @param ud |
||||
* @throws Exception |
||||
*/ |
||||
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception { |
||||
getUserService().updateDepartmentPostUsers(departmentId,"",ud); |
||||
} |
||||
|
||||
|
||||
// /**
|
||||
// * 验证密码是否正确
|
||||
// * @param psd 明文密码
|
||||
// * @param user 根据用户名获取得用户对象
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkPsd(String psd,User user){
|
||||
// String shaPsd = CipherUtils.jdksha256(psd);
|
||||
//
|
||||
// return shaPsd.equals(user.getPassword());
|
||||
// }
|
||||
public static User getCurrentUser(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserByUserName(username); |
||||
} |
||||
|
||||
public static UserBean getCurrentUserBean(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserBeanByUserName(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取用户部门角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static UserRolesBean getUserRolesBean(String username) throws Exception { |
||||
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取部门职务 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{ |
||||
return getUserRolesBean(username).getDepRoles(); |
||||
} |
||||
|
||||
/** |
||||
* 获取角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<String> getCustomRoles(String username) throws Exception{ |
||||
return getUserRolesBean(username).getCustomRoles(); |
||||
} |
||||
|
||||
public static UserBean getAdminUser() throws Exception { |
||||
String adminid = getUserService().getAdminUserIdList().get(0); |
||||
return getUser(adminid); |
||||
} |
||||
|
||||
public static String getUsernameFromToken(String token){ |
||||
String username = ExtendTokenProcessor.KEY.getUsername(token); |
||||
return username; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,320 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.base.TableData; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
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.file.TableDataConfig; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.method.HandlerMethod; |
||||
import com.fr.web.controller.ReportRequestService; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
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 |
||||
* @param token |
||||
* @param url |
||||
*/ |
||||
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:token:"+token); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(token)){ |
||||
writeToken2Cookie(httpServletResponse,token,-1); |
||||
|
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
|
||||
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token); |
||||
|
||||
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
try { |
||||
httpServletResponse.sendRedirect(url); |
||||
} catch (IOException e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!"); |
||||
} |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){ |
||||
String token = ""; |
||||
try { |
||||
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
private static void writeToken2Cookie(HttpServletResponse var1, String var2, int var3) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(var2)) { |
||||
Cookie var4 = new Cookie("fine_auth_token", var2); |
||||
long var5 = var3 == -2 ? 1209600000L : (long)var3; |
||||
var4.setMaxAge((int)var5); |
||||
var4.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var4); |
||||
Cookie var7 = new Cookie("fine_remember_login", String.valueOf(var3 == -2 ? -2 : -1)); |
||||
var7.setMaxAge((int)var5); |
||||
var7.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
var1.addCookie(var7); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception var8) { |
||||
FineLoggerFactory.getLogger().error(var8.getMessage(), var8); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @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); |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志-error |
||||
* @param message |
||||
*/ |
||||
public static void FRLogError(String message){ |
||||
FineLoggerFactory.getLogger().error("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 getDBPsd(String username,String password){ |
||||
PasswordValidator pv = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||
String uuid = UUIDUtil.generate(); |
||||
|
||||
return pv.encode(username, password, uuid); |
||||
} |
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
/** |
||||
* 根据originKey获取源链接 |
||||
* @param originKey |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getOriginUrl(String originKey) throws Exception { |
||||
if (StringUtils.isNotEmpty(originKey)) { |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(originKey); |
||||
DecisionStatusService.originUrlStatusService().delete(originKey); |
||||
if (originUrlResponseBean != null) { |
||||
return originUrlResponseBean.getOriginUrl(); |
||||
} |
||||
} |
||||
|
||||
return new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否开启模板认证 |
||||
* @param |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static boolean isTempAuth(HttpServletRequest req,HttpServletResponse res) throws Exception { |
||||
ReportTemplateRequestChecker checker = new ReportTemplateRequestChecker(); |
||||
HandlerMethod hm = new HandlerMethod(new ReportRequestService(),ReportRequestService.class.getMethod("preview", HttpServletRequest.class, HttpServletResponse.class, String.class)); |
||||
return checker.checkRequest(req,res,hm); |
||||
} |
||||
|
||||
/** |
||||
* 获取数据集数据 |
||||
* @param serverDataSetName |
||||
* @return |
||||
*/ |
||||
public static DataModel getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData(serverDataSetName); |
||||
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); |
||||
// userInfoDM.getRowCount();
|
||||
// userInfoDM.getColumnIndex();
|
||||
// userInfoDM.getValueAt()
|
||||
return userInfoDM; |
||||
} |
||||
|
||||
public static String getIndex(HttpServletRequest req){ |
||||
String url = req.getScheme()+"://"+req.getServerName()+":"+String.valueOf(req.getServerPort())+req.getRequestURI(); |
||||
return url; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileFilter; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
|
||||
/** |
||||
* 文件处理类 |
||||
*/ |
||||
public class FileUtils { |
||||
|
||||
/** |
||||
* 根据过滤器获取文件夹下所有文件,并按排序规则排序 |
||||
* @param folderPath |
||||
* @param filter |
||||
* @param c |
||||
* @return |
||||
*/ |
||||
public static File[] getFileInFolderAndSort(String folderPath,FileFilter filter,Comparator c){ |
||||
File folder = new File(folderPath); |
||||
|
||||
//如果传入的路径是文件路径,那么直接返回
|
||||
if(folder.isFile()){ |
||||
return new File[]{folder}; |
||||
} |
||||
|
||||
//如果过滤器为空,则返回全部文件,不为空进行筛选
|
||||
File[] result =filter == null ? folder.listFiles() : folder.listFiles(filter); |
||||
|
||||
if(c != null){ |
||||
Arrays.sort(result,c); |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import java.io.*; |
||||
|
||||
public class IOUtils { |
||||
|
||||
/** |
||||
* 将inputStream写入本地文件 |
||||
* @param url |
||||
* @param inputStream |
||||
*/ |
||||
public static void writeFile(String url, InputStream inputStream){ |
||||
int index; |
||||
byte[] bytes = new byte[1024]; |
||||
FileOutputStream downloadFile = null ; |
||||
try { |
||||
downloadFile = new FileOutputStream(url); |
||||
while ((index = inputStream.read(bytes)) != -1) { |
||||
downloadFile.write(bytes, 0, index); |
||||
downloadFile.flush(); |
||||
} |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("Exception:writeFile:"+e.getMessage()); |
||||
}finally { |
||||
try { |
||||
inputStream.close(); |
||||
downloadFile.close(); |
||||
} |
||||
catch (Exception e){ |
||||
FRUtils.FRLogInfo("Exception:writeFile:finally"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 字符串转输入流 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static InputStream strToInputStream(String str){ |
||||
try { |
||||
return new ByteArrayInputStream(str.getBytes("UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRUtils.FRLogInfo("IOUtils-strToInputStream:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public static String inputStreamToStr(InputStream inputStream) { |
||||
StringBuffer stringBuffer = new StringBuffer(); |
||||
byte[] byt = new byte[4096]; |
||||
|
||||
try { |
||||
for (int i; (i = inputStream.read(byt)) != -1; ) { |
||||
stringBuffer.append(new String(byt, 0, i)); |
||||
} |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogInfo("Exception:inputStreamToStr:"+e.getMessage()); |
||||
} |
||||
|
||||
return stringBuffer.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 读取txt文件 |
||||
* @param file |
||||
* @return |
||||
*/ |
||||
public static String readTxtFile(File file){ |
||||
if(file == null || !file.isFile() || !file.exists()){ |
||||
return ""; |
||||
} |
||||
|
||||
String result = ""; |
||||
BufferedReader br = null; |
||||
try{ |
||||
br = new BufferedReader(new FileReader(file)); |
||||
String line = ""; |
||||
while((line = br.readLine()) != null){ |
||||
result += "\n"+line; |
||||
} |
||||
|
||||
br.close(); |
||||
}catch(Exception e){ |
||||
FRUtils.FRLogError("读取txt文件异常!"); |
||||
}finally { |
||||
if(br != null){ |
||||
try { |
||||
br.close(); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogError("BufferedReader关闭异常"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.xx.zgydsso.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) { |
||||
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 responseText(HttpServletResponse res,String text){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/html;charset=utf-8"); |
||||
pw.println(text); |
||||
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(); |
||||
} |
||||
} |
@ -0,0 +1,329 @@
|
||||
package com.eco.plugin.xx.zgydsso.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
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); |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
/** |
||||
* 替换空字符串 |
||||
* @param str |
||||
* @param replace |
||||
* @return |
||||
*/ |
||||
public static String replaceNullStr(String str,String replace){ |
||||
if(isNullStr(str)){ |
||||
return replace; |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求体 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
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; |
||||
} |
||||
|
||||
/** |
||||
* 获取ip |
||||
* @return |
||||
*/ |
||||
public static String getIp(HttpServletRequest req){ |
||||
String realIp = req.getHeader("X-Real-IP"); |
||||
String fw = req.getHeader("X-Forwarded-For"); |
||||
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||
int var3 = fw.indexOf(","); |
||||
return var3 != -1 ? fw.substring(0, var3) : fw; |
||||
} else { |
||||
fw = realIp; |
||||
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||
return realIp; |
||||
} else { |
||||
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||
fw = req.getHeader("Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getRemoteAddr(); |
||||
} |
||||
|
||||
return fw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据key获取cookie |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||
Cookie[] cookies = req.getCookies(); |
||||
String cookie = ""; |
||||
|
||||
if(cookies == null || cookies.length <=0){ |
||||
return ""; |
||||
} |
||||
|
||||
for(int i = 0; i < cookies.length; i++) { |
||||
Cookie item = cookies[i]; |
||||
if (item.getName().equalsIgnoreCase(key)) { |
||||
cookie = item.getValue(); |
||||
} |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("cookie:"+cookie); |
||||
|
||||
return cookie; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是手机端的链接 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest req) { |
||||
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||
String userAgent = req.getHeader("user-agent"); |
||||
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||
for(String mobile : mobileArray) { |
||||
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return NetworkHelper.getDevice(req).isMobile(); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String encodeCH(String url ){ |
||||
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||
|
||||
while(matcher.find()){ |
||||
String chn = matcher.group(); |
||||
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||
} |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 获取web-inf文件夹下的文件 |
||||
* filename /resources/ip4enc.properties |
||||
*/ |
||||
public static InputStream getResourcesFile(String filename){ |
||||
return ResourceIOUtils.read(filename); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param res |
||||
* @param path /com/fr/plugin/loginAuth/html/getMac.html |
||||
* @param parameterMap |
||||
*/ |
||||
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){ |
||||
if(parameterMap == null){ |
||||
parameterMap = new HashMap<String, String>(); |
||||
} |
||||
|
||||
try { |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 去掉浏览器中的参数 |
||||
* @param url |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String removeParam(String url,String param){ |
||||
if(!url.contains("?"+param) && !url.contains("&"+param)){ |
||||
return url; |
||||
} |
||||
|
||||
return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); |
||||
} |
||||
|
||||
/** |
||||
* 获取跳转链接 |
||||
* @param req |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String getRedirectUrl(HttpServletRequest req,String param){ |
||||
String url = FRUtils.getAllUrl(req); |
||||
|
||||
if(isNotNullStr(param)){ |
||||
url = removeParam(url,param); |
||||
} |
||||
|
||||
url = encodeCH(url); |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 去除空格换行 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String trim(String str){ |
||||
return str.trim().replaceAll("\n","").replaceAll("\r",""); |
||||
} |
||||
|
||||
/** |
||||
* list 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String listToStr(List<String> list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null || list.size() <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(String str : list){ |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* array 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String arrayToStr(String[] list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null ||list.length <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(int i=0;i<list.length;i++){ |
||||
String str = list[i]; |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
} |
Loading…
Reference in new issue