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.
86 lines
3.4 KiB
86 lines
3.4 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.decision.webservice.v10.user.UserService;
|
||
|
import com.fr.plugin.SYNCConfig;
|
||
|
import com.fr.plugin.utils.BamboocloudUtils;
|
||
|
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.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import java.util.UUID;
|
||
|
|
||
|
public class ALLUserSync2Handler extends BaseHttpHandler {
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/userCreate";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest request, HttpServletResponse res) throws Exception {
|
||
|
String bodyparam = BamboocloudUtils.getRequestBody(request);
|
||
|
SYNCConfig syncConfig = SYNCConfig.getInstance();
|
||
|
bodyparam = BamboocloudUtils.getPlaintext(bodyparam, syncConfig.getSyncSecret(), "AES");
|
||
|
LogKit.info("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 password = (String) reqmap.get("bimRemotePwd");
|
||
|
BamboocloudUtils.checkUsernamePassword(username, password);
|
||
|
String uid = UUID.randomUUID().toString();
|
||
|
UserController userController = AuthorityContext.getInstance().getUserController();
|
||
|
UserService userService = UserService.getInstance();
|
||
|
String loginName = (String) reqmap.get("loginName");
|
||
|
PasswordValidator passwordValidator = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator();
|
||
|
User user = userService.getUserByUserName(loginName);
|
||
|
boolean add = false;
|
||
|
if (user == null) {
|
||
|
add = true;
|
||
|
user = new User();
|
||
|
user.setId(uid);
|
||
|
}
|
||
|
user.setUserName(loginName);
|
||
|
user.setRealName((String) reqmap.get("fullName"));
|
||
|
user.setEnable(true);
|
||
|
user.setPassword(passwordValidator.encode(username, password));
|
||
|
if (add) {
|
||
|
userController.add(user);
|
||
|
} else {
|
||
|
userController.update(user);
|
||
|
}
|
||
|
Map<String, Object> schema = new HashMap<String, Object>();
|
||
|
schema.put("uid", uid);
|
||
|
schema.put("bimRequestId", reqmap.get("bimRequestId"));
|
||
|
schema.put("resultCode", "0");
|
||
|
schema.put("message", "success");
|
||
|
|
||
|
String mapJson = JSON.toJSONString(schema);
|
||
|
mapJson = BamboocloudFacade.encrypt(mapJson, syncConfig.getSyncSecret(), "AES");
|
||
|
WebUtils.printAsString(res, mapJson);
|
||
|
// }
|
||
|
}
|
||
|
}
|