You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
4.2 KiB
102 lines
4.2 KiB
3 years ago
|
package com.fr.plugin.http.handler;
|
||
|
|
||
|
import com.alibaba.fastjson.JSON;
|
||
|
import com.banboocloud.Codec.BamboocloudFacade;
|
||
|
import com.fanruan.api.log.LogKit;
|
||
|
import com.fr.decision.authority.AuthorityContext;
|
||
|
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
|
||
|
import com.fr.decision.authority.controller.UserController;
|
||
|
import com.fr.decision.authority.data.User;
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.decision.privilege.encrpt.PasswordValidator;
|
||
|
import com.fr.decision.webservice.utils.UserSourceFactory;
|
||
|
import com.fr.plugin.SYNCConfig;
|
||
|
import com.fr.plugin.utils.BamboocloudUtils;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.stable.query.QueryFactory;
|
||
|
import com.fr.stable.query.condition.QueryCondition;
|
||
|
import com.fr.stable.query.restriction.RestrictionFactory;
|
||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.io.PrintWriter;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
public class ALLUserUpdateHandler extends BaseHttpHandler {
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/userUpdate";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
|
||
|
String bodyparam = BamboocloudUtils.getRequestBody(req);
|
||
|
System.out.println("first--param-->" + bodyparam);
|
||
|
SYNCConfig syncConfig = SYNCConfig.getInstance();
|
||
|
|
||
|
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
|
||
|
LogKit.info("xml--param-->" + bodyparam);
|
||
|
// bodyparam = XmlUtils.xmlToJson(bodyparam);
|
||
|
// System.out.println("json--param-->" + bodyparam);
|
||
|
Map<String, Object> reqmap = (Map<String, Object>) JSON.parse(bodyparam);
|
||
|
|
||
|
// if (BamboocloudUtils.verify(reqmap, "MD5").booleanValue()) {
|
||
|
String username = (String) reqmap.get("bimRemoteUser");
|
||
|
String bimRemotePwd = (String) reqmap.get("bimRemotePwd");
|
||
|
String uid = (String) reqmap.get("bimUid");
|
||
|
BamboocloudUtils.checkUsernamePassword(username, bimRemotePwd);
|
||
|
String password = (String) reqmap.get("password");
|
||
|
UserController userController = AuthorityContext.getInstance().getUserController();
|
||
|
User user = userController.findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", uid)));
|
||
|
if (user == null) {
|
||
|
LogKit.error("当前用户不存在:{}", uid);
|
||
|
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "500", "当前用户不存在" + uid));
|
||
|
LogKit.info("response---json-->" + mapJson);
|
||
|
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
|
||
|
WebUtils.printAsString(res, mapJson);
|
||
|
return;
|
||
|
}
|
||
|
PasswordValidator passwordValidator = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator();
|
||
|
String fullName = (String) reqmap.get("fullName");
|
||
|
if (StringUtils.isNotEmpty(fullName)) {
|
||
|
user.setRealName(fullName);
|
||
|
}
|
||
|
Object enable = reqmap.get("__ENABLE__");
|
||
|
if (enable != null) {
|
||
|
String en = enable.toString();
|
||
|
user.setEnable(StringUtils.equals(en, "true"));
|
||
|
}
|
||
|
if (!StringUtils.isEmpty(password)) {
|
||
|
user.setPassword(passwordValidator.encode(username, password));
|
||
|
}
|
||
|
userController.update(user);
|
||
|
String mapJson = JSON.toJSONString(createJson((String) reqmap.get("bimRequestId"), "0", "success"));
|
||
|
LogKit.info("response---json-->" + mapJson);
|
||
|
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
|
||
|
WebUtils.printAsString(res, mapJson);
|
||
|
// }
|
||
|
|
||
|
}
|
||
|
|
||
|
private Map createJson(String bimRequestId, String code, String msg) {
|
||
|
Map<String, Object> schema = new HashMap<String, Object>();
|
||
|
schema.put("bimRequestId", bimRequestId);
|
||
|
schema.put("resultCode", code);
|
||
|
schema.put("message", msg);
|
||
|
return schema;
|
||
|
}
|
||
|
}
|