Browse Source

open

master
pioneer 2 years ago
commit
b240bd2599
  1. 6
      README.md
  2. 20
      plugin.xml
  3. 24
      src/main/java/com/fr/plugin/user/tuomin/UserTMPluginLifecycleMonitor.java
  4. 257
      src/main/java/com/fr/plugin/user/tuomin/controller/TableDataSyncAction.java
  5. 132
      src/main/java/com/fr/plugin/user/tuomin/controller/UserTMController.java
  6. 14
      src/main/java/com/fr/plugin/user/tuomin/controller/UserTMControllerProvider.java
  7. 33
      src/main/java/com/fr/plugin/user/tuomin/webresource/UserTMWebResourceProvider.java
  8. 1686
      src/main/resources/com/fr/plugin/user/tuomin/userinfo.js

6
README.md

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

20
plugin.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.user.tuomin</id>
<name><![CDATA[用户信息脱敏插件]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[
[2022-06-30]用户信息脱敏插件。<br/>
]]></change-notes>
<extra-decision>
<ControllerRegisterProvider class="com.fr.plugin.user.tuomin.controller.UserTMControllerProvider"/>
<WebResourceProvider class="com.fr.plugin.user.tuomin.webresource.UserTMWebResourceProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.user.tuomin.UserTMPluginLifecycleMonitor"/>
<lifecycle-monitor class="com.fr.plugin.user.tuomin.UserTMPluginLifecycleMonitor"/>
</plugin>

24
src/main/java/com/fr/plugin/user/tuomin/UserTMPluginLifecycleMonitor.java

@ -0,0 +1,24 @@
package com.fr.plugin.user.tuomin;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.workspace.WorkContext;
@EnableMetrics
@FunctionRecorder
public class UserTMPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
FineLoggerFactory.getLogger().info(pluginContext.getID() + "插件启动:");
}
@Override
public void beforeStop(PluginContext pluginContext) {
FineLoggerFactory.getLogger().info(pluginContext.getID()+"插件停止");
}
}

257
src/main/java/com/fr/plugin/user/tuomin/controller/TableDataSyncAction.java

@ -0,0 +1,257 @@
package com.fr.plugin.user.tuomin.controller;
import com.fr.decision.authority.base.constant.type.operation.SyncOperationType;
import com.fr.decision.authority.controller.personnel.PersonnelController;
import com.fr.decision.authority.controller.personnel.PersonnelWork;
import com.fr.decision.sync.CascadeData;
import com.fr.decision.sync.SourceConflictData;
import com.fr.decision.sync.SourceConflictStrategy;
import com.fr.decision.sync.SyncDetail;
import com.fr.decision.sync.data.RowData;
import com.fr.decision.sync.result.FailedData;
import com.fr.decision.sync.result.SyncResultData;
import com.fr.decision.sync.result.SyncWorkResult;
import com.fr.decision.sync.work.SyncWork;
import com.fr.decision.sync.work.impl.*;
import com.fr.decision.webservice.interceptor.handler.PreHandlerFactory;
import com.fr.general.data.DataModel;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TableDataSyncAction implements PersonnelWork {
private SyncDetail syncDetail;
private DataModel dm;
private Map<Integer, SyncWork> syncWorks = new TreeMap();
private UserSyncWork userSyncWork;
public static com.fr.plugin.user.tuomin.controller.TableDataSyncAction create(SyncDetail var0) {
return new com.fr.plugin.user.tuomin.controller.TableDataSyncAction(var0);
}
private TableDataSyncAction(SyncDetail var1) {
this.syncDetail = var1;
this.dm = var1.getSyncSource().buildTableData(var1.getDataSetName()).createDataModelWithTimeout(Calculator.createCalculator(), (int)var1.getRate());
}
public void before(PersonnelController var1) throws Exception {
this.registerSyncWorks(var1);
this.checkPlatformDirtyData();
}
private static final String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
private boolean validatePwd(String pswd,String userName){
boolean falg = false;
try {
if (null==pswd&&pswd.isEmpty()&&pswd.length()>9){
return falg;
}
//不全是特殊符号 不全是数字 不全是字母 不全是大写 不全是小写
if (pswd.matches(PW_PATTERN)){
falg = true;
}
} catch (Exception e) {
falg = false;
}
if(falg == false){
FineLoggerFactory.getLogger().info("密码强度验证:长度,大小写字母,符号不符合");
return false;
}
if(pswd.toLowerCase().indexOf(userName.toLowerCase()) != -1){
FineLoggerFactory.getLogger().info("密码强度验证:密码不能包含用户名");
return false;
}
return true;
}
public SyncResultData execute(PersonnelController var1) throws Exception {
this.clearDiffSource();
this.preparePlatformData();
this.beforePrepareSyncData();
this.prepareSyncData();
this.afterPrepareSyncData();
Field[] fileds = this.userSyncWork.getClass().getDeclaredFields();
for(int i = 0 ; i < fileds.length;i++) {
Field field = fileds[i];
String fieldName = field.getName();
FineLoggerFactory.getLogger().info("fieldName:"+fieldName);
if(fieldName.equals("syncNamePasswordMap")){
try {
field.setAccessible(true);
Object obj = field.get( this.userSyncWork);
Map<String, String> syncNamePasswordMap = (Map<String, String>)obj;
FineLoggerFactory.getLogger().info("一共有几个用户导入:"+syncNamePasswordMap.size());
Set<String> keys = syncNamePasswordMap.keySet();
for(String key : keys){
String pwd = syncNamePasswordMap.get(key).toString();
//这里判断密码强度
boolean isOk = validatePwd(pwd,key);
if(isOk == false){
SyncResultData resultData = new SyncResultData();
resultData.setSuccessUserCount(-100);
return resultData;
}
}
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
this.sourceCover();
this.addOrUpdate();
this.delete();
return this.over();
}
private void registerSyncWorks(PersonnelController var1) {
this.userSyncWork = new UserSyncWork(var1, this.syncDetail);
SyncWork[] var2 = new SyncWork[]{userSyncWork, new DepartmentSyncWork(var1, this.syncDetail), new PostSyncWork(var1, this.syncDetail), new CustomRoleSyncWork(var1, this.syncDetail), new DepRoleSyncWork(var1, this.syncDetail), new UserRoleMiddleSyncWork(var1, this.syncDetail)};
SyncWork[] var3 = var2;
int var4 = var2.length;
for(int var5 = 0; var5 < var4; ++var5) {
SyncWork var6 = var3[var5];
this.syncWorks.put(var6.processOrder(), var6);
}
}
private void checkPlatformDirtyData() throws Exception {
Iterator var1 = this.syncWorks.values().iterator();
while(var1.hasNext()) {
SyncWork var2 = (SyncWork)var1.next();
var2.checkPlatformDirtyData();
}
}
private void preparePlatformData() throws Exception {
Iterator var1 = this.syncWorks.values().iterator();
while(var1.hasNext()) {
SyncWork var2 = (SyncWork)var1.next();
var2.preparePlatformData();
}
}
private void beforePrepareSyncData() throws Exception {
Iterator var1 = this.syncWorks.values().iterator();
while(var1.hasNext()) {
SyncWork var2 = (SyncWork)var1.next();
var2.beforePrepareSyncData(this.dm);
}
}
private void prepareSyncData() throws Exception {
for(int var1 = 0; var1 < this.dm.getRowCount(); ++var1) {
RowData var2 = new RowData(var1);
Iterator var3 = this.syncWorks.values().iterator();
while(var3.hasNext()) {
SyncWork var4 = (SyncWork)var3.next();
var4.prepareSyncData(this.dm, var2);
}
}
this.dm.release();
}
private void afterPrepareSyncData() throws Exception {
CascadeData var1 = new CascadeData();
SyncWork var3;
for(Iterator var2 = this.syncWorks.values().iterator(); var2.hasNext(); var1 = var3.afterPrepareSyncData(var1)) {
var3 = (SyncWork)var2.next();
}
}
private void sourceCover() throws Exception {
SourceConflictData var1 = new SourceConflictData();
SyncWork var3;
for(Iterator var2 = this.syncWorks.values().iterator(); var2.hasNext(); var1 = var3.resolveSourceConflict(var1)) {
var3 = (SyncWork)var2.next();
}
}
private void addOrUpdate() throws Exception {
Iterator var1 = this.syncWorks.values().iterator();
while(var1.hasNext()) {
SyncWork var2 = (SyncWork)var1.next();
var2.addOrUpdate();
}
}
private void delete() throws Exception {
if (this.syncDetail.getOperationType() == SyncOperationType.KEY) {
CascadeData var1 = new CascadeData();
Iterator var2 = this.syncWorks.values().iterator();
while(var2.hasNext()) {
SyncWork var3 = (SyncWork)var2.next();
var3.delete(var1);
}
}
}
private void clearDiffSource() throws Exception {
if (this.syncDetail.getSourceConflictStrategy() == SourceConflictStrategy.CLEAR) {
SyncWork[] var1 = new SyncWork[]{(SyncWork)this.syncWorks.get(1), (SyncWork)this.syncWorks.get(5), (SyncWork)this.syncWorks.get(2), (SyncWork)this.syncWorks.get(3), (SyncWork)this.syncWorks.get(4)};
SyncWork[] var2 = var1;
int var3 = var1.length;
for(int var4 = 0; var4 < var3; ++var4) {
SyncWork var5 = var2[var4];
var5.clearDiffSource();
}
}
}
private SyncResultData over() throws Exception {
SyncResultData var1 = new SyncResultData();
Iterator var2 = this.syncWorks.entrySet().iterator();
while(var2.hasNext()) {
Entry var3 = (Entry)var2.next();
SyncWorkResult var4 = ((SyncWork)var3.getValue()).over();
if (var4 != null) {
if ((Integer)var3.getKey() == 1) {
var1.setSuccessUserCount(var4.getAddOrUpdateCount());
var1.setCurrentUserCount(var4.getCurrentCount());
}
var1.addFailedData(var4.getRoleType(), (FailedData[])var4.getFailedData().toArray(new FailedData[0]));
var1.addOtherSourceRole(var4.getRoleType(), (String[])var4.getDiffSourceData().toArray(new String[0]));
}
}
return var1;
}
}

132
src/main/java/com/fr/plugin/user/tuomin/controller/UserTMController.java

@ -0,0 +1,132 @@
package com.fr.plugin.user.tuomin.controller;
import com.fr.config.Configuration;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
import com.fr.decision.config.Encryption;
import com.fr.decision.config.EncryptionConfig;
import com.fr.decision.config.SystemConfig;
import com.fr.decision.config.UserDataSetConfig;
import com.fr.decision.sync.SyncDetail;
import com.fr.decision.sync.SyncUserStatus;
import com.fr.decision.sync.result.SyncResultData;
import com.fr.decision.webservice.Response;
import com.fr.decision.webservice.annotation.DecisionControllerLog;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.decision.webservice.annotation.VisitRefer;
import com.fr.decision.webservice.bean.user.UserDataSetBean;
import com.fr.decision.webservice.bean.user.UserImportOperation;
import com.fr.decision.webservice.exception.user.EncryptChangeUserNotCleanupException;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.general.ComparatorUtils;
import com.fr.intelligence.IntelligenceRuntimeException;
import com.fr.log.FineLoggerFactory;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.*;
import com.fr.transaction.Configurations;
import com.fr.transaction.Worker;
import com.fr.transaction.WorkerAdaptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@EnableMetrics
@Controller
@LoginStatusChecker(
required = false
)
@RequestMapping({"/{version}"})
public class UserTMController {
@RequestMapping(
value = {"/dataset/newUsers"},
method = {RequestMethod.POST}
)
@VisitRefer(
refer = {"decision-management-user-add"}
)
@ResponseBody
public Response importUser(HttpServletRequest req, HttpServletResponse res, @PathVariable("version") String version, @RequestBody UserDataSetBean userDataSet, @RequestParam(value = "importOp",required = false,defaultValue = "0") int importOp) throws Exception {
String currentUser = LoginService.getInstance().getUserNameFromRequest(req);
FineLoggerFactory.getLogger().info("导入数据......");
SyncUserStatus status = importUsers(currentUser, userDataSet, UserImportOperation.parse(importOp));
if(status.getResultData().getSuccessUserCount() == -100){
return Response.error("500","导入失败,用户密码不满足密码强度");
}
else{
return Response.ok(status);
}
}
public SyncUserStatus importUsers(String currentUserName, UserDataSetBean userDataSetBean, UserImportOperation userImportOperation) throws Exception {
Encryption oldEncryption = EncryptionConfig.getInstance().getEncryption(ManualOperationType.KEY);
int oldEmbedEncryption = oldEncryption.getEncryption();
final int newEmbedEncryption = userDataSetBean.getEncryption();
final String newEmbedCustomEncrypt = userDataSetBean.getCustomEncrypt();
boolean encryptionChanged = !ComparatorUtils.equals(oldEmbedEncryption, newEmbedEncryption) || !ComparatorUtils.equals(oldEncryption.getCustomEncrypt(), userDataSetBean.getCustomEncrypt());
userDataSetBean.setTurnOn(false);
if (userImportOperation != UserImportOperation.CLEAR && encryptionChanged) {
throw new EncryptChangeUserNotCleanupException();
} else {
if (userImportOperation == UserImportOperation.CLEAR) {
UserService.getInstance().deleteAllCommonUsers((String)UserService.getInstance().getAdminUserNameList().get(0));
AuthorityContext.getInstance().getCustomRoleController().remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("creationType", ManualOperationType.KEY)).addRestriction(RestrictionFactory.neq("id", "super-user-custom-role")));
AuthorityContext.getInstance().getDepartmentController().remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("creationType", ManualOperationType.KEY)));
AuthorityContext.getInstance().getPostController().remove(QueryFactory.create().addRestriction(RestrictionFactory.eq("creationType", ManualOperationType.KEY)));
}
Configurations.update(new Worker() {
public void run() {
Encryption embedEncrypt = new Encryption();
embedEncrypt.setEncryption(newEmbedEncryption);
embedEncrypt.setCustomEncrypt(newEmbedCustomEncrypt);
EncryptionConfig.getInstance().removeEncryption(ManualOperationType.KEY);
EncryptionConfig.getInstance().setEncryption(ManualOperationType.KEY, embedEncrypt);
}
public Class<? extends Configuration>[] targets() {
return new Class[]{UserDataSetConfig.class, EncryptionConfig.class};
}
});
SyncUserStatus var10;
try {
SyncDetail detail = SyncDetail.parse(userDataSetBean);
SyncResultData syncResultData = AuthorityContext.getInstance().doPersonnelWork(TableDataSyncAction.create(detail));
SyncUserStatus var11 = (new SyncUserStatus()).resultData(syncResultData);
return var11;
} catch (IntelligenceRuntimeException var15) {
var10 = (new SyncUserStatus()).status(SyncUserStatus.Status.FAIL).error(var15);
} finally {
if (userImportOperation == UserImportOperation.CLEAR && encryptionChanged) {
class NamelessClass_1 extends WorkerAdaptor {
NamelessClass_1(Class x0, Class... x1) {
super(x0, x1);
}
public void run() {
SystemConfig.getInstance().setServerInitStatus("fail");
}
}
Configurations.update(new NamelessClass_1(SystemConfig.class, new Class[0]));
}
}
return var10;
}
}
}

14
src/main/java/com/fr/plugin/user/tuomin/controller/UserTMControllerProvider.java

@ -0,0 +1,14 @@
package com.fr.plugin.user.tuomin.controller;
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider;
public class UserTMControllerProvider extends AbstractControllerRegisterProvider {
@Override
public Class<?>[] getControllers() {
return new Class[]{
UserTMController.class
};
}
}

33
src/main/java/com/fr/plugin/user/tuomin/webresource/UserTMWebResourceProvider.java

@ -0,0 +1,33 @@
package com.fr.plugin.user.tuomin.webresource;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.intelli.record.Focus;
import com.fr.record.analyzer.EnableMetrics;
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.ParserType;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class UserTMWebResourceProvider extends AbstractWebResourceProvider{
@Override
public Atom attach() {
return MainComponent.KEY;
}
public Atom[] clients() {
return new Atom[]{
new Component() {
@Override
public ScriptPath script(RequestClient client) {
return ScriptPath.build( "com/fr/plugin/user/tuomin/userinfo.js", ParserType.DYNAMIC );
}
}
};
}
}

1686
src/main/resources/com/fr/plugin/user/tuomin/userinfo.js

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save